2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-03-30 14:46:33 +02:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2009-03-30 14:46:33 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-03-30 14:46:33 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2009-03-30 14:46:33 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-03-30 14:46:33 +02:00
|
|
|
|
|
|
|
|
#include "fakevimactions.h"
|
2012-05-03 10:43:04 +02:00
|
|
|
#include "fakevimhandler.h"
|
2009-03-30 14:46:33 +02:00
|
|
|
|
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>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QCoreApplication>
|
2009-03-30 14:46:33 +02:00
|
|
|
|
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;
|
|
|
|
|
}
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (!shortName.isEmpty())
|
2009-03-30 14:46:33 +02:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-03 10:43:04 +02:00
|
|
|
QString FakeVimSettings::trySetValue(const QString &name, const QString &value)
|
|
|
|
|
{
|
|
|
|
|
int code = m_nameToCode.value(name, -1);
|
|
|
|
|
if (code == -1)
|
|
|
|
|
return FakeVimHandler::tr("Unknown option: %1").arg(name);
|
|
|
|
|
if (code == ConfigTabStop || code == ConfigShiftWidth) {
|
|
|
|
|
if (value.toInt() <= 0)
|
|
|
|
|
return FakeVimHandler::tr("Argument must be positive: %1=%2")
|
|
|
|
|
.arg(name).arg(value);
|
|
|
|
|
}
|
|
|
|
|
SavedAction *act = item(code);
|
|
|
|
|
if (!act)
|
|
|
|
|
return FakeVimHandler::tr("Unknown option: %1").arg(name);
|
|
|
|
|
act->setValue(value);
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
|
2013-02-14 19:12:30 +01:00
|
|
|
item = new SavedAction(instance);
|
|
|
|
|
item->setText(QCoreApplication::translate("FakeVim::Internal",
|
|
|
|
|
"Path to .vimrc"));
|
|
|
|
|
item->setDefaultValue(QString());
|
|
|
|
|
item->setSettingsKey(group, _("VimRcPath"));
|
|
|
|
|
instance->insertItem(ConfigVimRcPath, 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"));
|
|
|
|
|
|
2012-07-22 14:30:56 +02:00
|
|
|
item = new SavedAction(instance);
|
|
|
|
|
item->setDefaultValue(false);
|
|
|
|
|
item->setValue(false);
|
|
|
|
|
item->setSettingsKey(group, _("SmartCase")); item->setCheckable(true);
|
|
|
|
|
item->setCheckable(true);
|
|
|
|
|
instance->insertItem(ConfigSmartCase, item, _("smartcase"), _("scs"));
|
|
|
|
|
|
2012-09-01 10:44:02 +02:00
|
|
|
item = new SavedAction(instance);
|
|
|
|
|
item->setDefaultValue(true);
|
|
|
|
|
item->setValue(true);
|
|
|
|
|
item->setSettingsKey(group, _("WrapScan")); item->setCheckable(true);
|
|
|
|
|
item->setCheckable(true);
|
|
|
|
|
instance->insertItem(ConfigWrapScan, item, _("wrapscan"), _("ws"));
|
|
|
|
|
|
2010-04-08 08:34:55 +02:00
|
|
|
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"));
|
|
|
|
|
|
2012-07-26 21:46:38 +02:00
|
|
|
item = new SavedAction(instance);
|
|
|
|
|
item->setDefaultValue(QString());
|
|
|
|
|
item->setValue(QString());
|
|
|
|
|
item->setSettingsKey(group, _("Clipboard"));
|
|
|
|
|
item->setCheckable(true);
|
|
|
|
|
instance->insertItem(ConfigClipboard, item, _("clipboard"), _("cb"));
|
|
|
|
|
|
2012-11-09 17:42:52 +01:00
|
|
|
item = new SavedAction(instance);
|
|
|
|
|
item->setDefaultValue(true);
|
|
|
|
|
item->setValue(true);
|
|
|
|
|
item->setSettingsKey(group, _("ShowCmd")); item->setCheckable(true);
|
|
|
|
|
item->setCheckable(true);
|
|
|
|
|
instance->insertItem(ConfigShowCmd, item, _("showcmd"), _("sc"));
|
|
|
|
|
|
2009-03-30 14:46:33 +02:00
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SavedAction *theFakeVimSetting(int code)
|
|
|
|
|
{
|
|
|
|
|
return theFakeVimSettings()->item(code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace FakeVim
|