[rkward] rkward: Allow to configure object name completion behavior (for script editor window, only, so far)
Thomas Friedrichsmeier
null at kde.org
Tue Jan 22 10:41:19 GMT 2019
Git commit 8c13f77993ebcb63932b3ed9f35bb098571ba2d6 by Thomas Friedrichsmeier.
Committed on 22/01/2019 at 10:41.
Pushed by tfry into branch 'master'.
Allow to configure object name completion behavior (for script editor window, only, so far)
Also, provide a group header for object name matches, and some further display tweaks.
M +35 -1 rkward/settings/rksettingsmodulecommandeditor.cpp
M +6 -1 rkward/settings/rksettingsmodulecommandeditor.h
M +38 -5 rkward/windows/rkcommandeditorwindow.cpp
M +4 -1 rkward/windows/rkcommandeditorwindow.h
https://commits.kde.org/rkward/8c13f77993ebcb63932b3ed9f35bb098571ba2d6
diff --git a/rkward/settings/rksettingsmodulecommandeditor.cpp b/rkward/settings/rksettingsmodulecommandeditor.cpp
index c624843d..8f6d5c82 100644
--- a/rkward/settings/rksettingsmodulecommandeditor.cpp
+++ b/rkward/settings/rksettingsmodulecommandeditor.cpp
@@ -2,7 +2,7 @@
rksettingsmodulecommandeditor - description
-------------------
begin : Tue Oct 23 2007
- copyright : (C) 2007, 2010, 2011 by Thomas Friedrichsmeier
+ copyright : (C) 2007-2019 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -26,9 +26,11 @@
#include <QCheckBox>
#include <QGroupBox>
#include <QLineEdit>
+#include <QComboBox>
#include "../misc/rkspinbox.h"
#include "../misc/rkcommonfunctions.h"
+#include "../core/robject.h"
#include "../rkglobals.h"
#include "../debug.h"
@@ -36,6 +38,7 @@
int RKSettingsModuleCommandEditor::completion_min_chars;
int RKSettingsModuleCommandEditor::completion_timeout;
bool RKSettingsModuleCommandEditor::completion_enabled;
+int RKSettingsModuleCommandEditor::completion_options;
bool RKSettingsModuleCommandEditor::arghinting_enabled;
bool RKSettingsModuleCommandEditor::autosave_enabled;
bool RKSettingsModuleCommandEditor::autosave_keep;
@@ -82,6 +85,30 @@ RKSettingsModuleCommandEditor::RKSettingsModuleCommandEditor (RKSettings *gui, Q
box_layout->addWidget (label);
box_layout->addWidget (completion_timeout_box);
+ label = new QLabel (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"));
+ label->setWordWrap (true);
+ 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 ((completion_options & RObject::DollarExpansion) ? 0 : 1);
+ connect (completion_list_member_operator_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &RKSettingsModuleCommandEditor::settingChanged);
+ box_layout->addWidget (label);
+ box_layout->addWidget (completion_list_member_operator_box);
+
+ label = new QLabel (i18n ("Include environment for objects on the search path:"));
+ label->setWordWrap (true);
+ 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 (completion_options & (RObject::IncludeEnvirIfNotGlobalEnv)) {
+ if (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, &RKSettingsModuleCommandEditor::settingChanged);
+ box_layout->addWidget (label);
+ box_layout->addWidget (completion_object_qualification_box);
+
main_vbox->addWidget (group);
arghinting_enabled_box = new QCheckBox (i18n ("Enable function argument hinting"), group);
@@ -163,6 +190,11 @@ void RKSettingsModuleCommandEditor::applyChanges () {
completion_min_chars = completion_min_chars_box->intValue ();
completion_timeout = completion_timeout_box->intValue ();
arghinting_enabled = arghinting_enabled_box->isChecked ();
+ completion_options = 0;
+ if (completion_list_member_operator_box->currentIndex () == 0) completion_options += RObject::DollarExpansion;
+ if (completion_object_qualification_box->currentIndex () == 2) completion_options += RObject::IncludeEnvirForGlobalEnv | RObject::IncludeEnvirIfNotGlobalEnv;
+ else if (completion_object_qualification_box->currentIndex () == 1) completion_options += RObject::IncludeEnvirIfNotGlobalEnv;
+ else completion_options += RObject::IncludeEnvirIfMasked;
autosave_enabled = autosave_enabled_box->isChecked ();
autosave_keep = autosave_keep_box->isChecked ();
@@ -184,6 +216,7 @@ void RKSettingsModuleCommandEditor::saveSettings (KConfig *config) {
cg.writeEntry ("Completion enabled", completion_enabled);
cg.writeEntry ("Completion min chars", completion_min_chars);
cg.writeEntry ("Completion timeout", completion_timeout);
+ cg.writeEntry ("Completion option flags", completion_options);
cg.writeEntry ("Argument hinting enabled", arghinting_enabled);
cg.writeEntry ("Autosave enabled", autosave_enabled);
@@ -201,6 +234,7 @@ void RKSettingsModuleCommandEditor::loadSettings (KConfig *config) {
completion_enabled = cg.readEntry ("Completion enabled", true);
completion_min_chars = cg.readEntry ("Completion min chars", 2);
completion_timeout = cg.readEntry ("Completion timeout", 500);
+ completion_options = cg.readEntry ("Completion option flags", RObject::DollarExpansion | RObject::IncludeEnvirIfMasked);
arghinting_enabled = cg.readEntry ("Argument hinting enabled", true);
autosave_enabled = cg.readEntry ("Autosave enabled", true);
diff --git a/rkward/settings/rksettingsmodulecommandeditor.h b/rkward/settings/rksettingsmodulecommandeditor.h
index bed059df..9cdbfa33 100644
--- a/rkward/settings/rksettingsmodulecommandeditor.h
+++ b/rkward/settings/rksettingsmodulecommandeditor.h
@@ -2,7 +2,7 @@
rksettingsmodulecommandeditor - description
-------------------
begin : Tue Oct 23 2007
- copyright : (C) 2007-2018 by Thomas Friedrichsmeier
+ copyright : (C) 2007-2019 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -23,6 +23,7 @@ class RKSpinBox;
class QCheckBox;
class QLineEdit;
class QGroupBox;
+class QComboBox;
/**
configuration for the Command Editor windows
@@ -49,6 +50,7 @@ public:
static int completionTimeout () { return completion_timeout; };
static bool completionEnabled () { return completion_enabled; };
static bool argHintingEnabled () { return arghinting_enabled; };
+ static int completionOptions () { return completion_options; };
static bool autosaveEnabled () { return autosave_enabled; };
static bool autosaveKeep () { return autosave_keep; };
@@ -65,11 +67,14 @@ private:
static int completion_timeout;
static bool completion_enabled;
static bool arghinting_enabled;
+ static int completion_options;
RKSpinBox* completion_min_chars_box;
RKSpinBox* completion_timeout_box;
QCheckBox* completion_enabled_box;
QCheckBox* arghinting_enabled_box;
+ QComboBox* completion_list_member_operator_box;
+ QComboBox* completion_object_qualification_box;
static bool autosave_enabled;
static bool autosave_keep;
diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index 577fabfc..218f85cc 100644
--- a/rkward/windows/rkcommandeditorwindow.cpp
+++ b/rkward/windows/rkcommandeditorwindow.cpp
@@ -1268,6 +1268,7 @@ RKCodeCompletionModel::RKCodeCompletionModel (RKCommandEditorWindow *parent) : K
setRowCount (0);
command_editor = parent;
+ setHasGroups (true);
}
RKCodeCompletionModel::~RKCodeCompletionModel () {
@@ -1291,12 +1292,11 @@ void RKCodeCompletionModel::updateCompletionList (const QString& symbol) {
int count = matches.size ();
icons.clear ();
icons.reserve (count);
- names = RObject::getFullNames (matches, RObject::IncludeEnvirIfMasked);
+ names = RObject::getFullNames (matches, RKSettingsModuleCommandEditor::completionOptions());
for (int i = 0; i < count; ++i) {
icons.append (RKStandardIcons::iconForObject (matches[i]));
}
- setRowCount (count);
current_symbol = symbol;
endResetModel ();
@@ -1320,14 +1320,43 @@ void RKCodeCompletionModel::executeCompletionItem (KTextEditor::View *view, cons
view->document ()->replaceText (word, names[index.row ()]);
}
+QModelIndex RKCodeCompletionModel::index (int row, int column, const QModelIndex& parent) const {
+ if (!parent.isValid ()) { // header item
+ if (row == 0) return createIndex (row, column, quintptr (0));
+ return QModelIndex ();
+ } else if (parent.parent ().isValid ()) {
+ return QModelIndex ();
+ }
+
+ if (row < 0 || row >= names.count () || column < 0 || column >= ColumnCount) {
+ return QModelIndex ();
+ }
+
+ return createIndex (row, column, 1); // regular item
+}
+
+QModelIndex RKCodeCompletionModel::parent (const QModelIndex& index) const {
+ if (index.internalId ()) return createIndex (0, 0, quintptr (0));
+ return QModelIndex ();
+}
+
+int RKCodeCompletionModel::rowCount (const QModelIndex& parent) const {
+ if (parent.parent ().isValid ()) return 0; // no children on completion entries
+ if (parent.isValid ()) return names.count ();
+ return (!names.isEmpty ()); // header item, if list not empty
+}
+
QVariant RKCodeCompletionModel::data (const QModelIndex& index, int role) const {
+ if (!index.parent ().isValid ()) { // group header
+ if (role == Qt::DisplayRole) return i18n ("Objects on search path");
+ if (role == GroupRole) return Qt::DisplayRole;
+ return QVariant ();
+ }
int col = index.column ();
int row = index.row ();
- if (index.parent ().isValid ()) return QVariant ();
-
- if ((role == Qt::DisplayRole) || (role==KTextEditor::CodeCompletionModel::CompletionRole)) {
+ if ((role == Qt::DisplayRole) || (role == KTextEditor::CodeCompletionModel::CompletionRole)) {
if (col == KTextEditor::CodeCompletionModel::Name) {
return (names.value (row));
}
@@ -1335,6 +1364,10 @@ QVariant RKCodeCompletionModel::data (const QModelIndex& index, int role) const
if (col == KTextEditor::CodeCompletionModel::Icon) {
return (icons.value (row));
}
+ } else if (role == KTextEditor::CodeCompletionModel::InheritanceDepth) {
+ return (row); // disable sorting
+ } else if (role == KTextEditor::CodeCompletionModel::MatchQuality) {
+ return (10);
}
return QVariant ();
diff --git a/rkward/windows/rkcommandeditorwindow.h b/rkward/windows/rkcommandeditorwindow.h
index b1c47063..89ebe070 100644
--- a/rkward/windows/rkcommandeditorwindow.h
+++ b/rkward/windows/rkcommandeditorwindow.h
@@ -2,7 +2,7 @@
rkcommandeditorwindow - description
-------------------
begin : Mon Aug 30 2004
- copyright : (C) 2004-2018 by Thomas Friedrichsmeier
+ copyright : (C) 2004-2019 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -118,6 +118,9 @@ public:
void completionInvoked (KTextEditor::View *, const KTextEditor::Range &, InvocationType) override;
void executeCompletionItem (KTextEditor::View *view, const KTextEditor::Range &word, const QModelIndex &index) const override;
QVariant data (const QModelIndex& index, int role=Qt::DisplayRole) const override;
+ int rowCount (const QModelIndex &parent) const override;
+ QModelIndex index (int row, int column, const QModelIndex &parent = QModelIndex ()) const override;
+ QModelIndex parent (const QModelIndex &index) const override;
bool isEmpty () const { return names.isEmpty (); };
private:
More information about the rkward-tracker
mailing list