From 0809986e501415fe2c8508800b94b5b3169dc048 Mon Sep 17 00:00:00 2001 From: Lukas Holecek Date: Thu, 14 Feb 2013 19:12:30 +0100 Subject: [PATCH] FakeVim: User-settable path to .vimrc with saner default for Windows Path to .vimrc configuration file can be set in options if "Read .vimrc" option is enabled. Default path for .vimrc is %USERPROFILE%/_vimrc on Windows, ~/.vimrc otherwise. Task-number: QTCREATORBUG-8748 Change-Id: I61ff8484e7635ce7a9361e2ad5cd3943e15613c1 Reviewed-by: hjk --- src/plugins/fakevim/fakevimactions.cpp | 7 + src/plugins/fakevim/fakevimactions.h | 1 + src/plugins/fakevim/fakevimoptions.ui | 360 +++++++++++++------------ src/plugins/fakevim/fakevimplugin.cpp | 36 ++- 4 files changed, 235 insertions(+), 169 deletions(-) diff --git a/src/plugins/fakevim/fakevimactions.cpp b/src/plugins/fakevim/fakevimactions.cpp index 071a42a1273..be8b5daa284 100644 --- a/src/plugins/fakevim/fakevimactions.cpp +++ b/src/plugins/fakevim/fakevimactions.cpp @@ -142,6 +142,13 @@ FakeVimSettings *theFakeVimSettings() item->setValue(false); instance->insertItem(ConfigReadVimRc, item); + item = new SavedAction(instance); + item->setText(QCoreApplication::translate("FakeVim::Internal", + "Path to .vimrc")); + item->setDefaultValue(QString()); + item->setSettingsKey(group, _("VimRcPath")); + instance->insertItem(ConfigVimRcPath, item); + item = new SavedAction(instance); item->setValue(true); item->setDefaultValue(true); diff --git a/src/plugins/fakevim/fakevimactions.h b/src/plugins/fakevim/fakevimactions.h index 13774b0e9d8..a730af62fa6 100644 --- a/src/plugins/fakevim/fakevimactions.h +++ b/src/plugins/fakevim/fakevimactions.h @@ -43,6 +43,7 @@ enum FakeVimSettingsCode { ConfigUseFakeVim, ConfigReadVimRc, + ConfigVimRcPath, ConfigStartOfLine, ConfigHlSearch, diff --git a/src/plugins/fakevim/fakevimoptions.ui b/src/plugins/fakevim/fakevimoptions.ui index f8275b8acaa..25e12a08351 100644 --- a/src/plugins/fakevim/fakevimoptions.ui +++ b/src/plugins/fakevim/fakevimoptions.ui @@ -7,7 +7,7 @@ 0 0 513 - 464 + 468 @@ -24,164 +24,6 @@ Vim Behavior - - - - Pass key sequences like Ctrl-S to Qt Creator core instead of interpreting them in FakeVim. This gives easier access to Qt Creator core functionality at the price of losing some features of FakeVim. - - - Pass control key - - - - - - - Highlight search results - - - - - - - Incremental search - - - - - - - Start of line - - - - - - - Smart indentation - - - - - - - Automatic indentation - - - - - - - - - 1 - - - 80 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Backspace: - - - - - - - - - - Keyword characters: - - - - - - - Vim tabstop option - - - Tabulator size: - - - - - - - - - Copy Text Editor Settings - - - - - - - Set Qt Style - - - - - - - Set Plain Style - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Shift width: - - - - - - - Expand tabulators - - - - - - - Show position of text marks - - - @@ -192,7 +34,7 @@ - + Qt::Vertical @@ -215,17 +57,48 @@ - - + + - Use smartcase + Start of line - - + + - Use wrapscan + Smart indentation + + + + + + + Expand tabulators + + + + + + + Automatic indentation + + + + + + + Pass key sequences like Ctrl-S to Qt Creator core instead of interpreting them in FakeVim. This gives easier access to Qt Creator core functionality at the price of losing some features of FakeVim. + + + Pass control key + + + + + + + Highlight search results @@ -263,6 +136,140 @@ + + + + Backspace: + + + + + + + Vim tabstop option + + + Tabulator size: + + + + + + + + + + Shift width: + + + + + + + Incremental search + + + + + + + + + Copy Text Editor Settings + + + + + + + Set Qt Style + + + + + + + Set Plain Style + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Show position of text marks + + + + + + + Use smartcase + + + + + + + Use wrapscan + + + + + + + + + 1 + + + 80 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Keyword characters: + + + + + + + Location of .vimrc: + + + @@ -270,6 +277,24 @@ + + + + + + Keep empty to use the default path, i.e. %USERPROFILE%\_vimrc on Windows, ~/.vimrc otherwise. + + + + + + + Browse... + + + + + @@ -303,10 +328,13 @@ checkBoxWrapScan checkBoxShowMarks checkBoxPassControlKey + checkBoxReadVimRc spinBoxShiftWidth spinBoxTabStop lineEditBackspace lineEditIsKeyword + lineEditVimRcPath + pushButtonVimRcPath pushButtonCopyTextEditorSettings pushButtonSetQtStyle pushButtonSetPlainStyle diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index 5e31a6e5e47..5a96b297e6d 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -71,6 +71,7 @@ #include #include +#include #include #include #include @@ -83,6 +84,7 @@ #include #include #include +#include #include #include #include @@ -254,6 +256,8 @@ private slots: void copyTextEditorSettings(); void setQtStyle(); void setPlainStyle(); + void openVimRc(); + void updateVimRcWidgets(); private: friend class DebuggerPlugin; @@ -272,6 +276,8 @@ QWidget *FakeVimOptionPage::createPage(QWidget *parent) m_ui.checkBoxUseFakeVim); m_group.insert(theFakeVimSetting(ConfigReadVimRc), m_ui.checkBoxReadVimRc); + m_group.insert(theFakeVimSetting(ConfigVimRcPath), + m_ui.lineEditVimRcPath); m_group.insert(theFakeVimSetting(ConfigExpandTab), m_ui.checkBoxExpandTab); @@ -318,6 +324,11 @@ QWidget *FakeVimOptionPage::createPage(QWidget *parent) SLOT(setQtStyle())); connect(m_ui.pushButtonSetPlainStyle, SIGNAL(clicked()), SLOT(setPlainStyle())); + connect(m_ui.pushButtonVimRcPath, SIGNAL(clicked()), + SLOT(openVimRc())); + connect(m_ui.checkBoxReadVimRc, SIGNAL(stateChanged(int)), + SLOT(updateVimRcWidgets())); + updateVimRcWidgets(); if (m_searchKeywords.isEmpty()) { QLatin1Char sep(' '); @@ -382,6 +393,21 @@ void FakeVimOptionPage::setPlainStyle() m_ui.lineEditBackspace->setText(QString()); } +void FakeVimOptionPage::openVimRc() +{ + const QString fileName = QFileDialog::getOpenFileName(); + if (!fileName.isNull()) + m_ui.lineEditVimRcPath->setText(fileName); +} + +void FakeVimOptionPage::updateVimRcWidgets() +{ + bool enabled = m_ui.checkBoxReadVimRc->isChecked(); + m_ui.labelVimRcPath->setEnabled(enabled); + m_ui.lineEditVimRcPath->setEnabled(enabled); + m_ui.pushButtonVimRcPath->setEnabled(enabled); +} + bool FakeVimOptionPage::matches(const QString &s) const { return m_searchKeywords.contains(s, Qt::CaseInsensitive); @@ -1066,6 +1092,8 @@ bool FakeVimPluginPrivate::initialize() this, SLOT(setUseFakeVim(QVariant))); connect(theFakeVimSetting(ConfigReadVimRc), SIGNAL(valueChanged(QVariant)), this, SLOT(maybeReadVimRc())); + connect(theFakeVimSetting(ConfigVimRcPath), SIGNAL(valueChanged(QVariant)), + this, SLOT(maybeReadVimRc())); // Delayed operations. connect(this, SIGNAL(delayedQuitRequested(bool,Core::IEditor*)), @@ -1185,9 +1213,11 @@ void FakeVimPluginPrivate::maybeReadVimRc() //qDebug() << theFakeVimSetting(ConfigShiftWidth)->value(); if (!theFakeVimSetting(ConfigReadVimRc)->value().toBool()) return; - QString fileName = - QDesktopServices::storageLocation(QDesktopServices::HomeLocation) - + _("/.vimrc"); + QString fileName = theFakeVimSetting(ConfigVimRcPath)->value().toString(); + if (fileName.isEmpty()) { + fileName = QDesktopServices::storageLocation(QDesktopServices::HomeLocation) + + (Utils::HostOsInfo::isWindowsHost() ? _("/_vimrc") : _("/.vimrc")); + } //qDebug() << "READING VIMRC: " << fileName; // Read it into a temporary handler for effects modifying global state. QPlainTextEdit editor;