forked from qt-creator/qt-creator
FakeVim: Simplify FakeVimSettings object
Change-Id: Ic4f4d23af021ed779a500183ca4b145dd3bc3443 Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
@@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
#include "fakevimactions.h"
|
#include "fakevimactions.h"
|
||||||
#include "fakevimhandler.h"
|
#include "fakevimhandler.h"
|
||||||
#include "fakevimtr.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
|
||||||
@@ -37,73 +36,92 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#ifdef FAKEVIM_STANDALONE
|
|
||||||
using namespace FakeVim::Internal::Utils;
|
|
||||||
#else
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
#endif
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// FakeVimSettings
|
|
||||||
//
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
namespace FakeVim {
|
namespace FakeVim {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
typedef QLatin1String _;
|
typedef QLatin1String _;
|
||||||
|
|
||||||
#ifdef FAKEVIM_STANDALONE
|
DummyAction::DummyAction(void *)
|
||||||
namespace Utils {
|
|
||||||
|
|
||||||
SavedAction::SavedAction(QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SavedAction::setValue(const QVariant &value)
|
void DummyAction::setValue(const QVariant &value)
|
||||||
{
|
{
|
||||||
m_value = value;
|
m_value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant SavedAction::value() const
|
QVariant DummyAction::value() const
|
||||||
{
|
{
|
||||||
return m_value;
|
return m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SavedAction::setDefaultValue(const QVariant &value)
|
void DummyAction::setDefaultValue(const QVariant &value)
|
||||||
{
|
{
|
||||||
m_defaultValue = value;
|
m_defaultValue = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant SavedAction::defaultValue() const
|
QVariant DummyAction::defaultValue() const
|
||||||
{
|
{
|
||||||
return m_defaultValue;
|
return m_defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SavedAction::setSettingsKey(const QString &key)
|
void DummyAction::setSettingsKey(const QString &group, const QString &key)
|
||||||
{
|
{
|
||||||
|
m_settingsGroup = group;
|
||||||
m_settingsKey = key;
|
m_settingsKey = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SavedAction::settingsKey() const
|
QString DummyAction::settingsKey() const
|
||||||
{
|
{
|
||||||
return m_settingsKey;
|
return m_settingsKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Utils
|
|
||||||
#endif // FAKEVIM_STANDALONE
|
|
||||||
|
|
||||||
FakeVimSettings::FakeVimSettings()
|
FakeVimSettings::FakeVimSettings()
|
||||||
{}
|
{
|
||||||
|
// Specific FakeVim settings
|
||||||
|
createAction(ConfigReadVimRc, false, _("ReadVimRc"));
|
||||||
|
createAction(ConfigVimRcPath, QString(), _("VimRcPath"));
|
||||||
|
#ifndef FAKEVIM_STANDALONE
|
||||||
|
createAction( ConfigUseFakeVim, false, _("UseFakeVim"));
|
||||||
|
item(ConfigUseFakeVim)->setText(tr("Use Vim-style Editing"));
|
||||||
|
item(ConfigReadVimRc)->setText(tr("Read .vimrc"));
|
||||||
|
item(ConfigVimRcPath)->setText(tr("Path to .vimrc"));
|
||||||
|
#endif
|
||||||
|
createAction(ConfigShowMarks, false, _("ShowMarks"), _("sm"));
|
||||||
|
createAction(ConfigPassControlKey, false, _("PassControlKey"), _("pck"));
|
||||||
|
createAction(ConfigPassKeys, true, _("PassKeys"), _("pk"));
|
||||||
|
|
||||||
|
// Emulated Vsetting
|
||||||
|
createAction(ConfigStartOfLine, true, _("StartOfLine"), _("sol"));
|
||||||
|
createAction(ConfigTabStop, 8, _("TabStop"), _("ts"));
|
||||||
|
createAction(ConfigSmartTab, false, _("SmartTab"), _("sta"));
|
||||||
|
createAction(ConfigHlSearch, true, _("HlSearch"), _("hls"));
|
||||||
|
createAction(ConfigShiftWidth, 8, _("ShiftWidth"), _("sw"));
|
||||||
|
createAction(ConfigExpandTab, false, _("ExpandTab"), _("et"));
|
||||||
|
createAction(ConfigAutoIndent, false, _("AutoIndent"), _("ai"));
|
||||||
|
createAction(ConfigSmartIndent, false, _("SmartIndent"), _("si"));
|
||||||
|
createAction(ConfigIncSearch, true, _("IncSearch"), _("is"));
|
||||||
|
createAction(ConfigUseCoreSearch, false, _("UseCoreSearch"), _("ucs"));
|
||||||
|
createAction(ConfigSmartCase, false, _("SmartCase"), _("scs"));
|
||||||
|
createAction(ConfigIgnoreCase, false, _("IgnoreCase"), _("ic"));
|
||||||
|
createAction(ConfigWrapScan, true, _("WrapScan"), _("ws"));
|
||||||
|
createAction(ConfigTildeOp, false, _("TildeOp"), _("top"));
|
||||||
|
createAction(ConfigShowCmd, true, _("ShowCmd"), _("sc"));
|
||||||
|
createAction(ConfigRelativeNumber, false, _("RelativeNumber"),_("rnu"));
|
||||||
|
createAction(ConfigScrollOff, 0, _("ScrollOff"), _("so"));
|
||||||
|
createAction(ConfigBackspace, _("indent,eol,start"), _("ConfigBackspace"), _("bs"));
|
||||||
|
createAction(ConfigIsKeyword, _("@,48-57,_,192-255,a-z,A-Z"), _("IsKeyword"), _("isk"));
|
||||||
|
createAction(ConfigClipboard, QString(), _("Clipboard"), _("cb"));
|
||||||
|
}
|
||||||
|
|
||||||
FakeVimSettings::~FakeVimSettings()
|
FakeVimSettings::~FakeVimSettings()
|
||||||
{
|
{
|
||||||
qDeleteAll(m_items);
|
qDeleteAll(m_items);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimSettings::insertItem(int code, SavedAction *item,
|
void FakeVimSettings::insertItem(int code, FakeVimAction *item,
|
||||||
const QString &longName, const QString &shortName)
|
const QString &longName, const QString &shortName)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(!m_items.contains(code), qDebug() << code; return);
|
QTC_ASSERT(!m_items.contains(code), qDebug() << code; return);
|
||||||
@@ -116,27 +134,25 @@ void FakeVimSettings::insertItem(int code, SavedAction *item,
|
|||||||
m_nameToCode[shortName] = code;
|
m_nameToCode[shortName] = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef FAKEVIM_STANDALONE
|
|
||||||
void FakeVimSettings::readSettings(QSettings *settings)
|
void FakeVimSettings::readSettings(QSettings *settings)
|
||||||
{
|
{
|
||||||
foreach (SavedAction *item, m_items)
|
foreach (FakeVimAction *item, m_items)
|
||||||
item->readSettings(settings);
|
item->readSettings(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimSettings::writeSettings(QSettings *settings)
|
void FakeVimSettings::writeSettings(QSettings *settings)
|
||||||
{
|
{
|
||||||
foreach (SavedAction *item, m_items)
|
foreach (FakeVimAction *item, m_items)
|
||||||
item->writeSettings(settings);
|
item->writeSettings(settings);
|
||||||
}
|
}
|
||||||
#endif // FAKEVIM_STANDALONE
|
|
||||||
|
|
||||||
SavedAction *FakeVimSettings::item(int code)
|
FakeVimAction *FakeVimSettings::item(int code)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_items.value(code, 0), qDebug() << "CODE: " << code; return 0);
|
QTC_ASSERT(m_items.value(code, 0), qDebug() << "CODE: " << code; return 0);
|
||||||
return m_items.value(code, 0);
|
return m_items.value(code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SavedAction *FakeVimSettings::item(const QString &name)
|
FakeVimAction *FakeVimSettings::item(const QString &name)
|
||||||
{
|
{
|
||||||
return m_items.value(m_nameToCode.value(name, -1), 0);
|
return m_items.value(m_nameToCode.value(name, -1), 0);
|
||||||
}
|
}
|
||||||
@@ -145,81 +161,38 @@ QString FakeVimSettings::trySetValue(const QString &name, const QString &value)
|
|||||||
{
|
{
|
||||||
int code = m_nameToCode.value(name, -1);
|
int code = m_nameToCode.value(name, -1);
|
||||||
if (code == -1)
|
if (code == -1)
|
||||||
return Tr::tr("Unknown option: %1").arg(name);
|
return tr("Unknown option: %1").arg(name);
|
||||||
if (code == ConfigTabStop || code == ConfigShiftWidth) {
|
if (code == ConfigTabStop || code == ConfigShiftWidth) {
|
||||||
if (value.toInt() <= 0)
|
if (value.toInt() <= 0)
|
||||||
return Tr::tr("Argument must be positive: %1=%2")
|
return tr("Argument must be positive: %1=%2")
|
||||||
.arg(name).arg(value);
|
.arg(name).arg(value);
|
||||||
}
|
}
|
||||||
SavedAction *act = item(code);
|
FakeVimAction *act = item(code);
|
||||||
if (!act)
|
if (!act)
|
||||||
return Tr::tr("Unknown option: %1").arg(name);
|
return tr("Unknown option: %1").arg(name);
|
||||||
act->setValue(value);
|
act->setValue(value);
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
SavedAction *createAction(FakeVimSettings *instance, int code, const QVariant &value,
|
void FakeVimSettings::createAction(int code, const QVariant &value,
|
||||||
const QString &settingsKey = QString(),
|
const QString &settingsKey,
|
||||||
const QString &shortKey = QString())
|
const QString &shortKey)
|
||||||
{
|
{
|
||||||
SavedAction *item = new SavedAction(instance);
|
FakeVimAction *item = new FakeVimAction(0);
|
||||||
item->setValue(value);
|
item->setValue(value);
|
||||||
#ifndef FAKEVIM_STANDALONE
|
|
||||||
item->setSettingsKey(_("FakeVim"), settingsKey);
|
item->setSettingsKey(_("FakeVim"), settingsKey);
|
||||||
item->setDefaultValue(value);
|
item->setDefaultValue(value);
|
||||||
item->setCheckable( value.canConvert<bool>() );
|
item->setCheckable(value.canConvert<bool>());
|
||||||
#endif
|
insertItem(code, item, settingsKey.toLower(), shortKey);
|
||||||
instance->insertItem(code, item, settingsKey.toLower(), shortKey);
|
|
||||||
return item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FakeVimSettings *theFakeVimSettings()
|
FakeVimSettings *theFakeVimSettings()
|
||||||
{
|
{
|
||||||
static FakeVimSettings *s = 0;
|
static FakeVimSettings s;
|
||||||
if (s)
|
return &s;
|
||||||
return s;
|
|
||||||
|
|
||||||
s = new FakeVimSettings;
|
|
||||||
|
|
||||||
// Specific FakeVim settings
|
|
||||||
createAction(s, ConfigReadVimRc, false, _("ReadVimRc"));
|
|
||||||
createAction(s, ConfigVimRcPath, QString(), _("VimRcPath"));
|
|
||||||
#ifndef FAKEVIM_STANDALONE
|
|
||||||
createAction(s, ConfigUseFakeVim, false, _("UseFakeVim"));
|
|
||||||
s->item(ConfigUseFakeVim)->setText(Tr::tr("Use Vim-style Editing"));
|
|
||||||
s->item(ConfigReadVimRc)->setText(Tr::tr("Read .vimrc"));
|
|
||||||
s->item(ConfigVimRcPath)->setText(Tr::tr("Path to .vimrc"));
|
|
||||||
#endif
|
|
||||||
createAction(s, ConfigShowMarks, false, _("ShowMarks"), _("sm"));
|
|
||||||
createAction(s, ConfigPassControlKey, false, _("PassControlKey"), _("pck"));
|
|
||||||
createAction(s, ConfigPassKeys, true, _("PassKeys"), _("pk"));
|
|
||||||
|
|
||||||
// Emulated Vim setting
|
|
||||||
createAction(s, ConfigStartOfLine, true, _("StartOfLine"), _("sol"));
|
|
||||||
createAction(s, ConfigTabStop, 8, _("TabStop"), _("ts"));
|
|
||||||
createAction(s, ConfigSmartTab, false, _("SmartTab"), _("sta"));
|
|
||||||
createAction(s, ConfigHlSearch, true, _("HlSearch"), _("hls"));
|
|
||||||
createAction(s, ConfigShiftWidth, 8, _("ShiftWidth"), _("sw"));
|
|
||||||
createAction(s, ConfigExpandTab, false, _("ExpandTab"), _("et"));
|
|
||||||
createAction(s, ConfigAutoIndent, false, _("AutoIndent"), _("ai"));
|
|
||||||
createAction(s, ConfigSmartIndent, false, _("SmartIndent"), _("si"));
|
|
||||||
createAction(s, ConfigIncSearch, true, _("IncSearch"), _("is"));
|
|
||||||
createAction(s, ConfigUseCoreSearch, false, _("UseCoreSearch"), _("ucs"));
|
|
||||||
createAction(s, ConfigSmartCase, false, _("SmartCase"), _("scs"));
|
|
||||||
createAction(s, ConfigIgnoreCase, false, _("IgnoreCase"), _("ic"));
|
|
||||||
createAction(s, ConfigWrapScan, true, _("WrapScan"), _("ws"));
|
|
||||||
createAction(s, ConfigTildeOp, false, _("TildeOp"), _("top"));
|
|
||||||
createAction(s, ConfigShowCmd, true, _("ShowCmd"), _("sc"));
|
|
||||||
createAction(s, ConfigRelativeNumber, false, _("RelativeNumber"),_("rnu"));
|
|
||||||
createAction(s, ConfigScrollOff, 0, _("ScrollOff"), _("so"));
|
|
||||||
createAction(s, ConfigBackspace, _("indent,eol,start"), _("ConfigBackspace"), _("bs"));
|
|
||||||
createAction(s, ConfigIsKeyword, _("@,48-57,_,192-255,a-z,A-Z"), _("IsKeyword"), _("isk"));
|
|
||||||
createAction(s, ConfigClipboard, QString(), _("Clipboard"), _("cb"));
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SavedAction *theFakeVimSetting(int code)
|
FakeVimAction *theFakeVimSetting(int code)
|
||||||
{
|
{
|
||||||
return theFakeVimSettings()->item(code);
|
return theFakeVimSettings()->item(code);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,37 +30,42 @@
|
|||||||
# include <utils/savedaction.h>
|
# include <utils/savedaction.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QSettings>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
namespace FakeVim {
|
namespace FakeVim {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
#ifdef FAKEVIM_STANDALONE
|
class DummyAction
|
||||||
namespace Utils {
|
|
||||||
|
|
||||||
class SavedAction : public QObject
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SavedAction(QObject *parent);
|
DummyAction(void *parent);
|
||||||
void setValue(const QVariant &value);
|
void setValue(const QVariant &value);
|
||||||
QVariant value() const;
|
QVariant value() const;
|
||||||
void setDefaultValue(const QVariant &value);
|
void setDefaultValue(const QVariant &value);
|
||||||
QVariant defaultValue() const;
|
QVariant defaultValue() const;
|
||||||
void setSettingsKey(const QString &key);
|
void setSettingsKey(const QString &group, const QString &key);
|
||||||
QString settingsKey() const;
|
QString settingsKey() const;
|
||||||
|
void setCheckable(bool) {}
|
||||||
|
|
||||||
|
void readSettings(QSettings *) {}
|
||||||
|
void writeSettings(QSettings *) {}
|
||||||
|
|
||||||
QVariant m_value;
|
QVariant m_value;
|
||||||
QVariant m_defaultValue;
|
QVariant m_defaultValue;
|
||||||
|
QString m_settingsGroup;
|
||||||
QString m_settingsKey;
|
QString m_settingsKey;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Utils
|
#ifdef FAKEVIM_STANDALONE
|
||||||
#endif // FAKEVIM_STANDALONE
|
typedef DummyAction FakeVimAction;
|
||||||
|
#else
|
||||||
|
typedef Utils::SavedAction FakeVimAction;
|
||||||
|
#endif
|
||||||
|
|
||||||
enum FakeVimSettingsCode
|
enum FakeVimSettingsCode
|
||||||
{
|
{
|
||||||
@@ -105,34 +110,36 @@ enum FakeVimSettingsCode
|
|||||||
ConfigRelativeNumber
|
ConfigRelativeNumber
|
||||||
};
|
};
|
||||||
|
|
||||||
class FakeVimSettings : public QObject
|
class FakeVimSettings
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_DECLARE_TR_FUNCTIONS(FakeVim)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FakeVimSettings();
|
FakeVimSettings();
|
||||||
~FakeVimSettings();
|
~FakeVimSettings();
|
||||||
void insertItem(int code, Utils::SavedAction *item,
|
void insertItem(int code, FakeVimAction *item,
|
||||||
const QString &longname = QString(),
|
const QString &longname = QString(),
|
||||||
const QString &shortname = QString());
|
const QString &shortname = QString());
|
||||||
|
|
||||||
Utils::SavedAction *item(int code);
|
FakeVimAction *item(int code);
|
||||||
Utils::SavedAction *item(const QString &name);
|
FakeVimAction *item(const QString &name);
|
||||||
QString trySetValue(const QString &name, const QString &value);
|
QString trySetValue(const QString &name, const QString &value);
|
||||||
|
|
||||||
#ifndef FAKEVIM_STANDALONE
|
|
||||||
void readSettings(QSettings *settings);
|
void readSettings(QSettings *settings);
|
||||||
void writeSettings(QSettings *settings);
|
void writeSettings(QSettings *settings);
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<int, Utils::SavedAction *> m_items;
|
void createAction(int code, const QVariant &value,
|
||||||
|
const QString &settingsKey = QString(),
|
||||||
|
const QString &shortKey = QString());
|
||||||
|
|
||||||
|
QHash<int, FakeVimAction *> m_items;
|
||||||
QHash<QString, int> m_nameToCode;
|
QHash<QString, int> m_nameToCode;
|
||||||
QHash<int, QString> m_codeToName;
|
QHash<int, QString> m_codeToName;
|
||||||
};
|
};
|
||||||
|
|
||||||
FakeVimSettings *theFakeVimSettings();
|
FakeVimSettings *theFakeVimSettings();
|
||||||
Utils::SavedAction *theFakeVimSetting(int code);
|
FakeVimAction *theFakeVimSetting(int code);
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace FakeVim
|
} // namespace FakeVim
|
||||||
|
|||||||
@@ -105,9 +105,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
#ifdef FAKEVIM_STANDALONE
|
|
||||||
using namespace FakeVim::Internal::Utils;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace FakeVim {
|
namespace FakeVim {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -5713,7 +5710,7 @@ bool FakeVimHandler::Private::handleExSetCommand(const ExCommand &cmd)
|
|||||||
if (negateOption)
|
if (negateOption)
|
||||||
optionName.remove(0, 2);
|
optionName.remove(0, 2);
|
||||||
|
|
||||||
SavedAction *act = theFakeVimSettings()->item(optionName);
|
FakeVimAction *act = theFakeVimSettings()->item(optionName);
|
||||||
if (!act) {
|
if (!act) {
|
||||||
showMessage(MessageError, Tr::tr("Unknown option:")
|
showMessage(MessageError, Tr::tr("Unknown option:")
|
||||||
+ QLatin1Char(' ') + cmd.args);
|
+ QLatin1Char(' ') + cmd.args);
|
||||||
|
|||||||
@@ -1025,7 +1025,7 @@ class FakeVimPluginPrivate : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
FakeVimPluginPrivate(FakeVimPlugin *);
|
FakeVimPluginPrivate(FakeVimPlugin *);
|
||||||
~FakeVimPluginPrivate();
|
|
||||||
friend class FakeVimPlugin;
|
friend class FakeVimPlugin;
|
||||||
friend class FakeVimExCommandsWidget;
|
friend class FakeVimExCommandsWidget;
|
||||||
friend class FakeVimUserCommandsPage;
|
friend class FakeVimUserCommandsPage;
|
||||||
@@ -1171,11 +1171,6 @@ FakeVimPluginPrivate::FakeVimPluginPrivate(FakeVimPlugin *plugin)
|
|||||||
m_statusBar = 0;
|
m_statusBar = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
FakeVimPluginPrivate::~FakeVimPluginPrivate()
|
|
||||||
{
|
|
||||||
theFakeVimSettings()->deleteLater();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FakeVimPluginPrivate::onCoreAboutToClose()
|
void FakeVimPluginPrivate::onCoreAboutToClose()
|
||||||
{
|
{
|
||||||
// Don't attach to editors anymore.
|
// Don't attach to editors anymore.
|
||||||
|
|||||||
Reference in New Issue
Block a user