2009-03-30 14:46:33 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2009-03-30 14:46:33 +02:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2009-03-30 14:46:33 +02:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2009-03-30 14:46:33 +02:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2009-03-30 14:46:33 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "fakevimactions.h"
|
|
|
|
|
|
2010-01-29 21:33:57 +01:00
|
|
|
// Please do not add any direct dependencies to other Qt Creator code here.
|
2009-03-30 14:46:33 +02:00
|
|
|
// 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
|
|
|
|
|
// allows easy reuse with any QTextEdit or QPlainTextEdit derived class.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
#include <QtCore/QFile>
|
|
|
|
|
#include <QtCore/QObject>
|
|
|
|
|
#include <QtCore/QPointer>
|
|
|
|
|
#include <QtCore/QProcess>
|
|
|
|
|
#include <QtCore/QRegExp>
|
|
|
|
|
#include <QtCore/QTextStream>
|
|
|
|
|
#include <QtCore/QtAlgorithms>
|
2009-05-13 14:39:55 +02:00
|
|
|
#include <QtCore/QCoreApplication>
|
2009-03-30 14:46:33 +02:00
|
|
|
#include <QtCore/QStack>
|
|
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
using namespace Utils;
|
2009-03-30 14:46:33 +02:00
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// FakeVimSettings
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
namespace FakeVim {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
FakeVimSettings::FakeVimSettings()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
FakeVimSettings::~FakeVimSettings()
|
|
|
|
|
{
|
|
|
|
|
qDeleteAll(m_items);
|
|
|
|
|
}
|
2010-01-29 21:33:57 +01:00
|
|
|
|
2009-03-30 14:46:33 +02:00
|
|
|
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);
|
|
|
|
|
}
|
2010-01-29 21:33:57 +01:00
|
|
|
|
2009-03-30 14:46:33 +02:00
|
|
|
SavedAction *FakeVimSettings::item(int code)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_items.value(code, 0), qDebug() << "CODE: " << code; return 0);
|
|
|
|
|
return m_items.value(code, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-30 15:27:59 +02:00
|
|
|
SavedAction *FakeVimSettings::item(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
return m_items.value(m_nameToCode.value(name, -1), 0);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-30 14:46:33 +02:00
|
|
|
FakeVimSettings *theFakeVimSettings()
|
|
|
|
|
{
|
|
|
|
|
static FakeVimSettings *instance = 0;
|
|
|
|
|
if (instance)
|
|
|
|
|
return instance;
|
|
|
|
|
|
|
|
|
|
instance = new FakeVimSettings;
|
|
|
|
|
|
2010-04-08 08:34:55 +02:00
|
|
|
typedef QLatin1String _;
|
2009-03-30 14:46:33 +02:00
|
|
|
SavedAction *item = 0;
|
|
|
|
|
|
2010-04-08 08:34:55 +02:00
|
|
|
const QString group = _("FakeVim");
|
2009-03-30 14:46:33 +02:00
|
|
|
item = new SavedAction(instance);
|
2010-04-08 08:34:55 +02:00
|
|
|
item->setText(QCoreApplication::translate("FakeVim::Internal",
|
2010-05-14 15:45:43 +02:00
|
|
|
"Use Vim-style Editing"));
|
2010-04-08 08:34:55 +02:00
|
|
|
item->setSettingsKey(group, _("UseFakeVim"));
|
2009-03-30 16:54:25 +02:00
|
|
|
item->setCheckable(true);
|
2009-12-11 13:24:53 +01:00
|
|
|
item->setValue(false);
|
2009-03-30 14:46:33 +02:00
|
|
|
instance->insertItem(ConfigUseFakeVim, item);
|
|
|
|
|
|
2010-04-16 17:47:02 +02:00
|
|
|
item = new SavedAction(instance);
|
|
|
|
|
item->setText(QCoreApplication::translate("FakeVim::Internal",
|
|
|
|
|
"Read .vimrc"));
|
|
|
|
|
item->setSettingsKey(group, _("ReadVimRc"));
|
|
|
|
|
item->setCheckable(true);
|
|
|
|
|
item->setValue(false);
|
|
|
|
|
instance->insertItem(ConfigReadVimRc, item);
|
|
|
|
|
|
2009-03-30 14:46:33 +02:00
|
|
|
item = new SavedAction(instance);
|
2010-03-08 11:44:43 +01:00
|
|
|
item->setValue(true);
|
|
|
|
|
item->setDefaultValue(true);
|
2010-04-08 08:34:55 +02:00
|
|
|
item->setSettingsKey(group, _("StartOfLine"));
|
2009-03-30 16:54:25 +02:00
|
|
|
item->setCheckable(true);
|
2010-04-08 08:34:55 +02:00
|
|
|
instance->insertItem(ConfigStartOfLine, item, _("startofline"), _("sol"));
|
2009-03-30 14:46:33 +02:00
|
|
|
|
|
|
|
|
item = new SavedAction(instance);
|
|
|
|
|
item->setDefaultValue(8);
|
2010-04-08 08:34:55 +02:00
|
|
|
item->setSettingsKey(group, _("TabStop"));
|
|
|
|
|
instance->insertItem(ConfigTabStop, item, _("tabstop"), _("ts"));
|
2009-03-30 14:46:33 +02:00
|
|
|
|
|
|
|
|
item = new SavedAction(instance);
|
|
|
|
|
item->setDefaultValue(false);
|
2009-12-11 13:24:53 +01:00
|
|
|
item->setValue(false);
|
2010-04-08 08:34:55 +02:00
|
|
|
item->setSettingsKey(group, _("SmartTab"));
|
|
|
|
|
instance->insertItem(ConfigSmartTab, item, _("smarttab"), _("sta"));
|
2009-03-30 14:46:33 +02:00
|
|
|
|
|
|
|
|
item = new SavedAction(instance);
|
|
|
|
|
item->setDefaultValue(true);
|
2009-12-11 13:24:53 +01:00
|
|
|
item->setValue(true);
|
2010-04-08 08:34:55 +02:00
|
|
|
item->setSettingsKey(group, _("HlSearch"));
|
2009-03-30 16:54:25 +02:00
|
|
|
item->setCheckable(true);
|
2010-04-08 08:34:55 +02:00
|
|
|
instance->insertItem(ConfigHlSearch, item, _("hlsearch"), _("hls"));
|
2009-03-30 14:46:33 +02:00
|
|
|
|
|
|
|
|
item = new SavedAction(instance);
|
|
|
|
|
item->setDefaultValue(8);
|
2010-04-08 08:34:55 +02:00
|
|
|
item->setSettingsKey(group, _("ShiftWidth"));
|
|
|
|
|
instance->insertItem(ConfigShiftWidth, item, _("shiftwidth"), _("sw"));
|
2009-03-30 14:46:33 +02:00
|
|
|
|
|
|
|
|
item = new SavedAction(instance);
|
|
|
|
|
item->setDefaultValue(false);
|
2009-12-11 13:24:53 +01:00
|
|
|
item->setValue(false);
|
2010-04-08 08:34:55 +02:00
|
|
|
item->setSettingsKey(group, _("ExpandTab"));
|
2009-03-30 16:54:25 +02:00
|
|
|
item->setCheckable(true);
|
2010-04-08 08:34:55 +02:00
|
|
|
instance->insertItem(ConfigExpandTab, item, _("expandtab"), _("et"));
|
2009-03-30 14:46:33 +02:00
|
|
|
|
|
|
|
|
item = new SavedAction(instance);
|
|
|
|
|
item->setDefaultValue(false);
|
2009-12-11 13:24:53 +01:00
|
|
|
item->setValue(false);
|
2010-04-08 08:34:55 +02:00
|
|
|
item->setSettingsKey(group, _("AutoIndent"));
|
2009-12-11 13:24:53 +01:00
|
|
|
item->setValue(false);
|
2009-03-30 16:54:25 +02:00
|
|
|
item->setCheckable(true);
|
2010-04-08 08:34:55 +02:00
|
|
|
instance->insertItem(ConfigAutoIndent, item, _("autoindent"), _("ai"));
|
2009-03-30 14:46:33 +02:00
|
|
|
|
2010-01-06 14:57:46 +01:00
|
|
|
item = new SavedAction(instance);
|
|
|
|
|
item->setDefaultValue(false);
|
|
|
|
|
item->setValue(false);
|
2010-04-08 08:34:55 +02:00
|
|
|
item->setSettingsKey(group, _("SmartIndent"));
|
2010-01-06 14:57:46 +01:00
|
|
|
item->setValue(false);
|
|
|
|
|
item->setCheckable(true);
|
2010-04-08 08:34:55 +02:00
|
|
|
instance->insertItem(ConfigSmartIndent, item, _("smartindent"), _("si"));
|
2010-01-06 14:57:46 +01:00
|
|
|
|
2009-06-02 11:56:58 +02:00
|
|
|
item = new SavedAction(instance);
|
|
|
|
|
item->setDefaultValue(true);
|
2009-12-11 13:24:53 +01:00
|
|
|
item->setValue(true);
|
2010-04-08 08:34:55 +02:00
|
|
|
item->setSettingsKey(group, _("IncSearch"));
|
2009-06-02 11:56:58 +02:00
|
|
|
item->setCheckable(true);
|
2010-04-08 08:34:55 +02:00
|
|
|
instance->insertItem(ConfigIncSearch, item, _("incsearch"), _("is"));
|
2009-06-02 11:56:58 +02:00
|
|
|
|
2009-03-30 14:46:33 +02:00
|
|
|
item = new SavedAction(instance);
|
2010-04-08 08:34:55 +02:00
|
|
|
item->setDefaultValue(false);
|
|
|
|
|
item->setValue(false);
|
|
|
|
|
item->setSettingsKey(group, _("UseCoreSearch")); item->setCheckable(true);
|
|
|
|
|
instance->insertItem(ConfigUseCoreSearch, item,
|
|
|
|
|
_("usecoresearch"), _("ucs"));
|
|
|
|
|
|
|
|
|
|
item = new SavedAction(instance);
|
|
|
|
|
item->setDefaultValue(_("indent,eol,start"));
|
|
|
|
|
item->setSettingsKey(group, _("Backspace"));
|
|
|
|
|
instance->insertItem(ConfigBackspace, item, _("backspace"), _("bs"));
|
2009-03-30 14:46:33 +02:00
|
|
|
|
2010-04-28 11:35:07 +02:00
|
|
|
item = new SavedAction(instance);
|
2010-04-28 16:19:51 +02:00
|
|
|
item->setDefaultValue(_("@,48-57,_,192-255,a-z,A-Z"));
|
2010-04-28 11:35:07 +02:00
|
|
|
item->setSettingsKey(group, _("IsKeyword"));
|
|
|
|
|
instance->insertItem(ConfigIsKeyword, item, _("iskeyword"), _("isk"));
|
|
|
|
|
|
2010-05-10 16:30:46 +02:00
|
|
|
// Invented here.
|
|
|
|
|
item = new SavedAction(instance);
|
|
|
|
|
item->setDefaultValue(false);
|
|
|
|
|
item->setValue(false);
|
|
|
|
|
item->setSettingsKey(group, _("ShowMarks"));
|
|
|
|
|
item->setCheckable(true);
|
|
|
|
|
instance->insertItem(ConfigShowMarks, item, _("showmarks"), _("sm"));
|
|
|
|
|
|
2010-09-24 09:07:08 +02:00
|
|
|
item = new SavedAction(instance);
|
|
|
|
|
item->setDefaultValue(false);
|
|
|
|
|
item->setValue(false);
|
|
|
|
|
item->setSettingsKey(group, _("PassControlKey"));
|
|
|
|
|
item->setCheckable(true);
|
|
|
|
|
instance->insertItem(ConfigPassControlKey, item, _("passcontrolkey"), _("pck"));
|
|
|
|
|
|
2009-03-30 14:46:33 +02:00
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SavedAction *theFakeVimSetting(int code)
|
|
|
|
|
{
|
|
|
|
|
return theFakeVimSettings()->item(code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace FakeVim
|