Commit 0809986e authored by Lukas Holecek's avatar Lukas Holecek Committed by hjk
Browse files

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: default avatarhjk <hjk121@nokiamail.com>
parent 1ffe15a4
......@@ -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);
......
......@@ -43,6 +43,7 @@ enum FakeVimSettingsCode
{
ConfigUseFakeVim,
ConfigReadVimRc,
ConfigVimRcPath,
ConfigStartOfLine,
ConfigHlSearch,
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>513</width>
<height>464</height>
<height>468</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
......@@ -24,27 +24,36 @@
<string>Vim Behavior</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="5" column="2">
<widget class="QCheckBox" name="checkBoxPassControlKey">
<property name="toolTip">
<string>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.</string>
</property>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxSmartTab">
<property name="text">
<string>Pass control key</string>
<string>Smart tabulators</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxHlSearch">
<property name="text">
<string>Highlight search results</string>
<item row="10" column="1" colspan="2">
<widget class="QLineEdit" name="lineEditIsKeyword"/>
</item>
<item row="12" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>17</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxIncSearch">
<item row="1" column="2">
<widget class="QCheckBox" name="checkBoxUseCoreSearch">
<property name="text">
<string>Incremental search</string>
<string>Use search dialog</string>
</property>
</widget>
</item>
......@@ -62,6 +71,13 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxExpandTab">
<property name="text">
<string>Expand tabulators</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxAutoIndent">
<property name="text">
......@@ -69,10 +85,27 @@
</property>
</widget>
</item>
<item row="8" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item row="5" column="2">
<widget class="QCheckBox" name="checkBoxPassControlKey">
<property name="toolTip">
<string>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.</string>
</property>
<property name="text">
<string>Pass control key</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxHlSearch">
<property name="text">
<string>Highlight search results</string>
</property>
</widget>
</item>
<item row="7" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QSpinBox" name="spinBoxTabStop">
<widget class="QSpinBox" name="spinBoxShiftWidth">
<property name="minimum">
<number>1</number>
</property>
......@@ -82,7 +115,7 @@
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
......@@ -96,20 +129,17 @@
</item>
</layout>
</item>
<item row="9" column="0">
<widget class="QLabel" name="labelBackspace">
<item row="6" column="0">
<widget class="QCheckBox" name="checkBoxShowCmd">
<property name="text">
<string>Backspace:</string>
<string>Show partial command</string>
</property>
</widget>
</item>
<item row="9" column="1" colspan="2">
<widget class="QLineEdit" name="lineEditBackspace"/>
</item>
<item row="10" column="0">
<widget class="QLabel" name="labelIsKeyword">
<item row="9" column="0">
<widget class="QLabel" name="labelBackspace">
<property name="text">
<string>Keyword characters:</string>
<string>Backspace:</string>
</property>
</widget>
</item>
......@@ -123,7 +153,24 @@
</property>
</widget>
</item>
<item row="12" column="0" colspan="3">
<item row="9" column="1" colspan="2">
<widget class="QLineEdit" name="lineEditBackspace"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="labelShiftWidth">
<property name="text">
<string>Shift width:</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxIncSearch">
<property name="text">
<string>Incremental search</string>
</property>
</widget>
</item>
<item row="13" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButtonCopyTextEditorSettings">
......@@ -161,20 +208,6 @@
</item>
</layout>
</item>
<item row="7" column="0">
<widget class="QLabel" name="labelShiftWidth">
<property name="text">
<string>Shift width:</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxExpandTab">
<property name="text">
<string>Expand tabulators</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QCheckBox" name="checkBoxShowMarks">
<property name="text">
......@@ -182,39 +215,6 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxSmartTab">
<property name="text">
<string>Smart tabulators</string>
</property>
</widget>
</item>
<item row="10" column="1" colspan="2">
<widget class="QLineEdit" name="lineEditIsKeyword"/>
</item>
<item row="11" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>17</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<widget class="QCheckBox" name="checkBoxUseCoreSearch">
<property name="text">
<string>Use search dialog</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QCheckBox" name="checkBoxSmartCase">
<property name="text">
......@@ -229,10 +229,10 @@
</property>
</widget>
</item>
<item row="7" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item row="8" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QSpinBox" name="spinBoxShiftWidth">
<widget class="QSpinBox" name="spinBoxTabStop">
<property name="minimum">
<number>1</number>
</property>
......@@ -242,7 +242,7 @@
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
......@@ -256,10 +256,17 @@
</item>
</layout>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="checkBoxShowCmd">
<item row="10" column="0">
<widget class="QLabel" name="labelIsKeyword">
<property name="text">
<string>Show partial command</string>
<string>Keyword characters:</string>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="labelVimRcPath">
<property name="text">
<string>Location of .vimrc:</string>
</property>
</widget>
</item>
......@@ -270,6 +277,24 @@
</property>
</widget>
</item>
<item row="11" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayoutVimRcPath">
<item>
<widget class="QLineEdit" name="lineEditVimRcPath">
<property name="toolTip">
<string>Keep empty to use the default path, i.e. %USERPROFILE%\_vimrc on Windows, ~/.vimrc otherwise.</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonVimRcPath">
<property name="text">
<string>Browse...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
......@@ -303,10 +328,13 @@
<tabstop>checkBoxWrapScan</tabstop>
<tabstop>checkBoxShowMarks</tabstop>
<tabstop>checkBoxPassControlKey</tabstop>
<tabstop>checkBoxReadVimRc</tabstop>
<tabstop>spinBoxShiftWidth</tabstop>
<tabstop>spinBoxTabStop</tabstop>
<tabstop>lineEditBackspace</tabstop>
<tabstop>lineEditIsKeyword</tabstop>
<tabstop>lineEditVimRcPath</tabstop>
<tabstop>pushButtonVimRcPath</tabstop>
<tabstop>pushButtonCopyTextEditorSettings</tabstop>
<tabstop>pushButtonSetQtStyle</tabstop>
<tabstop>pushButtonSetPlainStyle</tabstop>
......
......@@ -71,6 +71,7 @@
#include <find/textfindconstants.h>
#include <find/ifindsupport.h>
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
#include <utils/savedaction.h>
#include <utils/treewidgetcolumnstretcher.h>
......@@ -83,6 +84,7 @@
#include <QAbstractTableModel>
#include <QDebug>
#include <QFile>
#include <QFileDialog>
#include <QtPlugin>
#include <QObject>
#include <QSettings>
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment