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
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;
......
......@@ -18,6 +18,8 @@ SOURCES += \
fakevimplugin.cpp
HEADERS += \
fakevimconstants.h \
fakevimhandler.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 @@
#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
......@@ -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
......
<?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/>
</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 &quot;tabstop&quot; 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 &quot;autoindent&quot; 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>