[rkward] rkward: Add option (default) to start auto-completion only, when text changes, not on cursor navigation.

Thomas Friedrichsmeier null at kde.org
Thu Mar 7 09:22:36 GMT 2019


Git commit 053165f910e7d265e0783dfcb0115b572c15242d by Thomas Friedrichsmeier.
Committed on 07/03/2019 at 08:46.
Pushed by tfry into branch 'master'.

Add option (default) to start auto-completion only, when text changes, not on cursor navigation.

M  +9    -2    rkward/settings/rksettingsmodulecommandeditor.cpp
M  +3    -0    rkward/settings/rksettingsmodulecommandeditor.h
M  +3    -1    rkward/windows/rkcodecompletion.cpp

https://commits.kde.org/rkward/053165f910e7d265e0783dfcb0115b572c15242d

diff --git a/rkward/settings/rksettingsmodulecommandeditor.cpp b/rkward/settings/rksettingsmodulecommandeditor.cpp
index 51d1f799..9cf1c93b 100644
--- a/rkward/settings/rksettingsmodulecommandeditor.cpp
+++ b/rkward/settings/rksettingsmodulecommandeditor.cpp
@@ -39,6 +39,7 @@
 int RKSettingsModuleCommandEditor::auto_completion_min_chars;
 int RKSettingsModuleCommandEditor::auto_completion_timeout;
 bool RKSettingsModuleCommandEditor::auto_completion_enabled;
+bool RKSettingsModuleCommandEditor::auto_completion_cursor_activated;
 bool RKSettingsModuleCommandEditor::completion_type_enabled[RKSettingsModuleCommandEditor::N_COMPLETION_CATEGORIES];
 int RKSettingsModuleCommandEditor::completion_options;
 bool RKSettingsModuleCommandEditor::cursor_navigates_completions;
@@ -73,16 +74,19 @@ RKSettingsModuleCommandEditor::RKSettingsModuleCommandEditor (RKSettings *gui, Q
 	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, auto_completion_min_chars);
-	auto_completion_min_chars_box->setEnabled (auto_completion_enabled);
 	connect (auto_completion_min_chars_box, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &RKSettingsModuleCommandEditor::settingChanged);
 	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, auto_completion_timeout);
-	auto_completion_timeout_box->setEnabled (auto_completion_enabled);
 	connect (auto_completion_timeout_box, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &RKSettingsModuleCommandEditor::settingChanged);
 	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 (auto_completion_cursor_activated);
+	connect (auto_completion_cursor_activated_box, &QCheckBox::stateChanged, this, &RKSettingsModuleCommandEditor::settingChanged);
+	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);
 
@@ -191,6 +195,7 @@ void RKSettingsModuleCommandEditor::applyChanges () {
 	auto_completion_enabled = auto_completion_enabled_box->isChecked ();
 	auto_completion_min_chars = auto_completion_min_chars_box->intValue ();
 	auto_completion_timeout = auto_completion_timeout_box->intValue ();
+	auto_completion_cursor_activated = auto_completion_cursor_activated_box->isChecked ();
 	for (int i = 0; i < N_COMPLETION_CATEGORIES; ++i) {
 		completion_type_enabled[i] = completion_type_enabled_box[i]->isChecked ();
 	}
@@ -233,6 +238,7 @@ void RKSettingsModuleCommandEditor::saveSettings (KConfig *config) {
 	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) {
@@ -254,6 +260,7 @@ void RKSettingsModuleCommandEditor::loadSettings (KConfig *config) {
 	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) {
diff --git a/rkward/settings/rksettingsmodulecommandeditor.h b/rkward/settings/rksettingsmodulecommandeditor.h
index d29b685e..78a53930 100644
--- a/rkward/settings/rksettingsmodulecommandeditor.h
+++ b/rkward/settings/rksettingsmodulecommandeditor.h
@@ -59,6 +59,7 @@ public:
 	static int autoCompletionMinChars () { return auto_completion_min_chars; };
 	static int autoCompletionTimeout () { return auto_completion_timeout; };
 	static bool autoCompletionEnabled () { return auto_completion_enabled; };
+	static bool autoCompletionCursorActivated () { return (auto_completion_enabled && auto_completion_cursor_activated); };
 	static bool argHintingEnabled () { return isCompletionEnabled (Arghint); };  // TODO: remove me
 	static int completionOptions () { return completion_options; };
 	static bool isCompletionEnabled (CompletionCategories cat) { return completion_type_enabled[cat]; };
@@ -80,12 +81,14 @@ private:
 	static int auto_completion_min_chars;
 	static int auto_completion_timeout;
 	static bool auto_completion_enabled;
+	static bool auto_completion_cursor_activated;
 	static bool completion_type_enabled[N_COMPLETION_CATEGORIES];
 	static bool cursor_navigates_completions;
 
 	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[N_COMPLETION_CATEGORIES];
 	QCheckBox* cursor_navigates_completions_box;
 
diff --git a/rkward/windows/rkcodecompletion.cpp b/rkward/windows/rkcodecompletion.cpp
index 2354dfe8..b0f1bc53 100644
--- a/rkward/windows/rkcodecompletion.cpp
+++ b/rkward/windows/rkcodecompletion.cpp
@@ -336,8 +336,10 @@ void RKCompletionManager::cursorPositionChanged (KTextEditor::View* view, const
 			QString text = view->document ()->text (KTextEditor::Range (newPosition, cached_position));
 			if (text.contains (QChar ('(')) || text.contains (QChar (')'))) update_call = true;
 		}
+		tryCompletionProxy ();
+	} else if (RKSettingsModuleCommandEditor::autoCompletionCursorActivated ()) {
+		tryCompletionProxy ();
 	}
-	tryCompletionProxy ();
 }
 
 KTextEditor::Range RKCompletionManager::currentCallRange () const {



More information about the rkward-tracker mailing list