2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-03-30 14:46:33 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2009-03-30 14:46:33 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
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>
|
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
|
|
|
|
|
|
|
|
namespace FakeVim {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2016-03-01 23:24:59 +01:00
|
|
|
DummyAction::DummyAction(void *)
|
2013-03-08 17:50:16 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-01 23:24:59 +01:00
|
|
|
void DummyAction::setValue(const QVariant &value)
|
2013-03-08 17:50:16 +01:00
|
|
|
{
|
|
|
|
|
m_value = value;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-01 23:24:59 +01:00
|
|
|
QVariant DummyAction::value() const
|
2013-03-08 17:50:16 +01:00
|
|
|
{
|
|
|
|
|
return m_value;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-01 23:24:59 +01:00
|
|
|
void DummyAction::setDefaultValue(const QVariant &value)
|
2014-01-22 19:01:07 +02:00
|
|
|
{
|
|
|
|
|
m_defaultValue = value;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-01 23:24:59 +01:00
|
|
|
QVariant DummyAction::defaultValue() const
|
2014-01-22 19:01:07 +02:00
|
|
|
{
|
|
|
|
|
return m_defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-01 23:24:59 +01:00
|
|
|
void DummyAction::setSettingsKey(const QString &group, const QString &key)
|
2014-01-22 19:01:07 +02:00
|
|
|
{
|
2016-03-01 23:24:59 +01:00
|
|
|
m_settingsGroup = group;
|
2014-01-22 19:01:07 +02:00
|
|
|
m_settingsKey = key;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-01 23:24:59 +01:00
|
|
|
QString DummyAction::settingsKey() const
|
2014-01-22 19:01:07 +02:00
|
|
|
{
|
|
|
|
|
return m_settingsKey;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-30 14:46:33 +02:00
|
|
|
FakeVimSettings::FakeVimSettings()
|
2016-03-01 23:24:59 +01:00
|
|
|
{
|
|
|
|
|
// Specific FakeVim settings
|
2016-03-18 12:10:24 +01:00
|
|
|
createAction(ConfigReadVimRc, false, "ReadVimRc");
|
|
|
|
|
createAction(ConfigVimRcPath, QString(), "VimRcPath");
|
2016-03-01 23:24:59 +01:00
|
|
|
#ifndef FAKEVIM_STANDALONE
|
2016-03-18 12:10:24 +01:00
|
|
|
createAction(ConfigUseFakeVim, false, "UseFakeVim");
|
2016-03-01 23:24:59 +01:00
|
|
|
item(ConfigUseFakeVim)->setText(tr("Use Vim-style Editing"));
|
|
|
|
|
item(ConfigReadVimRc)->setText(tr("Read .vimrc"));
|
|
|
|
|
item(ConfigVimRcPath)->setText(tr("Path to .vimrc"));
|
|
|
|
|
#endif
|
2016-03-18 12:10:24 +01:00
|
|
|
createAction(ConfigShowMarks, false, "ShowMarks", "sm");
|
|
|
|
|
createAction(ConfigPassControlKey, false, "PassControlKey", "pck");
|
|
|
|
|
createAction(ConfigPassKeys, true, "PassKeys", "pk");
|
2016-03-01 23:24:59 +01:00
|
|
|
|
|
|
|
|
// Emulated Vsetting
|
2016-03-18 12:10:24 +01:00
|
|
|
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");
|
2019-03-28 10:21:33 +01:00
|
|
|
createAction(ConfigBlinkingCursor, false, "BlinkingCursor", "bc");
|
2016-03-18 12:10:24 +01:00
|
|
|
createAction(ConfigScrollOff, 0, "ScrollOff", "so");
|
|
|
|
|
createAction(ConfigBackspace, QString("indent,eol,start"), "ConfigBackspace", "bs");
|
|
|
|
|
createAction(ConfigIsKeyword, QString("@,48-57,_,192-255,a-z,A-Z"), "IsKeyword", "isk");
|
|
|
|
|
createAction(ConfigClipboard, QString(), "Clipboard", "cb");
|
2021-02-06 20:09:23 +01:00
|
|
|
createAction(ConfigFormatOptions, QString(), "formatoptions", "fo");
|
2021-01-25 21:06:53 +01:00
|
|
|
|
|
|
|
|
// Emulated plugins
|
|
|
|
|
createAction(ConfigEmulateVimCommentary, false, "commentary");
|
2021-02-06 19:22:26 +01:00
|
|
|
createAction(ConfigEmulateReplaceWithRegister, false, "ReplaceWithRegister");
|
2021-01-30 12:29:14 +01:00
|
|
|
createAction(ConfigEmulateExchange, false, "exchange");
|
2021-02-07 19:24:56 +01:00
|
|
|
createAction(ConfigEmulateArgTextObj, false, "argtextobj");
|
2021-01-30 14:16:02 +01:00
|
|
|
createAction(ConfigEmulateSurround, false, "surround");
|
2016-03-01 23:24:59 +01:00
|
|
|
}
|
2009-03-30 14:46:33 +02:00
|
|
|
|
|
|
|
|
FakeVimSettings::~FakeVimSettings()
|
|
|
|
|
{
|
|
|
|
|
qDeleteAll(m_items);
|
|
|
|
|
}
|
2010-01-29 21:33:57 +01:00
|
|
|
|
2016-03-01 23:24:59 +01:00
|
|
|
void FakeVimSettings::insertItem(int code, FakeVimAction *item,
|
2009-03-30 14:46:33 +02:00
|
|
|
const QString &longName, const QString &shortName)
|
|
|
|
|
{
|
2013-03-08 17:50:16 +01:00
|
|
|
QTC_ASSERT(!m_items.contains(code), qDebug() << code; return);
|
2009-03-30 14:46:33 +02:00
|
|
|
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)
|
|
|
|
|
{
|
2016-03-01 23:24:59 +01:00
|
|
|
foreach (FakeVimAction *item, m_items)
|
2009-03-30 14:46:33 +02:00
|
|
|
item->readSettings(settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimSettings::writeSettings(QSettings *settings)
|
|
|
|
|
{
|
2016-03-01 23:24:59 +01:00
|
|
|
foreach (FakeVimAction *item, m_items)
|
2009-03-30 14:46:33 +02:00
|
|
|
item->writeSettings(settings);
|
|
|
|
|
}
|
2010-01-29 21:33:57 +01:00
|
|
|
|
2016-03-01 23:24:59 +01:00
|
|
|
FakeVimAction *FakeVimSettings::item(int code)
|
2009-03-30 14:46:33 +02:00
|
|
|
{
|
2018-11-07 23:45:39 +01:00
|
|
|
QTC_ASSERT(m_items.value(code, 0), qDebug() << "CODE: " << code; return nullptr);
|
2009-03-30 14:46:33 +02:00
|
|
|
return m_items.value(code, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-01 23:24:59 +01:00
|
|
|
FakeVimAction *FakeVimSettings::item(const QString &name)
|
2009-03-30 15:27:59 +02:00
|
|
|
{
|
|
|
|
|
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)
|
2016-03-01 23:24:59 +01:00
|
|
|
return tr("Unknown option: %1").arg(name);
|
2012-05-03 10:43:04 +02:00
|
|
|
if (code == ConfigTabStop || code == ConfigShiftWidth) {
|
|
|
|
|
if (value.toInt() <= 0)
|
2016-03-01 23:24:59 +01:00
|
|
|
return tr("Argument must be positive: %1=%2")
|
2012-05-03 10:43:04 +02:00
|
|
|
.arg(name).arg(value);
|
|
|
|
|
}
|
2016-03-01 23:24:59 +01:00
|
|
|
FakeVimAction *act = item(code);
|
2012-05-03 10:43:04 +02:00
|
|
|
if (!act)
|
2016-03-01 23:24:59 +01:00
|
|
|
return tr("Unknown option: %1").arg(name);
|
2012-05-03 10:43:04 +02:00
|
|
|
act->setValue(value);
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-01 23:24:59 +01:00
|
|
|
void FakeVimSettings::createAction(int code, const QVariant &value,
|
|
|
|
|
const QString &settingsKey,
|
|
|
|
|
const QString &shortKey)
|
2009-03-30 14:46:33 +02:00
|
|
|
{
|
2018-11-07 23:45:39 +01:00
|
|
|
auto item = new FakeVimAction(nullptr);
|
2013-03-08 17:50:16 +01:00
|
|
|
item->setValue(value);
|
2016-03-18 12:10:24 +01:00
|
|
|
item->setSettingsKey("FakeVim", settingsKey);
|
2013-03-08 17:50:16 +01:00
|
|
|
item->setDefaultValue(value);
|
2016-03-01 23:24:59 +01:00
|
|
|
item->setCheckable(value.canConvert<bool>());
|
|
|
|
|
insertItem(code, item, settingsKey.toLower(), shortKey);
|
2013-03-08 17:50:16 +01:00
|
|
|
}
|
2009-03-30 14:46:33 +02:00
|
|
|
|
2013-03-08 17:50:16 +01:00
|
|
|
FakeVimSettings *theFakeVimSettings()
|
|
|
|
|
{
|
2016-03-01 23:24:59 +01:00
|
|
|
static FakeVimSettings s;
|
|
|
|
|
return &s;
|
|
|
|
|
}
|
2013-03-08 17:50:16 +01:00
|
|
|
|
2016-03-01 23:24:59 +01:00
|
|
|
FakeVimAction *theFakeVimSetting(int code)
|
2009-03-30 14:46:33 +02:00
|
|
|
{
|
|
|
|
|
return theFakeVimSettings()->item(code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace FakeVim
|