Commit c826e6dc authored by hjk's avatar hjk
Browse files

fakevim: re-organize settings handling

parent b8e9f38a
...@@ -242,7 +242,7 @@ class GdbOptionPage : public Core::IOptionsPage ...@@ -242,7 +242,7 @@ class GdbOptionPage : public Core::IOptionsPage
Q_OBJECT Q_OBJECT
public: public:
GdbOptionPage(DebuggerPlugin *plugin) : m_plugin(plugin) {} GdbOptionPage() {}
// IOptionsPage // IOptionsPage
QString id() const { return QLatin1String("General"); } QString id() const { return QLatin1String("General"); }
...@@ -258,7 +258,6 @@ private: ...@@ -258,7 +258,6 @@ private:
friend class DebuggerPlugin; friend class DebuggerPlugin;
Ui::GdbOptionPage m_ui; Ui::GdbOptionPage m_ui;
DebuggerPlugin *m_plugin;
Core::Utils::SavedActionSet m_group; Core::Utils::SavedActionSet m_group;
}; };
...@@ -332,7 +331,7 @@ class DumperOptionPage : public Core::IOptionsPage ...@@ -332,7 +331,7 @@ class DumperOptionPage : public Core::IOptionsPage
Q_OBJECT Q_OBJECT
public: public:
DumperOptionPage(DebuggerPlugin *plugin) : m_plugin(plugin) {} DumperOptionPage() {}
// IOptionsPage // IOptionsPage
QString id() const { return QLatin1String("DataDumper"); } QString id() const { return QLatin1String("DataDumper"); }
...@@ -350,7 +349,6 @@ private: ...@@ -350,7 +349,6 @@ private:
friend class DebuggerPlugin; friend class DebuggerPlugin;
Ui::DumperOptionPage m_ui; Ui::DumperOptionPage m_ui;
DebuggerPlugin *m_plugin;
Core::Utils::SavedActionSet m_group; Core::Utils::SavedActionSet m_group;
}; };
...@@ -650,9 +648,9 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess ...@@ -650,9 +648,9 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
m_manager, SLOT(setSimpleDockWidgetArrangement())); m_manager, SLOT(setSimpleDockWidgetArrangement()));
// FIXME: // FIXME:
m_generalOptionPage = new GdbOptionPage(this); m_generalOptionPage = new GdbOptionPage;
addObject(m_generalOptionPage); addObject(m_generalOptionPage);
m_dumperOptionPage = new DumperOptionPage(this); m_dumperOptionPage = new DumperOptionPage;
addObject(m_dumperOptionPage); addObject(m_dumperOptionPage);
m_locationMark = 0; m_locationMark = 0;
......
...@@ -18,6 +18,8 @@ SOURCES += \ ...@@ -18,6 +18,8 @@ SOURCES += \
fakevimplugin.cpp fakevimplugin.cpp
HEADERS += \ HEADERS += \
fakevimconstants.h \
fakevimhandler.h \ fakevimhandler.h \
fakevimplugin.h fakevimplugin.h
FORMS += \
fakevimoptions.ui
/**************************************************************************
**
** 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
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
#include "fakevimhandler.h" #include "fakevimhandler.h"
#include "fakevimconstants.h"
// Please do not add any direct dependencies to other Qt Creator code here. // Please do not add any direct dependencies to other Qt Creator code here.
// Instead emit signals and let the FakeVimPlugin channel the information to // 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 // Qt Creator. The idea is to keep this file here in a "clean" state that
...@@ -50,6 +48,7 @@ ...@@ -50,6 +48,7 @@
// spans between m_anchor (== anchor()) and m_tc.position() (== position()) // spans between m_anchor (== anchor()) and m_tc.position() (== position())
// The value of m_tc.anchor() is not used. // The value of m_tc.anchor() is not used.
#include <utils/qtcassert.h>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtCore/QFile> #include <QtCore/QFile>
...@@ -86,8 +85,114 @@ ...@@ -86,8 +85,114 @@
# define UNDO_DEBUG(s) # define UNDO_DEBUG(s)
#endif #endif
using namespace FakeVim::Internal; using namespace Core::Utils;
using namespace FakeVim::Constants;
///////////////////////////////////////////////////////////////////////
//
// 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: ...@@ -384,11 +489,10 @@ public:
QString m_oldNeedle; QString m_oldNeedle;
// vi style configuration // vi style configuration
QHash<QString, QString> m_config; QVariant config(int code) const { return theFakeVimSetting(code)->value(); }
bool hasConfig(const char *name) const bool hasConfig(int code) const { return config(code).toBool(); }
{ return m_config[name] == ConfigOn; } bool hasConfig(int code, const char *value) const // FIXME
bool hasConfig(const char *name, const char *value) const { return config(code).toString().contains(value); }
{ return m_config[name].contains(value); } // FIXME
// for restoring cursor position // for restoring cursor position
int m_savedYankPosition; int m_savedYankPosition;
...@@ -430,27 +534,6 @@ FakeVimHandler::Private::Private(FakeVimHandler *parent, QWidget *widget) ...@@ -430,27 +534,6 @@ FakeVimHandler::Private::Private(FakeVimHandler *parent, QWidget *widget)
m_cursorWidth = EDITOR(cursorWidth()); m_cursorWidth = EDITOR(cursorWidth());
m_inReplay = false; 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) bool FakeVimHandler::Private::wantsOverride(QKeyEvent *ev)
...@@ -1503,7 +1586,7 @@ EventResult FakeVimHandler::Private::handleInsertMode(int key, int, ...@@ -1503,7 +1586,7 @@ EventResult FakeVimHandler::Private::handleInsertMode(int key, int,
moveUp(count() * (linesOnScreen() - 2)); moveUp(count() * (linesOnScreen() - 2));
m_lastInsertion.clear(); m_lastInsertion.clear();
} else if (key == Key_Tab && hasConfig(ConfigExpandTab)) { } 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_lastInsertion.append(str);
m_tc.insertText(str); m_tc.insertText(str);
} else if (key >= control('a') && key <= control('z')) { } else if (key >= control('a') && key <= control('z')) {
...@@ -1817,16 +1900,18 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) ...@@ -1817,16 +1900,18 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
} else if (reSet.indexIn(cmd) != -1) { // :set } else if (reSet.indexIn(cmd) != -1) { // :set
QString arg = reSet.cap(2); QString arg = reSet.cap(2);
if (arg.isEmpty()) { if (arg.isEmpty()) {
QString info; //QString info;
foreach (const QString &key, m_config.keys()) //foreach (const QString &key, m_config.keys())
info += key + ": " + m_config.value(key) + "\n"; // info += key + ": " + m_config.value(key) + "\n";
emit q->extraInformationChanged(info); //emit q->extraInformationChanged(info);
} else if (m_config.contains(arg)) { theFakeVimSetting(SettingsDialog)->trigger(QVariant());
/*
} else if (theFakeVimSettings()->.contains(arg)) {
// boolean config to be switched on or non-boolean to show // boolean config to be switched on or non-boolean to show
QString oldValue = m_config.value(arg); QString oldValue = m_config.value(arg);
if (oldValue == ConfigOff) if (oldValue == false)
m_config[arg] = ConfigOn; m_config[arg] = true;
else if (oldValue == ConfigOn) else if (oldValue == true)
; // nothing to do ; // nothing to do
else else
showBlackMessage(arg + '=' + oldValue); showBlackMessage(arg + '=' + oldValue);
...@@ -1834,9 +1919,9 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) ...@@ -1834,9 +1919,9 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
// boolean config to be switched off // boolean config to be switched off
QString key = arg.mid(2); QString key = arg.mid(2);
QString oldValue = m_config.value(key); QString oldValue = m_config.value(key);
if (oldValue == ConfigOn) if (oldValue == true)
m_config[key] = ConfigOff; m_config[key] = false;
else if (oldValue == ConfigOff) else if (oldValue == false)
; // nothing to do ; // nothing to do
else else
showBlackMessage(key + '=' + oldValue); showBlackMessage(key + '=' + oldValue);
...@@ -1844,6 +1929,7 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) ...@@ -1844,6 +1929,7 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
// non-boolean config to set // non-boolean config to set
int p = arg.indexOf('='); int p = arg.indexOf('=');
m_config[arg.left(p)] = arg.mid(p + 1); m_config[arg.left(p)] = arg.mid(p + 1);
*/
} else { } else {
showRedMessage(tr("E512: Unknown option: ") + arg); showRedMessage(tr("E512: Unknown option: ") + arg);
} }
...@@ -1998,7 +2084,7 @@ void FakeVimHandler::Private::shiftRegionRight(int repeat) ...@@ -1998,7 +2084,7 @@ void FakeVimHandler::Private::shiftRegionRight(int repeat)
int endLine = lineForPosition(position()); int endLine = lineForPosition(position());
if (beginLine > endLine) if (beginLine > endLine)
qSwap(beginLine, endLine); qSwap(beginLine, endLine);
int len = m_config[ConfigShiftWidth].toInt() * repeat; int len = config(ConfigShiftWidth).toInt() * repeat;
QString indent(len, ' '); QString indent(len, ' ');
int firstPos = firstPositionInLine(beginLine); int firstPos = firstPositionInLine(beginLine);
...@@ -2023,8 +2109,8 @@ void FakeVimHandler::Private::shiftRegionLeft(int repeat) ...@@ -2023,8 +2109,8 @@ void FakeVimHandler::Private::shiftRegionLeft(int repeat)
int endLine = lineForPosition(position()); int endLine = lineForPosition(position());
if (beginLine > endLine) if (beginLine > endLine)
qSwap(beginLine, endLine); qSwap(beginLine, endLine);
int shift = m_config[ConfigShiftWidth].toInt() * repeat; int shift = config(ConfigShiftWidth).toInt() * repeat;
int tab = m_config[ConfigTabStop].toInt(); int tab = config(ConfigTabStop).toInt();
int firstPos = firstPositionInLine(beginLine); int firstPos = firstPositionInLine(beginLine);
recordBeginGroup(); recordBeginGroup();
...@@ -2541,9 +2627,9 @@ void FakeVimHandler::handleCommand(const QString &cmd) ...@@ -2541,9 +2627,9 @@ void FakeVimHandler::handleCommand(const QString &cmd)
d->handleExCommand(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() void FakeVimHandler::quit()
...@@ -2571,3 +2657,5 @@ QObject *FakeVimHandler::extraData() const ...@@ -2571,3 +2657,5 @@ QObject *FakeVimHandler::extraData() const
return d->m_extraData; return d->m_extraData;
} }
} // namespace Internal
} // namespace FakeVim
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#ifndef FAKEVIM_HANDLER_H #ifndef FAKEVIM_HANDLER_H
#define FAKEVIM_HANDLER_H #define FAKEVIM_HANDLER_H
#include <utils/savedaction.h>
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtGui/QTextEdit> #include <QtGui/QTextEdit>
...@@ -41,6 +43,55 @@ QT_END_NAMESPACE ...@@ -41,6 +43,55 @@ QT_END_NAMESPACE
namespace FakeVim { namespace FakeVim {
namespace Internal { 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 class FakeVimHandler : public QObject
{ {
Q_OBJECT Q_OBJECT
...@@ -60,7 +111,7 @@ public slots: ...@@ -60,7 +111,7 @@ public slots:
// This executes an "ex" style command taking context // This executes an "ex" style command taking context
// information from widget; // information from widget;
void handleCommand(const QString &cmd); void handleCommand(const QString &cmd);
void setConfigValue(const QString &key, const QString &value); void setConfigValue(int code, const QVariant &value);
void quit(); void quit();
// Convenience // Convenience
......
<?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 &quot;expandtab&quot; 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/>
<