From c826e6dcfe157ef32d3e0e962ab5eef834f8a541 Mon Sep 17 00:00:00 2001 From: hjk <qtc-committer@nokia.com> Date: Mon, 30 Mar 2009 12:40:08 +0200 Subject: [PATCH] fakevim: re-organize settings handling --- src/plugins/debugger/debuggerplugin.cpp | 10 +- src/plugins/fakevim/fakevim.pro | 4 +- src/plugins/fakevim/fakevimconstants.h | 58 ------- src/plugins/fakevim/fakevimhandler.cpp | 182 ++++++++++++++++------ src/plugins/fakevim/fakevimhandler.h | 53 ++++++- src/plugins/fakevim/fakevimoptions.ui | 197 ++++++++++++++++++++++++ src/plugins/fakevim/fakevimplugin.cpp | 133 ++++++++++++++-- 7 files changed, 510 insertions(+), 127 deletions(-) delete mode 100644 src/plugins/fakevim/fakevimconstants.h create mode 100644 src/plugins/fakevim/fakevimoptions.ui diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 3db99a052a0..1046a9307ba 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -242,7 +242,7 @@ class GdbOptionPage : public Core::IOptionsPage Q_OBJECT public: - GdbOptionPage(DebuggerPlugin *plugin) : m_plugin(plugin) {} + GdbOptionPage() {} // IOptionsPage QString id() const { return QLatin1String("General"); } @@ -258,7 +258,6 @@ private: friend class DebuggerPlugin; Ui::GdbOptionPage m_ui; - DebuggerPlugin *m_plugin; Core::Utils::SavedActionSet m_group; }; @@ -332,7 +331,7 @@ class DumperOptionPage : public Core::IOptionsPage Q_OBJECT public: - DumperOptionPage(DebuggerPlugin *plugin) : m_plugin(plugin) {} + DumperOptionPage() {} // IOptionsPage QString id() const { return QLatin1String("DataDumper"); } @@ -350,7 +349,6 @@ private: friend class DebuggerPlugin; Ui::DumperOptionPage m_ui; - DebuggerPlugin *m_plugin; Core::Utils::SavedActionSet m_group; }; @@ -650,9 +648,9 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess m_manager, SLOT(setSimpleDockWidgetArrangement())); // FIXME: - m_generalOptionPage = new GdbOptionPage(this); + m_generalOptionPage = new GdbOptionPage; addObject(m_generalOptionPage); - m_dumperOptionPage = new DumperOptionPage(this); + m_dumperOptionPage = new DumperOptionPage; addObject(m_dumperOptionPage); m_locationMark = 0; diff --git a/src/plugins/fakevim/fakevim.pro b/src/plugins/fakevim/fakevim.pro index 5c8ecd48429..1f7693b7e03 100644 --- a/src/plugins/fakevim/fakevim.pro +++ b/src/plugins/fakevim/fakevim.pro @@ -18,6 +18,8 @@ SOURCES += \ fakevimplugin.cpp HEADERS += \ - fakevimconstants.h \ fakevimhandler.h \ fakevimplugin.h + +FORMS += \ + fakevimoptions.ui diff --git a/src/plugins/fakevim/fakevimconstants.h b/src/plugins/fakevim/fakevimconstants.h deleted file mode 100644 index c1b7ff1b157..00000000000 --- a/src/plugins/fakevim/fakevimconstants.h +++ /dev/null @@ -1,58 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -**************************************************************************/ - -#ifndef FAKEVIMCONSTANTS_H -#define FAKEVIMCONSTANTS_H - -namespace FakeVim { -namespace Constants { - -const char * const ConfigOn = "on"; -const char * const ConfigOff = "off"; - -const char * const ConfigAutoIndent = "autoindent"; -const char * const ConfigExpandTab = "expandtab"; -const char * const ConfigHlSearch = "hlsearch"; -const char * const ConfigShiftWidth = "shiftwidth"; -const char * const ConfigSmartTab = "smarttab"; -const char * const ConfigStartOfLine = "startofline"; -const char * const ConfigTabStop = "tabstop"; - -const char * const ConfigBackspace = "backspace"; -// 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. - - -} // namespace Constants -} // namespace FakeVim - -#endif // FAKEVIMCONSTANTS_H - diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp index 72d0e6bd44e..9dfaa36388f 100644 --- a/src/plugins/fakevim/fakevimhandler.cpp +++ b/src/plugins/fakevim/fakevimhandler.cpp @@ -29,8 +29,6 @@ #include "fakevimhandler.h" -#include "fakevimconstants.h" - // Please do not add any direct dependencies to other Qt Creator code here. // Instead emit signals and let the FakeVimPlugin channel the information to // Qt Creator. The idea is to keep this file here in a "clean" state that @@ -50,6 +48,7 @@ // spans between m_anchor (== anchor()) and m_tc.position() (== position()) // The value of m_tc.anchor() is not used. +#include <utils/qtcassert.h> #include <QtCore/QDebug> #include <QtCore/QFile> @@ -86,8 +85,114 @@ # define UNDO_DEBUG(s) #endif -using namespace FakeVim::Internal; -using namespace FakeVim::Constants; +using namespace Core::Utils; + +/////////////////////////////////////////////////////////////////////// +// +// FakeVimSettings +// +/////////////////////////////////////////////////////////////////////// + +namespace FakeVim { +namespace Internal { + +FakeVimSettings::FakeVimSettings(QObject *parent) + : QObject(parent) +{} + +FakeVimSettings::~FakeVimSettings() +{ + qDeleteAll(m_items); +} + +void FakeVimSettings::insertItem(int code, SavedAction *item, + const QString &longName, const QString &shortName) +{ + QTC_ASSERT(!m_items.contains(code), qDebug() << code << item->toString(); return); + m_items[code] = item; + if (!longName.isEmpty()) { + m_nameToCode[longName] = code; + m_codeToName[code] = longName; + } + if (!shortName.isEmpty()) { + m_nameToCode[shortName] = code; + } +} + +void FakeVimSettings::readSettings(QSettings *settings) +{ + foreach (SavedAction *item, m_items) + item->readSettings(settings); +} + +void FakeVimSettings::writeSettings(QSettings *settings) +{ + foreach (SavedAction *item, m_items) + item->writeSettings(settings); +} + +SavedAction *FakeVimSettings::item(int code) +{ + QTC_ASSERT(m_items.value(code, 0), return 0); + return m_items.value(code, 0); +} + +FakeVimSettings *theFakeVimSettings() +{ + static FakeVimSettings *instance = 0; + if (instance) + return instance; + + instance = new FakeVimSettings; + + SavedAction *item = 0; + + bool plain = false; + + item = new SavedAction(instance); + item->setText(QObject::tr("FakeVim properties...")); + instance->insertItem(SettingsDialog, item); + + item = new SavedAction(instance); + item->setDefaultValue(plain ? false : true); + instance->insertItem(ConfigStartOfLine, item, "startofline", "sol"); + + item = new SavedAction(instance); + item->setDefaultValue(plain ? 8 : 4); + instance->insertItem(ConfigTabStop, item, "tabstop", "ts"); + + item = new SavedAction(instance); + item->setDefaultValue(plain ? false : true); + instance->insertItem(ConfigSmartTab, item, "smarttab", "sta"); + + item = new SavedAction(instance); + item->setDefaultValue(true); + instance->insertItem(ConfigHlSearch, item, "hlsearch", "hls"); + + item = new SavedAction(instance); + item->setDefaultValue(plain ? 8 : 4); + instance->insertItem(ConfigShiftWidth, item, "shiftwidth", "sw"); + + item = new SavedAction(instance); + item->setDefaultValue(plain ? false : true); + instance->insertItem(ConfigExpandTab, item, "expandtab", "et"); + + item = new SavedAction(instance); + item->setDefaultValue(plain ? true : false); + instance->insertItem(ConfigAutoIndent, item, "autoindent", "ai"); + + item = new SavedAction(instance); + item->setDefaultValue(plain ? "" : "indent,eol,start"); + instance->insertItem(ConfigBackspace, item, "backspace", "bs"); + + return instance; +} + +SavedAction *theFakeVimSetting(int code) +{ + return theFakeVimSettings()->item(code); +} + /////////////////////////////////////////////////////////////////////// @@ -384,11 +489,10 @@ public: QString m_oldNeedle; // vi style configuration - QHash<QString, QString> m_config; - bool hasConfig(const char *name) const - { return m_config[name] == ConfigOn; } - bool hasConfig(const char *name, const char *value) const - { return m_config[name].contains(value); } // FIXME + QVariant config(int code) const { return theFakeVimSetting(code)->value(); } + bool hasConfig(int code) const { return config(code).toBool(); } + bool hasConfig(int code, const char *value) const // FIXME + { return config(code).toString().contains(value); } // for restoring cursor position int m_savedYankPosition; @@ -430,27 +534,6 @@ FakeVimHandler::Private::Private(FakeVimHandler *parent, QWidget *widget) m_cursorWidth = EDITOR(cursorWidth()); m_inReplay = false; -#if 0 - // Plain - m_config[ConfigStartOfLine] = ConfigOn; - m_config[ConfigHlSearch] = ConfigOn; - m_config[ConfigTabStop] = "8"; - m_config[ConfigSmartTab] = ConfigOff; - m_config[ConfigShiftWidth] = "8"; - m_config[ConfigExpandTab] = ConfigOff; - m_config[ConfigAutoIndent] = ConfigOff; - m_config[ConfigBackspace] = ""; -#else - // Qt Local - m_config[ConfigStartOfLine] = ConfigOn; - m_config[ConfigHlSearch] = ConfigOn; - m_config[ConfigTabStop] = "4"; - m_config[ConfigSmartTab] = ConfigOff; - m_config[ConfigShiftWidth] = "4"; - m_config[ConfigExpandTab] = ConfigOn; - m_config[ConfigAutoIndent] = ConfigOff; - m_config[ConfigBackspace] = "indent,eol,start"; -#endif } bool FakeVimHandler::Private::wantsOverride(QKeyEvent *ev) @@ -1503,7 +1586,7 @@ EventResult FakeVimHandler::Private::handleInsertMode(int key, int, moveUp(count() * (linesOnScreen() - 2)); m_lastInsertion.clear(); } else if (key == Key_Tab && hasConfig(ConfigExpandTab)) { - QString str = QString(m_config[ConfigTabStop].toInt(), ' '); + QString str = QString(theFakeVimSetting(ConfigTabStop)->value().toInt(), ' '); m_lastInsertion.append(str); m_tc.insertText(str); } else if (key >= control('a') && key <= control('z')) { @@ -1817,16 +1900,18 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) } else if (reSet.indexIn(cmd) != -1) { // :set QString arg = reSet.cap(2); if (arg.isEmpty()) { - QString info; - foreach (const QString &key, m_config.keys()) - info += key + ": " + m_config.value(key) + "\n"; - emit q->extraInformationChanged(info); - } else if (m_config.contains(arg)) { + //QString info; + //foreach (const QString &key, m_config.keys()) + // info += key + ": " + m_config.value(key) + "\n"; + //emit q->extraInformationChanged(info); + theFakeVimSetting(SettingsDialog)->trigger(QVariant()); +/* + } else if (theFakeVimSettings()->.contains(arg)) { // boolean config to be switched on or non-boolean to show QString oldValue = m_config.value(arg); - if (oldValue == ConfigOff) - m_config[arg] = ConfigOn; - else if (oldValue == ConfigOn) + if (oldValue == false) + m_config[arg] = true; + else if (oldValue == true) ; // nothing to do else showBlackMessage(arg + '=' + oldValue); @@ -1834,9 +1919,9 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) // boolean config to be switched off QString key = arg.mid(2); QString oldValue = m_config.value(key); - if (oldValue == ConfigOn) - m_config[key] = ConfigOff; - else if (oldValue == ConfigOff) + if (oldValue == true) + m_config[key] = false; + else if (oldValue == false) ; // nothing to do else showBlackMessage(key + '=' + oldValue); @@ -1844,6 +1929,7 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) // non-boolean config to set int p = arg.indexOf('='); m_config[arg.left(p)] = arg.mid(p + 1); +*/ } else { showRedMessage(tr("E512: Unknown option: ") + arg); } @@ -1998,7 +2084,7 @@ void FakeVimHandler::Private::shiftRegionRight(int repeat) int endLine = lineForPosition(position()); if (beginLine > endLine) qSwap(beginLine, endLine); - int len = m_config[ConfigShiftWidth].toInt() * repeat; + int len = config(ConfigShiftWidth).toInt() * repeat; QString indent(len, ' '); int firstPos = firstPositionInLine(beginLine); @@ -2023,8 +2109,8 @@ void FakeVimHandler::Private::shiftRegionLeft(int repeat) int endLine = lineForPosition(position()); if (beginLine > endLine) qSwap(beginLine, endLine); - int shift = m_config[ConfigShiftWidth].toInt() * repeat; - int tab = m_config[ConfigTabStop].toInt(); + int shift = config(ConfigShiftWidth).toInt() * repeat; + int tab = config(ConfigTabStop).toInt(); int firstPos = firstPositionInLine(beginLine); recordBeginGroup(); @@ -2541,9 +2627,9 @@ void FakeVimHandler::handleCommand(const QString &cmd) d->handleExCommand(cmd); } -void FakeVimHandler::setConfigValue(const QString &key, const QString &value) +void FakeVimHandler::setConfigValue(int code, const QVariant &value) { - d->m_config[key] = value; + theFakeVimSetting(code)->setValue(value); } void FakeVimHandler::quit() @@ -2571,3 +2657,5 @@ QObject *FakeVimHandler::extraData() const return d->m_extraData; } +} // namespace Internal +} // namespace FakeVim diff --git a/src/plugins/fakevim/fakevimhandler.h b/src/plugins/fakevim/fakevimhandler.h index 7b5b183cf34..d8373ee41aa 100644 --- a/src/plugins/fakevim/fakevimhandler.h +++ b/src/plugins/fakevim/fakevimhandler.h @@ -30,6 +30,8 @@ #ifndef FAKEVIM_HANDLER_H #define FAKEVIM_HANDLER_H +#include <utils/savedaction.h> + #include <QtCore/QObject> #include <QtGui/QTextEdit> @@ -41,6 +43,55 @@ QT_END_NAMESPACE namespace FakeVim { namespace Internal { +enum FakeVimSettingsCode +{ + ConfigUseFakeVim, + ConfigStartOfLine, + ConfigHlSearch, + ConfigTabStop, + ConfigSmartTab, + ConfigShiftWidth, + ConfigExpandTab, + ConfigAutoIndent, + + // 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, + + // other actions + SettingsDialog, +}; + +class FakeVimSettings : public QObject +{ + Q_OBJECT + +public: + FakeVimSettings(QObject *parent = 0); + ~FakeVimSettings(); + + void insertItem(int code, Core::Utils::SavedAction *item, + const QString &longname = QString(), + const QString &shortname = QString()); + + Core::Utils::SavedAction *item(int code); + Core::Utils::SavedAction *item(const QString &name); + +public slots: + void readSettings(QSettings *settings); + void writeSettings(QSettings *settings); + +public: + QHash<int, Core::Utils::SavedAction *> m_items; + QHash<QString, int> m_nameToCode; + QHash<int, QString> m_codeToName; +}; + +FakeVimSettings *theFakeVimSettings(); +Core::Utils::SavedAction *theFakeVimSetting(int code); + class FakeVimHandler : public QObject { Q_OBJECT @@ -60,7 +111,7 @@ public slots: // This executes an "ex" style command taking context // information from widget; void handleCommand(const QString &cmd); - void setConfigValue(const QString &key, const QString &value); + void setConfigValue(int code, const QVariant &value); void quit(); // Convenience diff --git a/src/plugins/fakevim/fakevimoptions.ui b/src/plugins/fakevim/fakevimoptions.ui new file mode 100644 index 00000000000..4e3e8465993 --- /dev/null +++ b/src/plugins/fakevim/fakevimoptions.ui @@ -0,0 +1,197 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>FakeVimOptionPage</class> + <widget class="QWidget" name="FakeVimOptionPage"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>358</width> + <height>322</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QCheckBox" name="checkBoxUseFakeVim"> + <property name="text"> + <string>Use FakeVim</string> + </property> + </widget> + </item> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Vim style settings</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="2" column="0"> + <widget class="QLabel" name="labelExpandTab"> + <property name="toolTip"> + <string>vim's "expandtab" option</string> + </property> + <property name="text"> + <string>Expand tabulators:</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QCheckBox" name="checkBoxExpandTab"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="labelHlSearch"> + <property name="text"> + <string>Highlight search results:</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QCheckBox" name="checkBoxHlSearch"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="labelShiftWidth"> + <property name="text"> + <string>Shift width:</string> + </property> + </widget> + </item> + <item row="4" column="1"> + <widget class="QLineEdit" name="lineEditShiftWidth"/> + </item> + <item row="5" column="0"> + <widget class="QLabel" name="labelSmartTab"> + <property name="text"> + <string>Smart tabulators:</string> + </property> + </widget> + </item> + <item row="5" column="1"> + <widget class="QCheckBox" name="checkBoxSmartTab"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="6" column="0"> + <widget class="QLabel" name="labelStartOfLine"> + <property name="text"> + <string>Start of line:</string> + </property> + </widget> + </item> + <item row="6" column="1"> + <widget class="QCheckBox" name="checkBoxStartOfLine"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="7" column="0"> + <widget class="QLabel" name="label_2"> + <property name="toolTip"> + <string>vim's "tabstop" option</string> + </property> + <property name="text"> + <string>Tabulator size:</string> + </property> + </widget> + </item> + <item row="7" column="1"> + <widget class="QLineEdit" name="lineEditTabStop"/> + </item> + <item row="8" column="0"> + <widget class="QLabel" name="labelBackspace"> + <property name="text"> + <string>Backspace:</string> + </property> + </widget> + </item> + <item row="8" column="1"> + <widget class="QLineEdit" name="lineEditBackspace"/> + </item> + <item row="0" column="1"> + <widget class="QCheckBox" name="checkBoxAutoIndent"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="labelAutoIndent"> + <property name="toolTip"> + <string>VIM's "autoindent" option</string> + </property> + <property name="text"> + <string>Automatic indentation:</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QPushButton" name="pushButtonCopyTextEditorSettings"> + <property name="text"> + <string>Copy text editor settings</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButtonSetQtStyle"> + <property name="text"> + <string>Set Qt style</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButtonSetPlainStyle"> + <property name="text"> + <string>Set plain style</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>1</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index 65e907cdd8f..87027de5abb 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -29,8 +29,9 @@ #include "fakevimplugin.h" -#include "fakevimconstants.h" #include "fakevimhandler.h" +#include "ui_fakevimoptions.h" + #include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/coreconstants.h> @@ -38,6 +39,7 @@ #include <coreplugin/filemanager.h> #include <coreplugin/icore.h> #include <coreplugin/ifile.h> +#include <coreplugin/dialogs/ioptionspage.h> #include <coreplugin/messagemanager.h> #include <coreplugin/modemanager.h> #include <coreplugin/uniqueidmanager.h> @@ -56,6 +58,7 @@ #include <texteditor/textblockiterator.h> #include <utils/qtcassert.h> +#include <utils/savedaction.h> #include <indenter.h> @@ -89,6 +92,116 @@ const char * const INSTALL_KEY = "Alt+V,Alt+V"; } // namespace FakeVim +/////////////////////////////////////////////////////////////////////// +// +// FakeVimOptionPage +// +/////////////////////////////////////////////////////////////////////// + +namespace FakeVim { +namespace Internal { + +class FakeVimOptionPage : public Core::IOptionsPage +{ + Q_OBJECT + +public: + FakeVimOptionPage() {} + + // IOptionsPage + QString id() const { return QLatin1String("General"); } + QString trName() const { return tr("General"); } + QString category() const { return QLatin1String("FakeVim"); } + QString trCategory() const { return tr("FakeVim"); } + + QWidget *createPage(QWidget *parent); + void apply() { m_group.apply(ICore::instance()->settings()); } + void finish() { m_group.finish(); } + +private slots: + void copyTextEditorSettings(); + void setQtStyle(); + void setPlainStyle(); + +private: + friend class DebuggerPlugin; + Ui::FakeVimOptionPage m_ui; + + Core::Utils::SavedActionSet m_group; +}; + +QWidget *FakeVimOptionPage::createPage(QWidget *parent) +{ + QWidget *w = new QWidget(parent); + m_ui.setupUi(w); + + m_group.clear(); + m_group.insert(theFakeVimSetting(ConfigUseFakeVim), + m_ui.checkBoxUseFakeVim); + + m_group.insert(theFakeVimSetting(ConfigExpandTab), + m_ui.checkBoxExpandTab); + m_group.insert(theFakeVimSetting(ConfigHlSearch), + m_ui.checkBoxHlSearch); + m_group.insert(theFakeVimSetting(ConfigShiftWidth), + m_ui.lineEditShiftWidth); + + m_group.insert(theFakeVimSetting(ConfigSmartTab), + m_ui.checkBoxSmartTab); + m_group.insert(theFakeVimSetting(ConfigStartOfLine), + m_ui.checkBoxStartOfLine); + m_group.insert(theFakeVimSetting(ConfigTabStop), + m_ui.lineEditTabStop); + m_group.insert(theFakeVimSetting(ConfigBackspace), + m_ui.lineEditBackspace); + + m_group.insert(theFakeVimSetting(ConfigAutoIndent), + m_ui.checkBoxAutoIndent); + + connect(m_ui.pushButtonCopyTextEditorSettings, SIGNAL(clicked()), + this, SLOT(copyTextEditorSetting())); + connect(m_ui.pushButtonSetQtStyle, SIGNAL(clicked()), + this, SLOT(setQtStyle())); + connect(m_ui.pushButtonSetPlainStyle, SIGNAL(clicked()), + this, SLOT(setPlainStyle())); + + return w; +} + +void FakeVimOptionPage::copyTextEditorSettings() +{ + TextEditor::TabSettings ts = + TextEditor::TextEditorSettings::instance()->tabSettings(); + + m_ui.checkBoxExpandTab->setChecked(ts.m_spacesForTabs); + m_ui.lineEditTabStop->setText(QString::number(ts.m_tabSize)); + m_ui.lineEditShiftWidth->setText(QString::number(ts.m_indentSize)); + m_ui.checkBoxSmartTab->setChecked(ts.m_smartBackspace); + m_ui.checkBoxAutoIndent->setChecked(ts.m_autoIndent); +} + +void FakeVimOptionPage::setQtStyle() +{ + m_ui.checkBoxExpandTab->setChecked(true); + m_ui.lineEditTabStop->setText("4"); + m_ui.lineEditShiftWidth->setText("4"); + m_ui.checkBoxSmartTab->setChecked(true); + m_ui.checkBoxAutoIndent->setChecked(true); +} + +void FakeVimOptionPage::setPlainStyle() +{ + m_ui.checkBoxExpandTab->setChecked(false); + m_ui.lineEditTabStop->setText("8"); + m_ui.lineEditShiftWidth->setText("8"); + m_ui.checkBoxSmartTab->setChecked(false); + m_ui.checkBoxAutoIndent->setChecked(false); +} + +} // namespace Internal +} // namespace FakeVim + + /////////////////////////////////////////////////////////////////////// // // FakeVimPluginPrivate @@ -221,16 +334,6 @@ void FakeVimPluginPrivate::installHandler(Core::IEditor *editor) using namespace FakeVim::Constants; handler->setCurrentFileName(editor->file()->fileName()); TabSettings settings = bt->tabSettings(); - handler->setConfigValue(ConfigTabStop, - QString::number(settings.m_tabSize)); - handler->setConfigValue(ConfigShiftWidth, - QString::number(settings.m_indentSize)); - handler->setConfigValue(ConfigExpandTab, - settings.m_spacesForTabs ? ConfigOn : ConfigOff); - handler->setConfigValue(ConfigSmartTab, - settings.m_smartBackspace ? ConfigOn : ConfigOff); - handler->setConfigValue(ConfigAutoIndent, - settings.m_autoIndent ? ConfigOn : ConfigOff); } } @@ -317,10 +420,12 @@ void FakeVimPluginPrivate::indentRegion(int *amount, int beginLine, int endLine, if (!bt) return; + TextEditor::TabSettings tabSettings = + TextEditor::TextEditorSettings::instance()->tabSettings(); typedef SharedTools::Indenter<TextEditor::TextBlockIterator> Indenter; Indenter &indenter = Indenter::instance(); - indenter.setIndentSize(bt->tabSettings().m_indentSize); - indenter.setTabSize(bt->tabSettings().m_tabSize); + indenter.setIndentSize(tabSettings.m_indentSize); + indenter.setTabSize(tabSettings.m_tabSize); const QTextDocument *doc = bt->document(); QTextBlock begin = doc->findBlockByNumber(beginLine); @@ -340,7 +445,7 @@ void FakeVimPluginPrivate::indentRegion(int *amount, int beginLine, int endLine, const TextEditor::TextBlockIterator next(cur.next()); *amount = indenter.indentForBottomLine(current, docStart, next, typedChar); if (cur != end) - bt->tabSettings().indentLine(cur, *amount); + tabSettings.indentLine(cur, *amount); } if (cur != end) cur = cur.next(); -- GitLab