Commit 228447e2 authored by Thomas Friedrichsmeier's avatar Thomas Friedrichsmeier
Browse files

Add support for invoking completion via tab key

parent d5c0e347
......@@ -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!
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -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@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)) {
......
......@@ -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@kdemail.net
***************************************************************************/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment