[rkward/work/new_completion_to_console] rkward/settings: Add completion settings to console settings page
Thomas Friedrichsmeier
null at kde.org
Sun Apr 19 13:45:18 BST 2020
Git commit f7a348ebe5ba60c870913d37277b59f3cbdaab37 by Thomas Friedrichsmeier.
Committed on 19/04/2020 at 12:45.
Pushed by tfry into branch 'work/new_completion_to_console'.
Add completion settings to console settings page
M +98 -112 rkward/settings/rksettingsmodulecommandeditor.cpp
M +21 -0 rkward/settings/rksettingsmodulecommandeditor.h
M +6 -1 rkward/settings/rksettingsmoduleconsole.cpp
M +5 -1 rkward/settings/rksettingsmoduleconsole.h
https://commits.kde.org/rkward/f7a348ebe5ba60c870913d37277b59f3cbdaab37
diff --git a/rkward/settings/rksettingsmodulecommandeditor.cpp b/rkward/settings/rksettingsmodulecommandeditor.cpp
index 1d03eab4..8f091c72 100644
--- a/rkward/settings/rksettingsmodulecommandeditor.cpp
+++ b/rkward/settings/rksettingsmodulecommandeditor.cpp
@@ -43,121 +43,105 @@ int RKSettingsModuleCommandEditor::autosave_interval;
int RKSettingsModuleCommandEditor::num_recent_files;
QString RKSettingsModuleCommandEditor::script_file_filter;
-class RKCodeCompletionSettingsWidget : public RKSettingsModuleWidget {
-public:
- RKCodeCompletionSettingsWidget(QWidget *parent, RKSettingsModule *module, RKCodeCompletionSettings *settings) : RKSettingsModuleWidget(parent, module), settings(settings) {
- RK_TRACE (SETTINGS);
- QVBoxLayout* main_vbox = new QVBoxLayout (this);
- main_vbox->setContentsMargins(0,0,0,0);
-
- QGroupBox* group = new QGroupBox (i18n ("Code Completion / Code Hints"), this);
- QVBoxLayout* box_layout = new QVBoxLayout (group);
-
- QGridLayout *g_layout = new QGridLayout ();
- box_layout->addLayout (g_layout);
- makeCompletionTypeBoxes (QStringList () << i18n ("Function call tip") << i18n ("Function argument completion") << i18n ("Object name completion") << i18n ("Filename completion") << i18n ("Auto word completion"), g_layout);
-
- auto_completion_enabled_box = new QGroupBox (i18n ("Start code completions/hints, automatically"), group);
- auto_completion_enabled_box->setCheckable (true);
- auto_completion_enabled_box->setChecked (settings->auto_completion_enabled);
- connect (auto_completion_enabled_box, &QGroupBox::toggled, this, &RKCodeCompletionSettingsWidget::change);
- box_layout->addWidget (auto_completion_enabled_box);
-
- QFormLayout* form_layout = new QFormLayout (auto_completion_enabled_box);
- auto_completion_min_chars_box = new RKSpinBox (auto_completion_enabled_box);
- auto_completion_min_chars_box->setIntMode (1, INT_MAX, settings->auto_completion_min_chars);
- connect (auto_completion_min_chars_box, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &RKCodeCompletionSettingsWidget::change);
- form_layout->addRow ("Minimum number of characters", auto_completion_min_chars_box);
-
- auto_completion_timeout_box = new RKSpinBox (auto_completion_enabled_box);
- auto_completion_timeout_box->setIntMode (0, INT_MAX, settings->auto_completion_timeout);
- connect (auto_completion_timeout_box, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &RKCodeCompletionSettingsWidget::change);
- form_layout->addRow (i18n ("Timeout (milliseconds)"), auto_completion_timeout_box);
-
- auto_completion_cursor_activated_box = new QCheckBox (auto_completion_enabled_box);
- auto_completion_cursor_activated_box->setChecked (settings->auto_completion_cursor_activated);
- connect (auto_completion_cursor_activated_box, &QCheckBox::stateChanged, this, &RKCodeCompletionSettingsWidget::change);
- form_layout->addRow (i18n ("(Attempt to) start completion whenever the cursor position changes"), auto_completion_cursor_activated_box);
-
- form_layout = new QFormLayout ();
- box_layout->addLayout (form_layout);
-
- cursor_navigates_completions_box = new QCheckBox (i18n ("Up/down cursor keys navigate completion items"));
- cursor_navigates_completions_box->setChecked (settings->cursor_navigates_completions);
- RKCommonFunctions::setTips (i18n ("Should the up / down cursor keys be used to navigate among the completion items, while code completion is active? If this option is unchecked, Alt+up/down will navigate completion items, while up / down will behave as if no completion was active."), cursor_navigates_completions_box);
- connect (cursor_navigates_completions_box, &QCheckBox::stateChanged, this, &RKCodeCompletionSettingsWidget::change);
- form_layout->addRow (cursor_navigates_completions_box);
-
- completion_list_member_operator_box = new QComboBox (group);
- completion_list_member_operator_box->addItem (i18n ("'$'-operator (list$member)"));
- completion_list_member_operator_box->addItem (i18n ("'[['-operator (list[[\"member\"]])"));
- completion_list_member_operator_box->setCurrentIndex ((settings->completion_options & RObject::DollarExpansion) ? 0 : 1);
- connect (completion_list_member_operator_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &RKCodeCompletionSettingsWidget::change);
- form_layout->addRow (i18nc ("Note: list() and data.frame() are programming terms in R, and should not be translated, here", "Operator for access to members of list() and data.frame() objects"), completion_list_member_operator_box);
-
- completion_slot_operator_box = new QComboBox (group);
- completion_slot_operator_box->addItem (i18n ("'@'-operator (object at smember)"));
- completion_slot_operator_box->addItem (i18n ("'slot()'-function (slot(object, member))"));
- completion_slot_operator_box->setCurrentIndex ((settings->completion_options & RObject::ExplicitSlotsExpansion) ? 1 : 0);
- connect (completion_slot_operator_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &RKCodeCompletionSettingsWidget::change);
- form_layout->addRow (i18nc ("Note: S4-slot() is a programming term in R, and should not be translated, here", "Operator for access to S4-slot()s"), completion_slot_operator_box);
-
- completion_object_qualification_box = new QComboBox (group);
- completion_object_qualification_box->addItem (i18n ("For masked objects, only"));
- completion_object_qualification_box->addItem (i18n ("For objects outside of <i>.GlobalEnv</i>, only"));
- completion_object_qualification_box->addItem (i18n ("Always"));
- if (settings->completion_options & (RObject::IncludeEnvirIfNotGlobalEnv)) {
- if (settings->completion_options & (RObject::IncludeEnvirIfNotGlobalEnv)) completion_object_qualification_box->setCurrentIndex (2);
- else completion_object_qualification_box->setCurrentIndex (1);
- }
- connect (completion_object_qualification_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &RKCodeCompletionSettingsWidget::change);
- form_layout->addRow (i18n ("Include environment for objects on the search path:"), completion_object_qualification_box);
-
- main_vbox->addWidget(group);
+RKCodeCompletionSettingsWidget::RKCodeCompletionSettingsWidget(QWidget *parent, RKSettingsModule *module, RKCodeCompletionSettings *settings) : RKSettingsModuleWidget(parent, module), settings(settings) {
+ RK_TRACE (SETTINGS);
+ QVBoxLayout* main_vbox = new QVBoxLayout (this);
+ main_vbox->setContentsMargins(0,0,0,0);
+
+ QGroupBox* group = new QGroupBox (i18n ("Code Completion / Code Hints"), this);
+ QVBoxLayout* box_layout = new QVBoxLayout (group);
+
+ QGridLayout *g_layout = new QGridLayout ();
+ box_layout->addLayout (g_layout);
+ makeCompletionTypeBoxes (QStringList () << i18n ("Function call tip") << i18n ("Function argument completion") << i18n ("Object name completion") << i18n ("Filename completion") << i18n ("Auto word completion"), g_layout);
+
+ auto_completion_enabled_box = new QGroupBox (i18n ("Start code completions/hints, automatically"), group);
+ auto_completion_enabled_box->setCheckable (true);
+ auto_completion_enabled_box->setChecked (settings->auto_completion_enabled);
+ connect (auto_completion_enabled_box, &QGroupBox::toggled, this, &RKCodeCompletionSettingsWidget::change);
+ box_layout->addWidget (auto_completion_enabled_box);
+
+ QFormLayout* form_layout = new QFormLayout (auto_completion_enabled_box);
+ auto_completion_min_chars_box = new RKSpinBox (auto_completion_enabled_box);
+ auto_completion_min_chars_box->setIntMode (1, INT_MAX, settings->auto_completion_min_chars);
+ connect (auto_completion_min_chars_box, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &RKCodeCompletionSettingsWidget::change);
+ form_layout->addRow ("Minimum number of characters", auto_completion_min_chars_box);
+
+ auto_completion_timeout_box = new RKSpinBox (auto_completion_enabled_box);
+ auto_completion_timeout_box->setIntMode (0, INT_MAX, settings->auto_completion_timeout);
+ connect (auto_completion_timeout_box, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &RKCodeCompletionSettingsWidget::change);
+ form_layout->addRow (i18n ("Timeout (milliseconds)"), auto_completion_timeout_box);
+
+ auto_completion_cursor_activated_box = new QCheckBox (auto_completion_enabled_box);
+ auto_completion_cursor_activated_box->setChecked (settings->auto_completion_cursor_activated);
+ connect (auto_completion_cursor_activated_box, &QCheckBox::stateChanged, this, &RKCodeCompletionSettingsWidget::change);
+ form_layout->addRow (i18n ("(Attempt to) start completion whenever the cursor position changes"), auto_completion_cursor_activated_box);
+
+ form_layout = new QFormLayout ();
+ box_layout->addLayout (form_layout);
+
+ cursor_navigates_completions_box = new QCheckBox (i18n ("Up/down cursor keys navigate completion items"));
+ cursor_navigates_completions_box->setChecked (settings->cursor_navigates_completions);
+ RKCommonFunctions::setTips (i18n ("Should the up / down cursor keys be used to navigate among the completion items, while code completion is active? If this option is unchecked, Alt+up/down will navigate completion items, while up / down will behave as if no completion was active."), cursor_navigates_completions_box);
+ connect (cursor_navigates_completions_box, &QCheckBox::stateChanged, this, &RKCodeCompletionSettingsWidget::change);
+ form_layout->addRow (cursor_navigates_completions_box);
+
+ completion_list_member_operator_box = new QComboBox (group);
+ completion_list_member_operator_box->addItem (i18n ("'$'-operator (list$member)"));
+ completion_list_member_operator_box->addItem (i18n ("'[['-operator (list[[\"member\"]])"));
+ completion_list_member_operator_box->setCurrentIndex ((settings->completion_options & RObject::DollarExpansion) ? 0 : 1);
+ connect (completion_list_member_operator_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &RKCodeCompletionSettingsWidget::change);
+ form_layout->addRow (i18nc ("Note: list() and data.frame() are programming terms in R, and should not be translated, here", "Operator for access to members of list() and data.frame() objects"), completion_list_member_operator_box);
+
+ completion_slot_operator_box = new QComboBox (group);
+ completion_slot_operator_box->addItem (i18n ("'@'-operator (object at smember)"));
+ completion_slot_operator_box->addItem (i18n ("'slot()'-function (slot(object, member))"));
+ completion_slot_operator_box->setCurrentIndex ((settings->completion_options & RObject::ExplicitSlotsExpansion) ? 1 : 0);
+ connect (completion_slot_operator_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &RKCodeCompletionSettingsWidget::change);
+ form_layout->addRow (i18nc ("Note: S4-slot() is a programming term in R, and should not be translated, here", "Operator for access to S4-slot()s"), completion_slot_operator_box);
+
+ completion_object_qualification_box = new QComboBox (group);
+ completion_object_qualification_box->addItem (i18n ("For masked objects, only"));
+ completion_object_qualification_box->addItem (i18n ("For objects outside of <i>.GlobalEnv</i>, only"));
+ completion_object_qualification_box->addItem (i18n ("Always"));
+ if (settings->completion_options & (RObject::IncludeEnvirIfNotGlobalEnv)) {
+ if (settings->completion_options & (RObject::IncludeEnvirIfNotGlobalEnv)) completion_object_qualification_box->setCurrentIndex (2);
+ else completion_object_qualification_box->setCurrentIndex (1);
}
+ connect (completion_object_qualification_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &RKCodeCompletionSettingsWidget::change);
+ form_layout->addRow (i18n ("Include environment for objects on the search path:"), completion_object_qualification_box);
+
+ main_vbox->addWidget(group);
+}
- ~RKCodeCompletionSettingsWidget() {};
- void applyChanges() override {
- settings->auto_completion_enabled = auto_completion_enabled_box->isChecked ();
- settings->auto_completion_min_chars = auto_completion_min_chars_box->intValue ();
- settings->auto_completion_timeout = auto_completion_timeout_box->intValue ();
- settings->auto_completion_cursor_activated = auto_completion_cursor_activated_box->isChecked ();
- for (int i = 0; i < RKCodeCompletionSettings::N_COMPLETION_CATEGORIES; ++i) {
- settings->completion_type_enabled[i] = completion_type_enabled_box[i]->isChecked ();
- }
- settings->cursor_navigates_completions = cursor_navigates_completions_box->isChecked ();
-
- settings->completion_options = 0;
- if (completion_list_member_operator_box->currentIndex () == 0) settings->completion_options += RObject::DollarExpansion;
- if (completion_slot_operator_box->currentIndex () == 1) settings->completion_options += RObject::ExplicitSlotsExpansion;
- if (completion_object_qualification_box->currentIndex () == 2) settings->completion_options += RObject::IncludeEnvirForGlobalEnv | RObject::IncludeEnvirIfNotGlobalEnv;
- else if (completion_object_qualification_box->currentIndex () == 1) settings->completion_options += RObject::IncludeEnvirIfNotGlobalEnv;
- else settings->completion_options += RObject::IncludeEnvirIfMasked;
+void RKCodeCompletionSettingsWidget::applyChanges() {
+ settings->auto_completion_enabled = auto_completion_enabled_box->isChecked ();
+ settings->auto_completion_min_chars = auto_completion_min_chars_box->intValue ();
+ settings->auto_completion_timeout = auto_completion_timeout_box->intValue ();
+ settings->auto_completion_cursor_activated = auto_completion_cursor_activated_box->isChecked ();
+ for (int i = 0; i < RKCodeCompletionSettings::N_COMPLETION_CATEGORIES; ++i) {
+ settings->completion_type_enabled[i] = completion_type_enabled_box[i]->isChecked ();
}
-private:
- RKSpinBox* auto_completion_min_chars_box;
- RKSpinBox* auto_completion_timeout_box;
- QGroupBox* auto_completion_enabled_box;
- QCheckBox* auto_completion_cursor_activated_box;
- QCheckBox* completion_type_enabled_box[RKCodeCompletionSettings::N_COMPLETION_CATEGORIES];
- QCheckBox* cursor_navigates_completions_box;
- QComboBox* completion_list_member_operator_box;
- QComboBox* completion_slot_operator_box;
- QComboBox* completion_object_qualification_box;
-
- RKCodeCompletionSettings *settings;
-
- void makeCompletionTypeBoxes (const QStringList& labels, QGridLayout* layout) {
- RK_ASSERT (labels.count () == RKCodeCompletionSettings::N_COMPLETION_CATEGORIES);
- for (int i = 0; i < RKCodeCompletionSettings::N_COMPLETION_CATEGORIES; ++i) {
- QCheckBox *box = new QCheckBox(labels[i]);
- box->setChecked (settings->completion_type_enabled[i]);
- completion_type_enabled_box[i] = box;
- layout->addWidget (completion_type_enabled_box[i], i / 2, i % 2);
- connect (box, &QCheckBox::stateChanged, this, &RKCodeCompletionSettingsWidget::change);
- }
+ settings->cursor_navigates_completions = cursor_navigates_completions_box->isChecked ();
+
+ settings->completion_options = 0;
+ if (completion_list_member_operator_box->currentIndex () == 0) settings->completion_options += RObject::DollarExpansion;
+ if (completion_slot_operator_box->currentIndex () == 1) settings->completion_options += RObject::ExplicitSlotsExpansion;
+ if (completion_object_qualification_box->currentIndex () == 2) settings->completion_options += RObject::IncludeEnvirForGlobalEnv | RObject::IncludeEnvirIfNotGlobalEnv;
+ else if (completion_object_qualification_box->currentIndex () == 1) settings->completion_options += RObject::IncludeEnvirIfNotGlobalEnv;
+ else settings->completion_options += RObject::IncludeEnvirIfMasked;
+}
+
+void RKCodeCompletionSettingsWidget::makeCompletionTypeBoxes (const QStringList& labels, QGridLayout* layout) {
+ RK_ASSERT (labels.count () == RKCodeCompletionSettings::N_COMPLETION_CATEGORIES);
+ for (int i = 0; i < RKCodeCompletionSettings::N_COMPLETION_CATEGORIES; ++i) {
+ QCheckBox *box = new QCheckBox(labels[i]);
+ box->setChecked (settings->completion_type_enabled[i]);
+ completion_type_enabled_box[i] = box;
+ layout->addWidget (completion_type_enabled_box[i], i / 2, i % 2);
+ connect (box, &QCheckBox::stateChanged, this, &RKCodeCompletionSettingsWidget::change);
}
-};
+}
RKSettingsModuleCommandEditor::RKSettingsModuleCommandEditor (RKSettings *gui, QWidget *parent) : RKSettingsModule (gui, parent) {
RK_TRACE (SETTINGS);
@@ -166,7 +150,7 @@ RKSettingsModuleCommandEditor::RKSettingsModuleCommandEditor (RKSettings *gui, Q
main_vbox->addWidget (RKCommonFunctions::wordWrappedLabel (i18n ("Settings marked with (*) do not take effect until you restart RKWard")));
main_vbox->addSpacing (2 * RKGlobals::spacingHint ());
- main_vbox->addWidget (new RKCodeCompletionSettingsWidget (this, this, &completion_settings));
+ main_vbox->addWidget (completion_settings_widget = new RKCodeCompletionSettingsWidget (this, this, &completion_settings));
main_vbox->addSpacing (2 * RKGlobals::spacingHint ());
@@ -226,6 +210,8 @@ QString RKSettingsModuleCommandEditor::caption () {
void RKSettingsModuleCommandEditor::applyChanges () {
RK_TRACE (SETTINGS);
+ completion_settings_widget->applyChanges ();
+
autosave_enabled = autosave_enabled_box->isChecked ();
autosave_keep = autosave_keep_box->isChecked ();
autosave_interval = autosave_interval_box->intValue ();
diff --git a/rkward/settings/rksettingsmodulecommandeditor.h b/rkward/settings/rksettingsmodulecommandeditor.h
index 57f7148a..e5be1c5e 100644
--- a/rkward/settings/rksettingsmodulecommandeditor.h
+++ b/rkward/settings/rksettingsmodulecommandeditor.h
@@ -64,6 +64,27 @@ friend class RKCodeCompletionSettingsWidget;
int completion_options;
};
+class RKCodeCompletionSettingsWidget : public RKSettingsModuleWidget {
+public:
+ RKCodeCompletionSettingsWidget(QWidget *parent, RKSettingsModule *module, RKCodeCompletionSettings *settings);
+ ~RKCodeCompletionSettingsWidget() {};
+ void applyChanges() override;
+private:
+ void makeCompletionTypeBoxes (const QStringList& labels, QGridLayout* layout);
+
+ RKSpinBox* auto_completion_min_chars_box;
+ RKSpinBox* auto_completion_timeout_box;
+ QGroupBox* auto_completion_enabled_box;
+ QCheckBox* auto_completion_cursor_activated_box;
+ QCheckBox* completion_type_enabled_box[RKCodeCompletionSettings::N_COMPLETION_CATEGORIES];
+ QCheckBox* cursor_navigates_completions_box;
+ QComboBox* completion_list_member_operator_box;
+ QComboBox* completion_slot_operator_box;
+ QComboBox* completion_object_qualification_box;
+
+ RKCodeCompletionSettings *settings;
+};
+
/**
configuration for the Command Editor windows
diff --git a/rkward/settings/rksettingsmoduleconsole.cpp b/rkward/settings/rksettingsmoduleconsole.cpp
index 5abd8460..641d2e49 100644
--- a/rkward/settings/rksettingsmoduleconsole.cpp
+++ b/rkward/settings/rksettingsmoduleconsole.cpp
@@ -2,7 +2,7 @@
rksettingsmoduleconsole - description
-------------------
begin : Sun Oct 16 2005
- copyright : (C) 2005, 2006, 2007, 2009 by Thomas Friedrichsmeier
+ copyright : (C) 2005-2020 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -33,6 +33,8 @@
#include "../debug.h"
// static
+
+RKCodeCompletionSettings RKSettingsModuleConsole::completion_settings;
bool RKSettingsModuleConsole::save_history;
uint RKSettingsModuleConsole::max_history_length;
uint RKSettingsModuleConsole::max_console_lines;
@@ -45,6 +47,8 @@ RKSettingsModuleConsole::RKSettingsModuleConsole (RKSettings *gui, QWidget *pare
QVBoxLayout *vbox = new QVBoxLayout (this);
+ vbox->addWidget (completion_settings_widget = new RKCodeCompletionSettingsWidget (this, this, &completion_settings));
+
save_history_box = new QCheckBox (i18n ("Load/Save command history"), this);
save_history_box->setChecked (save_history);
connect (save_history_box, &QCheckBox::stateChanged, this, &RKSettingsModuleConsole::changedSetting);
@@ -164,6 +168,7 @@ void RKSettingsModuleConsole::saveCommandHistory (const QStringList &list) {
void RKSettingsModuleConsole::applyChanges () {
RK_TRACE (SETTINGS);
+ completion_settings_widget->applyChanges();
save_history = save_history_box->isChecked ();
max_history_length = max_history_length_spinner->value ();
max_console_lines = max_console_lines_spinner->value ();
diff --git a/rkward/settings/rksettingsmoduleconsole.h b/rkward/settings/rksettingsmoduleconsole.h
index e202f47a..5d6fb84d 100644
--- a/rkward/settings/rksettingsmoduleconsole.h
+++ b/rkward/settings/rksettingsmoduleconsole.h
@@ -2,7 +2,7 @@
rksettingsmoduleconsole - description
-------------------
begin : Sun Oct 16 2005
- copyright : (C) 2005-2018 by Thomas Friedrichsmeier
+ copyright : (C) 2005-2020 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -19,6 +19,7 @@
#include "rksettingsmodule.h"
+#include "rksettingsmodulecommandeditor.h" // For RKCodeCompletionSettings
#include <qnamespace.h>
class QCheckBox;
@@ -57,6 +58,7 @@ 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 const RKCodeCompletionSettings* completionSettings() { return &completion_settings; }
static QStringList loadCommandHistory ();
static void saveCommandHistory (const QStringList &list);
@@ -67,6 +69,7 @@ public:
public slots:
void changedSetting (int);
private:
+ static RKCodeCompletionSettings completion_settings;
static bool save_history;
static uint max_history_length;
static uint max_console_lines;
@@ -74,6 +77,7 @@ private:
static PipedCommandsHistoryMode add_piped_commands_to_history;
static bool context_sensitive_history_by_default;
+ RKCodeCompletionSettingsWidget *completion_settings_widget;
QCheckBox *save_history_box;
QCheckBox *reverse_context_mode_box;
QCheckBox *pipe_user_commands_through_console_box;
More information about the rkward-tracker
mailing list