[education/rkward] rkward: Bring scrollbar-minimap config directly into (context) menu, rater than settings dialog.
Thomas Friedrichsmeier
null at kde.org
Sat Apr 9 13:36:31 BST 2022
Git commit 4d5c510705e5d06e5380262d8f30196d66a25d88 by Thomas Friedrichsmeier.
Committed on 09/04/2022 at 12:35.
Pushed by tfry into branch 'master'.
Bring scrollbar-minimap config directly into (context) menu, rater than settings dialog.
Also, save dynamic word wrap state.
M +6 -7 rkward/rkconsole.cpp
M +9 -1 rkward/rkconsolepart.rc
M +11 -0 rkward/settings/rksettingsmodule.cpp
M +4 -0 rkward/settings/rksettingsmodule.h
M +2 -2 rkward/settings/rksettingsmoduleconsole.cpp
M +3 -1 rkward/settings/rksettingsmoduleconsole.h
https://invent.kde.org/education/rkward/commit/4d5c510705e5d06e5380262d8f30196d66a25d88
diff --git a/rkward/rkconsole.cpp b/rkward/rkconsole.cpp
index e19a5ccc..ecd5bcc5 100644
--- a/rkward/rkconsole.cpp
+++ b/rkward/rkconsole.cpp
@@ -96,12 +96,6 @@ RKConsole::RKConsole (QWidget *parent, bool tool_window, const char *name) : RKM
view = doc->createView (this);
layout->addWidget (view);
view->setStatusBarEnabled (false);
-
- KTextEditor::ConfigInterface *confint = qobject_cast<KTextEditor::ConfigInterface*> (view);
- RK_ASSERT (view);
- confint->setConfigValue("dynamic-word-wrap", false);
- confint->setConfigValue("scrollbar-minimap", RKSettingsModuleConsole::showMinimap());
-
setFocusProxy (view);
setFocusPolicy (Qt::StrongFocus);
@@ -140,6 +134,12 @@ RKConsole::RKConsole (QWidget *parent, bool tool_window, const char *name) : RKM
setMetaInfo (shortCaption (), QUrl ("rkward://page/rkward_console"), RKSettings::PageConsole);
initializeActivationSignals ();
initializeActions (getPart ()->actionCollection ());
+ KTextEditor::ConfigInterface *confint = qobject_cast<KTextEditor::ConfigInterface*> (view);
+ RK_ASSERT(confint);
+ QAction* action = RKSettingsModuleConsole::showMinimap()->makeAction(this, i18n("Scrollbar minimap"), [confint](bool val) { confint->setConfigValue("scrollbar-minimap", val); });
+ getPart()->actionCollection()->addAction("view_show_minimap", action);
+ action = RKSettingsModuleConsole::wordWrap()->makeAction(this, i18n("Dynamic word wrap"), [confint](bool val) { confint->setConfigValue("dynamic-word-wrap", val); });
+ getPart()->actionCollection()->addAction("view_dynamic_word_wrap", action);
nprefix = "> ";
iprefix = "+ ";
@@ -863,7 +863,6 @@ void RKConsole::initializeActions (KActionCollection *ac) {
addProxyAction ("file_print", i18n ("Print Console"));
addProxyAction ("file_export_html");
- addProxyAction ("view_dynamic_word_wrap");
addProxyAction ("view_inc_font_sizes");
addProxyAction ("view_dec_font_sizes");
diff --git a/rkward/rkconsolepart.rc b/rkward/rkconsolepart.rc
index 51961ed7..9c65f90f 100644
--- a/rkward/rkconsolepart.rc
+++ b/rkward/rkconsolepart.rc
@@ -1,5 +1,5 @@
<!DOCTYPE kpartgui>
-<kpartgui name="rkward_console" version="640">
+<kpartgui name="rkward_console" version="730">
<MenuBar>
<Menu name="file"><text>&File</text>
<Separator />
@@ -29,6 +29,7 @@ but avoids the total derangement of the edit menu over time.
</Menu>
<Menu name="view"><text>&View</text>
<Action name="view_dynamic_word_wrap" />
+ <Action name="view_show_minimap" />
<Action name="view_inc_font_sizes" />
<Action name="view_dec_font_sizes" />
</Menu>
@@ -51,6 +52,13 @@ but avoids the total derangement of the edit menu over time.
<Separator/>
<DefineGroup name="rkconsole_context_merge2"/>
<Separator/>
+ <Menu name="view"><text>&View</text>
+ <Action name="view_dynamic_word_wrap" />
+ <Action name="view_show_minimap" />
+ <Action name="view_inc_font_sizes" />
+ <Action name="view_dec_font_sizes" />
+ </Menu>
+ <Separator/>
<Action name="rkconsole_clear"/>
</Menu>
</kpartgui>
diff --git a/rkward/settings/rksettingsmodule.cpp b/rkward/settings/rksettingsmodule.cpp
index 728e8e92..afd9d4f2 100644
--- a/rkward/settings/rksettingsmodule.cpp
+++ b/rkward/settings/rksettingsmodule.cpp
@@ -48,6 +48,17 @@ QCheckBox* RKConfigValue<bool, bool>::makeCheckbox(const QString& label, RKSetti
return ret;
}
+template<>
+QAction* RKConfigValue<bool, bool>::makeAction(QObject *parent, const QString &label, std::function<void(bool)> handler) {
+ QAction *ret = new QAction(label, parent);
+ ret->setCheckable(true);
+ ret->setChecked(value);
+ QObject::connect(ret, &QAction::triggered, handler);
+ QObject::connect(ret, &QAction::triggered, parent, [this](bool val) { value=val; });
+ handler(value);
+ return ret;
+}
+
template<>
RKSpinBox* RKConfigValue<double, double>::makeSpinBox(double min, double max, RKSettingsModuleWidget* module) {
RKSpinBox* ret = new RKSpinBox();
diff --git a/rkward/settings/rksettingsmodule.h b/rkward/settings/rksettingsmodule.h
index 89370654..521a6058 100644
--- a/rkward/settings/rksettingsmodule.h
+++ b/rkward/settings/rksettingsmodule.h
@@ -22,6 +22,7 @@ class RKSettingsModule;
class RKSettingsModuleWidget;
class RKSetupWizardItem;
class RKSpinBox;
+class QAction;
/** Base class for RKWard config settings.
*
@@ -86,6 +87,9 @@ public:
}
}
RKSpinBox* makeSpinBox(T min, T max, RKSettingsModuleWidget* _module);
+/** For settings to be used outside the settings dialog: Create an appropriate action connected to this value. Call @param handler with the new value, whenever the action is triggered,
+ * and - for convenience - once while creating the action (for intialization) */
+ QAction* makeAction(QObject *parent, const QString &label, std::function<void(T)> handler);
private:
T value;
};
diff --git a/rkward/settings/rksettingsmoduleconsole.cpp b/rkward/settings/rksettingsmoduleconsole.cpp
index b4f7094d..41a6dbad 100644
--- a/rkward/settings/rksettingsmoduleconsole.cpp
+++ b/rkward/settings/rksettingsmoduleconsole.cpp
@@ -33,6 +33,7 @@ RKConfigValue<bool> RKSettingsModuleConsole::pipe_user_commands_through_console
RKConfigValue<RKSettingsModuleConsole::PipedCommandsHistoryMode, int> RKSettingsModuleConsole::add_piped_commands_to_history {"add piped commands to history", RKSettingsModuleConsole::AddSingleLine };
RKConfigValue<bool> RKSettingsModuleConsole::context_sensitive_history_by_default {"command history defaults to context sensitive", false};
RKConfigValue<bool> RKSettingsModuleConsole::show_minimap {"show minimap", true};
+RKConfigValue<bool> RKSettingsModuleConsole::word_wrap {"dynamic word wrap", false};
RKSettingsModuleConsole::RKSettingsModuleConsole (RKSettings *gui, QWidget *parent) : RKSettingsModule (gui, parent) {
RK_TRACE (SETTINGS);
@@ -51,8 +52,6 @@ RKSettingsModuleConsole::RKSettingsModuleConsole (RKSettings *gui, QWidget *pare
auto max_console_lines_spinner = max_console_lines.makeSpinBox(0, 10000, this);
vbox->addWidget (max_console_lines_spinner);
- vbox->addWidget(show_minimap.makeCheckbox(i18n("Show scrollbar mini map (setting takes effect after restart)"), this));
-
vbox->addSpacing (2*RKGlobals::spacingHint ());
auto pipe_user_commands_through_console_box = pipe_user_commands_through_console.makeCheckbox(i18n("Run commands from script editor through console"), this);
@@ -97,6 +96,7 @@ void RKSettingsModuleConsole::syncConfig(KConfig* config, RKConfigBase::ConfigSy
add_piped_commands_to_history.syncConfig(cg, a);
context_sensitive_history_by_default.syncConfig(cg, a);
show_minimap.syncConfig(cg, a);
+ word_wrap.syncConfig(cg, a);
if (a == RKConfigBase::LoadConfig) {
completion_settings.tabkey_invokes_completion = true;
}
diff --git a/rkward/settings/rksettingsmoduleconsole.h b/rkward/settings/rksettingsmoduleconsole.h
index e9fddadd..78e4a5fd 100644
--- a/rkward/settings/rksettingsmoduleconsole.h
+++ b/rkward/settings/rksettingsmoduleconsole.h
@@ -45,7 +45,8 @@ public:
@param current_state the current button state
@returns true, if a the search should be context sensitive, false for a normal search */
static bool shouldDoHistoryContextSensitive (Qt::KeyboardModifiers current_state);
- static bool showMinimap() { return show_minimap; };
+ static RKConfigValue<bool> *showMinimap() { return &show_minimap; };
+ static RKConfigValue<bool> *wordWrap() { return &word_wrap; };
static const RKCodeCompletionSettings* completionSettings() { return &completion_settings; }
static QStringList loadCommandHistory ();
@@ -64,6 +65,7 @@ private:
static RKConfigValue<PipedCommandsHistoryMode, int> add_piped_commands_to_history;
static RKConfigValue<bool> context_sensitive_history_by_default;
static RKConfigValue<bool> show_minimap;
+ static RKConfigValue<bool> word_wrap;
RKCodeCompletionSettingsWidget *completion_settings_widget;
};
More information about the rkward-tracker
mailing list