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.
|
|
|
|
|
|
2021-02-26 17:55:55 +01:00
|
|
|
#include <utils/layoutbuilder.h>
|
2009-03-30 14:46:33 +02:00
|
|
|
#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 {
|
|
|
|
|
|
2021-02-26 17:55:55 +01:00
|
|
|
#ifdef FAKEVIM_STANDALONE
|
|
|
|
|
FvBaseAspect::FvBaseAspect()
|
2013-03-08 17:50:16 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 17:55:55 +01:00
|
|
|
void FvBaseAspect::setValue(const QVariant &value)
|
2013-03-08 17:50:16 +01:00
|
|
|
{
|
|
|
|
|
m_value = value;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 17:55:55 +01:00
|
|
|
QVariant FvBaseAspect::value() const
|
2013-03-08 17:50:16 +01:00
|
|
|
{
|
|
|
|
|
return m_value;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 17:55:55 +01:00
|
|
|
void FvBaseAspect::setDefaultValue(const QVariant &value)
|
2014-01-22 19:01:07 +02:00
|
|
|
{
|
|
|
|
|
m_defaultValue = value;
|
2021-03-03 12:08:22 +01:00
|
|
|
m_value = value;
|
2014-01-22 19:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-26 17:55:55 +01:00
|
|
|
QVariant FvBaseAspect::defaultValue() const
|
2014-01-22 19:01:07 +02:00
|
|
|
{
|
|
|
|
|
return m_defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 17:55:55 +01:00
|
|
|
void FvBaseAspect::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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 17:55:55 +01:00
|
|
|
QString FvBaseAspect::settingsKey() const
|
2014-01-22 19:01:07 +02:00
|
|
|
{
|
|
|
|
|
return m_settingsKey;
|
|
|
|
|
}
|
2021-02-26 17:55:55 +01:00
|
|
|
#endif
|
2014-01-22 19:01:07 +02:00
|
|
|
|
2009-03-30 14:46:33 +02:00
|
|
|
FakeVimSettings::FakeVimSettings()
|
2016-03-01 23:24:59 +01:00
|
|
|
{
|
|
|
|
|
#ifndef FAKEVIM_STANDALONE
|
2021-02-26 17:55:55 +01:00
|
|
|
setup(&useFakeVim, false, "UseFakeVim", {}, tr("Use FakeVim"));
|
2016-03-01 23:24:59 +01:00
|
|
|
#endif
|
2021-02-26 17:55:55 +01:00
|
|
|
// Specific FakeVim settings
|
|
|
|
|
setup(&readVimRc, false, "ReadVimRc", {}, tr("Read .vimrc from location:"));
|
|
|
|
|
setup(&vimRcPath, QString(), "VimRcPath", {}, {}); // tr("Path to .vimrc")
|
|
|
|
|
setup(&showMarks, false, "ShowMarks", "sm", tr("Show position of text marks"));
|
|
|
|
|
setup(&passControlKey, false, "PassControlKey", "pck", tr("Pass control keys"));
|
|
|
|
|
setup(&passKeys, true, "PassKeys", "pk", tr("Pass keys in insert mode"));
|
2016-03-01 23:24:59 +01:00
|
|
|
|
|
|
|
|
// Emulated Vsetting
|
2021-02-26 17:55:55 +01:00
|
|
|
setup(&startOfLine, true, "StartOfLine", "sol", tr("Start of line"));
|
|
|
|
|
setup(&tabStop, 8, "TabStop", "ts", tr("Tabulator size:"));
|
|
|
|
|
setup(&smartTab, false, "SmartTab", "sta", tr("Smart tabulators"));
|
|
|
|
|
setup(&hlSearch, true, "HlSearch", "hls", tr("Highlight search results"));
|
|
|
|
|
setup(&shiftWidth, 8, "ShiftWidth", "sw", tr("Shift width:"));
|
|
|
|
|
setup(&expandTab, false, "ExpandTab", "et", tr("Expand tabulators"));
|
|
|
|
|
setup(&autoIndent, false, "AutoIndent", "ai", tr("Automatic indentation"));
|
|
|
|
|
setup(&smartIndent, false, "SmartIndent", "si", tr("Smart tabulators"));
|
|
|
|
|
setup(&incSearch, true, "IncSearch", "is", tr("Incremental search"));
|
|
|
|
|
setup(&useCoreSearch, false, "UseCoreSearch", "ucs", tr("Use search dialog"));
|
|
|
|
|
setup(&smartCase, false, "SmartCase", "scs", tr("Use smartcase"));
|
|
|
|
|
setup(&ignoreCase, false, "IgnoreCase", "ic", tr("Use ignorecase"));
|
|
|
|
|
setup(&wrapScan, true, "WrapScan", "ws", tr("Use wrapscan"));
|
|
|
|
|
setup(&tildeOp, false, "TildeOp", "top", tr("Use tildeop"));
|
|
|
|
|
setup(&showCmd, true, "ShowCmd", "sc", tr("Show partial command"));
|
|
|
|
|
setup(&relativeNumber, false, "RelativeNumber", "rnu", tr("Show line numbers relative to cursor"));
|
|
|
|
|
setup(&blinkingCursor, false, "BlinkingCursor", "bc", tr("Blinking cursor"));
|
|
|
|
|
setup(&scrollOff, 0, "ScrollOff", "so", tr("Scroll offset:"));
|
|
|
|
|
setup(&backspace, "indent,eol,start",
|
2021-03-03 12:03:20 +01:00
|
|
|
"Backspace", "bs", tr("Backspace:"));
|
2021-02-26 17:55:55 +01:00
|
|
|
setup(&isKeyword, "@,48-57,_,192-255,a-z,A-Z",
|
|
|
|
|
"IsKeyword", "isk", tr("Keyword characters:"));
|
|
|
|
|
setup(&clipboard, {}, "Clipboard", "cb", tr(""));
|
|
|
|
|
setup(&formatOptions, {}, "formatoptions", "fo", tr(""));
|
2021-01-25 21:06:53 +01:00
|
|
|
|
|
|
|
|
// Emulated plugins
|
2021-02-26 17:55:55 +01:00
|
|
|
setup(&emulateVimCommentary, false, "commentary", {}, "vim-commentary");
|
|
|
|
|
setup(&emulateReplaceWithRegister, false, "ReplaceWithRegister", {}, "ReplaceWithRegister");
|
|
|
|
|
setup(&emulateExchange, false, "exchange", {}, "vim-exchange");
|
|
|
|
|
setup(&emulateArgTextObj, false, "argtextobj", {}, "argtextobj.vim");
|
|
|
|
|
setup(&emulateSurround, false, "surround", {}, "vim-surround");
|
2009-03-30 14:46:33 +02:00
|
|
|
|
2021-02-26 17:55:55 +01:00
|
|
|
// Some polish
|
|
|
|
|
useFakeVim.setDisplayName(tr("Use Vim-style Editing"));
|
2010-01-29 21:33:57 +01:00
|
|
|
|
2021-02-26 17:55:55 +01:00
|
|
|
relativeNumber.setToolTip(tr("Displays line numbers relative to the line containing "
|
|
|
|
|
"text cursor."));
|
2009-03-30 14:46:33 +02:00
|
|
|
|
2021-02-26 17:55:55 +01:00
|
|
|
passControlKey.setToolTip(tr("Does not interpret key sequences like Ctrl-S in FakeVim "
|
|
|
|
|
"but handles them as regular shortcuts. This gives easier access to core functionality "
|
|
|
|
|
"at the price of losing some features of FakeVim."));
|
2009-03-30 14:46:33 +02:00
|
|
|
|
2021-02-26 17:55:55 +01:00
|
|
|
passKeys.setToolTip(tr("Does not interpret some key presses in insert mode so that "
|
|
|
|
|
"code can be properly completed and expanded."));
|
2010-01-29 21:33:57 +01:00
|
|
|
|
2021-02-26 17:55:55 +01:00
|
|
|
tabStop.setToolTip(tr("Vim tabstop option."));
|
|
|
|
|
|
|
|
|
|
#ifndef FAKEVIM_STANDALONE
|
|
|
|
|
backspace.setDisplayStyle(FvStringAspect::LineEditDisplay);
|
|
|
|
|
isKeyword.setDisplayStyle(FvStringAspect::LineEditDisplay);
|
|
|
|
|
|
|
|
|
|
const QString vimrcDefault = QLatin1String(HostOsInfo::isAnyUnixHost()
|
|
|
|
|
? "$HOME/.vimrc" : "%USERPROFILE%\\_vimrc");
|
|
|
|
|
vimRcPath.setExpectedKind(PathChooser::File);
|
|
|
|
|
vimRcPath.setToolTip(tr("Keep empty to use the default path, i.e. "
|
|
|
|
|
"%USERPROFILE%\\_vimrc on Windows, ~/.vimrc otherwise."));
|
|
|
|
|
vimRcPath.setPlaceHolderText(tr("Default: %1").arg(vimrcDefault));
|
|
|
|
|
vimRcPath.setDisplayStyle(FvStringAspect::PathChooserDisplay);
|
|
|
|
|
#endif
|
2009-03-30 14:46:33 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-26 17:55:55 +01:00
|
|
|
FakeVimSettings::~FakeVimSettings() = default;
|
|
|
|
|
|
|
|
|
|
FvBaseAspect *FakeVimSettings::item(const QString &name)
|
2009-03-30 15:27:59 +02:00
|
|
|
{
|
2021-02-26 17:55:55 +01:00
|
|
|
return m_nameToAspect.value(name, nullptr);
|
2009-03-30 15:27:59 +02:00
|
|
|
}
|
|
|
|
|
|
2012-05-03 10:43:04 +02:00
|
|
|
QString FakeVimSettings::trySetValue(const QString &name, const QString &value)
|
|
|
|
|
{
|
2021-02-26 17:55:55 +01:00
|
|
|
FvBaseAspect *aspect = m_nameToAspect.value(name, nullptr);
|
|
|
|
|
if (!aspect)
|
2016-03-01 23:24:59 +01:00
|
|
|
return tr("Unknown option: %1").arg(name);
|
2021-02-26 17:55:55 +01:00
|
|
|
if (aspect == &tabStop || aspect == &shiftWidth) {
|
2012-05-03 10:43:04 +02:00
|
|
|
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);
|
|
|
|
|
}
|
2021-02-26 17:55:55 +01:00
|
|
|
aspect->setValue(value);
|
2012-05-03 10:43:04 +02:00
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 17:55:55 +01:00
|
|
|
void FakeVimSettings::setup(FvBaseAspect *aspect,
|
|
|
|
|
const QVariant &value,
|
|
|
|
|
const QString &settingsKey,
|
|
|
|
|
const QString &shortName,
|
|
|
|
|
const QString &labelText)
|
2009-03-30 14:46:33 +02:00
|
|
|
{
|
2021-02-26 17:55:55 +01:00
|
|
|
aspect->setSettingsKey("FakeVim", settingsKey);
|
|
|
|
|
aspect->setDefaultValue(value);
|
|
|
|
|
#ifndef FAKEVIM_STANDALONE
|
|
|
|
|
aspect->setLabelText(labelText);
|
|
|
|
|
aspect->setAutoApply(false);
|
|
|
|
|
registerAspect(aspect);
|
|
|
|
|
|
|
|
|
|
if (auto boolAspect = dynamic_cast<FvBoolAspect *>(aspect))
|
|
|
|
|
boolAspect->setLabelPlacement(FvBoolAspect::LabelPlacement::AtCheckBoxWithoutDummyLabel);
|
|
|
|
|
#else
|
|
|
|
|
Q_UNUSED(labelText)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
const QString longName = settingsKey.toLower();
|
|
|
|
|
if (!longName.isEmpty()) {
|
|
|
|
|
m_nameToAspect[longName] = aspect;
|
|
|
|
|
m_aspectToName[aspect] = longName;
|
|
|
|
|
}
|
|
|
|
|
if (!shortName.isEmpty())
|
|
|
|
|
m_nameToAspect[shortName] = aspect;
|
2013-03-08 17:50:16 +01:00
|
|
|
}
|
2009-03-30 14:46:33 +02:00
|
|
|
|
2021-02-26 17:55:55 +01:00
|
|
|
FakeVimSettings *fakeVimSettings()
|
2013-03-08 17:50:16 +01:00
|
|
|
{
|
2016-03-01 23:24:59 +01:00
|
|
|
static FakeVimSettings s;
|
|
|
|
|
return &s;
|
|
|
|
|
}
|
2013-03-08 17:50:16 +01:00
|
|
|
|
2009-03-30 14:46:33 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace FakeVim
|