Commit 513ee02f authored by hjk's avatar hjk
Browse files

FakeVim: Use a single "FakeVim" translation context



Change-Id: I624dedddf88a017af107670794034282f0aafdcc
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 6fc20eec
......@@ -7,7 +7,8 @@ SOURCES += fakevimactions.cpp \
fakevimplugin.cpp
HEADERS += fakevimactions.h \
fakevimhandler.h \
fakevimplugin.h
fakevimplugin.h \
fakevimtr.h
FORMS += fakevimoptions.ui
equals(TEST, 1) {
......
......@@ -21,6 +21,7 @@ QtcPlugin {
"fakevimoptions.ui",
"fakevimplugin.cpp",
"fakevimplugin.h",
"fakevimtr.h",
]
Group {
......
......@@ -29,6 +29,7 @@
#include "fakevimactions.h"
#include "fakevimhandler.h"
#include "fakevimtr.h"
// Please do not add any direct dependencies to other Qt Creator code here.
// Instead emit signals and let the FakeVimPlugin channel the information to
......@@ -39,8 +40,6 @@
#include <utils/qtcassert.h>
#include <QDebug>
#include <QObject>
#include <QCoreApplication>
#ifdef FAKEVIM_STANDALONE
using namespace FakeVim::Internal::Utils;
......@@ -150,15 +149,15 @@ 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);
return Tr::tr("Unknown option: %1").arg(name);
if (code == ConfigTabStop || code == ConfigShiftWidth) {
if (value.toInt() <= 0)
return FakeVimHandler::tr("Argument must be positive: %1=%2")
return Tr::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);
return Tr::tr("Unknown option: %1").arg(name);
act->setValue(value);
return QString();
}
......@@ -191,12 +190,9 @@ FakeVimSettings *theFakeVimSettings()
createAction(s, ConfigVimRcPath, QString(), _("VimRcPath"));
#ifndef FAKEVIM_STANDALONE
createAction(s, ConfigUseFakeVim, false, _("UseFakeVim"));
s->item(ConfigUseFakeVim)->setText(QCoreApplication::translate("FakeVim::Internal",
"Use Vim-style Editing"));
s->item(ConfigReadVimRc)->setText(QCoreApplication::translate("FakeVim::Internal",
"Read .vimrc"));
s->item(ConfigVimRcPath)->setText(QCoreApplication::translate("FakeVim::Internal",
"Path to .vimrc"));
s->item(ConfigUseFakeVim)->setText(Tr::tr("Use Vim-style Editing"));
s->item(ConfigReadVimRc)->setText(Tr::tr("Read .vimrc"));
s->item(ConfigVimRcPath)->setText(Tr::tr("Path to .vimrc"));
#endif
createAction(s, ConfigShowMarks, false, _("ShowMarks"), _("sm"));
createAction(s, ConfigPassControlKey, false, _("PassControlKey"), _("pck"));
......
......@@ -60,6 +60,7 @@
#include "fakevimhandler.h"
#include "fakevimactions.h"
#include "fakevimtr.h"
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
......@@ -948,7 +949,7 @@ static bool startsWithWhitespace(const QString &str, int col)
inline QString msgMarkNotSet(const QString &text)
{
return FakeVimHandler::tr("Mark \"%1\" not set.").arg(text);
return Tr::tr("Mark \"%1\" not set.").arg(text);
}
class Input
......@@ -2787,7 +2788,7 @@ void FakeVimHandler::Private::prependMapping(const Inputs &inputs)
QList<Input> inputs = g.pendingInput.mid(i);
clearPendingInput();
g.pendingInput.append(inputs);
showMessage(MessageError, tr("Recursive mapping"));
showMessage(MessageError, Tr::tr("Recursive mapping"));
updateMiniBuffer();
return;
}
......@@ -3537,9 +3538,9 @@ void FakeVimHandler::Private::updateMiniBuffer()
.arg(l + 1).arg(physicalCursorColumn() + 1);
// FIXME: physical "-" logical
if (linesInDoc != 0)
status = FakeVimHandler::tr("%1%2%").arg(pos, -10).arg(l * 100 / linesInDoc, 4);
status = Tr::tr("%1%2%").arg(pos, -10).arg(l * 100 / linesInDoc, 4);
else
status = FakeVimHandler::tr("%1All").arg(pos, -10);
status = Tr::tr("%1All").arg(pos, -10);
emit q->statusDataChanged(status);
}
......@@ -3553,7 +3554,7 @@ void FakeVimHandler::Private::showMessage(MessageLevel level, const QString &msg
void FakeVimHandler::Private::notImplementedYet()
{
qDebug() << "Not implemented in FakeVim";
showMessage(MessageError, FakeVimHandler::tr("Not implemented in FakeVim."));
showMessage(MessageError, Tr::tr("Not implemented in FakeVim."));
}
void FakeVimHandler::Private::passShortcuts(bool enable)
......@@ -4194,7 +4195,7 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
finishMovement();
} else if (input.isControl('c')) {
if (isNoVisualMode())
showMessage(MessageInfo, tr("Type Alt-V, Alt-V to quit FakeVim mode."));
showMessage(MessageInfo, Tr::tr("Type Alt-V, Alt-V to quit FakeVim mode."));
else
leaveVisualMode();
} else if ((input.is('d') || input.is('x') || input.isKey(Key_Delete))
......@@ -5718,7 +5719,7 @@ bool FakeVimHandler::Private::handleExSetCommand(const ExCommand &cmd)
SavedAction *act = theFakeVimSettings()->item(optionName);
if (!act) {
showMessage(MessageError, FakeVimHandler::tr("Unknown option:")
showMessage(MessageError, Tr::tr("Unknown option:")
+ QLatin1Char(' ') + cmd.args);
} else if (act->defaultValue().type() == QVariant::Bool) {
bool oldValue = act->value().toBool();
......@@ -5729,10 +5730,10 @@ bool FakeVimHandler::Private::handleExSetCommand(const ExCommand &cmd)
act->setValue(!oldValue);
}
} else if (negateOption && !printOption) {
showMessage(MessageError, FakeVimHandler::tr("Invalid argument:")
showMessage(MessageError, Tr::tr("Invalid argument:")
+ QLatin1Char(' ') + cmd.args);
} else if (toggleOption) {
showMessage(MessageError, FakeVimHandler::tr("Trailing characters:")
showMessage(MessageError, Tr::tr("Trailing characters:")
+ QLatin1Char(' ') + cmd.args);
} else {
showMessage(MessageInfo, act->settingsKey().toLower() + _("=")
......@@ -5815,7 +5816,7 @@ bool FakeVimHandler::Private::handleExMoveCommand(const ExCommand &cmd)
int targetLine = lineCode == _("0") ? -1 : parseLineAddress(&lineCode);
if (targetLine >= startLine && targetLine < endLine) {
showMessage(MessageError, FakeVimHandler::tr("Move lines into themselves."));
showMessage(MessageError, Tr::tr("Move lines into themselves."));
return true;
}
......@@ -5859,7 +5860,7 @@ bool FakeVimHandler::Private::handleExMoveCommand(const ExCommand &cmd)
setMark(QLatin1Char('>'), lastPosition);
if (lines > 2)
showMessage(MessageInfo, FakeVimHandler::tr("%n lines moved.", 0, lines));
showMessage(MessageInfo, Tr::tr("%n lines moved.", 0, lines));
return true;
}
......@@ -5918,7 +5919,7 @@ bool FakeVimHandler::Private::handleExWriteCommand(const ExCommand &cmd)
QFile file1(fileName);
const bool exists = file1.exists();
if (exists && !forced && !noArgs) {
showMessage(MessageError, FakeVimHandler::tr
showMessage(MessageError, Tr::tr
("File \"%1\" exists (add ! to override)").arg(fileName));
} else if (file1.open(QIODevice::ReadWrite)) {
// Nobody cared, so act ourselves.
......@@ -5932,22 +5933,22 @@ bool FakeVimHandler::Private::handleExWriteCommand(const ExCommand &cmd)
QTextStream ts(&file2);
ts << contents;
} else {
showMessage(MessageError, FakeVimHandler::tr
showMessage(MessageError, Tr::tr
("Cannot open file \"%1\" for writing").arg(fileName));
}
// Check result by reading back.
QFile file3(fileName);
file3.open(QIODevice::ReadOnly);
QByteArray ba = file3.readAll();
showMessage(MessageInfo, FakeVimHandler::tr("\"%1\" %2 %3L, %4C written.")
.arg(fileName).arg(exists ? _(" ") : tr(" [New] "))
showMessage(MessageInfo, Tr::tr("\"%1\" %2 %3L, %4C written.")
.arg(fileName).arg(exists ? _(" ") : Tr::tr(" [New] "))
.arg(ba.count('\n')).arg(ba.size()));
//if (quitAll)
// passUnknownExCommand(forced ? "qa!" : "qa");
//else if (quit)
// passUnknownExCommand(forced ? "q!" : "q");
} else {
showMessage(MessageError, FakeVimHandler::tr
showMessage(MessageError, Tr::tr
("Cannot open file \"%1\" for reading").arg(fileName));
}
return true;
......@@ -5977,7 +5978,7 @@ bool FakeVimHandler::Private::handleExReadCommand(const ExCommand &cmd)
endEditBlock();
showMessage(MessageInfo, FakeVimHandler::tr("\"%1\" %2L, %3C")
showMessage(MessageInfo, Tr::tr("\"%1\" %2L, %3C")
.arg(m_currentFileName).arg(data.count(QLatin1Char('\n'))).arg(data.size()));
return true;
......@@ -6004,7 +6005,7 @@ bool FakeVimHandler::Private::handleExBangCommand(const ExCommand &cmd) // :!
endEditBlock();
leaveVisualMode();
//qDebug() << "FILTER: " << command;
showMessage(MessageInfo, FakeVimHandler::tr("%n lines filtered.", 0,
showMessage(MessageInfo, Tr::tr("%n lines filtered.", 0,
input.count(QLatin1Char('\n'))));
} else if (!result.isEmpty()) {
emit q->extraInformationChanged(result);
......@@ -6092,7 +6093,7 @@ bool FakeVimHandler::Private::handleExSourceCommand(const ExCommand &cmd)
QString fileName = cmd.args;
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
showMessage(MessageError, FakeVimHandler::tr("Cannot open file %1").arg(fileName));
showMessage(MessageError, Tr::tr("Cannot open file %1").arg(fileName));
return true;
}
......@@ -6165,7 +6166,7 @@ void FakeVimHandler::Private::handleExCommand(const QString &line0)
QString lastCommand = line;
while (parseExCommmand(&line, &cmd)) {
if (!handleExCommandHelper(cmd)) {
showMessage(MessageError, tr("Not an editor command: %1").arg(lastCommand));
showMessage(MessageError, Tr::tr("Not an editor command: %1").arg(lastCommand));
break;
}
lastCommand = line;
......@@ -6257,8 +6258,7 @@ QTextCursor FakeVimHandler::Private::search(const SearchData &sd, int startPos,
if (!needleExp.isValid()) {
if (showMessages) {
QString error = needleExp.errorString();
showMessage(MessageError,
FakeVimHandler::tr("Invalid regular expression: %1").arg(error));
showMessage(MessageError, Tr::tr("Invalid regular expression: %1").arg(error));
}
if (sd.highlightMatches)
highlightMatches(QString());
......@@ -6294,18 +6294,18 @@ QTextCursor FakeVimHandler::Private::search(const SearchData &sd, int startPos,
if (tc.isNull()) {
if (showMessages) {
showMessage(MessageError,
FakeVimHandler::tr("Pattern not found: %1").arg(sd.needle));
Tr::tr("Pattern not found: %1").arg(sd.needle));
}
} else if (showMessages) {
QString msg = sd.forward
? FakeVimHandler::tr("Search hit BOTTOM, continuing at TOP.")
: FakeVimHandler::tr("Search hit TOP, continuing at BOTTOM.");
? Tr::tr("Search hit BOTTOM, continuing at TOP.")
: Tr::tr("Search hit TOP, continuing at BOTTOM.");
showMessage(MessageWarning, msg);
}
} else if (showMessages) {
QString msg = sd.forward
? FakeVimHandler::tr("Search hit BOTTOM without match for: %1")
: FakeVimHandler::tr("Search hit TOP without match for: %1");
? Tr::tr("Search hit BOTTOM without match for: %1")
: Tr::tr("Search hit TOP without match for: %1");
showMessage(MessageError, msg.arg(sd.needle));
}
}
......@@ -6412,7 +6412,7 @@ void FakeVimHandler::Private::indentSelectedText(QChar typedChar)
const int lines = endLine - beginLine + 1;
if (lines > 2)
showMessage(MessageInfo, FakeVimHandler::tr("%n lines indented.", 0, lines));
showMessage(MessageInfo, Tr::tr("%n lines indented.", 0, lines));
}
void FakeVimHandler::Private::indentText(const Range &range, QChar typedChar)
......@@ -6469,7 +6469,7 @@ void FakeVimHandler::Private::shiftRegionRight(int repeat)
const int lines = endLine - beginLine + 1;
if (lines > 2) {
showMessage(MessageInfo,
FakeVimHandler::tr("%n lines %1ed %2 time.", 0, lines)
Tr::tr("%n lines %1ed %2 time.", 0, lines)
.arg(repeat > 0 ? '>' : '<').arg(qAbs(repeat)));
}
}
......@@ -7042,7 +7042,7 @@ void FakeVimHandler::Private::yankText(const Range &range, int reg)
const int lines = document()->findBlock(range.endPos).blockNumber()
- document()->findBlock(range.beginPos).blockNumber() + 1;
if (lines > 2)
showMessage(MessageInfo, FakeVimHandler::tr("%n lines yanked.", 0, lines));
showMessage(MessageInfo, Tr::tr("%n lines yanked.", 0, lines));
}
void FakeVimHandler::Private::transformText(const Range &range,
......@@ -7747,8 +7747,8 @@ void FakeVimHandler::Private::undoRedo(bool undo)
CursorPosition lastPos(m_cursor);
if (undo ? !document()->isUndoAvailable() : !document()->isRedoAvailable()) {
const QString msg = undo ? FakeVimHandler::tr("Already at oldest change.")
: FakeVimHandler::tr("Already at newest change.");
const QString msg = undo ? Tr::tr("Already at oldest change.")
: Tr::tr("Already at newest change.");
showMessage(MessageInfo, msg);
UNDO_DEBUG(msg);
return;
......
......@@ -31,6 +31,7 @@
#include "fakevimactions.h"
#include "fakevimhandler.h"
#include "fakevimtr.h"
#include "ui_fakevimoptions.h"
#include <coreplugin/actionmanager/actioncontainer.h>
......@@ -373,9 +374,9 @@ public:
FakeVimOptionPage()
{
setId(SETTINGS_ID);
setDisplayName(tr("General"));
setDisplayName(Tr::tr("General"));
setCategory(SETTINGS_CATEGORY);
setDisplayCategory(tr("FakeVim"));
setDisplayCategory(Tr::tr("FakeVim"));
setCategoryIcon(_(SETTINGS_CATEGORY_FAKEVIM_ICON));
}
......@@ -404,9 +405,9 @@ QWidget *FakeVimOptionPage::widget()
const QString vimrcDefault = Utils::HostOsInfo::isAnyUnixHost() ?
QLatin1String("$HOME/.vimrc") : QLatin1String("%USERPROFILE%\\_vimrc");
m_ui.pathChooserVimRcPath->setExpectedKind(Utils::PathChooser::File);
m_ui.pathChooserVimRcPath->lineEdit()->setToolTip(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."));
m_ui.pathChooserVimRcPath->lineEdit()->setPlaceholderText(tr("Default: %1").arg(vimrcDefault));
m_ui.pathChooserVimRcPath->lineEdit()->setPlaceholderText(Tr::tr("Default: %1").arg(vimrcDefault));
m_group.clear();
m_group.insert(theFakeVimSetting(ConfigUseFakeVim),
......@@ -553,9 +554,9 @@ public:
: m_q(q)
{
setId(SETTINGS_EX_CMDS_ID);
setDisplayName(tr("Ex Command Mapping"));
setDisplayName(Tr::tr("Ex Command Mapping"));
setCategory(SETTINGS_CATEGORY);
setDisplayCategory(tr("FakeVim"));
setDisplayCategory(Tr::tr("FakeVim"));
setCategoryIcon(_(SETTINGS_CATEGORY_FAKEVIM_ICON));
}
......@@ -578,10 +579,10 @@ private:
QWidget *FakeVimExCommandsPage::widget()
{
QWidget *w = CommandMappings::widget();
setPageTitle(tr("Ex Command Mapping"));
setTargetHeader(tr("Ex Trigger Expression"));
setTargetLabelText(tr("Regular expression:"));
setTargetEditTitle(tr("Ex Command"));
setPageTitle(Tr::tr("Ex Command Mapping"));
setTargetHeader(Tr::tr("Ex Trigger Expression"));
setTargetLabelText(Tr::tr("Regular expression:"));
setTargetEditTitle(Tr::tr("Ex Command"));
setImportExportEnabled(false);
return w;
}
......@@ -728,8 +729,8 @@ QVariant FakeVimUserCommandsModel::headerData(int section,
{
if (orient == Qt::Horizontal && role == Qt::DisplayRole) {
switch (section) {
case 0: return tr("Action");
case 1: return tr("Command");
case 0: return Tr::tr("Action");
case 1: return Tr::tr("Command");
};
}
return QVariant();
......@@ -775,9 +776,9 @@ public:
: m_q(q)
{
setId(SETTINGS_USER_CMDS_ID);
setDisplayName(tr("User Command Mapping"));
setDisplayName(Tr::tr("User Command Mapping"));
setCategory(SETTINGS_CATEGORY);
setDisplayCategory(tr("FakeVim"));
setDisplayCategory(Tr::tr("FakeVim"));
setCategoryIcon(_(SETTINGS_CATEGORY_FAKEVIM_ICON));
}
......@@ -1094,7 +1095,7 @@ QVariant FakeVimUserCommandsModel::data(const QModelIndex &index, int role) cons
if (role == Qt::DisplayRole || role == Qt::EditRole) {
switch (index.column()) {
case 0: // Action
return tr("User command #%1").arg(index.row() + 1);
return Tr::tr("User command #%1").arg(index.row() + 1);
case 1: // Command
return m_q->userCommandMap().value(index.row() + 1);
}
......@@ -1202,7 +1203,7 @@ bool FakeVimPluginPrivate::initialize()
Command *cmd = 0;
cmd = ActionManager::registerAction(theFakeVimSetting(ConfigUseFakeVim),
INSTALL_HANDLER, globalcontext, true);
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+V,Meta+V") : tr("Alt+V,Alt+V")));
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? Tr::tr("Meta+V,Meta+V") : Tr::tr("Alt+V,Alt+V")));
ActionContainer *advancedMenu =
ActionManager::actionContainer(Core::Constants::M_EDIT_ADVANCED);
......@@ -1211,10 +1212,10 @@ bool FakeVimPluginPrivate::initialize()
const Id base = "FakeVim.UserAction";
for (int i = 1; i < 10; ++i) {
QAction *act = new QAction(this);
act->setText(tr("Execute User Action #%1").arg(i));
act->setText(Tr::tr("Execute User Action #%1").arg(i));
act->setData(i);
cmd = ActionManager::registerAction(act, base.withSuffix(i), globalcontext);
cmd->setDefaultKeySequence(QKeySequence((UseMacShortcuts ? tr("Meta+V,%1") : tr("Alt+V,%1")).arg(i)));
cmd->setDefaultKeySequence(QKeySequence((UseMacShortcuts ? Tr::tr("Meta+V,%1") : Tr::tr("Alt+V,%1")).arg(i)));
connect(act, SIGNAL(triggered()), SLOT(userActionTriggered()));
}
......@@ -1981,13 +1982,13 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
QFile file3(fileName);
file3.open(QIODevice::ReadOnly);
QByteArray ba = file3.readAll();
handler->showMessage(MessageInfo, FakeVimHandler::tr("\"%1\" %2 %3L, %4C written")
handler->showMessage(MessageInfo, Tr::tr("\"%1\" %2 %3L, %4C written")
.arg(fileName).arg(QLatin1Char(' '))
.arg(ba.count('\n')).arg(ba.size()));
if (cmd.cmd == _("wq"))
delayedQuitRequested(cmd.hasBang, m_editorToHandler.key(handler));
} else {
handler->showMessage(MessageError, tr("File not saved"));
handler->showMessage(MessageError, Tr::tr("File not saved"));
}
} else if (cmd.matches(_("wa"), _("wall"))) {
// :w[all]
......@@ -1995,9 +1996,9 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
QList<IDocument *> failed;
bool success = DocumentManager::saveModifiedDocuments(toSave, QString(), 0, QString(), 0, &failed);
if (!success)
handler->showMessage(MessageInfo, tr("Saving succeeded"));
handler->showMessage(MessageInfo, Tr::tr("Saving succeeded"));
else
handler->showMessage(MessageError, 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"))) {
// :q[uit]
emit delayedQuitRequested(cmd.hasBang, m_editorToHandler.key(handler));
......
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** 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.
**
** GNU Lesser General Public License Usage
** 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
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef FAKEVIMTR_H
#define FAKEVIMTR_H
#include <QCoreApplication>
namespace FakeVim {
struct Tr
{
Q_DECLARE_TR_FUNCTIONS(FakeVim)
};
} // namespace FakeVim
#endif // FAKEVIMTR
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment