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 @@ -1,318 +1,304 @@ /*************************************************************************** rksettingsmodulecommandeditor - description ------------------- begin : Tue Oct 23 2007 copyright : (C) 2007-2019 by Thomas Friedrichsmeier email : thomas.friedrichsmeier@kdemail.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "rksettingsmodulecommandeditor.h" #include #include #include #include #include #include #include #include #include #include #include #include "../misc/rkspinbox.h" #include "../misc/rkcommonfunctions.h" #include "../core/robject.h" #include "../rkglobals.h" #include "../debug.h" // static members RKCodeCompletionSettings RKSettingsModuleCommandEditor::completion_settings; bool RKSettingsModuleCommandEditor::autosave_enabled; bool RKSettingsModuleCommandEditor::autosave_keep; 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(&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(&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(&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@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(&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 .GlobalEnv, 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(&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(&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(&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(&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@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(&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 .GlobalEnv, 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(&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); QVBoxLayout* main_vbox = new QVBoxLayout (this); 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 ()); QGroupBox *group = autosave_enabled_box = new QGroupBox (i18n ("Autosaves"), this); autosave_enabled_box->setCheckable (true); autosave_enabled_box->setChecked (autosave_enabled); connect (autosave_enabled_box, &QGroupBox::toggled, this, &RKSettingsModuleCommandEditor::settingChanged); QFormLayout *form_layout = new QFormLayout (group); autosave_interval_box = new RKSpinBox (group); autosave_interval_box->setIntMode (1, INT_MAX, autosave_interval); connect (autosave_interval_box, static_cast(&QSpinBox::valueChanged), this, &RKSettingsModuleCommandEditor::settingChanged); form_layout->addRow (i18n ("Autosave interval (minutes)"), autosave_interval_box); autosave_keep_box = new QCheckBox (i18n ("Keep autosave file after manual save"), group); autosave_keep_box->setChecked (autosave_keep); connect (autosave_keep_box, &QCheckBox::stateChanged, this, &RKSettingsModuleCommandEditor::settingChanged); form_layout->addRow (autosave_keep_box); main_vbox->addWidget (group); main_vbox->addSpacing (2 * RKGlobals::spacingHint ()); group = new QGroupBox (i18n ("Opening script files"), this); form_layout = new QFormLayout (group); num_recent_files_box = new RKSpinBox (group); num_recent_files_box->setIntMode (1, INT_MAX, num_recent_files); RKCommonFunctions::setTips (i18n ("

The number of recent files to remember (in the Open Recent R Script File menu).

") + RKCommonFunctions::noteSettingsTakesEffectAfterRestart (), num_recent_files_box, group); connect (num_recent_files_box, static_cast(&QSpinBox::valueChanged), this, &RKSettingsModuleCommandEditor::settingChanged); form_layout->addRow (i18n ("Number of scripts in recent file lists (*)"), num_recent_files_box); script_file_filter_box = new QLineEdit (group); script_file_filter_box->setText (script_file_filter); RKCommonFunctions::setTips (i18n ("

A list of filters (file name extensions) that should be treated as R script files. Most importantly, files matching one of these filters will always be opened with R syntax highlighting.

Filters are case insensitive.

"), script_file_filter_box); connect (script_file_filter_box, &QLineEdit::textChanged, this, &RKSettingsModuleCommandEditor::settingChanged); form_layout->addRow (i18n ("R script file filters (separated by spaces)"), script_file_filter_box); main_vbox->addWidget (group); main_vbox->addStretch (); } RKSettingsModuleCommandEditor::~RKSettingsModuleCommandEditor () { RK_TRACE (SETTINGS); } void RKSettingsModuleCommandEditor::settingChanged () { RK_TRACE (SETTINGS); change (); } QString RKSettingsModuleCommandEditor::caption () { RK_TRACE (SETTINGS); return (i18n ("Script editor")); } 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 (); num_recent_files = num_recent_files_box->intValue (); script_file_filter = script_file_filter_box->text (); } void RKSettingsModuleCommandEditor::save (KConfig *config) { RK_TRACE (SETTINGS); saveSettings (config); } QString completionTypeToConfigKey (int cat) { if (cat == RKCodeCompletionSettings::Calltip) return "Calltips"; if (cat == RKCodeCompletionSettings::Arghint) return "Argument completion"; if (cat == RKCodeCompletionSettings::Object) return "Object completion"; if (cat == RKCodeCompletionSettings::Filename) return "Filename completion"; if (cat == RKCodeCompletionSettings::AutoWord) return "Auto word completion"; RK_ASSERT(false); return QString (); } void RKCodeCompletionSettings::saveSettings(KConfigGroup& cg) { RK_TRACE (SETTINGS); cg.writeEntry ("Completion enabled", auto_completion_enabled); cg.writeEntry ("Completion min chars", auto_completion_min_chars); cg.writeEntry ("Completion timeout", auto_completion_timeout); cg.writeEntry ("Auto completion on cursor navigation", auto_completion_cursor_activated); cg.writeEntry ("Completion option flags", completion_options); cg.writeEntry ("Cursor navigate completions", cursor_navigates_completions); for (int i = 0; i < N_COMPLETION_CATEGORIES; ++i) { cg.writeEntry (completionTypeToConfigKey (i), completion_type_enabled[i]); } } void RKSettingsModuleCommandEditor::saveSettings (KConfig *config) { RK_TRACE (SETTINGS); KConfigGroup cg = config->group ("Command Editor Windows"); completion_settings.saveSettings(cg); cg.writeEntry ("Autosave enabled", autosave_enabled); cg.writeEntry ("Autosave keep saves", autosave_keep); cg.writeEntry ("Autosave interval", autosave_interval); cg.writeEntry ("Max number of recent files", num_recent_files); cg.writeEntry ("Script file filter", script_file_filter); } void RKCodeCompletionSettings::loadSettings(KConfigGroup& cg) { RK_TRACE (SETTINGS); auto_completion_enabled = cg.readEntry ("Completion enabled", true); auto_completion_min_chars = cg.readEntry ("Completion min chars", 2); auto_completion_timeout = cg.readEntry ("Completion timeout", 250); auto_completion_cursor_activated = cg.readEntry ("Auto completion on cursor navigation", false); completion_options = cg.readEntry ("Completion option flags", (int) RObject::IncludeEnvirIfMasked); cursor_navigates_completions = cg.readEntry ("Cursor navigate completions", false); for (int i = 0; i < N_COMPLETION_CATEGORIES; ++i) { completion_type_enabled[i] = cg.readEntry (completionTypeToConfigKey (i), true); } } void RKSettingsModuleCommandEditor::loadSettings (KConfig *config) { RK_TRACE (SETTINGS); KConfigGroup cg = config->group ("Command Editor Windows"); completion_settings.loadSettings(cg); autosave_enabled = cg.readEntry ("Autosave enabled", true); autosave_keep = cg.readEntry ("Autosave keep saves", false); autosave_interval = cg.readEntry ("Autosave interval", 5); num_recent_files = cg.readEntry ("Max number of recent files", 10); script_file_filter = cg.readEntry ("Script file filter", "*.R *.S *.q *.Rhistory"); } // static bool RKSettingsModuleCommandEditor::matchesScriptFileFilter (const QString &filename) { RK_TRACE (SETTINGS); const QStringList exts = script_file_filter.split (' '); foreach (const QString& ext, exts) { QRegExp reg (ext, Qt::CaseInsensitive, QRegExp::Wildcard); if (reg.exactMatch (filename)) return true; } return false; } 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 @@ -1,116 +1,137 @@ /*************************************************************************** rksettingsmodulecommandeditor - description ------------------- begin : Tue Oct 23 2007 copyright : (C) 2007-2019 by Thomas Friedrichsmeier email : thomas.friedrichsmeier@kdemail.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef RKSETTINGSMODULECOMMANDEDITOR_H #define RKSETTINGSMODULECOMMANDEDITOR_H #include "rksettingsmodule.h" class RKSpinBox; class QCheckBox; class QLineEdit; class QGroupBox; class QComboBox; class QGridLayout; class RKCodeCompletionSettingsWidget; class RKCodeCompletionSettings { public: RKCodeCompletionSettings() {}; ~RKCodeCompletionSettings() {}; void loadSettings(KConfigGroup &config); void saveSettings(KConfigGroup &config); enum CompletionCategories { Calltip = 0, Arghint, Object, Filename, AutoWord, N_COMPLETION_CATEGORIES }; /// min number of character to try code completion int autoMinChars () const { return auto_completion_min_chars; }; int autoTimeout () const { return auto_completion_timeout; }; bool autoEnabled () const { return auto_completion_enabled; }; bool autoCursorActivated () const { return (auto_completion_enabled && auto_completion_cursor_activated); }; bool argHintingEnabled () const { return isEnabled (Arghint); }; // TODO: remove me int options () const { return completion_options; }; bool isEnabled (CompletionCategories cat) const { return completion_type_enabled[cat]; }; bool cursorNavigatesCompletions () const { return cursor_navigates_completions; }; private: friend class RKCodeCompletionSettingsWidget; int auto_completion_min_chars; int auto_completion_timeout; bool auto_completion_enabled; bool auto_completion_cursor_activated; bool completion_type_enabled[N_COMPLETION_CATEGORIES]; bool cursor_navigates_completions; 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 @author Thomas Friedrichsmeier */ class RKSettingsModuleCommandEditor : public RKSettingsModule { Q_OBJECT public: RKSettingsModuleCommandEditor (RKSettings *gui, QWidget *parent); ~RKSettingsModuleCommandEditor (); void applyChanges () override; void save (KConfig *config) override; static void saveSettings (KConfig *config); static void loadSettings (KConfig *config); static void validateSettingsInteractive (QList*) {}; QString caption () override; static const RKCodeCompletionSettings* completionSettings() { return &completion_settings; }; static bool autosaveEnabled () { return autosave_enabled; }; static bool autosaveKeep () { return autosave_keep; }; static int autosaveInterval () { return autosave_interval; }; static QString autosaveSuffix () { return ".rkward_autosave"; }; static int maxNumRecentFiles () { return num_recent_files; }; static QString scriptFileFilter () { return script_file_filter; }; static bool matchesScriptFileFilter (const QString &filename); public slots: void settingChanged (); private: static RKCodeCompletionSettings completion_settings; static bool autosave_enabled; static bool autosave_keep; static int autosave_interval; RKCodeCompletionSettingsWidget *completion_settings_widget; QGroupBox* autosave_enabled_box; QCheckBox* autosave_keep_box; RKSpinBox* autosave_interval_box; RKSpinBox* num_recent_files_box; QLineEdit* script_file_filter_box; static int num_recent_files; static QString script_file_filter; }; #endif 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 @@ -1,186 +1,191 @@ /*************************************************************************** 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@kdemail.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "rksettingsmoduleconsole.h" #include #include #include #include #include #include #include #include #include #include "../rbackend/rcommand.h" #include "../rkglobals.h" #include "../debug.h" // static + +RKCodeCompletionSettings RKSettingsModuleConsole::completion_settings; bool RKSettingsModuleConsole::save_history; uint RKSettingsModuleConsole::max_history_length; uint RKSettingsModuleConsole::max_console_lines; bool RKSettingsModuleConsole::pipe_user_commands_through_console; RKSettingsModuleConsole::PipedCommandsHistoryMode RKSettingsModuleConsole::add_piped_commands_to_history; bool RKSettingsModuleConsole::context_sensitive_history_by_default; RKSettingsModuleConsole::RKSettingsModuleConsole (RKSettings *gui, QWidget *parent) : RKSettingsModule (gui, parent) { RK_TRACE (SETTINGS); 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); vbox->addWidget (save_history_box); vbox->addWidget (new QLabel (i18n ("Maximum length of command history"), this)); max_history_length_spinner = new QSpinBox(this); max_history_length_spinner->setMaximum(10000); max_history_length_spinner->setMinimum(0); max_history_length_spinner->setSingleStep(10); max_history_length_spinner->setValue(max_history_length); max_history_length_spinner->setSpecialValueText (i18n ("Unlimited")); connect (max_history_length_spinner, static_cast(&QSpinBox::valueChanged), this, &RKSettingsModuleConsole::changedSetting); vbox->addWidget (max_history_length_spinner); vbox->addWidget (new QLabel (i18n ("Maximum number of paragraphs/lines to display in the console"), this)); max_console_lines_spinner = new QSpinBox(this); max_console_lines_spinner->setMaximum(10000); max_console_lines_spinner->setMinimum(0); max_console_lines_spinner->setSingleStep(10); max_console_lines_spinner->setValue(max_console_lines); max_console_lines_spinner->setSpecialValueText (i18n ("Unlimited")); connect (max_console_lines_spinner, static_cast(&QSpinBox::valueChanged), this, &RKSettingsModuleConsole::changedSetting); vbox->addWidget (max_console_lines_spinner); vbox->addSpacing (2*RKGlobals::spacingHint ()); pipe_user_commands_through_console_box = new QCheckBox (i18n ("Run commands from script editor through console"), this); pipe_user_commands_through_console_box->setChecked (pipe_user_commands_through_console); connect (pipe_user_commands_through_console_box, &QCheckBox::stateChanged, this, &RKSettingsModuleConsole::changedSetting); vbox->addWidget (pipe_user_commands_through_console_box); vbox->addWidget (new QLabel (i18n ("Also add those commands to console history"), this)); add_piped_commands_to_history_box = new QComboBox (this); add_piped_commands_to_history_box->insertItem ((int) DontAdd, i18n ("Do not add")); add_piped_commands_to_history_box->insertItem ((int) AddSingleLine, i18n ("Add only if single line")); add_piped_commands_to_history_box->insertItem ((int) AlwaysAdd, i18n ("Add all commands")); add_piped_commands_to_history_box->setCurrentIndex ((int) add_piped_commands_to_history); connect (add_piped_commands_to_history_box, static_cast(&QComboBox::currentIndexChanged), this, &RKSettingsModuleConsole::changedSetting); add_piped_commands_to_history_box->setEnabled (pipe_user_commands_through_console_box->isChecked ()); vbox->addWidget (add_piped_commands_to_history_box); vbox->addSpacing (2*RKGlobals::spacingHint ()); reverse_context_mode_box = new QCheckBox (i18n ("Command history is context sensitive by default"), this); connect (reverse_context_mode_box, &QCheckBox::stateChanged, this, &RKSettingsModuleConsole::changedSetting); reverse_context_mode_box->setChecked (context_sensitive_history_by_default); vbox->addWidget (reverse_context_mode_box); vbox->addStretch (); } RKSettingsModuleConsole::~RKSettingsModuleConsole () { RK_TRACE (SETTINGS); } void RKSettingsModuleConsole::changedSetting (int) { RK_TRACE (SETTINGS); change (); add_piped_commands_to_history_box->setEnabled (pipe_user_commands_through_console_box->isChecked ()); } //static bool RKSettingsModuleConsole::shouldDoHistoryContextSensitive (Qt::KeyboardModifiers current_state) { RK_TRACE (SETTINGS); if (current_state & Qt::ShiftModifier) return (!context_sensitive_history_by_default); return context_sensitive_history_by_default; } //static void RKSettingsModuleConsole::saveSettings (KConfig *config) { RK_TRACE (SETTINGS); KConfigGroup cg = config->group ("Console Settings"); cg.writeEntry ("save history", save_history); cg.writeEntry ("max history length", max_history_length); cg.writeEntry ("max console lines", max_console_lines); cg.writeEntry ("pipe user commands through console", pipe_user_commands_through_console); cg.writeEntry ("add piped commands to history", (int) add_piped_commands_to_history); cg.writeEntry ("command history defaults to context sensitive", context_sensitive_history_by_default); } //static void RKSettingsModuleConsole::loadSettings (KConfig *config) { RK_TRACE (SETTINGS); KConfigGroup cg = config->group ("Console Settings"); save_history = cg.readEntry ("save history", true); max_history_length = cg.readEntry ("max history length", 100); max_console_lines = cg.readEntry ("max console lines", 500); pipe_user_commands_through_console = cg.readEntry ("pipe user commands through console", true); add_piped_commands_to_history = (PipedCommandsHistoryMode) cg.readEntry ("add piped commands to history", (int) AddSingleLine); context_sensitive_history_by_default = cg.readEntry ("command history defaults to context sensitive", false); } //static QStringList RKSettingsModuleConsole::loadCommandHistory () { RK_TRACE (SETTINGS); KConfigGroup cg = KSharedConfig::openConfig ()->group ("Console Settings"); return cg.readEntry ("history", QStringList ()); } //static void RKSettingsModuleConsole::saveCommandHistory (const QStringList &list) { RK_TRACE (SETTINGS); KConfigGroup cg = KSharedConfig::openConfig ()->group ("Console Settings"); if (save_history) { cg.writeEntry ("history", list); } cg.sync (); } 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 (); pipe_user_commands_through_console = pipe_user_commands_through_console_box->isChecked (); add_piped_commands_to_history = (PipedCommandsHistoryMode) add_piped_commands_to_history_box->currentIndex (); context_sensitive_history_by_default = reverse_context_mode_box->isChecked (); } void RKSettingsModuleConsole::save (KConfig *config) { RK_TRACE (SETTINGS); saveSettings (config); } QString RKSettingsModuleConsole::caption () { RK_TRACE (SETTINGS); return (i18n ("Console")); } 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 @@ -1,85 +1,89 @@ /*************************************************************************** rksettingsmoduleconsole - description ------------------- begin : Sun Oct 16 2005 - copyright : (C) 2005-2018 by Thomas Friedrichsmeier + copyright : (C) 2005-2020 by Thomas Friedrichsmeier email : thomas.friedrichsmeier@kdemail.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef RKSETTINGSMODULECONSOLE_H #define RKSETTINGSMODULECONSOLE_H #include "rksettingsmodule.h" +#include "rksettingsmodulecommandeditor.h" // For RKCodeCompletionSettings #include class QCheckBox; class QComboBox; class QSpinBox; /** Settings module for the console. Allows you to configure whether to store command history, command history length. Future extensions: color for warnings/errors, etc. @author Thomas Friedrichsmeier */ class RKSettingsModuleConsole : public RKSettingsModule { Q_OBJECT public: RKSettingsModuleConsole (RKSettings *gui, QWidget *parent); ~RKSettingsModuleConsole (); static void saveSettings (KConfig *config); static void loadSettings (KConfig *config); static void validateSettingsInteractive (QList*) {}; void applyChanges () override; void save (KConfig *config) override; static bool saveHistory () { return save_history; }; static uint maxHistoryLength () { return max_history_length; }; static uint maxConsoleLines () { return max_console_lines; }; static bool pipeUserCommandsThroughConsole () { return pipe_user_commands_through_console; }; enum PipedCommandsHistoryMode { DontAdd = 0, AddSingleLine = 1, AlwaysAdd = 2 }; static PipedCommandsHistoryMode addPipedCommandsToHistory () { return add_piped_commands_to_history; }; /** Given the button state, return whether the command history should be navigated context sensitive or insensitive @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); QString caption () override; QUrl helpURL () override { return QUrl ("rkward://page/rkward_console#settings"); }; public slots: void changedSetting (int); private: + static RKCodeCompletionSettings completion_settings; static bool save_history; static uint max_history_length; static uint max_console_lines; static bool pipe_user_commands_through_console; 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; QComboBox *add_piped_commands_to_history_box; QSpinBox *max_history_length_spinner; QSpinBox *max_console_lines_spinner; }; #endif