From 50f93710b71ea6c27d46d867b37add378dde72e9 Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 26 Feb 2021 17:55:55 +0100 Subject: FakeVim: Aspectify settings Change-Id: Ic73edce82e192779ed3efe86a5cb747a52d94d36 Reviewed-by: Christian Stenger --- src/plugins/fakevim/CMakeLists.txt | 1 - src/plugins/fakevim/fakevim.pro | 3 +- src/plugins/fakevim/fakevim.qbs | 1 - src/plugins/fakevim/fakevimactions.cpp | 203 +++++++-------- src/plugins/fakevim/fakevimactions.h | 164 ++++++------ src/plugins/fakevim/fakevimhandler.cpp | 127 +++++----- src/plugins/fakevim/fakevimoptions.ui | 443 --------------------------------- src/plugins/fakevim/fakevimplugin.cpp | 272 +++++++++++--------- 8 files changed, 400 insertions(+), 814 deletions(-) delete mode 100644 src/plugins/fakevim/fakevimoptions.ui 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 #include #include @@ -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()); - 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(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 +# include #endif #include #include #include #include -#include #include 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 m_items; - QHash m_nameToCode; - QHash m_codeToName; + QHash m_nameToAspect; + QHash 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 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(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 @@ - - - FakeVim::Internal::FakeVimOptionPage - - - - 0 - 0 - 580 - 568 - - - - - - - Use FakeVim - - - - - - - Vim Behavior - - - - - - - - Use ignorecase - - - - - - - Use smartcase - - - - - - - Start of line - - - - - - - Smart tabulators - - - - - - - Use search dialog - - - - - - - Displays line numbers relative to the line containing text cursor. - - - Show line numbers relative to cursor - - - - - - - Highlight search results - - - - - - - Incremental search - - - - - - - Show position of text marks - - - - - - - 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. - - - Pass control key - - - - - - - Automatic indentation - - - - - - - Show partial command - - - - - - - Blinking cursor - - - - - - - Expand tabulators - - - - - - - Use wrapscan - - - - - - - Does not interpret some key presses in insert mode so that code can be properly completed and expanded. - - - Pass keys in insert mode - - - - - - - Smart indentation - - - - - - - - - Plugin Emulation - - - - - - vim-exchange - - - - - - - argtextobj.vim - - - - - - - ReplaceWithRegister - - - - - - - vim-commentary - - - false - - - - - - - vim-surround - - - - - - - - - - - - Shift width: - - - spinBoxShiftWidth - - - - - - - 1 - - - 80 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Vim tabstop option. - - - Tabulator size: - - - spinBoxTabStop - - - - - - - 1 - - - 80 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Scroll offset: - - - spinBoxScrollOff - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - QFormLayout::ExpandingFieldsGrow - - - - - Backspace: - - - lineEditBackspace - - - - - - - - - - Keyword characters: - - - lineEditIsKeyword - - - - - - - - - - Read .vimrc from location: - - - - - - - - - - - - - - Copy Text Editor Settings - - - - - - - Set Qt Style - - - - - - - Set Plain Style - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - Utils::PathChooser - QWidget -
utils/pathchooser.h
- 1 -
-
- - checkBoxUseFakeVim - checkBoxAutoIndent - checkBoxSmartIndent - checkBoxExpandTab - checkBoxSmartTab - checkBoxHlSearch - checkBoxShowCmd - checkBoxStartOfLine - checkBoxPassKeys - checkBoxIncSearch - checkBoxUseCoreSearch - checkBoxIgnoreCase - checkBoxSmartCase - checkBoxWrapScan - checkBoxShowMarks - checkBoxPassControlKey - checkBoxRelativeNumber - spinBoxShiftWidth - spinBoxTabStop - spinBoxScrollOff - lineEditBackspace - lineEditIsKeyword - checkBoxReadVimRc - pathChooserVimRcPath - pushButtonCopyTextEditorSettings - pushButtonSetQtStyle - pushButtonSetPlainStyle - - - -
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 #include @@ -67,26 +66,31 @@ #include #include +#include #include #include -#include +#include #include #include -#include +#include #include #include #include +#include #include #include #include +#include +#include #include #include #include #include #include +#include #include #include #include @@ -380,129 +384,149 @@ private: void updateVimRcWidgets(); QPointer 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() -- cgit v1.2.3