aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhjk <[email protected]>2021-02-26 17:55:55 +0100
committerhjk <[email protected]>2021-03-03 07:12:21 +0000
commit50f93710b71ea6c27d46d867b37add378dde72e9 (patch)
treefa0c300099ce0c4abe0f8e74fac4b14b8de1615b
parent3e082109980df5b6f10d7a91fee3e819bf2b976b (diff)
FakeVim: Aspectify settings
Change-Id: Ic73edce82e192779ed3efe86a5cb747a52d94d36 Reviewed-by: Christian Stenger <[email protected]>
-rw-r--r--src/plugins/fakevim/CMakeLists.txt1
-rw-r--r--src/plugins/fakevim/fakevim.pro3
-rw-r--r--src/plugins/fakevim/fakevim.qbs1
-rw-r--r--src/plugins/fakevim/fakevimactions.cpp203
-rw-r--r--src/plugins/fakevim/fakevimactions.h164
-rw-r--r--src/plugins/fakevim/fakevimhandler.cpp127
-rw-r--r--src/plugins/fakevim/fakevimoptions.ui443
-rw-r--r--src/plugins/fakevim/fakevimplugin.cpp272
8 files changed, 400 insertions, 814 deletions
diff --git a/src/plugins/fakevim/CMakeLists.txt b/src/plugins/fakevim/CMakeLists.txt
index ddb6f3c1f1e..a7c1cf736c4 100644
--- a/src/plugins/fakevim/CMakeLists.txt
+++ b/src/plugins/fakevim/CMakeLists.txt
@@ -5,7 +5,6 @@ add_qtc_plugin(FakeVim
fakevim.qrc
fakevimactions.cpp fakevimactions.h
fakevimhandler.cpp fakevimhandler.h
- fakevimoptions.ui
fakevimplugin.cpp fakevimplugin.h
fakevimtr.h
)
diff --git a/src/plugins/fakevim/fakevim.pro b/src/plugins/fakevim/fakevim.pro
index 2ee8c0afbfa..9ec458b82e7 100644
--- a/src/plugins/fakevim/fakevim.pro
+++ b/src/plugins/fakevim/fakevim.pro
@@ -2,14 +2,15 @@
include(../../qtcreatorplugin.pri)
QT += gui
+
SOURCES += fakevimactions.cpp \
fakevimhandler.cpp \
fakevimplugin.cpp
+
HEADERS += fakevimactions.h \
fakevimhandler.h \
fakevimplugin.h \
fakevimtr.h
-FORMS += fakevimoptions.ui
equals(TEST, 1) {
SOURCES += fakevim_test.cpp
diff --git a/src/plugins/fakevim/fakevim.qbs b/src/plugins/fakevim/fakevim.qbs
index e16041166cf..230cd50de06 100644
--- a/src/plugins/fakevim/fakevim.qbs
+++ b/src/plugins/fakevim/fakevim.qbs
@@ -21,7 +21,6 @@ QtcPlugin {
"fakevimactions.h",
"fakevimhandler.cpp",
"fakevimhandler.h",
- "fakevimoptions.ui",
"fakevimplugin.cpp",
"fakevimplugin.h",
"fakevimtr.h",
diff --git a/src/plugins/fakevim/fakevimactions.cpp b/src/plugins/fakevim/fakevimactions.cpp
index 3d549c176c2..839d494b78b 100644
--- a/src/plugins/fakevim/fakevimactions.cpp
+++ b/src/plugins/fakevim/fakevimactions.cpp
@@ -31,7 +31,7 @@
// Qt Creator. The idea is to keep this file here in a "clean" state that
// allows easy reuse with any QTextEdit or QPlainTextEdit derived class.
-
+#include <utils/layoutbuilder.h>
#include <utils/qtcassert.h>
#include <QDebug>
@@ -41,168 +41,171 @@ using namespace Utils;
namespace FakeVim {
namespace Internal {
-DummyAction::DummyAction(void *)
+#ifdef FAKEVIM_STANDALONE
+FvBaseAspect::FvBaseAspect()
{
}
-void DummyAction::setValue(const QVariant &value)
+void FvBaseAspect::setValue(const QVariant &value)
{
m_value = value;
}
-QVariant DummyAction::value() const
+QVariant FvBaseAspect::value() const
{
return m_value;
}
-void DummyAction::setDefaultValue(const QVariant &value)
+void FvBaseAspect::setDefaultValue(const QVariant &value)
{
m_defaultValue = value;
}
-QVariant DummyAction::defaultValue() const
+QVariant FvBaseAspect::defaultValue() const
{
return m_defaultValue;
}
-void DummyAction::setSettingsKey(const QString &group, const QString &key)
+void FvBaseAspect::setSettingsKey(const QString &group, const QString &key)
{
m_settingsGroup = group;
m_settingsKey = key;
}
-QString DummyAction::settingsKey() const
+QString FvBaseAspect::settingsKey() const
{
return m_settingsKey;
}
+#endif
FakeVimSettings::FakeVimSettings()
{
- // Specific FakeVim settings
- createAction(ConfigReadVimRc, false, "ReadVimRc");
- createAction(ConfigVimRcPath, QString(), "VimRcPath");
#ifndef FAKEVIM_STANDALONE
- createAction(ConfigUseFakeVim, false, "UseFakeVim");
- item(ConfigUseFakeVim)->setText(tr("Use Vim-style Editing"));
- item(ConfigReadVimRc)->setText(tr("Read .vimrc"));
- item(ConfigVimRcPath)->setText(tr("Path to .vimrc"));
+ setup(&useFakeVim, false, "UseFakeVim", {}, tr("Use FakeVim"));
#endif
- createAction(ConfigShowMarks, false, "ShowMarks", "sm");
- createAction(ConfigPassControlKey, false, "PassControlKey", "pck");
- createAction(ConfigPassKeys, true, "PassKeys", "pk");
+ // Specific FakeVim settings
+ setup(&readVimRc, false, "ReadVimRc", {}, tr("Read .vimrc from location:"));
+ setup(&vimRcPath, QString(), "VimRcPath", {}, {}); // tr("Path to .vimrc")
+ setup(&showMarks, false, "ShowMarks", "sm", tr("Show position of text marks"));
+ setup(&passControlKey, false, "PassControlKey", "pck", tr("Pass control keys"));
+ setup(&passKeys, true, "PassKeys", "pk", tr("Pass keys in insert mode"));
// Emulated Vsetting
- createAction(ConfigStartOfLine, true, "StartOfLine", "sol");
- createAction(ConfigTabStop, 8, "TabStop", "ts");
- createAction(ConfigSmartTab, false, "SmartTab", "sta");
- createAction(ConfigHlSearch, true, "HlSearch", "hls");
- createAction(ConfigShiftWidth, 8, "ShiftWidth", "sw");
- createAction(ConfigExpandTab, false, "ExpandTab", "et");
- createAction(ConfigAutoIndent, false, "AutoIndent", "ai");
- createAction(ConfigSmartIndent, false, "SmartIndent", "si");
- createAction(ConfigIncSearch, true, "IncSearch", "is");
- createAction(ConfigUseCoreSearch, false, "UseCoreSearch", "ucs");
- createAction(ConfigSmartCase, false, "SmartCase", "scs");
- createAction(ConfigIgnoreCase, false, "IgnoreCase", "ic");
- createAction(ConfigWrapScan, true, "WrapScan", "ws");
- createAction(ConfigTildeOp, false, "TildeOp", "top");
- createAction(ConfigShowCmd, true, "ShowCmd", "sc");
- createAction(ConfigRelativeNumber, false, "RelativeNumber", "rnu");
- createAction(ConfigBlinkingCursor, false, "BlinkingCursor", "bc");
- createAction(ConfigScrollOff, 0, "ScrollOff", "so");
- createAction(ConfigBackspace, QString("indent,eol,start"), "ConfigBackspace", "bs");
- createAction(ConfigIsKeyword, QString("@,48-57,_,192-255,a-z,A-Z"), "IsKeyword", "isk");
- createAction(ConfigClipboard, QString(), "Clipboard", "cb");
- createAction(ConfigFormatOptions, QString(), "formatoptions", "fo");
+ setup(&startOfLine, true, "StartOfLine", "sol", tr("Start of line"));
+ setup(&tabStop, 8, "TabStop", "ts", tr("Tabulator size:"));
+ setup(&smartTab, false, "SmartTab", "sta", tr("Smart tabulators"));
+ setup(&hlSearch, true, "HlSearch", "hls", tr("Highlight search results"));
+ setup(&shiftWidth, 8, "ShiftWidth", "sw", tr("Shift width:"));
+ setup(&expandTab, false, "ExpandTab", "et", tr("Expand tabulators"));
+ setup(&autoIndent, false, "AutoIndent", "ai", tr("Automatic indentation"));
+ setup(&smartIndent, false, "SmartIndent", "si", tr("Smart tabulators"));
+ setup(&incSearch, true, "IncSearch", "is", tr("Incremental search"));
+ setup(&useCoreSearch, false, "UseCoreSearch", "ucs", tr("Use search dialog"));
+ setup(&smartCase, false, "SmartCase", "scs", tr("Use smartcase"));
+ setup(&ignoreCase, false, "IgnoreCase", "ic", tr("Use ignorecase"));
+ setup(&wrapScan, true, "WrapScan", "ws", tr("Use wrapscan"));
+ setup(&tildeOp, false, "TildeOp", "top", tr("Use tildeop"));
+ setup(&showCmd, true, "ShowCmd", "sc", tr("Show partial command"));
+ setup(&relativeNumber, false, "RelativeNumber", "rnu", tr("Show line numbers relative to cursor"));
+ setup(&blinkingCursor, false, "BlinkingCursor", "bc", tr("Blinking cursor"));
+ setup(&scrollOff, 0, "ScrollOff", "so", tr("Scroll offset:"));
+ setup(&backspace, "indent,eol,start",
+ "ConfigBackspace","bs", tr("Backspace:"));
+ setup(&isKeyword, "@,48-57,_,192-255,a-z,A-Z",
+ "IsKeyword", "isk", tr("Keyword characters:"));
+ setup(&clipboard, {}, "Clipboard", "cb", tr(""));
+ setup(&formatOptions, {}, "formatoptions", "fo", tr(""));
// Emulated plugins
- createAction(ConfigEmulateVimCommentary, false, "commentary");
- createAction(ConfigEmulateReplaceWithRegister, false, "ReplaceWithRegister");
- createAction(ConfigEmulateExchange, false, "exchange");
- createAction(ConfigEmulateArgTextObj, false, "argtextobj");
- createAction(ConfigEmulateSurround, false, "surround");
-}
+ setup(&emulateVimCommentary, false, "commentary", {}, "vim-commentary");
+ setup(&emulateReplaceWithRegister, false, "ReplaceWithRegister", {}, "ReplaceWithRegister");
+ setup(&emulateExchange, false, "exchange", {}, "vim-exchange");
+ setup(&emulateArgTextObj, false, "argtextobj", {}, "argtextobj.vim");
+ setup(&emulateSurround, false, "surround", {}, "vim-surround");
-FakeVimSettings::~FakeVimSettings()
-{
- qDeleteAll(m_items);
-}
+ // Some polish
+ useFakeVim.setDisplayName(tr("Use Vim-style Editing"));
-void FakeVimSettings::insertItem(int code, FakeVimAction *item,
- const QString &longName, const QString &shortName)
-{
- QTC_ASSERT(!m_items.contains(code), qDebug() << code; return);
- m_items[code] = item;
- if (!longName.isEmpty()) {
- m_nameToCode[longName] = code;
- m_codeToName[code] = longName;
- }
- if (!shortName.isEmpty())
- m_nameToCode[shortName] = code;
-}
+ relativeNumber.setToolTip(tr("Displays line numbers relative to the line containing "
+ "text cursor."));
-void FakeVimSettings::readSettings(QSettings *settings)
-{
- foreach (FakeVimAction *item, m_items)
- item->readSettings(settings);
-}
+ passControlKey.setToolTip(tr("Does not interpret key sequences like Ctrl-S in FakeVim "
+ "but handles them as regular shortcuts. This gives easier access to core functionality "
+ "at the price of losing some features of FakeVim."));
-void FakeVimSettings::writeSettings(QSettings *settings)
-{
- foreach (FakeVimAction *item, m_items)
- item->writeSettings(settings);
-}
+ passKeys.setToolTip(tr("Does not interpret some key presses in insert mode so that "
+ "code can be properly completed and expanded."));
-FakeVimAction *FakeVimSettings::item(int code)
-{
- QTC_ASSERT(m_items.value(code, 0), qDebug() << "CODE: " << code; return nullptr);
- return m_items.value(code, 0);
+ tabStop.setToolTip(tr("Vim tabstop option."));
+
+#ifndef FAKEVIM_STANDALONE
+ backspace.setDisplayStyle(FvStringAspect::LineEditDisplay);
+ isKeyword.setDisplayStyle(FvStringAspect::LineEditDisplay);
+
+ const QString vimrcDefault = QLatin1String(HostOsInfo::isAnyUnixHost()
+ ? "$HOME/.vimrc" : "%USERPROFILE%\\_vimrc");
+ vimRcPath.setExpectedKind(PathChooser::File);
+ vimRcPath.setToolTip(tr("Keep empty to use the default path, i.e. "
+ "%USERPROFILE%\\_vimrc on Windows, ~/.vimrc otherwise."));
+ vimRcPath.setPlaceHolderText(tr("Default: %1").arg(vimrcDefault));
+ vimRcPath.setDisplayStyle(FvStringAspect::PathChooserDisplay);
+#endif
}
-FakeVimAction *FakeVimSettings::item(const QString &name)
+FakeVimSettings::~FakeVimSettings() = default;
+
+FvBaseAspect *FakeVimSettings::item(const QString &name)
{
- return m_items.value(m_nameToCode.value(name, -1), 0);
+ return m_nameToAspect.value(name, nullptr);
}
QString FakeVimSettings::trySetValue(const QString &name, const QString &value)
{
- int code = m_nameToCode.value(name, -1);
- if (code == -1)
+ FvBaseAspect *aspect = m_nameToAspect.value(name, nullptr);
+ if (!aspect)
return tr("Unknown option: %1").arg(name);
- if (code == ConfigTabStop || code == ConfigShiftWidth) {
+ if (aspect == &tabStop || aspect == &shiftWidth) {
if (value.toInt() <= 0)
return tr("Argument must be positive: %1=%2")
.arg(name).arg(value);
}
- FakeVimAction *act = item(code);
- if (!act)
- return tr("Unknown option: %1").arg(name);
- act->setValue(value);
+ aspect->setValue(value);
return QString();
}
-void FakeVimSettings::createAction(int code, const QVariant &value,
- const QString &settingsKey,
- const QString &shortKey)
+void FakeVimSettings::setup(FvBaseAspect *aspect,
+ const QVariant &value,
+ const QString &settingsKey,
+ const QString &shortName,
+ const QString &labelText)
{
- auto item = new FakeVimAction(nullptr);
- item->setValue(value);
- item->setSettingsKey("FakeVim", settingsKey);
- item->setDefaultValue(value);
- item->setCheckable(value.canConvert<bool>());
- insertItem(code, item, settingsKey.toLower(), shortKey);
+ aspect->setSettingsKey("FakeVim", settingsKey);
+ aspect->setDefaultValue(value);
+#ifndef FAKEVIM_STANDALONE
+ aspect->setLabelText(labelText);
+ aspect->setAutoApply(false);
+ registerAspect(aspect);
+
+ if (auto boolAspect = dynamic_cast<FvBoolAspect *>(aspect))
+ boolAspect->setLabelPlacement(FvBoolAspect::LabelPlacement::AtCheckBoxWithoutDummyLabel);
+#else
+ Q_UNUSED(labelText)
+#endif
+
+ const QString longName = settingsKey.toLower();
+ if (!longName.isEmpty()) {
+ m_nameToAspect[longName] = aspect;
+ m_aspectToName[aspect] = longName;
+ }
+ if (!shortName.isEmpty())
+ m_nameToAspect[shortName] = aspect;
}
-FakeVimSettings *theFakeVimSettings()
+FakeVimSettings *fakeVimSettings()
{
static FakeVimSettings s;
return &s;
}
-FakeVimAction *theFakeVimSetting(int code)
-{
- return theFakeVimSettings()->item(code);
-}
-
} // namespace Internal
} // namespace FakeVim
diff --git a/src/plugins/fakevim/fakevimactions.h b/src/plugins/fakevim/fakevimactions.h
index 419232aeb8c..69131c76696 100644
--- a/src/plugins/fakevim/fakevimactions.h
+++ b/src/plugins/fakevim/fakevimactions.h
@@ -26,23 +26,25 @@
#pragma once
#ifndef FAKEVIM_STANDALONE
-# include <utils/savedaction.h>
+# include <utils/aspects.h>
#endif
#include <QCoreApplication>
#include <QHash>
#include <QObject>
#include <QString>
-#include <QSettings>
#include <QVariant>
namespace FakeVim {
namespace Internal {
-class DummyAction
+#ifdef FAKEVIM_STANDALONE
+class FvBaseAspect
{
public:
- DummyAction(void *parent);
+ FvBaseAspect();
+ virtual ~FvBaseAspect() {}
+
void setValue(const QVariant &value);
QVariant value() const;
void setDefaultValue(const QVariant &value);
@@ -50,105 +52,121 @@ public:
void setSettingsKey(const QString &group, const QString &key);
QString settingsKey() const;
void setCheckable(bool) {}
+ void setDisplayName(const QString &) {}
+ void setToolTip(const QString &) {}
- void readSettings(QSettings *) {}
- void writeSettings(QSettings *) {}
-
+private:
QVariant m_value;
QVariant m_defaultValue;
QString m_settingsGroup;
QString m_settingsKey;
};
-#ifdef FAKEVIM_STANDALONE
-using FakeVimAction = DummyAction;
+class FvBoolAspect : public FvBaseAspect
+{
+public:
+ bool value() const { return FvBaseAspect::value().toBool(); }
+};
+
+class FvIntegerAspect : public FvBaseAspect
+{
+public:
+ qint64 value() const { return FvBaseAspect::value().toLongLong(); }
+};
+
+class FvStringAspect : public FvBaseAspect
+{
+public:
+ QString value() const { return FvBaseAspect::value().toString(); }
+};
+
+class FvAspectContainer : public FvBaseAspect
+{
+public:
+};
+
#else
-using FakeVimAction = Utils::SavedAction;
+
+using FvAspectContainer = Utils::AspectContainer;
+using FvBaseAspect = Utils::BaseAspect;
+using FvBoolAspect = Utils::BoolAspect;
+using FvIntegerAspect = Utils::IntegerAspect;
+using FvStringAspect = Utils::StringAspect;
+
#endif
-enum FakeVimSettingsCode
+class FakeVimSettings final : public FvAspectContainer
{
- ConfigUseFakeVim,
- ConfigReadVimRc,
- ConfigVimRcPath,
-
- ConfigStartOfLine,
- ConfigHlSearch,
- ConfigTabStop,
- ConfigSmartTab,
- ConfigShiftWidth,
- ConfigExpandTab,
- ConfigAutoIndent,
- ConfigSmartIndent,
-
- ConfigIncSearch,
- ConfigUseCoreSearch,
- ConfigSmartCase,
- ConfigIgnoreCase,
- ConfigWrapScan,
+ Q_DECLARE_TR_FUNCTIONS(FakeVim)
+
+public:
+ FakeVimSettings();
+ ~FakeVimSettings();
+
+ FvBaseAspect *item(const QString &name);
+ QString trySetValue(const QString &name, const QString &value);
+
+ FvBoolAspect useFakeVim;
+ FvBoolAspect readVimRc;
+ FvStringAspect vimRcPath;
+
+ FvBoolAspect startOfLine;
+ FvIntegerAspect tabStop;
+ FvBoolAspect hlSearch;
+ FvBoolAspect smartTab;
+ FvIntegerAspect shiftWidth;
+ FvBoolAspect expandTab;
+ FvBoolAspect autoIndent;
+ FvBoolAspect smartIndent;
+
+ FvBoolAspect incSearch;
+ FvBoolAspect useCoreSearch;
+ FvBoolAspect smartCase;
+ FvBoolAspect ignoreCase;
+ FvBoolAspect wrapScan;
// command ~ behaves as g~
- ConfigTildeOp,
+ FvBoolAspect tildeOp;
// indent allow backspacing over autoindent
// eol allow backspacing over line breaks (join lines)
// start allow backspacing over the start of insert; CTRL-W and CTRL-U
// stop once at the start of insert.
- ConfigBackspace,
+ FvStringAspect backspace;
// @,48-57,_,192-255
- ConfigIsKeyword,
+ FvStringAspect isKeyword;
// other actions
- ConfigShowMarks,
- ConfigPassControlKey,
- ConfigPassKeys,
- ConfigClipboard,
- ConfigShowCmd,
- ConfigScrollOff,
- ConfigRelativeNumber,
- ConfigFormatOptions,
+ FvBoolAspect showMarks;
+ FvBoolAspect passControlKey;
+ FvBoolAspect passKeys;
+ FvStringAspect clipboard;
+ FvBoolAspect showCmd;
+ FvIntegerAspect scrollOff;
+ FvBoolAspect relativeNumber;
+ FvStringAspect formatOptions;
// Plugin emulation
- ConfigEmulateVimCommentary,
- ConfigEmulateReplaceWithRegister,
- ConfigEmulateExchange,
- ConfigEmulateArgTextObj,
- ConfigEmulateSurround,
-
- ConfigBlinkingCursor
-};
-
-class FakeVimSettings
-{
- Q_DECLARE_TR_FUNCTIONS(FakeVim)
-
-public:
- FakeVimSettings();
- ~FakeVimSettings();
- void insertItem(int code, FakeVimAction *item,
- const QString &longname = QString(),
- const QString &shortname = QString());
-
- FakeVimAction *item(int code);
- FakeVimAction *item(const QString &name);
- QString trySetValue(const QString &name, const QString &value);
+ FvBoolAspect emulateVimCommentary;
+ FvBoolAspect emulateReplaceWithRegister;
+ FvBoolAspect emulateExchange;
+ FvBoolAspect emulateArgTextObj;
+ FvBoolAspect emulateSurround;
- void readSettings(QSettings *settings);
- void writeSettings(QSettings *settings);
+ FvBoolAspect blinkingCursor;
private:
- void createAction(int code, const QVariant &value,
- const QString &settingsKey = QString(),
- const QString &shortKey = QString());
+ void setup(FvBaseAspect *aspect, const QVariant &value,
+ const QString &settingsKey,
+ const QString &shortName,
+ const QString &label);
- QHash<int, FakeVimAction *> m_items;
- QHash<QString, int> m_nameToCode;
- QHash<int, QString> m_codeToName;
+ QHash<QString, FvBaseAspect *> m_nameToAspect;
+ QHash<FvBaseAspect *, QString> m_aspectToName;
};
-FakeVimSettings *theFakeVimSettings();
-FakeVimAction *theFakeVimSetting(int code);
+FakeVimSettings *fakeVimSettings();
} // namespace Internal
} // namespace FakeVim
diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp
index 9526fb78377..37301602a48 100644
--- a/src/plugins/fakevim/fakevimhandler.cpp
+++ b/src/plugins/fakevim/fakevimhandler.cpp
@@ -289,21 +289,6 @@ QDebug operator<<(QDebug ts, const CursorPosition &pos)
}
// vi style configuration
-static QVariant config(int code)
-{
- return theFakeVimSetting(code)->value();
-}
-
-static bool hasConfig(int code)
-{
- return config(code).toBool();
-}
-
-static bool hasConfig(int code, const QString &value)
-{
- return config(code).toString().contains(value);
-}
-
class Mark
{
@@ -447,8 +432,8 @@ static QRegularExpression vimPatternToQtPattern(const QString &needle)
*/
// FIXME: Option smartcase should be used only if search was typed by user.
- const bool ignoreCaseOption = hasConfig(ConfigIgnoreCase);
- const bool smartCaseOption = hasConfig(ConfigSmartCase);
+ const bool ignoreCaseOption = fakeVimSettings()->ignoreCase.value();
+ const bool smartCaseOption = fakeVimSettings()->smartCase.value();
const bool initialIgnoreCase = ignoreCaseOption
&& !(smartCaseOption && needle.contains(QRegularExpression("[A-Z]")));
@@ -2443,6 +2428,8 @@ public:
bool surroundUpperCaseS; // True for yS and cS, false otherwise
QString surroundFunction; // Used for storing the function name provided to ys{motion}f
} g;
+
+ FakeVimSettings &s = *fakeVimSettings();
};
FakeVimHandler::Private::GlobalData FakeVimHandler::Private::g;
@@ -2581,7 +2568,7 @@ void FakeVimHandler::Private::leaveFakeVim(bool needUpdate)
// The command might have destroyed the editor.
if (m_textedit || m_plaintextedit) {
- if (hasConfig(ConfigShowMarks))
+ if (s.showMarks.value())
updateSelection();
updateMiniBuffer();
@@ -2630,7 +2617,7 @@ bool FakeVimHandler::Private::wantsOverride(QKeyEvent *ev)
// We are interested in overriding most Ctrl key combinations.
if (isOnlyControlModifier(mods)
- && !config(ConfigPassControlKey).toBool()
+ && !s.passControlKey.value()
&& ((key >= Key_A && key <= Key_Z && key != Key_K)
|| key == Key_BracketLeft || key == Key_BracketRight)) {
// Ctrl-K is special as it is the Core's default notion of Locator
@@ -2840,7 +2827,7 @@ void FakeVimHandler::Private::ensureCursorVisible()
void FakeVimHandler::Private::updateEditor()
{
- setTabSize(config(ConfigTabStop).toInt());
+ setTabSize(s.tabStop.value());
setupCharClass();
}
@@ -3113,7 +3100,7 @@ void FakeVimHandler::Private::stopIncrementalFind()
void FakeVimHandler::Private::updateFind(bool isComplete)
{
- if (!isComplete && !hasConfig(ConfigIncSearch))
+ if (!isComplete && !s.incSearch.value())
return;
g.currentMessage.clear();
@@ -3215,7 +3202,7 @@ void FakeVimHandler::Private::pushUndoState(bool overwrite)
pos = firstPositionInLine(lineForPosition(pos));
else if (isVisualBlockMode())
pos = blockAt(pos).position() + qMin(columnAt(anchor()), columnAt(position()));
- } else if (g.movetype == MoveLineWise && hasConfig(ConfigStartOfLine)) {
+ } else if (g.movetype == MoveLineWise && s.startOfLine.value()) {
QTextCursor tc = m_cursor;
if (g.submode == ShiftLeftSubMode || g.submode == ShiftRightSubMode
|| g.submode == IndentSubMode) {
@@ -3675,8 +3662,7 @@ void FakeVimHandler::Private::finishMovement(const QString &dotCommandMovement)
return;
} else if (g.submode == ExchangeSubMode) {
exchangeRange(currentRange());
- } else if (g.submode == ReplaceWithRegisterSubMode
- && hasConfig(ConfigEmulateReplaceWithRegister)) {
+ } else if (g.submode == ReplaceWithRegisterSubMode && s.emulateReplaceWithRegister.value()) {
pushUndoState(false);
beginEditBlock();
replaceWithRegister(currentRange());
@@ -3789,7 +3775,7 @@ void FakeVimHandler::Private::clearCurrentMode()
void FakeVimHandler::Private::updateSelection()
{
QList<QTextEdit::ExtraSelection> selections = m_extraSelections;
- if (hasConfig(ConfigShowMarks)) {
+ if (s.showMarks.value()) {
for (auto it = m_buffer->marks.cbegin(), end = m_buffer->marks.cend(); it != end; ++it) {
QTextEdit::ExtraSelection sel;
sel.cursor = m_cursor;
@@ -3808,7 +3794,7 @@ void FakeVimHandler::Private::updateSelection()
void FakeVimHandler::Private::updateHighlights()
{
- if (hasConfig(ConfigUseCoreSearch) || !hasConfig(ConfigHlSearch) || g.highlightsCleared) {
+ if (s.useCoreSearch.value() || !s.hlSearch.value() || g.highlightsCleared) {
if (m_highlighted.isEmpty())
return;
m_highlighted.clear();
@@ -3855,7 +3841,7 @@ void FakeVimHandler::Private::updateMiniBuffer()
} else if (!g.mapStates.isEmpty() && !g.mapStates.last().silent) {
// Do not reset previous message when after running a mapped command.
return;
- } else if (g.mode == CommandMode && !g.currentCommand.isEmpty() && hasConfig(ConfigShowCmd)) {
+ } else if (g.mode == CommandMode && !g.currentCommand.isEmpty() && s.showCmd.value()) {
msg = g.currentCommand;
messageLevel = MessageShowCmd;
} else if (g.mode == CommandMode && isVisualMode()) {
@@ -3962,7 +3948,7 @@ bool FakeVimHandler::Private::handleCommandSubSubMode(const Input &input)
handled = selectBlockTextObject(g.subsubdata.is('i'), '{', '}');
else if (input.is('"') || input.is('\'') || input.is('`'))
handled = selectQuotedStringTextObject(g.subsubdata.is('i'), input.asChar());
- else if (input.is('a') && hasConfig(ConfigEmulateArgTextObj))
+ else if (input.is('a') && s.emulateArgTextObj.value())
handled = selectArgumentTextObject(g.subsubdata.is('i'));
else
handled = false;
@@ -4105,7 +4091,7 @@ bool FakeVimHandler::Private::handleMovement(const Input &input)
g.subsubmode = NoSubSubMode;
} else if (input.is('/') || input.is('?')) {
g.lastSearchForward = input.is('/');
- if (hasConfig(ConfigUseCoreSearch)) {
+ if (s.useCoreSearch.value()) {
// re-use the core dialog.
g.findPending = true;
m_findStartPosition = position();
@@ -4280,7 +4266,7 @@ bool FakeVimHandler::Private::handleMovement(const Input &input)
m_cursor = EDITOR(cursorForPosition(QPoint(0, EDITOR(height()) / 2)));
handleStartOfLine();
} else if (input.is('n') || input.is('N')) {
- if (hasConfig(ConfigUseCoreSearch)) {
+ if (s.useCoreSearch.value()) {
bool forward = (input.is('n')) ? g.lastSearchForward : !g.lastSearchForward;
int pos = position();
q->findNextRequested(!forward);
@@ -4369,7 +4355,7 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
handled = handleNoSubMode(input);
} else if (g.submode == ExchangeSubMode) {
handled = handleExchangeSubMode(input);
- } else if (g.submode == ChangeSubMode && input.is('x') && hasConfig(ConfigEmulateExchange)) {
+ } else if (g.submode == ChangeSubMode && input.is('x') && s.emulateExchange.value()) {
// Exchange submode is "cx", so we need to switch over from ChangeSubMode here
g.submode = ExchangeSubMode;
handled = true;
@@ -4379,15 +4365,15 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
} else if (g.submode == AddSurroundingSubMode) {
handled = handleAddSurroundingSubMode(input);
} else if (g.submode == ChangeSubMode && (input.is('s') || input.is('S'))
- && hasConfig(ConfigEmulateSurround)) {
+ && s.emulateSurround.value()) {
g.submode = ChangeSurroundingSubMode;
g.surroundUpperCaseS = input.is('S');
handled = true;
- } else if (g.submode == DeleteSubMode && input.is('s') && hasConfig(ConfigEmulateSurround)) {
+ } else if (g.submode == DeleteSubMode && input.is('s') && s.emulateSurround.value()) {
g.submode = DeleteSurroundingSubMode;
handled = true;
} else if (g.submode == YankSubMode && (input.is('s') || input.is('S'))
- && hasConfig(ConfigEmulateSurround)) {
+ && s.emulateSurround.value()) {
g.submode = AddSurroundingSubMode;
g.movetype = MoveInclusive;
g.surroundUpperCaseS = input.is('S');
@@ -4396,10 +4382,10 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
|| g.submode == DeleteSubMode
|| g.submode == YankSubMode) {
handled = handleChangeDeleteYankSubModes(input);
- } else if (g.submode == CommentSubMode && hasConfig(ConfigEmulateVimCommentary)) {
+ } else if (g.submode == CommentSubMode && s.emulateVimCommentary.value()) {
handled = handleCommentSubMode(input);
} else if (g.submode == ReplaceWithRegisterSubMode
- && hasConfig(ConfigEmulateReplaceWithRegister)) {
+ && s.emulateReplaceWithRegister.value()) {
handled = handleReplaceWithRegisterSubMode(input);
} else if (g.submode == ReplaceSubMode) {
handled = handleReplaceSubMode(input);
@@ -4542,7 +4528,7 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
setTargetColumn();
} else if (input.isControl('a')) {
changeNumberTextObject(count());
- } else if (g.gflag && input.is('c') && hasConfig(ConfigEmulateVimCommentary)) {
+ } else if (g.gflag && input.is('c') && s.emulateVimCommentary.value()) {
if (isVisualMode()) {
pushUndoState();
@@ -4567,7 +4553,7 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
pushUndoState();
setAnchor();
}
- } else if (g.gflag && input.is('r') && hasConfig(ConfigEmulateReplaceWithRegister)) {
+ } else if (g.gflag && input.is('r') && s.emulateReplaceWithRegister.value()) {
g.submode = ReplaceWithRegisterSubMode;
if (isVisualMode()) {
dotCommand = visualDotCommand() + QString::number(count()) + "gr";
@@ -4726,7 +4712,7 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
int repeat = count();
while (--repeat >= 0)
redo();
- } else if (input.is('S') && isVisualMode() && hasConfig(ConfigEmulateSurround)) {
+ } else if (input.is('S') && isVisualMode() && s.emulateSurround.value()) {
g.submode = AddSurroundingSubMode;
g.subsubmode = SurroundSubSubMode;
} else if (input.is('s')) {
@@ -4811,7 +4797,7 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
if (isVisualMode()) {
leaveVisualMode();
finishMovement();
- } else if (g.gflag || (g.submode == InvertCaseSubMode && hasConfig(ConfigTildeOp))) {
+ } else if (g.gflag || (g.submode == InvertCaseSubMode && s.tildeOp.value())) {
if (atEndOfLine())
moveLeft();
setAnchor();
@@ -5457,15 +5443,15 @@ void FakeVimHandler::Private::handleInsertMode(const Input &input)
if (!handleInsertInEditor(Input(Qt::Key_Backspace, Qt::NoModifier))) {
joinPreviousEditBlock();
if (!m_buffer->lastInsertion.isEmpty()
- || hasConfig(ConfigBackspace, "start")
- || hasConfig(ConfigBackspace, "2")) {
+ || s.backspace.value().contains("start")
+ || s.backspace.value().contains("2")) {
const int line = cursorLine() + 1;
const Column col = cursorColumn();
QString data = lineContents(line);
const Column ind = indentation(data);
if (col.logical <= ind.logical && col.logical
&& startsWithWhitespace(data, col.physical)) {
- const int ts = config(ConfigTabStop).toInt();
+ const int ts = s.tabStop.value();
const int newl = col.logical - 1 - (col.logical - 1) % ts;
const QString prefix = tabExpand(newl);
setLineContents(line, prefix + data.mid(col.physical));
@@ -5490,8 +5476,8 @@ void FakeVimHandler::Private::handleInsertMode(const Input &input)
movePageUp();
} else if (input.isKey(Key_Tab)) {
m_buffer->insertState.insertingSpaces = true;
- if (hasConfig(ConfigExpandTab)) {
- const int ts = config(ConfigTabStop).toInt();
+ if (s.expandTab.value()) {
+ const int ts = s.tabStop.value();
const int col = logicalCursorColumn();
QString str = QString(ts - col % ts, ' ');
insertText(str);
@@ -5501,8 +5487,8 @@ void FakeVimHandler::Private::handleInsertMode(const Input &input)
m_buffer->insertState.insertingSpaces = false;
} else if (input.isControl('d')) {
// remove one level of indentation from the current line
- int shift = config(ConfigShiftWidth).toInt();
- int tab = config(ConfigTabStop).toInt();
+ const int shift = s.shiftWidth.value();
+ const int tab = s.tabStop.value();
int line = cursorLine() + 1;
int pos = firstPositionInLine(line);
QString text = lineContents(line);
@@ -5545,7 +5531,7 @@ void FakeVimHandler::Private::insertInInsertMode(const QString &text)
{
joinPreviousEditBlock();
insertText(text);
- if (hasConfig(ConfigSmartIndent) && isElectricCharacter(text.at(0))) {
+ if (s.smartIndent.value() && isElectricCharacter(text.at(0))) {
const QString leftText = block().text()
.left(position() - 1 - block().position());
if (leftText.simplified().isEmpty()) {
@@ -6174,8 +6160,7 @@ bool FakeVimHandler::Private::handleExSetCommand(const ExCommand &cmd)
if (cmd.args.contains('=')) {
// Non-boolean config to set.
int p = cmd.args.indexOf('=');
- QString error = theFakeVimSettings()
- ->trySetValue(cmd.args.left(p), cmd.args.mid(p + 1));
+ QString error = s.trySetValue(cmd.args.left(p), cmd.args.mid(p + 1));
if (!error.isEmpty())
showMessage(MessageError, error);
} else {
@@ -6190,7 +6175,7 @@ bool FakeVimHandler::Private::handleExSetCommand(const ExCommand &cmd)
if (negateOption)
optionName.remove(0, 2);
- FakeVimAction *act = theFakeVimSettings()->item(optionName);
+ FvBaseAspect *act = s.item(optionName);
if (!act) {
showMessage(MessageError, Tr::tr("Unknown option:") + ' ' + cmd.args);
} else if (act->defaultValue().type() == QVariant::Bool) {
@@ -6317,7 +6302,7 @@ bool FakeVimHandler::Private::handleExMoveCommand(const ExCommand &cmd)
if (!insertAtEnd)
moveUp(1);
- if (hasConfig(ConfigStartOfLine))
+ if (s.startOfLine.value())
moveToFirstNonBlankOnLine();
if (lastAnchor.line >= startLine && lastAnchor.line <= endLine)
@@ -6790,7 +6775,7 @@ QTextCursor FakeVimHandler::Private::search(const SearchData &sd, int startPos,
}
if (tc.isNull()) {
- if (hasConfig(ConfigWrapScan)) {
+ if (s.wrapScan.value()) {
tc = QTextCursor(document());
tc.movePosition(sd.forward ? StartOfDocument : EndOfDocument);
if (sd.forward)
@@ -6950,10 +6935,10 @@ void FakeVimHandler::Private::shiftRegionRight(int repeat)
std::swap(beginLine, endLine);
targetPos = position();
}
- if (hasConfig(ConfigStartOfLine))
+ if (s.startOfLine.value())
targetPos = firstPositionInLine(beginLine);
- const int sw = config(ConfigShiftWidth).toInt();
+ const int sw = s.shiftWidth.value();
g.movetype = MoveLineWise;
beginEditBlock();
QTextBlock block = document()->findBlockByLineNumber(beginLine - 1);
@@ -7102,7 +7087,7 @@ void FakeVimHandler::Private::setupCharClass()
const QChar c = QLatin1Char(i);
m_charClass[i] = c.isSpace() ? 0 : 1;
}
- const QString conf = config(ConfigIsKeyword).toString();
+ const QString conf = s.isKeyword.value();
for (const QString &part : conf.split(',')) {
if (part.contains('-')) {
const int from = someInt(part.section('-', 0, 0));
@@ -7291,7 +7276,7 @@ int FakeVimHandler::Private::physicalCursorColumn() const
int FakeVimHandler::Private::physicalToLogicalColumn
(const int physical, const QString &line) const
{
- const int ts = config(ConfigTabStop).toInt();
+ const int ts = s.tabStop.value();
int p = 0;
int logical = 0;
while (p < physical) {
@@ -7312,7 +7297,7 @@ int FakeVimHandler::Private::physicalToLogicalColumn
int FakeVimHandler::Private::logicalToPhysicalColumn
(const int logical, const QString &line) const
{
- const int ts = config(ConfigTabStop).toInt();
+ const int ts = s.tabStop.value();
int physical = 0;
for (int l = 0; l < logical && physical < line.size(); ++physical) {
QChar c = line.at(physical);
@@ -7326,7 +7311,7 @@ int FakeVimHandler::Private::logicalToPhysicalColumn
int FakeVimHandler::Private::windowScrollOffset() const
{
- return qMin(theFakeVimSetting(ConfigScrollOff)->value().toInt(), linesOnScreen() / 2);
+ return qMin(static_cast<int>(s.scrollOff.value()), linesOnScreen() / 2);
}
int FakeVimHandler::Private::logicalCursorColumn() const
@@ -7590,7 +7575,7 @@ void FakeVimHandler::Private::transformText(const Range &range, const Transforma
void FakeVimHandler::Private::insertText(QTextCursor &tc, const QString &text)
{
- if (hasConfig(ConfigPassKeys)) {
+ if (s.passKeys.value()) {
if (tc.hasSelection() && text.isEmpty()) {
QKeyEvent event(QEvent::KeyPress, Qt::Key_Delete, Qt::NoModifier, QString());
passEventToEditor(event, tc);
@@ -7932,7 +7917,7 @@ void FakeVimHandler::Private::joinLines(int count, bool preserveSpace)
moveRight();
// If the line we started from is a comment, remove the comment string from the next line
- if (startingLineIsComment && config(ConfigFormatOptions).toString().contains('f')) {
+ if (startingLineIsComment && s.formatOptions.value().contains('f')) {
if (characterAtCursor() == '/' && characterAt(position() + 1) == '/')
moveRight(2);
else if (characterAtCursor() == '*' || characterAtCursor() == '#')
@@ -7950,7 +7935,7 @@ void FakeVimHandler::Private::joinLines(int count, bool preserveSpace)
void FakeVimHandler::Private::insertNewLine()
{
- if ( m_buffer->editBlockLevel <= 1 && hasConfig(ConfigPassKeys) ) {
+ if (m_buffer->editBlockLevel <= 1 && s.passKeys.value()) {
QKeyEvent event(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier, "\n");
if (passEventToEditor(event, m_cursor))
return;
@@ -7962,7 +7947,7 @@ void FakeVimHandler::Private::insertNewLine()
bool FakeVimHandler::Private::handleInsertInEditor(const Input &input)
{
- if (m_buffer->editBlockLevel > 0 || !hasConfig(ConfigPassKeys))
+ if (m_buffer->editBlockLevel > 0 || !s.passKeys.value())
return false;
joinPreviousEditBlock();
@@ -8649,7 +8634,7 @@ void FakeVimHandler::Private::jump(int distance)
Column FakeVimHandler::Private::indentation(const QString &line) const
{
- int ts = config(ConfigTabStop).toInt();
+ int ts = s.tabStop.value();
int physical = 0;
int logical = 0;
int n = line.size();
@@ -8668,8 +8653,8 @@ Column FakeVimHandler::Private::indentation(const QString &line) const
QString FakeVimHandler::Private::tabExpand(int n) const
{
- int ts = config(ConfigTabStop).toInt();
- if (hasConfig(ConfigExpandTab) || ts < 1)
+ int ts = s.tabStop.value();
+ if (s.expandTab.value() || ts < 1)
return QString(n, ' ');
return QString(n / ts, '\t')
+ QString(n % ts, ' ');
@@ -8677,10 +8662,10 @@ QString FakeVimHandler::Private::tabExpand(int n) const
void FakeVimHandler::Private::insertAutomaticIndentation(bool goingDown, bool forceAutoIndent)
{
- if (!forceAutoIndent && !hasConfig(ConfigAutoIndent) && !hasConfig(ConfigSmartIndent))
+ if (!forceAutoIndent && !s.autoIndent.value() && !s.smartIndent.value())
return;
- if (hasConfig(ConfigSmartIndent)) {
+ if (s.smartIndent.value()) {
QTextBlock bl = block();
Range range(bl.position(), bl.position());
indentText(range, '\n');
@@ -8699,7 +8684,7 @@ void FakeVimHandler::Private::insertAutomaticIndentation(bool goingDown, bool fo
void FakeVimHandler::Private::handleStartOfLine()
{
- if (hasConfig(ConfigStartOfLine))
+ if (s.startOfLine.value())
moveToFirstNonBlankOnLine();
}
@@ -9296,7 +9281,7 @@ void FakeVimHandler::Private::getRegisterType(int *reg, bool *isClipboard, bool
*reg = c.toLower().unicode();
if (c == '"') {
- QStringList list = config(ConfigClipboard).toString().split(',');
+ QStringList list = s.clipboard.value().split(',');
clipboard = list.contains("unnamedplus");
selection = list.contains("unnamed");
} else if (c == '+') {
@@ -9350,7 +9335,7 @@ void FakeVimHandler::updateGlobalMarksFilenames(const QString &oldFileName, cons
bool FakeVimHandler::eventFilter(QObject *ob, QEvent *ev)
{
#ifndef FAKEVIM_STANDALONE
- if (!theFakeVimSetting(ConfigUseFakeVim)->value().toBool())
+ if (!fakeVimSettings()->useFakeVim.value())
return QObject::eventFilter(ob, ev);
#endif
diff --git a/src/plugins/fakevim/fakevimoptions.ui b/src/plugins/fakevim/fakevimoptions.ui
deleted file mode 100644
index b9f7a1845fd..00000000000
--- a/src/plugins/fakevim/fakevimoptions.ui
+++ /dev/null
@@ -1,443 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>FakeVim::Internal::FakeVimOptionPage</class>
- <widget class="QWidget" name="FakeVim::Internal::FakeVimOptionPage">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>580</width>
- <height>568</height>
- </rect>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout_2">
- <item>
- <widget class="QCheckBox" name="checkBoxUseFakeVim">
- <property name="text">
- <string>Use FakeVim</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QGroupBox" name="behaviorBox">
- <property name="title">
- <string>Vim Behavior</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <layout class="QGridLayout" name="gridLayout_3">
- <item row="2" column="1">
- <widget class="QCheckBox" name="checkBoxIgnoreCase">
- <property name="text">
- <string>Use ignorecase</string>
- </property>
- </widget>
- </item>
- <item row="3" column="1">
- <widget class="QCheckBox" name="checkBoxSmartCase">
- <property name="text">
- <string>Use smartcase</string>
- </property>
- </widget>
- </item>
- <item row="6" column="0">
- <widget class="QCheckBox" name="checkBoxStartOfLine">
- <property name="text">
- <string>Start of line</string>
- </property>
- </widget>
- </item>
- <item row="3" column="0">
- <widget class="QCheckBox" name="checkBoxSmartTab">
- <property name="text">
- <string>Smart tabulators</string>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QCheckBox" name="checkBoxUseCoreSearch">
- <property name="text">
- <string>Use search dialog</string>
- </property>
- </widget>
- </item>
- <item row="7" column="1">
- <widget class="QCheckBox" name="checkBoxRelativeNumber">
- <property name="toolTip">
- <string>Displays line numbers relative to the line containing text cursor.</string>
- </property>
- <property name="text">
- <string>Show line numbers relative to cursor</string>
- </property>
- </widget>
- </item>
- <item row="4" column="0">
- <widget class="QCheckBox" name="checkBoxHlSearch">
- <property name="text">
- <string>Highlight search results</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QCheckBox" name="checkBoxIncSearch">
- <property name="text">
- <string>Incremental search</string>
- </property>
- </widget>
- </item>
- <item row="5" column="1">
- <widget class="QCheckBox" name="checkBoxShowMarks">
- <property name="text">
- <string>Show position of text marks</string>
- </property>
- </widget>
- </item>
- <item row="6" column="1">
- <widget class="QCheckBox" name="checkBoxPassControlKey">
- <property name="toolTip">
- <string>Does not interpret key sequences like Ctrl-S in FakeVim but handles them as regular shortcuts. This gives easier access to core functionality at the price of losing some features of FakeVim.</string>
- </property>
- <property name="text">
- <string>Pass control key</string>
- </property>
- </widget>
- </item>
- <item row="0" column="0">
- <widget class="QCheckBox" name="checkBoxAutoIndent">
- <property name="text">
- <string>Automatic indentation</string>
- </property>
- </widget>
- </item>
- <item row="5" column="0">
- <widget class="QCheckBox" name="checkBoxShowCmd">
- <property name="text">
- <string>Show partial command</string>
- </property>
- </widget>
- </item>
- <item row="8" column="0">
- <widget class="QCheckBox" name="checkBoxBlinkingCursor">
- <property name="text">
- <string>Blinking cursor</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <widget class="QCheckBox" name="checkBoxExpandTab">
- <property name="text">
- <string>Expand tabulators</string>
- </property>
- </widget>
- </item>
- <item row="4" column="1">
- <widget class="QCheckBox" name="checkBoxWrapScan">
- <property name="text">
- <string>Use wrapscan</string>
- </property>
- </widget>
- </item>
- <item row="7" column="0">
- <widget class="QCheckBox" name="checkBoxPassKeys">
- <property name="toolTip">
- <string>Does not interpret some key presses in insert mode so that code can be properly completed and expanded.</string>
- </property>
- <property name="text">
- <string>Pass keys in insert mode</string>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QCheckBox" name="checkBoxSmartIndent">
- <property name="text">
- <string>Smart indentation</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <widget class="QGroupBox" name="groupBox">
- <property name="title">
- <string>Plugin Emulation</string>
- </property>
- <layout class="QGridLayout" name="gridLayout">
- <item row="3" column="0">
- <widget class="QCheckBox" name="checkBoxExchange">
- <property name="text">
- <string>vim-exchange</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <widget class="QCheckBox" name="checkBoxArgTextObj">
- <property name="text">
- <string>argtextobj.vim</string>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QCheckBox" name="checkBoxReplaceWithRegister">
- <property name="text">
- <string>ReplaceWithRegister</string>
- </property>
- </widget>
- </item>
- <item row="0" column="0">
- <widget class="QCheckBox" name="checkBoxVimCommentary">
- <property name="text">
- <string>vim-commentary</string>
- </property>
- <property name="checked">
- <bool>false</bool>
- </property>
- </widget>
- </item>
- <item row="4" column="0">
- <widget class="QCheckBox" name="checkBoxVimSurround">
- <property name="text">
- <string>vim-surround</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_5">
- <item>
- <widget class="QLabel" name="labelShiftWidth">
- <property name="text">
- <string>Shift width:</string>
- </property>
- <property name="buddy">
- <cstring>spinBoxShiftWidth</cstring>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QSpinBox" name="spinBoxShiftWidth">
- <property name="minimum">
- <number>1</number>
- </property>
- <property name="maximum">
- <number>80</number>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer_3">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QLabel" name="labelTabulator">
- <property name="toolTip">
- <string>Vim tabstop option.</string>
- </property>
- <property name="text">
- <string>Tabulator size:</string>
- </property>
- <property name="buddy">
- <cstring>spinBoxTabStop</cstring>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QSpinBox" name="spinBoxTabStop">
- <property name="minimum">
- <number>1</number>
- </property>
- <property name="maximum">
- <number>80</number>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer_4">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QLabel" name="labelScrollOff">
- <property name="text">
- <string>Scroll offset:</string>
- </property>
- <property name="buddy">
- <cstring>spinBoxScrollOff</cstring>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QSpinBox" name="spinBoxScrollOff"/>
- </item>
- <item>
- <spacer name="horizontalSpacer_2">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </item>
- <item>
- <layout class="QFormLayout" name="formLayout">
- <property name="fieldGrowthPolicy">
- <enum>QFormLayout::ExpandingFieldsGrow</enum>
- </property>
- <item row="0" column="0">
- <widget class="QLabel" name="labelBackspace">
- <property name="text">
- <string>Backspace:</string>
- </property>
- <property name="buddy">
- <cstring>lineEditBackspace</cstring>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QLineEdit" name="lineEditBackspace"/>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="labelIsKeyword">
- <property name="text">
- <string>Keyword characters:</string>
- </property>
- <property name="buddy">
- <cstring>lineEditIsKeyword</cstring>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QLineEdit" name="lineEditIsKeyword"/>
- </item>
- <item row="2" column="0">
- <widget class="QCheckBox" name="checkBoxReadVimRc">
- <property name="text">
- <string>Read .vimrc from location:</string>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="Utils::PathChooser" name="pathChooserVimRcPath" native="true"/>
- </item>
- </layout>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QPushButton" name="pushButtonCopyTextEditorSettings">
- <property name="text">
- <string>Copy Text Editor Settings</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="pushButtonSetQtStyle">
- <property name="text">
- <string>Set Qt Style</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="pushButtonSetPlainStyle">
- <property name="text">
- <string>Set Plain Style</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </item>
- <item>
- <spacer name="verticalSpacer">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </widget>
- </item>
- </layout>
- </widget>
- <customwidgets>
- <customwidget>
- <class>Utils::PathChooser</class>
- <extends>QWidget</extends>
- <header location="global">utils/pathchooser.h</header>
- <container>1</container>
- </customwidget>
- </customwidgets>
- <tabstops>
- <tabstop>checkBoxUseFakeVim</tabstop>
- <tabstop>checkBoxAutoIndent</tabstop>
- <tabstop>checkBoxSmartIndent</tabstop>
- <tabstop>checkBoxExpandTab</tabstop>
- <tabstop>checkBoxSmartTab</tabstop>
- <tabstop>checkBoxHlSearch</tabstop>
- <tabstop>checkBoxShowCmd</tabstop>
- <tabstop>checkBoxStartOfLine</tabstop>
- <tabstop>checkBoxPassKeys</tabstop>
- <tabstop>checkBoxIncSearch</tabstop>
- <tabstop>checkBoxUseCoreSearch</tabstop>
- <tabstop>checkBoxIgnoreCase</tabstop>
- <tabstop>checkBoxSmartCase</tabstop>
- <tabstop>checkBoxWrapScan</tabstop>
- <tabstop>checkBoxShowMarks</tabstop>
- <tabstop>checkBoxPassControlKey</tabstop>
- <tabstop>checkBoxRelativeNumber</tabstop>
- <tabstop>spinBoxShiftWidth</tabstop>
- <tabstop>spinBoxTabStop</tabstop>
- <tabstop>spinBoxScrollOff</tabstop>
- <tabstop>lineEditBackspace</tabstop>
- <tabstop>lineEditIsKeyword</tabstop>
- <tabstop>checkBoxReadVimRc</tabstop>
- <tabstop>pathChooserVimRcPath</tabstop>
- <tabstop>pushButtonCopyTextEditorSettings</tabstop>
- <tabstop>pushButtonSetQtStyle</tabstop>
- <tabstop>pushButtonSetPlainStyle</tabstop>
- </tabstops>
- <resources/>
- <connections/>
-</ui>
diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp
index 72f19334e4e..cd612e3371a 100644
--- a/src/plugins/fakevim/fakevimplugin.cpp
+++ b/src/plugins/fakevim/fakevimplugin.cpp
@@ -28,7 +28,6 @@
#include "fakevimactions.h"
#include "fakevimhandler.h"
#include "fakevimtr.h"
-#include "ui_fakevimoptions.h"
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
@@ -67,26 +66,31 @@
#include <texteditor/codeassist/assistinterface.h>
#include <texteditor/codeassist/genericproposal.h>
+#include <utils/aspects.h>
#include <utils/fancylineedit.h>
#include <utils/hostosinfo.h>
-#include <utils/qtcassert.h>
+#include <utils/layoutbuilder.h>
#include <utils/pathchooser.h>
#include <utils/qtcassert.h>
-#include <utils/savedaction.h>
+#include <utils/qtcassert.h>
#include <utils/stylehelper.h>
#include <cpptools/cpptoolsconstants.h>
#include <extensionsystem/pluginmanager.h>
+#include <QAction>
#include <QAbstractTableModel>
#include <QDebug>
#include <QFile>
+#include <QGridLayout>
+#include <QGroupBox>
#include <QGuiApplication>
#include <QItemDelegate>
#include <QPainter>
#include <QPlainTextEdit>
#include <QPointer>
+#include <QPushButton>
#include <QRegularExpression>
#include <QScrollBar>
#include <QSettings>
@@ -380,129 +384,149 @@ private:
void updateVimRcWidgets();
QPointer<QWidget> m_widget;
- Ui::FakeVimOptionPage m_ui;
- SavedActionSet m_group;
};
QWidget *FakeVimOptionPage::widget()
{
if (!m_widget) {
m_widget = new QWidget;
- m_ui.setupUi(m_widget);
- const QString vimrcDefault = QLatin1String(HostOsInfo::isAnyUnixHost()
- ? "$HOME/.vimrc" : "%USERPROFILE%\\_vimrc");
- m_ui.pathChooserVimRcPath->setExpectedKind(PathChooser::File);
- m_ui.pathChooserVimRcPath->lineEdit()->setToolTip(Tr::tr("Keep empty to use the default path, i.e. "
- "%USERPROFILE%\\_vimrc on Windows, ~/.vimrc otherwise."));
- m_ui.pathChooserVimRcPath->lineEdit()->setPlaceholderText(Tr::tr("Default: %1").arg(vimrcDefault));
-
- m_group.clear();
- m_group.insert(theFakeVimSetting(ConfigUseFakeVim), m_ui.checkBoxUseFakeVim);
- m_group.insert(theFakeVimSetting(ConfigReadVimRc), m_ui.checkBoxReadVimRc);
- m_group.insert(theFakeVimSetting(ConfigVimRcPath), m_ui.pathChooserVimRcPath);
-
- m_group.insert(theFakeVimSetting(ConfigExpandTab), m_ui.checkBoxExpandTab);
- m_group.insert(theFakeVimSetting(ConfigHlSearch), m_ui.checkBoxHlSearch);
- m_group.insert(theFakeVimSetting(ConfigShiftWidth), m_ui.spinBoxShiftWidth);
- m_group.insert(theFakeVimSetting(ConfigShowMarks), m_ui.checkBoxShowMarks);
-
- m_group.insert(theFakeVimSetting(ConfigSmartTab), m_ui.checkBoxSmartTab);
- m_group.insert(theFakeVimSetting(ConfigStartOfLine), m_ui.checkBoxStartOfLine);
- m_group.insert(theFakeVimSetting(ConfigPassKeys), m_ui.checkBoxPassKeys);
- m_group.insert(theFakeVimSetting(ConfigTabStop), m_ui.spinBoxTabStop);
- m_group.insert(theFakeVimSetting(ConfigScrollOff), m_ui.spinBoxScrollOff);
- m_group.insert(theFakeVimSetting(ConfigBackspace), m_ui.lineEditBackspace);
- m_group.insert(theFakeVimSetting(ConfigIsKeyword), m_ui.lineEditIsKeyword);
-
- m_group.insert(theFakeVimSetting(ConfigPassControlKey), m_ui.checkBoxPassControlKey);
- m_group.insert(theFakeVimSetting(ConfigAutoIndent), m_ui.checkBoxAutoIndent);
- m_group.insert(theFakeVimSetting(ConfigSmartIndent), m_ui.checkBoxSmartIndent);
-
- m_group.insert(theFakeVimSetting(ConfigIncSearch), m_ui.checkBoxIncSearch);
- m_group.insert(theFakeVimSetting(ConfigUseCoreSearch), m_ui.checkBoxUseCoreSearch);
- m_group.insert(theFakeVimSetting(ConfigSmartCase), m_ui.checkBoxSmartCase);
- m_group.insert(theFakeVimSetting(ConfigIgnoreCase), m_ui.checkBoxIgnoreCase);
- m_group.insert(theFakeVimSetting(ConfigWrapScan), m_ui.checkBoxWrapScan);
-
- m_group.insert(theFakeVimSetting(ConfigShowCmd), m_ui.checkBoxShowCmd);
-
- m_group.insert(theFakeVimSetting(ConfigRelativeNumber), m_ui.checkBoxRelativeNumber);
- m_group.insert(theFakeVimSetting(ConfigBlinkingCursor), m_ui.checkBoxBlinkingCursor);
-
- m_group.insert(theFakeVimSetting(ConfigEmulateVimCommentary), m_ui.checkBoxVimCommentary);
- m_group.insert(theFakeVimSetting(ConfigEmulateReplaceWithRegister), m_ui.checkBoxReplaceWithRegister);
- m_group.insert(theFakeVimSetting(ConfigEmulateExchange), m_ui.checkBoxExchange);
- m_group.insert(theFakeVimSetting(ConfigEmulateArgTextObj), m_ui.checkBoxArgTextObj);
- m_group.insert(theFakeVimSetting(ConfigEmulateSurround), m_ui.checkBoxVimSurround);
-
- connect(m_ui.pushButtonCopyTextEditorSettings, &QAbstractButton::clicked,
+
+ auto copyTextEditorSettings = new QPushButton(tr("Copy Text Editor Settings"));
+ auto setQtStyle = new QPushButton(tr("Set Qt Style"));
+ auto setPlainStyle = new QPushButton(tr("Set Plain Style"));
+
+ using namespace Layouting;
+ FakeVimSettings &s = *fakeVimSettings();
+
+ Row bools {
+ Column {
+ s.autoIndent,
+ s.smartIndent,
+ s.expandTab,
+ s.smartTab,
+ s.hlSearch,
+ s.showCmd,
+ s.startOfLine,
+ s.passKeys,
+ s.blinkingCursor
+ },
+ Column {
+ s.incSearch,
+ s.useCoreSearch,
+ s.ignoreCase,
+ s.smartCase,
+ s.wrapScan,
+ s.showMarks,
+ s.passControlKey,
+ s.relativeNumber,
+ s.tildeOp
+ }
+ };
+
+ Row ints { s.shiftWidth, s.tabStop, s.scrollOff, Stretch() };
+
+ Column strings {
+ s.backspace,
+ s.isKeyword,
+ Row {s.readVimRc, s.vimRcPath}
+ };
+
+ Column {
+ s.useFakeVim,
+
+ Group {
+ bools,
+ ints,
+ strings
+ }.withTitle(tr("Vim Behavior")),
+
+ Group {
+ s.emulateVimCommentary,
+ s.emulateReplaceWithRegister,
+ s.emulateArgTextObj,
+ s.emulateExchange,
+ s.emulateSurround
+ }.withTitle(tr("Plugin Emulation")),
+
+ Row { copyTextEditorSettings, setQtStyle, setPlainStyle, Stretch() },
+ Stretch()
+
+ }.attachTo(m_widget);
+
+ connect(copyTextEditorSettings, &QAbstractButton::clicked,
this, &FakeVimOptionPage::copyTextEditorSettings);
- connect(m_ui.pushButtonSetQtStyle, &QAbstractButton::clicked,
+ connect(setQtStyle, &QAbstractButton::clicked,
this, &FakeVimOptionPage::setQtStyle);
- connect(m_ui.pushButtonSetPlainStyle, &QAbstractButton::clicked,
+ connect(setPlainStyle, &QAbstractButton::clicked,
this, &FakeVimOptionPage::setPlainStyle);
- connect(m_ui.checkBoxReadVimRc, &QCheckBox::stateChanged,
+ connect(&s.readVimRc, &FvBaseAspect::changed,
this, &FakeVimOptionPage::updateVimRcWidgets);
updateVimRcWidgets();
-
}
return m_widget;
}
void FakeVimOptionPage::apply()
{
- m_group.apply(ICore::settings());
+ FakeVimSettings &s = *fakeVimSettings();
+ s.apply();
+ s.writeSettings(ICore::settings());
}
void FakeVimOptionPage::finish()
{
- m_group.finish();
+ FakeVimSettings &s = *fakeVimSettings();
+ s.cancel();
delete m_widget;
}
void FakeVimOptionPage::copyTextEditorSettings()
{
+ FakeVimSettings &s = *fakeVimSettings();
TabSettings ts = TextEditorSettings::codeStyle()->tabSettings();
TypingSettings tps = TextEditorSettings::typingSettings();
- m_ui.checkBoxExpandTab->setChecked(ts.m_tabPolicy != TabSettings::TabsOnlyTabPolicy);
- m_ui.spinBoxTabStop->setValue(ts.m_tabSize);
- m_ui.spinBoxShiftWidth->setValue(ts.m_indentSize);
- m_ui.checkBoxSmartTab->setChecked(
- tps.m_smartBackspaceBehavior == TypingSettings::BackspaceFollowsPreviousIndents);
- m_ui.checkBoxAutoIndent->setChecked(true);
- m_ui.checkBoxSmartIndent->setChecked(tps.m_autoIndent);
- m_ui.checkBoxIncSearch->setChecked(true);
+ s.expandTab.setValue(ts.m_tabPolicy != TabSettings::TabsOnlyTabPolicy);
+ s.tabStop.setValue(ts.m_tabSize);
+ s.shiftWidth.setValue(ts.m_indentSize);
+ s.smartTab.setValue(tps.m_smartBackspaceBehavior
+ == TypingSettings::BackspaceFollowsPreviousIndents);
+ s.autoIndent.setValue(true);
+ s.smartIndent.setValue(tps.m_autoIndent);
+ s.incSearch.setValue(true);
}
void FakeVimOptionPage::setQtStyle()
{
- m_ui.checkBoxExpandTab->setChecked(true);
- m_ui.spinBoxTabStop->setValue(4);
- m_ui.spinBoxShiftWidth->setValue(4);
- m_ui.checkBoxSmartTab->setChecked(true);
- m_ui.checkBoxAutoIndent->setChecked(true);
- m_ui.checkBoxSmartIndent->setChecked(true);
- m_ui.checkBoxIncSearch->setChecked(true);
- m_ui.lineEditBackspace->setText("indent,eol,start");
- m_ui.checkBoxPassKeys->setChecked(true);
+ FakeVimSettings &s = *fakeVimSettings();
+ s.expandTab.setVolatileValue(true);
+ s.tabStop.setVolatileValue(4);
+ s.shiftWidth.setVolatileValue(4);
+ s.smartTab.setVolatileValue(true);
+ s.autoIndent.setVolatileValue(true);
+ s.smartIndent.setVolatileValue(true);
+ s.incSearch.setVolatileValue(true);
+ s.backspace.setVolatileValue(QString("indent,eol,start"));
+ s.passKeys.setVolatileValue(true);
}
void FakeVimOptionPage::setPlainStyle()
{
- m_ui.checkBoxExpandTab->setChecked(false);
- m_ui.spinBoxTabStop->setValue(8);
- m_ui.spinBoxShiftWidth->setValue(8);
- m_ui.checkBoxSmartTab->setChecked(false);
- m_ui.checkBoxAutoIndent->setChecked(false);
- m_ui.checkBoxSmartIndent->setChecked(false);
- m_ui.checkBoxIncSearch->setChecked(false);
- m_ui.lineEditBackspace->clear();
- m_ui.checkBoxPassKeys->setChecked(false);
+ FakeVimSettings &s = *fakeVimSettings();
+ s.expandTab.setVolatileValue(false);
+ s.tabStop.setVolatileValue(8);
+ s.shiftWidth.setVolatileValue(8);
+ s.smartTab.setVolatileValue(false);
+ s.autoIndent.setVolatileValue(false);
+ s.smartIndent.setVolatileValue(false);
+ s.incSearch.setVolatileValue(false);
+ s.backspace.setVolatileValue(QString());
+ s.passKeys.setVolatileValue(false);
}
void FakeVimOptionPage::updateVimRcWidgets()
{
- m_ui.pathChooserVimRcPath->setEnabled(m_ui.checkBoxReadVimRc->isChecked());
+ FakeVimSettings &s = *fakeVimSettings();
+ s.vimRcPath.setEnabled(s.readVimRc.value());
}
@@ -531,13 +555,13 @@ public:
void documentRenamed(Core::IDocument *document, const QString &oldName, const QString &newName);
void renameFileNameInEditors(const QString &oldName, const QString &newName);
- void setUseFakeVim(const QVariant &value);
+ void setUseFakeVim(bool on);
void setUseFakeVimInternal(bool on);
void quitFakeVim();
void fold(FakeVimHandler *handler, int depth, bool fold);
void maybeReadVimRc();
- void setShowRelativeLineNumbers(const QVariant &value);
- void updateCursorBlinking(const QVariant &value);
+ void setShowRelativeLineNumbers(bool on);
+ void setCursorBlinking(bool on);
void resetCommandBuffer();
void showCommandBuffer(FakeVimHandler *handler, const QString &contents,
@@ -1199,8 +1223,13 @@ bool FakeVimPluginPrivate::initialize()
*/
readSettings();
+ // Vimrc can break test so don't source it if running tests.
+ if (!ExtensionSystem::PluginManager::testRunRequested())
+ maybeReadVimRc();
+
Command *cmd = nullptr;
- cmd = ActionManager::registerAction(theFakeVimSetting(ConfigUseFakeVim)->action(),
+
+ cmd = ActionManager::registerAction(fakeVimSettings()->useFakeVim.action(),
INSTALL_HANDLER, Context(Core::Constants::C_GLOBAL), true);
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+Shift+Y,Meta+Shift+Y")
: Tr::tr("Alt+Y,Alt+Y")));
@@ -1238,16 +1267,17 @@ bool FakeVimPluginPrivate::initialize()
connect(DocumentManager::instance(), &DocumentManager::documentRenamed,
this, &FakeVimPluginPrivate::documentRenamed);
- connect(theFakeVimSetting(ConfigUseFakeVim), &SavedAction::valueChanged,
+ FakeVimSettings &s = *fakeVimSettings();
+ connect(&s.useFakeVim, &FvBoolAspect::valueChanged,
this, &FakeVimPluginPrivate::setUseFakeVim);
- connect(theFakeVimSetting(ConfigReadVimRc), &SavedAction::valueChanged,
+ connect(&s.readVimRc, &FvBaseAspect::changed,
this, &FakeVimPluginPrivate::maybeReadVimRc);
- connect(theFakeVimSetting(ConfigVimRcPath), &SavedAction::valueChanged,
+ connect(&s.vimRcPath, &FvBaseAspect::changed,
this, &FakeVimPluginPrivate::maybeReadVimRc);
- connect(theFakeVimSetting(ConfigRelativeNumber), &SavedAction::valueChanged,
+ connect(&s.relativeNumber, &FvBoolAspect::valueChanged,
this, &FakeVimPluginPrivate::setShowRelativeLineNumbers);
- connect(theFakeVimSetting(ConfigBlinkingCursor), &SavedAction::valueChanged,
- this, &FakeVimPluginPrivate::updateCursorBlinking);
+ connect(&s.blinkingCursor, &FvBoolAspect::valueChanged,
+ this, &FakeVimPluginPrivate::setCursorBlinking);
// Delayed operations.
connect(this, &FakeVimPluginPrivate::delayedQuitRequested,
@@ -1255,12 +1285,7 @@ bool FakeVimPluginPrivate::initialize()
connect(this, &FakeVimPluginPrivate::delayedQuitAllRequested,
this, &FakeVimPluginPrivate::handleDelayedQuitAll, Qt::QueuedConnection);
- // Vimrc can break test so don't source it if running tests.
- if (!ExtensionSystem::PluginManager::testRunRequested())
- maybeReadVimRc();
- // << "MODE: " << theFakeVimSetting(ConfigUseFakeVim)->value();
-
- updateCursorBlinking(theFakeVimSetting(ConfigBlinkingCursor)->value());
+ setCursorBlinking(s.blinkingCursor.value());
return true;
}
@@ -1271,7 +1296,7 @@ void FakeVimPluginPrivate::userActionTriggered(int key)
FakeVimHandler *handler = m_editorToHandler[editor];
if (handler) {
// If disabled, enable FakeVim mode just for single user command.
- bool enableFakeVim = !theFakeVimSetting(ConfigUseFakeVim)->value().toBool();
+ bool enableFakeVim = !fakeVimSettings()->useFakeVim.value();
if (enableFakeVim)
setUseFakeVimInternal(true);
@@ -1287,9 +1312,9 @@ void FakeVimPluginPrivate::createRelativeNumberWidget(IEditor *editor)
{
if (auto textEditor = TextEditorWidget::fromEditor(editor)) {
auto relativeNumbers = new RelativeNumbersColumn(textEditor);
- connect(theFakeVimSetting(ConfigRelativeNumber), &SavedAction::valueChanged,
+ connect(&fakeVimSettings()->relativeNumber, &FvBaseAspect::changed,
relativeNumbers, &QObject::deleteLater);
- connect(theFakeVimSetting(ConfigUseFakeVim), &SavedAction::valueChanged,
+ connect(&fakeVimSettings()->useFakeVim, &FvBaseAspect::changed,
relativeNumbers, &QObject::deleteLater);
relativeNumbers->show();
}
@@ -1298,14 +1323,14 @@ void FakeVimPluginPrivate::createRelativeNumberWidget(IEditor *editor)
void FakeVimPluginPrivate::writeSettings()
{
QSettings *settings = ICore::settings();
- theFakeVimSettings()->writeSettings(settings);
+ fakeVimSettings()->writeSettings(settings);
}
void FakeVimPluginPrivate::readSettings()
{
QSettings *settings = ICore::settings();
- theFakeVimSettings()->readSettings(settings);
+ fakeVimSettings()->readSettings(settings);
m_exCommandMap = m_defaultExCommandMap;
int size = settings->beginReadArray(exCommandMapGroup);
@@ -1333,9 +1358,9 @@ void FakeVimPluginPrivate::maybeReadVimRc()
//qDebug() << theFakeVimSetting(ConfigReadVimRc)
// << theFakeVimSetting(ConfigReadVimRc)->value();
//qDebug() << theFakeVimSetting(ConfigShiftWidth)->value();
- if (!theFakeVimSetting(ConfigReadVimRc)->value().toBool())
+ if (!fakeVimSettings()->readVimRc.value())
return;
- QString fileName = theFakeVimSetting(ConfigVimRcPath)->value().toString();
+ QString fileName = fakeVimSettings()->vimRcPath.value();
if (fileName.isEmpty()) {
fileName = QStandardPaths::writableLocation(QStandardPaths::HomeLocation)
+ QLatin1String(HostOsInfo::isWindowsHost() ? "/_vimrc" : "/.vimrc");
@@ -1642,9 +1667,9 @@ void FakeVimPluginPrivate::editorOpened(IEditor *editor)
return;
TabSettings tabSettings;
- tabSettings.m_indentSize = theFakeVimSetting(ConfigShiftWidth)->value().toInt();
- tabSettings.m_tabSize = theFakeVimSetting(ConfigTabStop)->value().toInt();
- tabSettings.m_tabPolicy = theFakeVimSetting(ConfigExpandTab)->value().toBool()
+ tabSettings.m_indentSize = fakeVimSettings()->shiftWidth.value();
+ tabSettings.m_tabSize = fakeVimSettings()->tabStop.value();
+ tabSettings.m_tabPolicy = fakeVimSettings()->expandTab.value()
? TabSettings::SpacesOnlyTabPolicy : TabSettings::TabsOnlyTabPolicy;
tabSettings.m_continuationAlignBehavior =
tew->textDocument()->tabSettings().m_continuationAlignBehavior;
@@ -1847,11 +1872,11 @@ void FakeVimPluginPrivate::editorOpened(IEditor *editor)
handler->installEventFilter();
// pop up the bar
- if (theFakeVimSetting(ConfigUseFakeVim)->value().toBool()) {
+ if (fakeVimSettings()->useFakeVim.value()) {
resetCommandBuffer();
handler->setupWidget();
- if (theFakeVimSetting(ConfigRelativeNumber)->value().toBool())
+ if (fakeVimSettings()->relativeNumber.value())
createRelativeNumberWidget(editor);
}
}
@@ -1888,14 +1913,13 @@ void FakeVimPluginPrivate::renameFileNameInEditors(const QString &oldName, const
}
}
-void FakeVimPluginPrivate::setUseFakeVim(const QVariant &value)
+void FakeVimPluginPrivate::setUseFakeVim(bool on)
{
- //qDebug() << "SET USE FAKEVIM" << value;
- bool on = value.toBool();
+ //qDebug() << "SET USE FAKEVIM" << on;
Find::setUseFakeVim(on);
setUseFakeVimInternal(on);
- setShowRelativeLineNumbers(theFakeVimSetting(ConfigRelativeNumber)->value());
- updateCursorBlinking(theFakeVimSetting(ConfigBlinkingCursor)->value());
+ setShowRelativeLineNumbers(fakeVimSettings()->relativeNumber.value());
+ setCursorBlinking(fakeVimSettings()->blinkingCursor.value());
}
void FakeVimPluginPrivate::setUseFakeVimInternal(bool on)
@@ -1918,20 +1942,20 @@ void FakeVimPluginPrivate::setUseFakeVimInternal(bool on)
}
}
-void FakeVimPluginPrivate::setShowRelativeLineNumbers(const QVariant &value)
+void FakeVimPluginPrivate::setShowRelativeLineNumbers(bool on)
{
- if (value.toBool() && theFakeVimSetting(ConfigUseFakeVim)->value().toBool()) {
+ if (on && fakeVimSettings()->useFakeVim.value()) {
foreach (IEditor *editor, m_editorToHandler.keys())
createRelativeNumberWidget(editor);
}
}
-void FakeVimPluginPrivate::updateCursorBlinking(const QVariant &value)
+void FakeVimPluginPrivate::setCursorBlinking(bool on)
{
if (m_savedCursorFlashTime == 0)
m_savedCursorFlashTime = QGuiApplication::styleHints()->cursorFlashTime();
- bool blink = value.toBool() || !theFakeVimSetting(ConfigUseFakeVim)->value().toBool();
+ const bool blink = on || !fakeVimSettings()->useFakeVim.value();
QGuiApplication::styleHints()->setCursorFlashTime(blink ? m_savedCursorFlashTime : 0);
}
@@ -2062,7 +2086,7 @@ void FakeVimPluginPrivate::handleDelayedQuitAll(bool forced)
void FakeVimPluginPrivate::quitFakeVim()
{
- theFakeVimSetting(ConfigUseFakeVim)->setValue(false);
+ fakeVimSettings()->useFakeVim.setValue(false);
}
void FakeVimPluginPrivate::resetCommandBuffer()