FakeVim: Modernize

Take advantage of QT_RESTRICTED_CAST_TO_ASCII, auto, etc.

Change-Id: I4602fd6ef5f24b12cb9fe09ce39ad907e76fe259
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
hjk
2016-03-18 12:10:24 +01:00
parent a2fa0f76f8
commit d4f5cab923
3 changed files with 546 additions and 555 deletions

View File

@@ -41,8 +41,6 @@ using namespace Utils;
namespace FakeVim { namespace FakeVim {
namespace Internal { namespace Internal {
typedef QLatin1String _;
DummyAction::DummyAction(void *) DummyAction::DummyAction(void *)
{ {
} }
@@ -81,39 +79,39 @@ QString DummyAction::settingsKey() const
FakeVimSettings::FakeVimSettings() FakeVimSettings::FakeVimSettings()
{ {
// Specific FakeVim settings // Specific FakeVim settings
createAction(ConfigReadVimRc, false, _("ReadVimRc")); createAction(ConfigReadVimRc, false, "ReadVimRc");
createAction(ConfigVimRcPath, QString(), _("VimRcPath")); createAction(ConfigVimRcPath, QString(), "VimRcPath");
#ifndef FAKEVIM_STANDALONE #ifndef FAKEVIM_STANDALONE
createAction( ConfigUseFakeVim, false, _("UseFakeVim")); createAction(ConfigUseFakeVim, false, "UseFakeVim");
item(ConfigUseFakeVim)->setText(tr("Use Vim-style Editing")); item(ConfigUseFakeVim)->setText(tr("Use Vim-style Editing"));
item(ConfigReadVimRc)->setText(tr("Read .vimrc")); item(ConfigReadVimRc)->setText(tr("Read .vimrc"));
item(ConfigVimRcPath)->setText(tr("Path to .vimrc")); item(ConfigVimRcPath)->setText(tr("Path to .vimrc"));
#endif #endif
createAction(ConfigShowMarks, false, _("ShowMarks"), _("sm")); createAction(ConfigShowMarks, false, "ShowMarks", "sm");
createAction(ConfigPassControlKey, false, _("PassControlKey"), _("pck")); createAction(ConfigPassControlKey, false, "PassControlKey", "pck");
createAction(ConfigPassKeys, true, _("PassKeys"), _("pk")); createAction(ConfigPassKeys, true, "PassKeys", "pk");
// Emulated Vsetting // Emulated Vsetting
createAction(ConfigStartOfLine, true, _("StartOfLine"), _("sol")); createAction(ConfigStartOfLine, true, "StartOfLine", "sol");
createAction(ConfigTabStop, 8, _("TabStop"), _("ts")); createAction(ConfigTabStop, 8, "TabStop", "ts");
createAction(ConfigSmartTab, false, _("SmartTab"), _("sta")); createAction(ConfigSmartTab, false, "SmartTab", "sta");
createAction(ConfigHlSearch, true, _("HlSearch"), _("hls")); createAction(ConfigHlSearch, true, "HlSearch", "hls");
createAction(ConfigShiftWidth, 8, _("ShiftWidth"), _("sw")); createAction(ConfigShiftWidth, 8, "ShiftWidth", "sw");
createAction(ConfigExpandTab, false, _("ExpandTab"), _("et")); createAction(ConfigExpandTab, false, "ExpandTab", "et");
createAction(ConfigAutoIndent, false, _("AutoIndent"), _("ai")); createAction(ConfigAutoIndent, false, "AutoIndent", "ai");
createAction(ConfigSmartIndent, false, _("SmartIndent"), _("si")); createAction(ConfigSmartIndent, false, "SmartIndent", "si");
createAction(ConfigIncSearch, true, _("IncSearch"), _("is")); createAction(ConfigIncSearch, true, "IncSearch", "is");
createAction(ConfigUseCoreSearch, false, _("UseCoreSearch"), _("ucs")); createAction(ConfigUseCoreSearch, false, "UseCoreSearch", "ucs");
createAction(ConfigSmartCase, false, _("SmartCase"), _("scs")); createAction(ConfigSmartCase, false, "SmartCase", "scs");
createAction(ConfigIgnoreCase, false, _("IgnoreCase"), _("ic")); createAction(ConfigIgnoreCase, false, "IgnoreCase", "ic");
createAction(ConfigWrapScan, true, _("WrapScan"), _("ws")); createAction(ConfigWrapScan, true, "WrapScan", "ws");
createAction(ConfigTildeOp, false, _("TildeOp"), _("top")); createAction(ConfigTildeOp, false, "TildeOp", "top");
createAction(ConfigShowCmd, true, _("ShowCmd"), _("sc")); createAction(ConfigShowCmd, true, "ShowCmd", "sc");
createAction(ConfigRelativeNumber, false, _("RelativeNumber"),_("rnu")); createAction(ConfigRelativeNumber, false, "RelativeNumber", "rnu");
createAction(ConfigScrollOff, 0, _("ScrollOff"), _("so")); createAction(ConfigScrollOff, 0, "ScrollOff", "so");
createAction(ConfigBackspace, _("indent,eol,start"), _("ConfigBackspace"), _("bs")); createAction(ConfigBackspace, QString("indent,eol,start"), "ConfigBackspace", "bs");
createAction(ConfigIsKeyword, _("@,48-57,_,192-255,a-z,A-Z"), _("IsKeyword"), _("isk")); createAction(ConfigIsKeyword, QString("@,48-57,_,192-255,a-z,A-Z"), "IsKeyword", "isk");
createAction(ConfigClipboard, QString(), _("Clipboard"), _("cb")); createAction(ConfigClipboard, QString(), "Clipboard", "cb");
} }
FakeVimSettings::~FakeVimSettings() FakeVimSettings::~FakeVimSettings()
@@ -180,7 +178,7 @@ void FakeVimSettings::createAction(int code, const QVariant &value,
{ {
FakeVimAction *item = new FakeVimAction(0); FakeVimAction *item = new FakeVimAction(0);
item->setValue(value); item->setValue(value);
item->setSettingsKey(_("FakeVim"), settingsKey); item->setSettingsKey("FakeVim", settingsKey);
item->setDefaultValue(value); item->setDefaultValue(value);
item->setCheckable(value.canConvert<bool>()); item->setCheckable(value.canConvert<bool>());
insertItem(code, item, settingsKey.toLower(), shortKey); insertItem(code, item, settingsKey.toLower(), shortKey);

File diff suppressed because it is too large Load Diff

View File

@@ -99,6 +99,7 @@
using namespace TextEditor; using namespace TextEditor;
using namespace Core; using namespace Core;
using namespace Utils;
namespace FakeVim { namespace FakeVim {
namespace Internal { namespace Internal {
@@ -109,7 +110,6 @@ const char SETTINGS_CATEGORY_FAKEVIM_ICON[] = ":/fakevim/images/category_fakevim
const char SETTINGS_ID[] = "A.FakeVim.General"; const char SETTINGS_ID[] = "A.FakeVim.General";
const char SETTINGS_EX_CMDS_ID[] = "B.FakeVim.ExCommands"; const char SETTINGS_EX_CMDS_ID[] = "B.FakeVim.ExCommands";
const char SETTINGS_USER_CMDS_ID[] = "C.FakeVim.UserCommands"; const char SETTINGS_USER_CMDS_ID[] = "C.FakeVim.UserCommands";
typedef QLatin1String _;
class MiniBuffer : public QStackedWidget class MiniBuffer : public QStackedWidget
{ {
@@ -161,14 +161,14 @@ public:
QString css; QString css;
if (messageLevel == MessageError) { if (messageLevel == MessageError) {
css = _("border:1px solid rgba(255,255,255,150);" css = "border:1px solid rgba(255,255,255,150);"
"background-color:rgba(255,0,0,100);"); "background-color:rgba(255,0,0,100);";
} else if (messageLevel == MessageWarning) { } else if (messageLevel == MessageWarning) {
css = _("border:1px solid rgba(255,255,255,120);" css = "border:1px solid rgba(255,255,255,120);"
"background-color:rgba(255,255,0,20);"); "background-color:rgba(255,255,0,20);";
} else if (messageLevel == MessageShowCmd) { } else if (messageLevel == MessageShowCmd) {
css = _("border:1px solid rgba(255,255,255,120);" css = "border:1px solid rgba(255,255,255,120);"
"background-color:rgba(100,255,100,30);"); "background-color:rgba(100,255,100,30);";
} }
m_label->setStyleSheet(QString::fromLatin1( m_label->setStyleSheet(QString::fromLatin1(
"*{border-radius:2px;padding-left:4px;padding-right:4px;%1}").arg(css)); "*{border-radius:2px;padding-left:4px;padding-right:4px;%1}").arg(css));
@@ -363,7 +363,7 @@ public:
setDisplayName(Tr::tr("General")); setDisplayName(Tr::tr("General"));
setCategory(SETTINGS_CATEGORY); setCategory(SETTINGS_CATEGORY);
setDisplayCategory(Tr::tr("FakeVim")); setDisplayCategory(Tr::tr("FakeVim"));
setCategoryIcon(_(SETTINGS_CATEGORY_FAKEVIM_ICON)); setCategoryIcon(SETTINGS_CATEGORY_FAKEVIM_ICON);
} }
QWidget *widget(); QWidget *widget();
@@ -379,7 +379,7 @@ private slots:
private: private:
QPointer<QWidget> m_widget; QPointer<QWidget> m_widget;
Ui::FakeVimOptionPage m_ui; Ui::FakeVimOptionPage m_ui;
Utils::SavedActionSet m_group; SavedActionSet m_group;
}; };
QWidget *FakeVimOptionPage::widget() QWidget *FakeVimOptionPage::widget()
@@ -387,9 +387,9 @@ QWidget *FakeVimOptionPage::widget()
if (!m_widget) { if (!m_widget) {
m_widget = new QWidget; m_widget = new QWidget;
m_ui.setupUi(m_widget); m_ui.setupUi(m_widget);
const QString vimrcDefault = Utils::HostOsInfo::isAnyUnixHost() ? const QString vimrcDefault = QLatin1String(HostOsInfo::isAnyUnixHost()
QLatin1String("$HOME/.vimrc") : QLatin1String("%USERPROFILE%\\_vimrc"); ? "$HOME/.vimrc" : "%USERPROFILE%\\_vimrc");
m_ui.pathChooserVimRcPath->setExpectedKind(Utils::PathChooser::File); m_ui.pathChooserVimRcPath->setExpectedKind(PathChooser::File);
m_ui.pathChooserVimRcPath->lineEdit()->setToolTip(Tr::tr("Keep empty to use the default path, i.e. " m_ui.pathChooserVimRcPath->lineEdit()->setToolTip(Tr::tr("Keep empty to use the default path, i.e. "
"%USERPROFILE%\\_vimrc on Windows, ~/.vimrc otherwise.")); "%USERPROFILE%\\_vimrc on Windows, ~/.vimrc otherwise."));
m_ui.pathChooserVimRcPath->lineEdit()->setPlaceholderText(Tr::tr("Default: %1").arg(vimrcDefault)); m_ui.pathChooserVimRcPath->lineEdit()->setPlaceholderText(Tr::tr("Default: %1").arg(vimrcDefault));
@@ -498,7 +498,7 @@ void FakeVimOptionPage::setQtStyle()
m_ui.checkBoxAutoIndent->setChecked(true); m_ui.checkBoxAutoIndent->setChecked(true);
m_ui.checkBoxSmartIndent->setChecked(true); m_ui.checkBoxSmartIndent->setChecked(true);
m_ui.checkBoxIncSearch->setChecked(true); m_ui.checkBoxIncSearch->setChecked(true);
m_ui.lineEditBackspace->setText(_("indent,eol,start")); m_ui.lineEditBackspace->setText("indent,eol,start");
m_ui.checkBoxPassKeys->setChecked(true); m_ui.checkBoxPassKeys->setChecked(true);
} }
@@ -552,7 +552,7 @@ private:
FakeVimPluginPrivate *m_q; FakeVimPluginPrivate *m_q;
QGroupBox *m_commandBox; QGroupBox *m_commandBox;
Utils::FancyLineEdit *m_commandEdit; FancyLineEdit *m_commandEdit;
}; };
FakeVimExCommandsWidget::FakeVimExCommandsWidget(FakeVimPluginPrivate *q, QWidget *parent) FakeVimExCommandsWidget::FakeVimExCommandsWidget(FakeVimPluginPrivate *q, QWidget *parent)
@@ -568,10 +568,10 @@ FakeVimExCommandsWidget::FakeVimExCommandsWidget(FakeVimPluginPrivate *q, QWidge
m_commandBox = new QGroupBox(Tr::tr("Ex Command"), this); m_commandBox = new QGroupBox(Tr::tr("Ex Command"), this);
m_commandBox->setEnabled(false); m_commandBox->setEnabled(false);
auto boxLayout = new QHBoxLayout(m_commandBox); auto boxLayout = new QHBoxLayout(m_commandBox);
m_commandEdit = new Utils::FancyLineEdit(m_commandBox); m_commandEdit = new FancyLineEdit(m_commandBox);
m_commandEdit->setFiltering(true); m_commandEdit->setFiltering(true);
m_commandEdit->setPlaceholderText(QString()); m_commandEdit->setPlaceholderText(QString());
connect(m_commandEdit, &Utils::FancyLineEdit::textChanged, connect(m_commandEdit, &FancyLineEdit::textChanged,
this, &FakeVimExCommandsWidget::commandChanged); this, &FakeVimExCommandsWidget::commandChanged);
auto resetButton = new QPushButton(Tr::tr("Reset"), m_commandBox); auto resetButton = new QPushButton(Tr::tr("Reset"), m_commandBox);
resetButton->setToolTip(Tr::tr("Reset to default.")); resetButton->setToolTip(Tr::tr("Reset to default."));
@@ -598,7 +598,7 @@ public:
setDisplayName(Tr::tr("Ex Command Mapping")); setDisplayName(Tr::tr("Ex Command Mapping"));
setCategory(SETTINGS_CATEGORY); setCategory(SETTINGS_CATEGORY);
setDisplayCategory(Tr::tr("FakeVim")); setDisplayCategory(Tr::tr("FakeVim"));
setCategoryIcon(_(SETTINGS_CATEGORY_FAKEVIM_ICON)); setCategoryIcon(SETTINGS_CATEGORY_FAKEVIM_ICON);
} }
QWidget *widget() override; QWidget *widget() override;
@@ -630,16 +630,15 @@ void FakeVimExCommandsWidget::initialize()
if (c->action() && c->action()->isSeparator()) if (c->action() && c->action()->isSeparator())
continue; continue;
QTreeWidgetItem *item = new QTreeWidgetItem; auto item = new QTreeWidgetItem;
const QString name = c->id().toString(); const QString name = c->id().toString();
const int pos = name.indexOf(QLatin1Char('.')); const int pos = name.indexOf('.');
const QString section = name.left(pos); const QString section = name.left(pos);
const QString subId = name.mid(pos + 1); const QString subId = name.mid(pos + 1);
item->setData(0, CommandRole, name); item->setData(0, CommandRole, name);
if (!sections.contains(section)) { if (!sections.contains(section)) {
QTreeWidgetItem *categoryItem = auto categoryItem = new QTreeWidgetItem(commandList(), { section });
new QTreeWidgetItem(commandList(), QStringList() << section);
QFont f = categoryItem->font(0); QFont f = categoryItem->font(0);
f.setBold(true); f.setBold(true);
categoryItem->setFont(0, f); categoryItem->setFont(0, f);
@@ -787,7 +786,7 @@ public:
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &,
const QModelIndex &) const const QModelIndex &) const
{ {
QLineEdit *lineEdit = new QLineEdit(parent); auto lineEdit = new QLineEdit(parent);
lineEdit->setFrame(false); lineEdit->setFrame(false);
return lineEdit; return lineEdit;
} }
@@ -813,7 +812,7 @@ public:
setDisplayName(Tr::tr("User Command Mapping")); setDisplayName(Tr::tr("User Command Mapping"));
setCategory(SETTINGS_CATEGORY); setCategory(SETTINGS_CATEGORY);
setDisplayCategory(Tr::tr("FakeVim")); setDisplayCategory(Tr::tr("FakeVim"));
setCategoryIcon(_(SETTINGS_CATEGORY_FAKEVIM_ICON)); setCategoryIcon(SETTINGS_CATEGORY_FAKEVIM_ICON);
} }
void apply(); void apply();
@@ -834,16 +833,16 @@ QWidget *FakeVimUserCommandsPage::widget()
if (!m_widget) { if (!m_widget) {
m_widget = new QWidget; m_widget = new QWidget;
FakeVimUserCommandsModel *model = new FakeVimUserCommandsModel(m_q); auto model = new FakeVimUserCommandsModel(m_q);
QTreeView *widget = new QTreeView; auto widget = new QTreeView;
model->setParent(widget); model->setParent(widget);
widget->setModel(model); widget->setModel(model);
widget->resizeColumnToContents(0); widget->resizeColumnToContents(0);
FakeVimUserCommandsDelegate *delegate = new FakeVimUserCommandsDelegate(widget); auto delegate = new FakeVimUserCommandsDelegate(widget);
widget->setItemDelegateForColumn(1, delegate); widget->setItemDelegateForColumn(1, delegate);
QGridLayout *layout = new QGridLayout(m_widget); auto layout = new QGridLayout(m_widget);
layout->addWidget(widget, 0, 0); layout->addWidget(widget, 0, 0);
m_widget->setLayout(layout); m_widget->setLayout(layout);
} }
@@ -991,7 +990,7 @@ public:
&& !seen.contains(found) && !seen.contains(found)
&& sel.anchor() != basePosition) { && sel.anchor() != basePosition) {
seen.insert(found); seen.insert(found);
AssistProposalItem *item = new FakeVimAssistProposalItem(m_provider); auto item = new FakeVimAssistProposalItem(m_provider);
item->setText(found); item->setText(found);
items.append(item); items.append(item);
} }
@@ -1150,18 +1149,18 @@ bool FakeVimUserCommandsModel::setData(const QModelIndex &index,
FakeVimPluginPrivate::FakeVimPluginPrivate(FakeVimPlugin *plugin) FakeVimPluginPrivate::FakeVimPluginPrivate(FakeVimPlugin *plugin)
: q(plugin) : q(plugin)
{ {
defaultExCommandMap()[_(CppTools::Constants::SWITCH_HEADER_SOURCE)] = defaultExCommandMap()[CppTools::Constants::SWITCH_HEADER_SOURCE] =
QRegExp(_("^A$")); QRegExp("^A$");
defaultExCommandMap()[_("Coreplugin.OutputPane.previtem")] = defaultExCommandMap()["Coreplugin.OutputPane.previtem"] =
QRegExp(_("^(cN(ext)?|cp(revious)?)!?( (.*))?$")); QRegExp("^(cN(ext)?|cp(revious)?)!?( (.*))?$");
defaultExCommandMap()[_("Coreplugin.OutputPane.nextitem")] = defaultExCommandMap()["Coreplugin.OutputPane.nextitem"] =
QRegExp(_("^cn(ext)?!?( (.*))?$")); QRegExp("^cn(ext)?!?( (.*))?$");
defaultExCommandMap()[_(TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR)] = defaultExCommandMap()[TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR] =
QRegExp(_("^tag?$")); QRegExp("^tag?$");
defaultExCommandMap()[_(Core::Constants::GO_BACK)] = defaultExCommandMap()[Core::Constants::GO_BACK] =
QRegExp(_("^pop?$")); QRegExp("^pop?$");
defaultExCommandMap()[_("QtCreator.Locate")] = defaultExCommandMap()["QtCreator.Locate"] =
QRegExp(_("^e$")); QRegExp("^e$");
for (int i = 1; i < 10; ++i) { for (int i = 1; i < 10; ++i) {
QString cmd = QString::fromLatin1(":echo User command %1 executed.<CR>"); QString cmd = QString::fromLatin1(":echo User command %1 executed.<CR>");
@@ -1257,13 +1256,13 @@ bool FakeVimPluginPrivate::initialize()
connect(DocumentManager::instance(), &DocumentManager::documentRenamed, connect(DocumentManager::instance(), &DocumentManager::documentRenamed,
this, &FakeVimPluginPrivate::documentRenamed); this, &FakeVimPluginPrivate::documentRenamed);
connect(theFakeVimSetting(ConfigUseFakeVim), &Utils::SavedAction::valueChanged, connect(theFakeVimSetting(ConfigUseFakeVim), &SavedAction::valueChanged,
this, &FakeVimPluginPrivate::setUseFakeVim); this, &FakeVimPluginPrivate::setUseFakeVim);
connect(theFakeVimSetting(ConfigReadVimRc), &Utils::SavedAction::valueChanged, connect(theFakeVimSetting(ConfigReadVimRc), &SavedAction::valueChanged,
this, &FakeVimPluginPrivate::maybeReadVimRc); this, &FakeVimPluginPrivate::maybeReadVimRc);
connect(theFakeVimSetting(ConfigVimRcPath), &Utils::SavedAction::valueChanged, connect(theFakeVimSetting(ConfigVimRcPath), &SavedAction::valueChanged,
this, &FakeVimPluginPrivate::maybeReadVimRc); this, &FakeVimPluginPrivate::maybeReadVimRc);
connect(theFakeVimSetting(ConfigRelativeNumber), &Utils::SavedAction::valueChanged, connect(theFakeVimSetting(ConfigRelativeNumber), &SavedAction::valueChanged,
this, &FakeVimPluginPrivate::setShowRelativeLineNumbers); this, &FakeVimPluginPrivate::setShowRelativeLineNumbers);
// Delayed operations. // Delayed operations.
@@ -1301,10 +1300,10 @@ void FakeVimPluginPrivate::userActionTriggered(int key)
void FakeVimPluginPrivate::createRelativeNumberWidget(IEditor *editor) void FakeVimPluginPrivate::createRelativeNumberWidget(IEditor *editor)
{ {
if (TextEditorWidget *textEditor = qobject_cast<TextEditorWidget *>(editor->widget())) { if (TextEditorWidget *textEditor = qobject_cast<TextEditorWidget *>(editor->widget())) {
RelativeNumbersColumn *relativeNumbers = new RelativeNumbersColumn(textEditor); auto relativeNumbers = new RelativeNumbersColumn(textEditor);
connect(theFakeVimSetting(ConfigRelativeNumber), &Utils::SavedAction::valueChanged, connect(theFakeVimSetting(ConfigRelativeNumber), &SavedAction::valueChanged,
relativeNumbers, &QObject::deleteLater); relativeNumbers, &QObject::deleteLater);
connect(theFakeVimSetting(ConfigUseFakeVim), &Utils::SavedAction::valueChanged, connect(theFakeVimSetting(ConfigUseFakeVim), &SavedAction::valueChanged,
relativeNumbers, &QObject::deleteLater); relativeNumbers, &QObject::deleteLater);
relativeNumbers->show(); relativeNumbers->show();
} }
@@ -1323,7 +1322,7 @@ void FakeVimPluginPrivate::writeSettings()
theFakeVimSettings()->writeSettings(settings); theFakeVimSettings()->writeSettings(settings);
{ // block { // block
settings->beginWriteArray(_(exCommandMapGroup)); settings->beginWriteArray(exCommandMapGroup);
int count = 0; int count = 0;
typedef ExCommandMap::const_iterator Iterator; typedef ExCommandMap::const_iterator Iterator;
const Iterator end = exCommandMap().constEnd(); const Iterator end = exCommandMap().constEnd();
@@ -1334,8 +1333,8 @@ void FakeVimPluginPrivate::writeSettings()
if ((defaultExCommandMap().contains(id) && defaultExCommandMap()[id] != re) if ((defaultExCommandMap().contains(id) && defaultExCommandMap()[id] != re)
|| (!defaultExCommandMap().contains(id) && !re.pattern().isEmpty())) { || (!defaultExCommandMap().contains(id) && !re.pattern().isEmpty())) {
settings->setArrayIndex(count); settings->setArrayIndex(count);
settings->setValue(_(idKey), id); settings->setValue(idKey, id);
settings->setValue(_(reKey), re.pattern()); settings->setValue(reKey, re.pattern());
++count; ++count;
} }
} }
@@ -1343,7 +1342,7 @@ void FakeVimPluginPrivate::writeSettings()
} // block } // block
{ // block { // block
settings->beginWriteArray(_(userCommandMapGroup)); settings->beginWriteArray(userCommandMapGroup);
int count = 0; int count = 0;
typedef UserCommandMap::const_iterator Iterator; typedef UserCommandMap::const_iterator Iterator;
const Iterator end = userCommandMap().constEnd(); const Iterator end = userCommandMap().constEnd();
@@ -1355,8 +1354,8 @@ void FakeVimPluginPrivate::writeSettings()
&& defaultUserCommandMap()[key] != cmd) && defaultUserCommandMap()[key] != cmd)
|| (!defaultUserCommandMap().contains(key) && !cmd.isEmpty())) { || (!defaultUserCommandMap().contains(key) && !cmd.isEmpty())) {
settings->setArrayIndex(count); settings->setArrayIndex(count);
settings->setValue(_(idKey), key); settings->setValue(idKey, key);
settings->setValue(_(cmdKey), cmd); settings->setValue(cmdKey, cmd);
++count; ++count;
} }
} }
@@ -1371,21 +1370,21 @@ void FakeVimPluginPrivate::readSettings()
theFakeVimSettings()->readSettings(settings); theFakeVimSettings()->readSettings(settings);
exCommandMap() = defaultExCommandMap(); exCommandMap() = defaultExCommandMap();
int size = settings->beginReadArray(_(exCommandMapGroup)); int size = settings->beginReadArray(exCommandMapGroup);
for (int i = 0; i < size; ++i) { for (int i = 0; i < size; ++i) {
settings->setArrayIndex(i); settings->setArrayIndex(i);
const QString id = settings->value(_(idKey)).toString(); const QString id = settings->value(idKey).toString();
const QString re = settings->value(_(reKey)).toString(); const QString re = settings->value(reKey).toString();
exCommandMap()[id] = QRegExp(re); exCommandMap()[id] = QRegExp(re);
} }
settings->endArray(); settings->endArray();
userCommandMap() = defaultUserCommandMap(); userCommandMap() = defaultUserCommandMap();
size = settings->beginReadArray(_(userCommandMapGroup)); size = settings->beginReadArray(userCommandMapGroup);
for (int i = 0; i < size; ++i) { for (int i = 0; i < size; ++i) {
settings->setArrayIndex(i); settings->setArrayIndex(i);
const int id = settings->value(_(idKey)).toInt(); const int id = settings->value(idKey).toInt();
const QString cmd = settings->value(_(cmdKey)).toString(); const QString cmd = settings->value(cmdKey).toString();
userCommandMap()[id] = cmd; userCommandMap()[id] = cmd;
} }
settings->endArray(); settings->endArray();
@@ -1401,13 +1400,13 @@ void FakeVimPluginPrivate::maybeReadVimRc()
QString fileName = theFakeVimSetting(ConfigVimRcPath)->value().toString(); QString fileName = theFakeVimSetting(ConfigVimRcPath)->value().toString();
if (fileName.isEmpty()) { if (fileName.isEmpty()) {
fileName = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) fileName = QStandardPaths::writableLocation(QStandardPaths::HomeLocation)
+ (Utils::HostOsInfo::isWindowsHost() ? _("/_vimrc") : _("/.vimrc")); + (HostOsInfo::isWindowsHost() ? "/_vimrc" : "/.vimrc");
} }
//qDebug() << "READING VIMRC: " << fileName; //qDebug() << "READING VIMRC: " << fileName;
// Read it into a temporary handler for effects modifying global state. // Read it into a temporary handler for effects modifying global state.
QPlainTextEdit editor; QPlainTextEdit editor;
FakeVimHandler handler(&editor); FakeVimHandler handler(&editor);
handler.handleCommand(_("source ") + fileName); handler.handleCommand("source " + fileName);
//writeSettings(); //writeSettings();
//qDebug() << theFakeVimSetting(ConfigShiftWidth)->value(); //qDebug() << theFakeVimSetting(ConfigShiftWidth)->value();
} }
@@ -1477,28 +1476,28 @@ void FakeVimPluginPrivate::windowCommand(const QString &map, int count)
// normalize mapping // normalize mapping
const QString key = map.toUpper(); const QString key = map.toUpper();
if (key == _("C") || key == _("<C-C>")) if (key == "C" || key == "<C-C>")
triggerAction(Core::Constants::REMOVE_CURRENT_SPLIT); triggerAction(Core::Constants::REMOVE_CURRENT_SPLIT);
else if (key == _("N") || key == _("<C-N>")) else if (key == "N" || key == "<C-N>")
triggerAction(Core::Constants::GOTONEXT); triggerAction(Core::Constants::GOTONEXT);
else if (key == _("O") || key == _("<C-O>")) else if (key == "O" || key == "<C-O>")
keepOnlyWindow(); keepOnlyWindow();
else if (key == _("P") || key == _("<C-P>")) else if (key == "P" || key == "<C-P>")
triggerAction(Core::Constants::GOTOPREV); triggerAction(Core::Constants::GOTOPREV);
else if (key == _("S") || key == _("<C-S>")) else if (key == "S" || key == "<C-S>")
triggerAction(Core::Constants::SPLIT); triggerAction(Core::Constants::SPLIT);
else if (key == _("V") || key == _("<C-V>")) else if (key == "V" || key == "<C-V>")
triggerAction(Core::Constants::SPLIT_SIDE_BY_SIDE); triggerAction(Core::Constants::SPLIT_SIDE_BY_SIDE);
else if (key == _("W") || key == _("<C-W>")) else if (key == "W" || key == "<C-W>")
triggerAction(Core::Constants::GOTO_NEXT_SPLIT); triggerAction(Core::Constants::GOTO_NEXT_SPLIT);
else if (key.contains(_("RIGHT")) || key == _("L") || key == _("<S-L>")) else if (key.contains("RIGHT") || key == "L" || key == "<S-L>")
moveSomewhere(&moveRightWeight, key == _("<S-L>") ? -1 : count); moveSomewhere(&moveRightWeight, key == "<S-L>" ? -1 : count);
else if (key.contains(_("LEFT")) || key == _("H") || key == _("<S-H>")) else if (key.contains("LEFT") || key == "H" || key == "<S-H>")
moveSomewhere(&moveLeftWeight, key == _("<S-H>") ? -1 : count); moveSomewhere(&moveLeftWeight, key == "<S-H>" ? -1 : count);
else if (key.contains(_("UP")) || key == _("K") || key == _("<S-K>")) else if (key.contains("UP") || key == "K" || key == "<S-K>")
moveSomewhere(&moveUpWeight, key == _("<S-K>") ? -1 : count); moveSomewhere(&moveUpWeight, key == "<S-K>" ? -1 : count);
else if (key.contains(_("DOWN")) || key == _("J") || key == _("<S-J>")) else if (key.contains("DOWN") || key == "J" || key == "<S-J>")
moveSomewhere(&moveDownWeight, key == _("<S-J>") ? -1 : count); moveSomewhere(&moveDownWeight, key == "<S-J>" ? -1 : count);
else else
qDebug() << "UNKNOWN WINDOW COMMAND: <C-W>" << map; qDebug() << "UNKNOWN WINDOW COMMAND: <C-W>" << map;
} }
@@ -1772,7 +1771,7 @@ void FakeVimPluginPrivate::editorOpened(IEditor *editor)
//qDebug() << "OPENING: " << editor << editor->widget() //qDebug() << "OPENING: " << editor << editor->widget()
// << "MODE: " << theFakeVimSetting(ConfigUseFakeVim)->value(); // << "MODE: " << theFakeVimSetting(ConfigUseFakeVim)->value();
FakeVimHandler *handler = new FakeVimHandler(widget, 0); auto handler = new FakeVimHandler(widget, 0);
// the handler might have triggered the deletion of the editor: // the handler might have triggered the deletion of the editor:
// make sure that it can return before being deleted itself // make sure that it can return before being deleted itself
new DeferredDeleter(widget, handler); new DeferredDeleter(widget, handler);
@@ -1982,7 +1981,7 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
editor->setFocus(); editor->setFocus();
*handled = true; *handled = true;
if (cmd.matches(_("w"), _("write")) || cmd.cmd == _("wq")) { if (cmd.matches("w", "write") || cmd.cmd == "wq") {
// :w[rite] // :w[rite]
IEditor *editor = m_editorToHandler.key(handler); IEditor *editor = m_editorToHandler.key(handler);
const QString fileName = handler->currentFileName(); const QString fileName = handler->currentFileName();
@@ -1994,14 +1993,13 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
file3.open(QIODevice::ReadOnly); file3.open(QIODevice::ReadOnly);
QByteArray ba = file3.readAll(); QByteArray ba = file3.readAll();
handler->showMessage(MessageInfo, Tr::tr("\"%1\" %2 %3L, %4C written") handler->showMessage(MessageInfo, Tr::tr("\"%1\" %2 %3L, %4C written")
.arg(fileName).arg(QLatin1Char(' ')) .arg(fileName).arg(' ').arg(ba.count('\n')).arg(ba.size()));
.arg(ba.count('\n')).arg(ba.size())); if (cmd.cmd == "wq")
if (cmd.cmd == _("wq"))
delayedQuitRequested(cmd.hasBang, m_editorToHandler.key(handler)); delayedQuitRequested(cmd.hasBang, m_editorToHandler.key(handler));
} else { } else {
handler->showMessage(MessageError, Tr::tr("File not saved")); handler->showMessage(MessageError, Tr::tr("File not saved"));
} }
} else if (cmd.matches(_("wa"), _("wall"))) { } else if (cmd.matches("wa", "wall")) {
// :w[all] // :w[all]
QList<IDocument *> toSave = DocumentManager::modifiedDocuments(); QList<IDocument *> toSave = DocumentManager::modifiedDocuments();
QList<IDocument *> failed; QList<IDocument *> failed;
@@ -2010,52 +2008,52 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
handler->showMessage(MessageInfo, Tr::tr("Saving succeeded")); handler->showMessage(MessageInfo, Tr::tr("Saving succeeded"));
else else
handler->showMessage(MessageError, Tr::tr("%n files not saved", 0, failed.size())); handler->showMessage(MessageError, Tr::tr("%n files not saved", 0, failed.size()));
} else if (cmd.matches(_("q"), _("quit"))) { } else if (cmd.matches("q", "quit")) {
// :q[uit] // :q[uit]
emit delayedQuitRequested(cmd.hasBang, m_editorToHandler.key(handler)); emit delayedQuitRequested(cmd.hasBang, m_editorToHandler.key(handler));
} else if (cmd.matches(_("qa"), _("qall"))) { } else if (cmd.matches("qa", "qall")) {
// :qa[ll] // :qa[ll]
emit delayedQuitAllRequested(cmd.hasBang); emit delayedQuitAllRequested(cmd.hasBang);
} else if (cmd.matches(_("sp"), _("split"))) { } else if (cmd.matches("sp", "split")) {
// :sp[lit] // :sp[lit]
triggerAction(Core::Constants::SPLIT); triggerAction(Core::Constants::SPLIT);
} else if (cmd.matches(_("vs"), _("vsplit"))) { } else if (cmd.matches("vs", "vsplit")) {
// :vs[plit] // :vs[plit]
triggerAction(Core::Constants::SPLIT_SIDE_BY_SIDE); triggerAction(Core::Constants::SPLIT_SIDE_BY_SIDE);
} else if (cmd.matches(_("mak"), _("make"))) { } else if (cmd.matches("mak", "make")) {
// :mak[e][!] [arguments] // :mak[e][!] [arguments]
triggerAction(ProjectExplorer::Constants::BUILD); triggerAction(ProjectExplorer::Constants::BUILD);
} else if (cmd.matches(_("se"), _("set"))) { } else if (cmd.matches("se", "set")) {
if (cmd.args.isEmpty()) { if (cmd.args.isEmpty()) {
// :se[t] // :se[t]
ICore::showOptionsDialog(SETTINGS_ID); ICore::showOptionsDialog(SETTINGS_ID);
} else if (cmd.args == _("ic") || cmd.args == _("ignorecase")) { } else if (cmd.args == "ic" || cmd.args == "ignorecase") {
// :set nc // :set nc
setActionChecked(Core::Constants::CASE_SENSITIVE, false); setActionChecked(Core::Constants::CASE_SENSITIVE, false);
} else if (cmd.args == _("noic") || cmd.args == _("noignorecase")) { } else if (cmd.args == "noic" || cmd.args == "noignorecase") {
// :set noic // :set noic
setActionChecked(Core::Constants::CASE_SENSITIVE, true); setActionChecked(Core::Constants::CASE_SENSITIVE, true);
} }
*handled = false; // Let the handler see it as well. *handled = false; // Let the handler see it as well.
} else if (cmd.matches(_("n"), _("next"))) { } else if (cmd.matches("n", "next")) {
// :n[ext] // :n[ext]
switchToFile(currentFile() + cmd.count); switchToFile(currentFile() + cmd.count);
} else if (cmd.matches(_("prev"), _("previous")) || cmd.matches(_("N"), _("Next"))) { } else if (cmd.matches("prev", "previous") || cmd.matches("N", "Next")) {
// :prev[ious], :N[ext] // :prev[ious], :N[ext]
switchToFile(currentFile() - cmd.count); switchToFile(currentFile() - cmd.count);
} else if (cmd.matches(_("bn"), _("bnext"))) { } else if (cmd.matches("bn", "bnext")) {
// :bn[ext] // :bn[ext]
switchToFile(currentFile() + cmd.count); switchToFile(currentFile() + cmd.count);
} else if (cmd.matches(_("bp"), _("bprevious")) || cmd.matches(_("bN"), _("bNext"))) { } else if (cmd.matches("bp", "bprevious") || cmd.matches("bN", "bNext")) {
// :bp[revious], :bN[ext] // :bp[revious], :bN[ext]
switchToFile(currentFile() - cmd.count); switchToFile(currentFile() - cmd.count);
} else if (cmd.matches(_("on"), _("only"))) { } else if (cmd.matches("on", "only")) {
// :on[ly] // :on[ly]
keepOnlyWindow(); keepOnlyWindow();
} else if (cmd.cmd == _("AS")) { } else if (cmd.cmd == "AS") {
triggerAction(Core::Constants::SPLIT); triggerAction(Core::Constants::SPLIT);
triggerAction(CppTools::Constants::SWITCH_HEADER_SOURCE); triggerAction(CppTools::Constants::SWITCH_HEADER_SOURCE);
} else if (cmd.cmd == _("AV")) { } else if (cmd.cmd == "AV") {
triggerAction(Core::Constants::SPLIT_SIDE_BY_SIDE); triggerAction(Core::Constants::SPLIT_SIDE_BY_SIDE);
triggerAction(CppTools::Constants::SWITCH_HEADER_SOURCE); triggerAction(CppTools::Constants::SWITCH_HEADER_SOURCE);
} else { } else {
@@ -2152,7 +2150,7 @@ void FakeVimPluginPrivate::indentRegion(int beginBlock, int endBlock,
for (int i = beginBlock; i <= endBlock; ++i) { for (int i = beginBlock; i <= endBlock; ++i) {
lineLengths[i - beginBlock] = block.text().length(); lineLengths[i - beginBlock] = block.text().length();
if (typedChar == 0 && block.text().simplified().isEmpty()) { if (typedChar.unicode() == 0 && block.text().simplified().isEmpty()) {
// clear empty lines // clear empty lines
QTextCursor cursor(block); QTextCursor cursor(block);
while (!cursor.atBlockEnd()) while (!cursor.atBlockEnd())
@@ -2185,12 +2183,12 @@ void FakeVimPluginPrivate::showCommandBuffer(const QString &contents,
void FakeVimPluginPrivate::showExtraInformation(const QString &text) void FakeVimPluginPrivate::showExtraInformation(const QString &text)
{ {
EditorManager::splitSideBySide(); EditorManager::splitSideBySide();
QString title = _("stdout.txt"); QString title = "stdout.txt";
IEditor *iedit = EditorManager::openEditorWithContents(Id(), &title, text.toUtf8()); IEditor *iedit = EditorManager::openEditorWithContents(Id(), &title, text.toUtf8());
EditorManager::activateEditor(iedit); EditorManager::activateEditor(iedit);
FakeVimHandler *handler = m_editorToHandler.value(iedit, 0); FakeVimHandler *handler = m_editorToHandler.value(iedit, 0);
QTC_ASSERT(handler, return); QTC_ASSERT(handler, return);
handler->handleCommand(_("0")); handler->handleCommand("0");
} }
void FakeVimPluginPrivate::changeSelection(const QList<QTextEdit::ExtraSelection> &selection) void FakeVimPluginPrivate::changeSelection(const QList<QTextEdit::ExtraSelection> &selection)
@@ -2293,7 +2291,7 @@ void FakeVimPlugin::setupTest(QString *title, FakeVimHandler **handler, QWidget
*edit = iedit->widget(); *edit = iedit->widget();
*handler = d->m_editorToHandler.value(iedit, 0); *handler = d->m_editorToHandler.value(iedit, 0);
(*handler)->setupWidget(); (*handler)->setupWidget();
(*handler)->handleCommand(_("set startofline")); (*handler)->handleCommand("set startofline");
// *handler = 0; // *handler = 0;
// m_statusMessage.clear(); // m_statusMessage.clear();
@@ -2323,7 +2321,7 @@ void FakeVimPlugin::setupTest(QString *title, FakeVimHandler **handler, QWidget
// this, SLOT(changeStatusData(QString))); // this, SLOT(changeStatusData(QString)));
// QCOMPARE(EDITOR(toPlainText()), lines); // QCOMPARE(EDITOR(toPlainText()), lines);
(*handler)->handleCommand(_("set iskeyword=@,48-57,_,192-255,a-z,A-Z")); (*handler)->handleCommand("set iskeyword=@,48-57,_,192-255,a-z,A-Z");
} }
#endif #endif