[rkward/work/new_completion_to_console] /: Add support for invoking completion via tab key

Thomas Friedrichsmeier null at kde.org
Mon Apr 27 21:29:34 BST 2020


Git commit 228447e2319ad35320c6eea67094389107cba40c by Thomas Friedrichsmeier.
Committed on 27/04/2020 at 20:29.
Pushed by tfry into branch 'work/new_completion_to_console'.

Add support for invoking completion via tab key

M  +1    -1    ChangeLog
M  +9    -0    rkward/settings/rksettingsmodulecommandeditor.cpp
M  +11   -8    rkward/settings/rksettingsmodulecommandeditor.h
M  +10   -2    rkward/windows/rkcodecompletion.cpp
M  +1    -1    rkward/windows/rkcodecompletion.h

https://commits.kde.org/rkward/228447e2319ad35320c6eea67094389107cba40c

diff --git a/ChangeLog b/ChangeLog
index 74985e2f..cff680ca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,7 +6,7 @@
     - Support pdf?
 - <text> elements in plugins may now also contain clickable links, including rkward://-scheme links
 * TODO: Bring new code hinting features to the console window!
-  - Tab key (+option)
+  - Tab key-option should default to on in console, but not script editor
   - Clean up unused code
 - On unix-systems, RKWard can now be run without installation
   - TODO: common.js is not found in plugins!
diff --git a/rkward/settings/rksettingsmodulecommandeditor.cpp b/rkward/settings/rksettingsmodulecommandeditor.cpp
index 504fd926..11ae8ce9 100644
--- a/rkward/settings/rksettingsmodulecommandeditor.cpp
+++ b/rkward/settings/rksettingsmodulecommandeditor.cpp
@@ -80,6 +80,12 @@ RKCodeCompletionSettingsWidget::RKCodeCompletionSettingsWidget(QWidget *parent,
 	form_layout = new QFormLayout ();
 	box_layout->addLayout (form_layout);
 
+	tabkey_invokes_completion_box = new QCheckBox(group);
+	tabkey_invokes_completion_box->setChecked(settings->tabkey_invokes_completion);
+	RKCommonFunctions::setTips (i18n ("Note: Further shorcuts can be assigned, and by default, Ctlr+Space invokes completions, in addition to this. Further, Pressing the tab key, while completions are shown, performs partial completion (if possible), independent of this setting."), tabkey_invokes_completion_box);
+	connect (tabkey_invokes_completion_box, &QCheckBox::stateChanged, this, &RKCodeCompletionSettingsWidget::change);
+	form_layout->addRow (i18n ("Tab key invokes code completion"), tabkey_invokes_completion_box);
+
 	cursor_navigates_completions_box = new QComboBox(group);
 	cursor_navigates_completions_box->addItem(i18n("Up/down cursor keys"));
 	cursor_navigates_completions_box->addItem(i18n("Alt+Up/down cursor keys"));
@@ -129,6 +135,7 @@ void RKCodeCompletionSettingsWidget::applyChanges() {
 		settings->completion_type_enabled[i] = completion_type_enabled_box[i]->isChecked ();
 	}
 	settings->cursor_navigates_completions = (cursor_navigates_completions_box->currentIndex() == 0);
+	settings->tabkey_invokes_completion = tabkey_invokes_completion_box->isChecked();
 
 	if (show_common) {
 		settings->completion_options = 0;
@@ -251,6 +258,7 @@ void RKCodeCompletionSettings::saveSettings(KConfigGroup& cg) {
 	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);
+	cg.writeEntry ("Tabkey invokes completion", tabkey_invokes_completion);
 	for (int i = 0; i < N_COMPLETION_CATEGORIES; ++i) {
 		cg.writeEntry (completionTypeToConfigKey (i), completion_type_enabled[i]);
 	}
@@ -279,6 +287,7 @@ void RKCodeCompletionSettings::loadSettings(KConfigGroup& cg) {
 	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);
+	tabkey_invokes_completion = cg.readEntry ("Tabkey invokes completion", false);
 	for (int i = 0; i < N_COMPLETION_CATEGORIES; ++i) {
 		completion_type_enabled[i] = cg.readEntry (completionTypeToConfigKey (i), true);
 	}
diff --git a/rkward/settings/rksettingsmodulecommandeditor.h b/rkward/settings/rksettingsmodulecommandeditor.h
index 341b1204..2112d6bc 100644
--- a/rkward/settings/rksettingsmodulecommandeditor.h
+++ b/rkward/settings/rksettingsmodulecommandeditor.h
@@ -45,20 +45,22 @@ public:
 	};
 
 /// 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; };
+	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; };
+	bool tabKeyInvokesCompletion() const { return tabkey_invokes_completion; };
 private:
 friend class RKCodeCompletionSettingsWidget;
 	int auto_completion_min_chars;
 	int auto_completion_timeout;
 	bool auto_completion_enabled;
 	bool auto_completion_cursor_activated;
+	bool tabkey_invokes_completion;
 	bool completion_type_enabled[N_COMPLETION_CATEGORIES];
 	bool cursor_navigates_completions;
 	int completion_options;
@@ -76,6 +78,7 @@ private:
 	RKSpinBox* auto_completion_timeout_box;
 	QGroupBox* auto_completion_enabled_box;
 	QCheckBox* auto_completion_cursor_activated_box;
+	QCheckBox* tabkey_invokes_completion_box;
 	QCheckBox* completion_type_enabled_box[RKCodeCompletionSettings::N_COMPLETION_CATEGORIES];
 	QComboBox* cursor_navigates_completions_box;
 	QComboBox* completion_list_member_operator_box;
diff --git a/rkward/windows/rkcodecompletion.cpp b/rkward/windows/rkcodecompletion.cpp
index 784b7523..109ac112 100644
--- a/rkward/windows/rkcodecompletion.cpp
+++ b/rkward/windows/rkcodecompletion.cpp
@@ -2,7 +2,7 @@
                           rkcodecompletion  -  description
                              -------------------
     begin                : Thu Feb 21 2019
-    copyright            : (C) 2004-2019 by Thomas Friedrichsmeier
+    copyright            : (C) 2004-2020 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -359,9 +359,17 @@ KTextEditor::Range RKCompletionManager::currentCallRange () const {
 bool RKCompletionManager::eventFilter (QObject*, QEvent* event) {
 	if (event->type () == QEvent::KeyPress || event->type () == QEvent::ShortcutOverride) {
 		RK_TRACE (COMMANDEDITOR);	// avoid loads of empty traces, putting this here
-		if (!cc_iface->isCompletionActive()) return false;
 		QKeyEvent *k = static_cast<QKeyEvent *> (event);
 
+		if (!cc_iface->isCompletionActive()) {
+			if (k->type () == QEvent::ShortcutOverride) return true; // retriggered as key event
+			if (settings->tabKeyInvokesCompletion() && k->key() == Qt::Key_Tab && k->modifiers() == Qt::NoModifier) {
+				userTriggeredCompletion();
+				return true;
+			}
+			return false;
+		}
+
 		// If only the calltip is active, make sure the tab-key and enter behave as a regular keys. There is no completion in this case.
 		if (active_models.count () == 1 && active_models[0] == callhint_model) {
 			if (((k->key () == Qt::Key_Tab) || (k->key () == Qt::Key_Return) || (k->key () == Qt::Key_Enter)) || (k->key () == Qt::Key_Backtab)) {
diff --git a/rkward/windows/rkcodecompletion.h b/rkward/windows/rkcodecompletion.h
index 7044e9bc..33325dae 100644
--- a/rkward/windows/rkcodecompletion.h
+++ b/rkward/windows/rkcodecompletion.h
@@ -2,7 +2,7 @@
                           rkcodecompletion  -  description
                              -------------------
     begin                : Thu Feb 21 2019
-    copyright            : (C) 2004-2019 by Thomas Friedrichsmeier
+    copyright            : (C) 2004-2020 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 



More information about the rkward-tracker mailing list