diff options
author | hjk <hjk@qt.io> | 2018-01-26 14:27:32 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2018-01-26 17:27:15 +0000 |
commit | 5250959bd944082a8bc44edec1fa20fb3dec533a (patch) | |
tree | 93fb8bdb4ba20c262ec7223d2694f8cbaeea7362 /src/plugins/fakevim | |
parent | 268efa4a0bc45b331d2f989690124af0860a98ff (diff) | |
download | qt-creator-5250959bd944082a8bc44edec1fa20fb3dec533a.tar.gz |
FakeVim: Reorganize internal class dependencies
Initially, this was just meant to remove the nowadays unneeded
object pool registrations, but some of the internal encapsalization
is not much more than line noise. So do what most other plugins do:
Keep a global pointer to most of the 'singleton' data, instead of
passing around one value that will never be different.
Change-Id: I24bf02d1ffa53c8f0d4890db3579a434b1233d42
Reviewed-by: Lukas Holecek <hluk@email.cz>
Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/plugins/fakevim')
-rw-r--r-- | src/plugins/fakevim/fakevimplugin.cpp | 496 | ||||
-rw-r--r-- | src/plugins/fakevim/fakevimplugin.h | 2 |
2 files changed, 206 insertions, 292 deletions
diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index 4f0b90bec3..782c33ba77 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -110,6 +110,8 @@ const char SETTINGS_ID[] = "A.FakeVim.General"; const char SETTINGS_EX_CMDS_ID[] = "B.FakeVim.ExCommands"; const char SETTINGS_USER_CMDS_ID[] = "C.FakeVim.UserCommands"; +static class FakeVimPluginPrivate *dd = nullptr; + class MiniBuffer : public QStackedWidget { Q_OBJECT @@ -181,11 +183,11 @@ public: } if (m_eventFilter != eventFilter) { - if (m_eventFilter != 0) { + if (m_eventFilter != nullptr) { m_edit->removeEventFilter(m_eventFilter); - disconnect(this, &MiniBuffer::edited, 0, 0); + disconnect(this, &MiniBuffer::edited, nullptr, nullptr); } - if (eventFilter != 0) { + if (eventFilter != nullptr) { m_edit->installEventFilter(eventFilter); connect(this, &MiniBuffer::edited, eventFilter, &FakeVimHandler::miniBufferTextEdited); @@ -353,8 +355,6 @@ typedef QMap<int, QString> UserCommandMap; class FakeVimOptionPage : public IOptionsPage { - Q_OBJECT - public: FakeVimOptionPage() { @@ -393,60 +393,36 @@ QWidget *FakeVimOptionPage::widget() 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(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); connect(m_ui.pushButtonCopyTextEditorSettings, &QAbstractButton::clicked, this, &FakeVimOptionPage::copyTextEditorSettings); @@ -518,7 +494,99 @@ void FakeVimOptionPage::updateVimRcWidgets() m_ui.pathChooserVimRcPath->setEnabled(m_ui.checkBoxReadVimRc->isChecked()); } -//const char *FAKEVIM_CONTEXT = "FakeVim"; + +/////////////////////////////////////////////////////////////////////// +// +// FakeVimPluginPrivate +// +/////////////////////////////////////////////////////////////////////// + +class FakeVimPluginRunData; + +class FakeVimPluginPrivate : public QObject +{ + Q_OBJECT + +public: + FakeVimPluginPrivate(); + + bool initialize(); + + void editorOpened(Core::IEditor *); + void editorAboutToClose(Core::IEditor *); + void currentEditorAboutToChange(Core::IEditor *); + + void allDocumentsRenamed(const QString &oldName, const QString &newName); + 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 setUseFakeVimInternal(bool on); + void quitFakeVim(); + void triggerCompletions(FakeVimHandler *handler); + void triggerSimpleCompletions(FakeVimHandler *handler, const QString &needle, bool forward); + void windowCommand(FakeVimHandler *handler, const QString &key, int count); + void find(bool reverse); + void findNext(bool reverse); + void foldToggle(FakeVimHandler *handler, int depth); + void foldAll(FakeVimHandler *handler, bool fold); + void fold(FakeVimHandler *handler, int depth, bool fold); + void foldGoTo(FakeVimHandler *handler, int count, bool current); + void jumpToGlobalMark(FakeVimHandler *, QChar mark, bool backTickMode, const QString &fileName); + void maybeReadVimRc(); + void disableBlockSelection(FakeVimHandler *handler); + void setBlockSelection(FakeVimHandler *handler, const QTextCursor &cursor); + void blockSelection(FakeVimHandler *handler, QTextCursor *cursor); + void hasBlockSelection(FakeVimHandler *handler, bool *on); + void setShowRelativeLineNumbers(const QVariant &value); + + void resetCommandBuffer(); + void showCommandBuffer(FakeVimHandler *handler, const QString &contents, + int cursorPos, int anchorPos, int messageLevel); + void showExtraInformation(FakeVimHandler *handler, const QString &msg); + void changeSelection(FakeVimHandler *handler, const QList<QTextEdit::ExtraSelection> &selections); + void highlightMatches(FakeVimHandler *handler, const QString &needle); + void moveToMatchingParenthesis(FakeVimHandler *handler, bool *moved, bool *forward, QTextCursor *cursor); + void checkForElectricCharacter(FakeVimHandler *handler, bool *result, QChar c); + void indentRegion(FakeVimHandler *handler, int beginBlock, int endBlock, QChar typedChar); + void handleExCommand(FakeVimHandler *handler, bool *handled, const ExCommand &cmd); + + void writeSettings(); + void readSettings(); + + void handleDelayedQuitAll(bool forced); + void handleDelayedQuit(bool forced, Core::IEditor *editor); + void userActionTriggered(int key); + + void switchToFile(int n); + int currentFile() const; + + void createRelativeNumberWidget(IEditor *editor); + +signals: + void delayedQuitRequested(bool forced, Core::IEditor *editor); + void delayedQuitAllRequested(bool forced); + +public: + QHash<IEditor *, FakeVimHandler *> m_editorToHandler; + + void triggerAction(Id id); + void setActionChecked(Id id, bool check); + + typedef int (*DistFunction)(const QRect &cursor, const QRect &other); + void moveSomewhere(FakeVimHandler *handler, DistFunction f, int count); + + void keepOnlyWindow(); // :only + + ExCommandMap m_exCommandMap; + ExCommandMap m_defaultExCommandMap; + + UserCommandMap m_userCommandMap; + UserCommandMap m_defaultUserCommandMap; + + MiniBuffer *m_miniBuffer = nullptr; + FakeVimPluginRunData *runData = nullptr; +}; /////////////////////////////////////////////////////////////////////// // @@ -530,10 +598,8 @@ enum { CommandRole = Qt::UserRole }; class FakeVimExCommandsWidget : public CommandMappings { - Q_OBJECT - public: - FakeVimExCommandsWidget(FakeVimPluginPrivate *q, QWidget *parent = 0); + FakeVimExCommandsWidget(); protected: void commandChanged(); @@ -545,19 +611,15 @@ protected: private: void initialize(); - ExCommandMap &exCommandMap(); - ExCommandMap &defaultExCommandMap(); ExCommandMap exCommandMapFromWidget(); - FakeVimPluginPrivate *m_q; QGroupBox *m_commandBox; FancyLineEdit *m_commandEdit; friend class FakeVimExCommandsPage; // allow the page accessing the ExCommandMaps }; -FakeVimExCommandsWidget::FakeVimExCommandsWidget(FakeVimPluginPrivate *q, QWidget *parent) - : CommandMappings(parent), m_q(q) +FakeVimExCommandsWidget::FakeVimExCommandsWidget() { setPageTitle(Tr::tr("Ex Command Mapping")); setTargetHeader(Tr::tr("Ex Trigger Expression")); @@ -589,11 +651,8 @@ FakeVimExCommandsWidget::FakeVimExCommandsWidget(FakeVimPluginPrivate *q, QWidge class FakeVimExCommandsPage : public IOptionsPage { - Q_OBJECT - public: - FakeVimExCommandsPage(FakeVimPluginPrivate *q) - : m_q(q) + FakeVimExCommandsPage() { setId(SETTINGS_EX_CMDS_ID); setDisplayName(Tr::tr("Ex Command Mapping")); @@ -602,21 +661,20 @@ public: setCategoryIcon(Utils::Icon(SETTINGS_CATEGORY_FAKEVIM_ICON)); } - QWidget *widget() override; + QWidget *widget() override + { + if (!m_widget) + m_widget = new FakeVimExCommandsWidget; + return m_widget; + } + void apply() override; void finish() override {} private: - FakeVimPluginPrivate *m_q; QPointer<FakeVimExCommandsWidget> m_widget; }; -QWidget *FakeVimExCommandsPage::widget() -{ - if (!m_widget) - m_widget = new FakeVimExCommandsWidget(m_q); - return m_widget; -} const char exCommandMapGroup[] = "FakeVimExCommand"; const char userCommandMapGroup[] = "FakeVimUserCommand"; @@ -630,10 +688,10 @@ void FakeVimExCommandsPage::apply() return; // now save the mappings if necessary const ExCommandMap &newMapping = m_widget->exCommandMapFromWidget(); - ExCommandMap &globalCommandMapping = m_widget->exCommandMap(); + ExCommandMap &globalCommandMapping = dd->m_exCommandMap; if (newMapping != globalCommandMapping) { - const ExCommandMap &defaultMap = m_widget->defaultExCommandMap(); + const ExCommandMap &defaultMap = dd->m_defaultExCommandMap; QSettings *settings = ICore::settings(); settings->beginWriteArray(exCommandMapGroup); int count = 0; @@ -687,11 +745,11 @@ void FakeVimExCommandsWidget::initialize() item->setText(1, c->description()); QString regex; - if (exCommandMap().contains(name)) - regex = exCommandMap()[name].pattern(); + if (dd->m_exCommandMap.contains(name)) + regex = dd->m_exCommandMap[name].pattern(); item->setText(2, regex); - if (regex != defaultExCommandMap()[name].pattern()) + if (regex != dd->m_defaultExCommandMap[name].pattern()) setModified(item, true); } @@ -721,7 +779,7 @@ void FakeVimExCommandsWidget::commandChanged() if (current->data(0, Qt::UserRole).isValid()) current->setText(2, regex); - setModified(current, regex != defaultExCommandMap()[name].pattern()); + setModified(current, regex != dd->m_defaultExCommandMap[name].pattern()); } void FakeVimExCommandsWidget::resetToDefault() @@ -731,8 +789,8 @@ void FakeVimExCommandsWidget::resetToDefault() return; const QString name = current->data(0, CommandRole).toString(); QString regex; - if (defaultExCommandMap().contains(name)) - regex = defaultExCommandMap()[name].pattern(); + if (dd->m_defaultExCommandMap.contains(name)) + regex = dd->m_defaultExCommandMap[name].pattern(); m_commandEdit->setText(regex); } @@ -746,8 +804,8 @@ void FakeVimExCommandsWidget::defaultAction() QTreeWidgetItem *item = section->child(j); const QString name = item->data(0, CommandRole).toString(); QString regex; - if (defaultExCommandMap().contains(name)) - regex = defaultExCommandMap()[name].pattern(); + if (dd->m_defaultExCommandMap.contains(name)) + regex = dd->m_defaultExCommandMap[name].pattern(); setModified(item, false); item->setText(2, regex); if (item == commandList()->currentItem()) @@ -764,12 +822,9 @@ void FakeVimExCommandsWidget::defaultAction() class FakeVimUserCommandsModel : public QAbstractTableModel { - Q_OBJECT public: - FakeVimUserCommandsModel(FakeVimPluginPrivate *q) : m_q(q) {} - ~FakeVimUserCommandsModel() {} + FakeVimUserCommandsModel() { m_commandMap = dd->m_userCommandMap; } - void initCommandMap(const UserCommandMap &commandMap) { m_commandMap = commandMap; } UserCommandMap commandMap() const { return m_commandMap; } int rowCount(const QModelIndex &parent) const; int columnCount(const QModelIndex &parent) const; @@ -779,7 +834,6 @@ public: Qt::ItemFlags flags(const QModelIndex &index) const; private: - FakeVimPluginPrivate *m_q; UserCommandMap m_commandMap; }; @@ -839,11 +893,8 @@ public: class FakeVimUserCommandsPage : public IOptionsPage { - Q_OBJECT - public: - FakeVimUserCommandsPage(FakeVimPluginPrivate *q) - : m_q(q) + FakeVimUserCommandsPage() { setId(SETTINGS_USER_CMDS_ID); setDisplayName(Tr::tr("User Command Mapping")); @@ -857,12 +908,9 @@ public: QWidget *widget(); void initialize() {} - UserCommandMap &userCommandMap(); - UserCommandMap &defaultUserCommandMap(); - UserCommandMap currentCommandMap(); + UserCommandMap currentCommandMap() { return m_model->commandMap(); } private: - FakeVimPluginPrivate *m_q; QPointer<QWidget> m_widget; FakeVimUserCommandsModel *m_model; }; @@ -872,8 +920,7 @@ QWidget *FakeVimUserCommandsPage::widget() if (!m_widget) { m_widget = new QWidget; - m_model = new FakeVimUserCommandsModel(m_q); - m_model->initCommandMap(userCommandMap()); + m_model = new FakeVimUserCommandsModel; auto widget = new QTreeView; m_model->setParent(widget); widget->setModel(m_model); @@ -896,7 +943,7 @@ void FakeVimUserCommandsPage::apply() // now save the mappings if necessary const UserCommandMap ¤t = currentCommandMap(); - UserCommandMap &userMap = userCommandMap(); + UserCommandMap &userMap = dd->m_userCommandMap; if (current != userMap) { QSettings *settings = ICore::settings(); @@ -908,9 +955,9 @@ void FakeVimUserCommandsPage::apply() const int key = it.key(); const QString cmd = it.value(); - if ((defaultUserCommandMap().contains(key) - && defaultUserCommandMap()[key] != cmd) - || (!defaultUserCommandMap().contains(key) && !cmd.isEmpty())) { + if ((dd->m_defaultUserCommandMap.contains(key) + && dd->m_defaultUserCommandMap[key] != cmd) + || (!dd->m_defaultUserCommandMap.contains(key) && !cmd.isEmpty())) { settings->setArrayIndex(count); settings->setValue(idKey, key); settings->setValue(cmdKey, cmd); @@ -919,7 +966,7 @@ void FakeVimUserCommandsPage::apply() } settings->endArray(); userMap.clear(); - userMap.unite(defaultUserCommandMap()); + userMap.unite(dd->m_defaultUserCommandMap); userMap.unite(current); } } @@ -955,7 +1002,7 @@ public: void setInactive() { m_needle.clear(); - m_handler = 0; + m_handler = nullptr; } const QString &needle() const @@ -1078,108 +1125,18 @@ IAssistProcessor *FakeVimCompletionAssistProvider::createProcessor() const /////////////////////////////////////////////////////////////////////// // -// FakeVimPluginPrivate +// FakeVimPluginRunData // /////////////////////////////////////////////////////////////////////// -class FakeVimPluginPrivate : public QObject +class FakeVimPluginRunData { - Q_OBJECT - public: - FakeVimPluginPrivate(FakeVimPlugin *); - - friend class FakeVimPlugin; - friend class FakeVimExCommandsWidget; - friend class FakeVimUserCommandsPage; - friend class FakeVimUserCommandsModel; - - bool initialize(); - void aboutToShutdown(); - -private: - void onCoreAboutToClose(); - void editorOpened(Core::IEditor *); - void editorAboutToClose(Core::IEditor *); - void currentEditorAboutToChange(Core::IEditor *); - - void allDocumentsRenamed(const QString &oldName, const QString &newName); - 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 setUseFakeVimInternal(bool on); - void quitFakeVim(); - void triggerCompletions(FakeVimHandler *handler); - void triggerSimpleCompletions(FakeVimHandler *handler, const QString &needle, bool forward); - void windowCommand(FakeVimHandler *handler, const QString &key, int count); - void find(bool reverse); - void findNext(bool reverse); - void foldToggle(FakeVimHandler *handler, int depth); - void foldAll(FakeVimHandler *handler, bool fold); - void fold(FakeVimHandler *handler, int depth, bool fold); - void foldGoTo(FakeVimHandler *handler, int count, bool current); - void jumpToGlobalMark(FakeVimHandler *, QChar mark, bool backTickMode, const QString &fileName); - void maybeReadVimRc(); - void disableBlockSelection(FakeVimHandler *handler); - void setBlockSelection(FakeVimHandler *handler, const QTextCursor &cursor); - void blockSelection(FakeVimHandler *handler, QTextCursor *cursor); - void hasBlockSelection(FakeVimHandler *handler, bool *on); - void setShowRelativeLineNumbers(const QVariant &value); - - void resetCommandBuffer(); - void showCommandBuffer(FakeVimHandler *handler, const QString &contents, - int cursorPos, int anchorPos, int messageLevel); - void showExtraInformation(FakeVimHandler *handler, const QString &msg); - void changeSelection(FakeVimHandler *handler, const QList<QTextEdit::ExtraSelection> &selections); - void highlightMatches(FakeVimHandler *handler, const QString &needle); - void moveToMatchingParenthesis(FakeVimHandler *handler, bool *moved, bool *forward, QTextCursor *cursor); - void checkForElectricCharacter(FakeVimHandler *handler, bool *result, QChar c); - void indentRegion(FakeVimHandler *handler, int beginBlock, int endBlock, QChar typedChar); - void handleExCommand(FakeVimHandler *handler, bool *handled, const ExCommand &cmd); - - void writeSettings(); - void readSettings(); - - void handleDelayedQuitAll(bool forced); - void handleDelayedQuit(bool forced, Core::IEditor *editor); - void userActionTriggered(int key); + FakeVimOptionPage optionsPage; + FakeVimExCommandsPage exCommandsPage; + FakeVimUserCommandsPage userCommandsPage; - void switchToFile(int n); - int currentFile() const; - - void createRelativeNumberWidget(IEditor *editor); - -signals: - void delayedQuitRequested(bool forced, Core::IEditor *editor); - void delayedQuitAllRequested(bool forced); - -private: - FakeVimPlugin *q; - QHash<IEditor *, FakeVimHandler *> m_editorToHandler; - - void triggerAction(Id id); - void setActionChecked(Id id, bool check); - - typedef int (*DistFunction)(const QRect &cursor, const QRect &other); - void moveSomewhere(FakeVimHandler *handler, DistFunction f, int count); - - void keepOnlyWindow(); // :only - - ExCommandMap &exCommandMap() { return m_exCommandMap; } - ExCommandMap &defaultExCommandMap() { return m_defaultExCommandMap; } - ExCommandMap m_exCommandMap; - ExCommandMap m_defaultExCommandMap; - - UserCommandMap &userCommandMap() { return m_userCommandMap; } - UserCommandMap &defaultUserCommandMap() { return m_defaultUserCommandMap; } - UserCommandMap m_userCommandMap; - UserCommandMap m_defaultUserCommandMap; - - MiniBuffer *m_miniBuffer = nullptr; - // @TODO: Delete - //WordCompletion *m_wordCompletion; - FakeVimCompletionAssistProvider *m_wordProvider = nullptr; + FakeVimCompletionAssistProvider wordProvider; }; QVariant FakeVimUserCommandsModel::data(const QModelIndex &index, int role) const @@ -1208,47 +1165,30 @@ bool FakeVimUserCommandsModel::setData(const QModelIndex &index, return true; } -FakeVimPluginPrivate::FakeVimPluginPrivate(FakeVimPlugin *plugin) - : q(plugin) +FakeVimPluginPrivate::FakeVimPluginPrivate() { - defaultExCommandMap()[CppTools::Constants::SWITCH_HEADER_SOURCE] = + m_defaultExCommandMap[CppTools::Constants::SWITCH_HEADER_SOURCE] = QRegExp("^A$"); - defaultExCommandMap()["Coreplugin.OutputPane.previtem"] = + m_defaultExCommandMap["Coreplugin.OutputPane.previtem"] = QRegExp("^(cN(ext)?|cp(revious)?)!?( (.*))?$"); - defaultExCommandMap()["Coreplugin.OutputPane.nextitem"] = + m_defaultExCommandMap["Coreplugin.OutputPane.nextitem"] = QRegExp("^cn(ext)?!?( (.*))?$"); - defaultExCommandMap()[TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR] = + m_defaultExCommandMap[TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR] = QRegExp("^tag?$"); - defaultExCommandMap()[Core::Constants::GO_BACK] = + m_defaultExCommandMap[Core::Constants::GO_BACK] = QRegExp("^pop?$"); - defaultExCommandMap()["QtCreator.Locate"] = + m_defaultExCommandMap["QtCreator.Locate"] = QRegExp("^e$"); for (int i = 1; i < 10; ++i) { QString cmd = QString::fromLatin1(":echo User command %1 executed.<CR>"); - defaultUserCommandMap().insert(i, cmd.arg(i)); + m_defaultUserCommandMap.insert(i, cmd.arg(i)); } } -void FakeVimPluginPrivate::onCoreAboutToClose() -{ - // Don't attach to editors anymore. - disconnect(EditorManager::instance(), &EditorManager::editorOpened, - this, &FakeVimPluginPrivate::editorOpened); -} - -void FakeVimPluginPrivate::aboutToShutdown() -{ - delete m_wordProvider; - m_wordProvider = 0; -} - bool FakeVimPluginPrivate::initialize() { - //m_wordCompletion = new WordCompletion; - //q->addAutoReleasedObject(m_wordCompletion); - m_wordProvider = new FakeVimCompletionAssistProvider; - + runData = new FakeVimPluginRunData; /* // Set completion settings and keep them up to date. TextEditorSettings *textEditorSettings = TextEditorSettings::instance(); @@ -1256,18 +1196,11 @@ bool FakeVimPluginPrivate::initialize() connect(textEditorSettings, &TextEditorSettings::completionSettingsChanged, completion, &TextEditorWidget::setCompletionSettings); */ - - Context globalcontext(Core::Constants::C_GLOBAL); - - q->addAutoReleasedObject(new FakeVimOptionPage); - q->addAutoReleasedObject(new FakeVimExCommandsPage(this)); - q->addAutoReleasedObject(new FakeVimUserCommandsPage(this)); - readSettings(); - Command *cmd = 0; + Command *cmd = nullptr; cmd = ActionManager::registerAction(theFakeVimSetting(ConfigUseFakeVim), - INSTALL_HANDLER, globalcontext, true); + INSTALL_HANDLER, Context(Core::Constants::C_GLOBAL), true); cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? Tr::tr("Meta+Shift+V,Meta+Shift+V") : Tr::tr("Alt+V,Alt+V"))); ActionContainer *advancedMenu = @@ -1283,8 +1216,11 @@ bool FakeVimPluginPrivate::initialize() connect(act, &QAction::triggered, this, [this, i] { userActionTriggered(i); }); } - connect(ICore::instance(), &ICore::coreAboutToClose, - this, &FakeVimPluginPrivate::onCoreAboutToClose); + connect(ICore::instance(), &ICore::coreAboutToClose, this, [] { + // Don't attach to editors anymore. + disconnect(EditorManager::instance(), &EditorManager::editorOpened, + dd, &FakeVimPluginPrivate::editorOpened); + }); // EditorManager connect(EditorManager::instance(), &EditorManager::editorAboutToClose, @@ -1332,7 +1268,7 @@ void FakeVimPluginPrivate::userActionTriggered(int key) if (enableFakeVim) setUseFakeVimInternal(true); - const QString cmd = userCommandMap().value(key); + const QString cmd = m_userCommandMap.value(key); handler->handleInput(cmd); if (enableFakeVim) @@ -1364,23 +1300,23 @@ void FakeVimPluginPrivate::readSettings() theFakeVimSettings()->readSettings(settings); - exCommandMap() = defaultExCommandMap(); + m_exCommandMap = m_defaultExCommandMap; int size = settings->beginReadArray(exCommandMapGroup); for (int i = 0; i < size; ++i) { settings->setArrayIndex(i); const QString id = settings->value(idKey).toString(); const QString re = settings->value(reKey).toString(); - exCommandMap()[id] = QRegExp(re); + m_exCommandMap[id] = QRegExp(re); } settings->endArray(); - userCommandMap() = defaultUserCommandMap(); + m_userCommandMap = m_defaultUserCommandMap; size = settings->beginReadArray(userCommandMapGroup); for (int i = 0; i < size; ++i) { settings->setArrayIndex(i); const int id = settings->value(idKey).toInt(); const QString cmd = settings->value(cmdKey).toString(); - userCommandMap()[id] = cmd; + m_userCommandMap[id] = cmd; } settings->endArray(); } @@ -1705,7 +1641,7 @@ void FakeVimPluginPrivate::jumpToGlobalMark(FakeVimHandler *, IEditor *iedit = EditorManager::openEditor(fileName); if (!iedit) return; - FakeVimHandler *handler = m_editorToHandler.value(iedit, 0); + FakeVimHandler *handler = m_editorToHandler.value(iedit, nullptr); if (handler) handler->jumpToLocalMark(mark, backTickMode); } @@ -1886,15 +1822,14 @@ void FakeVimPluginPrivate::triggerCompletions(FakeVimHandler *handler) { QTC_ASSERT(handler, return); if (TextEditorWidget *editor = qobject_cast<TextEditorWidget *>(handler->widget())) - editor->invokeAssist(Completion, m_wordProvider); + editor->invokeAssist(Completion, &runData->wordProvider); // CompletionSupport::instance()->complete(editor->editor(), TextCompletion, false); } void FakeVimPluginPrivate::triggerSimpleCompletions(FakeVimHandler *handler, const QString &needle, bool forward) { QTC_ASSERT(handler, return); -// m_wordCompletion->setActive(needle, forward, handler); - m_wordProvider->setActive(needle, forward, handler); + runData->wordProvider.setActive(needle, forward, handler); } void FakeVimPluginPrivate::disableBlockSelection(FakeVimHandler *handler) @@ -2035,9 +1970,8 @@ void FakeVimPluginPrivate::handleExCommand(FakeVimHandler *handler, bool *handle triggerAction(CppTools::Constants::SWITCH_HEADER_SOURCE); } else { // Check whether one of the configure commands matches. - typedef ExCommandMap::const_iterator Iterator; - const Iterator end = exCommandMap().constEnd(); - for (Iterator it = exCommandMap().constBegin(); it != end; ++it) { + const auto end = m_exCommandMap.constEnd(); + for (auto it = m_exCommandMap.constBegin(); it != end; ++it) { const QString &id = it.key(); QRegExp re = it.value(); if (!re.pattern().isEmpty() && re.indexIn(cmd.cmd) != -1) { @@ -2201,16 +2135,6 @@ void FakeVimPluginPrivate::switchToFile(int n) EditorManager::activateEditorForEntry(DocumentModel::entries().at(n)); } -ExCommandMap &FakeVimExCommandsWidget::exCommandMap() -{ - return m_q->exCommandMap(); -} - -ExCommandMap &FakeVimExCommandsWidget::defaultExCommandMap() -{ - return m_q->defaultExCommandMap(); -} - ExCommandMap FakeVimExCommandsWidget::exCommandMapFromWidget() { ExCommandMap map; @@ -2222,8 +2146,8 @@ ExCommandMap FakeVimExCommandsWidget::exCommandMapFromWidget() QTreeWidgetItem *item = section->child(j); const QString name = item->data(0, CommandRole).toString(); const QString regex = item->data(2, Qt::DisplayRole).toString(); - if ((regex.isEmpty() && defaultExCommandMap().value(name).isEmpty()) - || (!regex.isEmpty() && defaultExCommandMap().value(name).pattern() == regex)) + if ((regex.isEmpty() && dd->m_defaultExCommandMap.value(name).isEmpty()) + || (!regex.isEmpty() && dd->m_defaultExCommandMap.value(name).pattern() == regex)) continue; map[name] = QRegExp(regex); } @@ -2231,20 +2155,7 @@ ExCommandMap FakeVimExCommandsWidget::exCommandMapFromWidget() return map; } -UserCommandMap &FakeVimUserCommandsPage::userCommandMap() -{ - return m_q->userCommandMap(); -} -UserCommandMap &FakeVimUserCommandsPage::defaultUserCommandMap() -{ - return m_q->defaultUserCommandMap(); -} - -UserCommandMap FakeVimUserCommandsPage::currentCommandMap() -{ - return m_model->commandMap(); -} /////////////////////////////////////////////////////////////////////// // @@ -2253,32 +2164,37 @@ UserCommandMap FakeVimUserCommandsPage::currentCommandMap() /////////////////////////////////////////////////////////////////////// FakeVimPlugin::FakeVimPlugin() - : d(new FakeVimPluginPrivate(this)) -{} +{ + dd = new FakeVimPluginPrivate; +} FakeVimPlugin::~FakeVimPlugin() { - delete d; + delete dd; + dd = nullptr; } bool FakeVimPlugin::initialize(const QStringList &arguments, QString *errorMessage) { Q_UNUSED(arguments) Q_UNUSED(errorMessage) - return d->initialize(); + return dd->initialize(); } ExtensionSystem::IPlugin::ShutdownFlag FakeVimPlugin::aboutToShutdown() { - StatusBarManager::destroyStatusBarWidget(d->m_miniBuffer); - d->m_miniBuffer = nullptr; + delete dd->runData; + dd->runData = nullptr; + + StatusBarManager::destroyStatusBarWidget(dd->m_miniBuffer); + dd->m_miniBuffer = nullptr; return SynchronousShutdown; } void FakeVimPlugin::extensionsInitialized() { - d->m_miniBuffer = new MiniBuffer; - StatusBarManager::addStatusBarWidget(d->m_miniBuffer, StatusBarManager::LastLeftAligned); + dd->m_miniBuffer = new MiniBuffer; + StatusBarManager::addStatusBarWidget(dd->m_miniBuffer, StatusBarManager::LastLeftAligned); } #ifdef WITH_TESTS @@ -2288,7 +2204,7 @@ void FakeVimPlugin::setupTest(QString *title, FakeVimHandler **handler, QWidget IEditor *iedit = EditorManager::openEditorWithContents(Id(), title); EditorManager::activateEditor(iedit); *edit = iedit->widget(); - *handler = d->m_editorToHandler.value(iedit, 0); + *handler = dd->m_editorToHandler.value(iedit, 0); (*handler)->setupWidget(); (*handler)->handleCommand("set startofline"); diff --git a/src/plugins/fakevim/fakevimplugin.h b/src/plugins/fakevim/fakevimplugin.h index 60789b8711..98f526ce44 100644 --- a/src/plugins/fakevim/fakevimplugin.h +++ b/src/plugins/fakevim/fakevimplugin.h @@ -31,7 +31,6 @@ namespace FakeVim { namespace Internal { class FakeVimHandler; -class FakeVimPluginPrivate; class FakeVimPlugin : public ExtensionSystem::IPlugin { @@ -50,7 +49,6 @@ private: private: friend class FakeVimPluginPrivate; - FakeVimPluginPrivate *d; #ifdef WITH_TESTS private slots: |