Commit 1f74468a authored by Orgad Shaneh's avatar Orgad Shaneh Committed by hjk
Browse files

FakeVim: Compile with QT_NO_CAST_FROM_ASCII



Change-Id: I5ed7bb6f39689d5657709e2ab4a2fa90594abb0e
Reviewed-by: default avatarhjk <qthjk@ovi.com>
Reviewed-by: default avatarLukas Holecek <hluk@email.cz>
parent 288d1aad
......@@ -7,7 +7,7 @@ include(../../plugins/coreplugin/coreplugin.pri)
include(../../plugins/texteditor/texteditor.pri)
include(../../plugins/find/find.pri)
# DEFINES += QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII
DEFINES += QT_NO_CAST_FROM_ASCII
QT += gui
SOURCES += fakevimactions.cpp \
fakevimhandler.cpp \
......
......@@ -10,7 +10,9 @@ QtcPlugin {
Depends { name: "TextEditor" }
Depends { name: "Find" }
Depends { name: "Qt.widgets" }
Depends { name: "cpp" }
cpp.defines: base.concat(["QT_NO_CAST_FROM_ASCII"])
files: [
"fakevimactions.cpp",
"fakevimactions.h",
......
......@@ -66,21 +66,21 @@
#define LINE_END ">\n"
// Format of message after comparison fails (used by KEYS, COMMAND).
static const QString helpFormat =
static const QString helpFormat = QLatin1String(
"\n\tBefore command [%1]:\n" \
LINE_START "%2" LINE_END \
"\n\tAfter the command:\n" \
LINE_START "%3" LINE_END \
"\n\tShould be:\n" \
LINE_START "%4" LINE_END;
LINE_START "%4" LINE_END);
// Compare document contents with a expectedText.
// Also check cursor position if the expectedText contains | chracter.
#define COMPARE(beforeText, beforePosition, afterText, afterPosition, expectedText, cmd) \
do { \
QString before(beforeText); \
QString actual(afterText); \
QString expected(expectedText); \
QByteArray before(beforeText); \
QByteArray actual(afterText); \
QByteArray expected = expectedText; \
data.oldPosition = beforePosition; \
data.oldText = before; \
if (expected.contains(X)) {\
......@@ -88,10 +88,10 @@ static const QString helpFormat =
actual = textWithCursor(actual, afterPosition); \
} \
QString help = helpFormat \
.arg(QString(cmd)) \
.arg(before.replace('\n', LINE_END LINE_START)) \
.arg(actual.replace('\n', LINE_END LINE_START)) \
.arg(expected.replace('\n', LINE_END LINE_START)); \
.arg(QLatin1String(cmd)) \
.arg(QLatin1String(before.replace('\n', LINE_END LINE_START))) \
.arg(QLatin1String(actual.replace('\n', LINE_END LINE_START))) \
.arg(QLatin1String(expected.replace('\n', LINE_END LINE_START))); \
QVERIFY2(actual == expected, help.toLatin1().constData()); \
} while (false)
......@@ -99,7 +99,7 @@ static const QString helpFormat =
// Escape is always prepended to keys so that previous command is cancelled.
#define KEYS(keys, expected) \
do { \
QString beforeText(data.text()); \
QByteArray beforeText(data.text()); \
int beforePosition = data.position(); \
data.doKeys("<ESC>"); \
data.doKeys(keys); \
......@@ -109,7 +109,7 @@ static const QString helpFormat =
// Run Ex command and check if the expected result is same as document contents.
#define COMMAND(cmd, expected) \
do { \
QString beforeText(data.text()); \
QByteArray beforeText(data.text()); \
int beforePosition = data.position(); \
data.doCommand(cmd); \
COMPARE(beforeText, beforePosition, data.text(), data.position(), (expected), (":" cmd)); \
......@@ -123,7 +123,7 @@ static const QString helpFormat =
data.doKeys("<ESC>"); \
const int newPosition = data.position(); \
const int oldPosition = data.oldPosition; \
const QString redo = data.text(); \
const QByteArray redo = data.text(); \
KEYS("u", data.oldText); \
const QTextCursor tc = data.cursor(); \
const int pos = tc.position(); \
......@@ -140,18 +140,18 @@ static const QString helpFormat =
using namespace FakeVim::Internal;
using namespace TextEditor;
static QString textWithCursor(const QString &text, int position)
static QByteArray textWithCursor(const QByteArray &text, int position)
{
return (position == -1) ? text : (text.left(position) + X + text.mid(position));
}
static QString textWithCursor(const QString &text, const QTextBlock &block, int column)
static QByteArray textWithCursor(const QByteArray &text, const QTextBlock &block, int column)
{
const int pos = block.position() + qMin(column, qMax(0, block.length() - 2));
return text.left(pos) + X + text.mid(pos);
}
const QString testLines =
const QByteArray testLines =
/* 0 1 2 3 4 */
/* 0123456789012345678901234567890123457890 */
"\n"
......@@ -165,18 +165,29 @@ const QString testLines =
" return app.exec();\n"
"}\n";
const QStringList l = testLines.split('\n');
const QList<QByteArray> l = testLines.split('\n');
static QByteArray bajoin(const QList<QByteArray> &balist)
{
QByteArray res;
for (int i = 0; i < balist.size(); ++i) {
if (i)
res += '\n';
res += balist.at(i);
}
return res;
}
// Insert cursor char at pos, negative counts from back.
static QString cursor(int line, int column)
static QByteArray cursor(int line, int column)
{
const int col = column >= 0 ? column : l[line].size() + column;
QStringList res = l.mid(0, line) << textWithCursor(l[line], col);
QList<QByteArray> res = l.mid(0, line) << textWithCursor(l[line], col);
res.append(l.mid(line + 1));
return res.join("\n");
return bajoin(res);
}
static QString lmid(int i, int n = -1) { return QStringList(l.mid(i, n)).join("\n"); }
static QByteArray lmid(int i, int n = -1) { return bajoin(l.mid(i, n)); }
// Data for tests containing BaseTextEditorWidget and FakeVimHAndler.
struct FakeVimPlugin::TestData
......@@ -186,7 +197,7 @@ struct FakeVimPlugin::TestData
QString title;
int oldPosition;
QString oldText;
QByteArray oldText;
BaseTextEditorWidget *editor() const { return qobject_cast<BaseTextEditorWidget *>(edit); }
......@@ -202,27 +213,27 @@ struct FakeVimPlugin::TestData
handler->setTextCursorPosition(position);
}
QString text() const { return editor()->toPlainText(); }
QByteArray text() const { return editor()->toPlainText().toUtf8(); }
void doCommand(const QString &cmd) { handler->handleCommand(cmd); }
void doKeys(const QString &keys) { handler->handleInput(keys); }
void doCommand(const char *cmd) { handler->handleCommand(QLatin1String(cmd)); }
void doKeys(const char *keys) { handler->handleInput(QLatin1String(keys)); }
void setText(const QString &text)
void setText(const char *text)
{
doKeys("<ESC>");
QString str = text;
QByteArray str = text;
int i = str.indexOf(X);
if (i != -1)
str.remove(i, 1);
editor()->document()->setPlainText(str);
editor()->document()->setPlainText(QLatin1String(str));
setPosition(i);
}
// Simulate text completion by inserting text directly to editor widget (bypassing FakeVim).
void completeText(const QString &text)
void completeText(const char *text)
{
QTextCursor tc = editor()->textCursor();
tc.insertText(text);
tc.insertText(QLatin1String(text));
editor()->setTextCursor(tc);
}
......@@ -237,7 +248,7 @@ struct FakeVimPlugin::TestData
void FakeVimPlugin::setup(TestData *data)
{
setupTest(&data->title, &data->handler, &data->edit);
data->handler->handleInput("<ESC><ESC>gg");
data->handler->handleInput(QLatin1String("<ESC><ESC>gg"));
}
......@@ -255,10 +266,10 @@ void FakeVimPlugin::test_vim_indentation()
data.doCommand("set expandtab");
data.doCommand("set tabstop=4");
data.doCommand("set shiftwidth=4");
QCOMPARE(data.handler->physicalIndentation(" \t\t\tx"), 6 + 3);
QCOMPARE(data.handler->logicalIndentation (" \t\t\tx"), 4 + 3 * 4);
QCOMPARE(data.handler->physicalIndentation(" \t\t\tx"), 5 + 3);
QCOMPARE(data.handler->logicalIndentation (" \t\t\tx"), 4 + 3 * 4);
QCOMPARE(data.handler->physicalIndentation(QLatin1String(" \t\t\tx")), 6 + 3);
QCOMPARE(data.handler->logicalIndentation (QLatin1String(" \t\t\tx")), 4 + 3 * 4);
QCOMPARE(data.handler->physicalIndentation(QLatin1String(" \t\t\tx")), 5 + 3);
QCOMPARE(data.handler->logicalIndentation (QLatin1String(" \t\t\tx")), 4 + 3 * 4);
QCOMPARE(data.handler->tabExpand(3), QLatin1String(" "));
QCOMPARE(data.handler->tabExpand(4), QLatin1String(" "));
......@@ -271,10 +282,10 @@ void FakeVimPlugin::test_vim_indentation()
data.doCommand("set expandtab");
data.doCommand("set tabstop=8");
data.doCommand("set shiftwidth=4");
QCOMPARE(data.handler->physicalIndentation(" \t\t\tx"), 6 + 3);
QCOMPARE(data.handler->logicalIndentation (" \t\t\tx"), 0 + 3 * 8);
QCOMPARE(data.handler->physicalIndentation(" \t\t\tx"), 5 + 3);
QCOMPARE(data.handler->logicalIndentation (" \t\t\tx"), 0 + 3 * 8);
QCOMPARE(data.handler->physicalIndentation(QLatin1String(" \t\t\tx")), 6 + 3);
QCOMPARE(data.handler->logicalIndentation (QLatin1String(" \t\t\tx")), 0 + 3 * 8);
QCOMPARE(data.handler->physicalIndentation(QLatin1String(" \t\t\tx")), 5 + 3);
QCOMPARE(data.handler->logicalIndentation (QLatin1String(" \t\t\tx")), 0 + 3 * 8);
QCOMPARE(data.handler->tabExpand(3), QLatin1String(" "));
QCOMPARE(data.handler->tabExpand(4), QLatin1String(" "));
......@@ -287,10 +298,10 @@ void FakeVimPlugin::test_vim_indentation()
data.doCommand("set noexpandtab");
data.doCommand("set tabstop=4");
data.doCommand("set shiftwidth=4");
QCOMPARE(data.handler->physicalIndentation(" \t\t\tx"), 6 + 3);
QCOMPARE(data.handler->logicalIndentation (" \t\t\tx"), 4 + 3 * 4);
QCOMPARE(data.handler->physicalIndentation(" \t\t\tx"), 5 + 3);
QCOMPARE(data.handler->logicalIndentation (" \t\t\tx"), 4 + 3 * 4);
QCOMPARE(data.handler->physicalIndentation(QLatin1String(" \t\t\tx")), 6 + 3);
QCOMPARE(data.handler->logicalIndentation (QLatin1String(" \t\t\tx")), 4 + 3 * 4);
QCOMPARE(data.handler->physicalIndentation(QLatin1String(" \t\t\tx")), 5 + 3);
QCOMPARE(data.handler->logicalIndentation (QLatin1String(" \t\t\tx")), 4 + 3 * 4);
QCOMPARE(data.handler->tabExpand(3), QLatin1String(" "));
QCOMPARE(data.handler->tabExpand(4), QLatin1String("\t"));
......@@ -303,10 +314,10 @@ void FakeVimPlugin::test_vim_indentation()
data.doCommand("set noexpandtab");
data.doCommand("set tabstop=8");
data.doCommand("set shiftwidth=4");
QCOMPARE(data.handler->physicalIndentation(" \t\t\tx"), 6 + 3);
QCOMPARE(data.handler->logicalIndentation (" \t\t\tx"), 0 + 3 * 8);
QCOMPARE(data.handler->physicalIndentation(" \t\t\tx"), 5 + 3);
QCOMPARE(data.handler->logicalIndentation (" \t\t\tx"), 0 + 3 * 8);
QCOMPARE(data.handler->physicalIndentation(QLatin1String(" \t\t\tx")), 6 + 3);
QCOMPARE(data.handler->logicalIndentation (QLatin1String(" \t\t\tx")), 0 + 3 * 8);
QCOMPARE(data.handler->physicalIndentation(QLatin1String(" \t\t\tx")), 5 + 3);
QCOMPARE(data.handler->logicalIndentation (QLatin1String(" \t\t\tx")), 0 + 3 * 8);
QCOMPARE(data.handler->tabExpand(3), QLatin1String(" "));
QCOMPARE(data.handler->tabExpand(4), QLatin1String(" "));
......
This diff is collapsed.
......@@ -111,6 +111,7 @@ const char SETTINGS_CATEGORY_FAKEVIM_ICON[] = ":/core/images/category_fakevim.pn
const char SETTINGS_ID[] = "A.General";
const char SETTINGS_EX_CMDS_ID[] = "B.ExCommands";
const char SETTINGS_USER_CMDS_ID[] = "C.UserCommands";
typedef QLatin1String _;
class MiniBuffer : public QStackedWidget
{
......@@ -143,20 +144,20 @@ public:
hide();
} else {
show();
m_label->setText(messageLevel == MessageMode ? "-- " + contents + " --" : contents);
m_label->setText(messageLevel == MessageMode ? _("-- ") + contents + _(" --") : contents);
QString css;
if (messageLevel == MessageError) {
css = QString("border:1px solid rgba(255,255,255,150);"
"background-color:rgba(255,0,0,100);");
css = _("border:1px solid rgba(255,255,255,150);"
"background-color:rgba(255,0,0,100);");
} else if (messageLevel == MessageWarning) {
css = QString("border:1px solid rgba(255,255,255,120);"
"background-color:rgba(255,255,0,20);");
css = _("border:1px solid rgba(255,255,255,120);"
"background-color:rgba(255,255,0,20);");
} else if (messageLevel == MessageShowCmd) {
css = QString("border:1px solid rgba(255,255,255,120);"
"background-color:rgba(100,255,100,30);");
css = _("border:1px solid rgba(255,255,255,120);"
"background-color:rgba(100,255,100,30);");
}
m_label->setStyleSheet(QString(
m_label->setStyleSheet(QString::fromLatin1(
"*{border-radius:2px;padding-left:4px;padding-right:4px;%1}").arg(css));
if (m_edit->hasFocus())
......@@ -221,7 +222,6 @@ private:
typedef QMap<QString, QRegExp> ExCommandMap;
typedef QMap<int, QString> UserCommandMap;
typedef QLatin1String _;
class FakeVimOptionPage : public IOptionsPage
{
......@@ -948,18 +948,18 @@ FakeVimPluginPrivate::FakeVimPluginPrivate(FakeVimPlugin *plugin)
m_fakeVimOptionsPage = 0;
m_fakeVimExCommandsPage = 0;
m_fakeVimUserCommandsPage = 0;
defaultExCommandMap()[CppTools::Constants::SWITCH_HEADER_SOURCE] =
QRegExp("^A$");
defaultExCommandMap()["Coreplugin.OutputPane.previtem"] =
QRegExp("^(cN(ext)?|cp(revious)?)!?( (.*))?$");
defaultExCommandMap()["Coreplugin.OutputPane.nextitem"] =
QRegExp("^cn(ext)?!?( (.*))?$");
defaultExCommandMap()[TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR] =
QRegExp("^tag?$");
defaultExCommandMap()[Core::Constants::GO_BACK] =
QRegExp("^pop?$");
defaultExCommandMap()[_(CppTools::Constants::SWITCH_HEADER_SOURCE)] =
QRegExp(_("^A$"));
defaultExCommandMap()[_("Coreplugin.OutputPane.previtem")] =
QRegExp(_("^(cN(ext)?|cp(revious)?)!?( (.*))?$"));
defaultExCommandMap()[_("Coreplugin.OutputPane.nextitem")] =
QRegExp(_("^cn(ext)?!?( (.*))?$"));
defaultExCommandMap()[_(TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR)] =
QRegExp(_("^tag?$"));
defaultExCommandMap()[_(Core::Constants::GO_BACK)] =
QRegExp(_("^pop?$"));
defaultExCommandMap()[_("QtCreator.Locate")] =
QRegExp("^e$");
QRegExp(_("^e$"));
for (int i = 1; i < 10; ++i) {
QString cmd = QString::fromLatin1(":echo User command %1 executed.<CR>");
......@@ -1040,7 +1040,7 @@ bool FakeVimPluginPrivate::initialize()
QAction *act = new QAction(this);
act->setText(tr("Execute User Action #%1").arg(i));
act->setData(i);
QString id = QString("FakeVim.UserAction%1").arg(i);
QString id = QString::fromLatin1("FakeVim.UserAction%1").arg(i);
cmd = ActionManager::registerAction(act, Id(id), globalcontext);
cmd->setDefaultKeySequence(QKeySequence((UseMacShortcuts ? tr("Meta+V,%1") : tr("Alt+V,%1")).arg(i)));
connect(act, SIGNAL(triggered()), SLOT(userActionTriggered()));
......@@ -1179,12 +1179,12 @@ void FakeVimPluginPrivate::maybeReadVimRc()
return;
QString fileName =
QDesktopServices::storageLocation(QDesktopServices::HomeLocation)
+ "/.vimrc";
+ _("/.vimrc");
//qDebug() << "READING VIMRC: " << fileName;
// Read it into a temporary handler for effects modifying global state.
QPlainTextEdit editor;
FakeVimHandler handler(&editor);
handler.handleCommand("source " + fileName);
handler.handleCommand(_("source ") + fileName);
//writeSettings();
//qDebug() << theFakeVimSetting(ConfigShiftWidth)->value();
}
......@@ -1712,7 +1712,7 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
return;
*handled = true;
if (cmd.matches("w", "write") || cmd.cmd == "wq") {
if (cmd.matches(_("w"), _("write")) || cmd.cmd == _("wq")) {
// :w[rite]
IEditor *editor = m_editorToHandler.key(handler);
const QString fileName = handler->currentFileName();
......@@ -1724,14 +1724,14 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
file3.open(QIODevice::ReadOnly);
QByteArray ba = file3.readAll();
handler->showMessage(MessageInfo, FakeVimHandler::tr("\"%1\" %2 %3L, %4C written")
.arg(fileName).arg(" ")
.arg(fileName).arg(QLatin1Char(' '))
.arg(ba.count('\n')).arg(ba.size()));
if (cmd.cmd == "wq")
if (cmd.cmd == _("wq"))
delayedQuitRequested(cmd.hasBang, m_editorToHandler.key(handler));
} else {
handler->showMessage(MessageError, tr("File not saved"));
}
} else if (cmd.matches("wa", "wall")) {
} else if (cmd.matches(_("wa"), _("wall"))) {
// :w[all]
QList<IDocument *> toSave = DocumentManager::modifiedDocuments();
QList<IDocument *> failed = DocumentManager::saveModifiedDocumentsSilently(toSave);
......@@ -1739,54 +1739,54 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
handler->showMessage(MessageInfo, tr("Saving succeeded"));
else
handler->showMessage(MessageError, tr("%n files not saved", 0, failed.size()));
} else if (cmd.matches("q", "quit")) {
} else if (cmd.matches(_("q"), _("quit"))) {
// :q[uit]
emit delayedQuitRequested(cmd.hasBang, m_editorToHandler.key(handler));
} else if (cmd.matches("qa", "qall")) {
} else if (cmd.matches(_("qa"), _("qall"))) {
// :qa[ll]
emit delayedQuitAllRequested(cmd.hasBang);
} else if (cmd.matches("sp", "split")) {
} else if (cmd.matches(_("sp"), _("split"))) {
// :sp[lit]
triggerAction(Core::Constants::SPLIT);
} else if (cmd.matches("vs", "vsplit")) {
} else if (cmd.matches(_("vs"), _("vsplit"))) {
// :vs[plit]
triggerAction(Core::Constants::SPLIT_SIDE_BY_SIDE);
} else if (cmd.matches("mak", "make")) {
} else if (cmd.matches(_("mak"), _("make"))) {
// :mak[e][!] [arguments]
triggerAction(ProjectExplorer::Constants::BUILD);
} else if (cmd.matches("se", "set")) {
} else if (cmd.matches(_("se"), _("set"))) {
if (cmd.args.isEmpty()) {
// :se[t]
showSettingsDialog();
} else if (cmd.args == "ic" || cmd.args == "ignorecase") {
} else if (cmd.args == _("ic") || cmd.args == _("ignorecase")) {
// :set nc
setActionChecked(Find::Constants::CASE_SENSITIVE, false);
} else if (cmd.args == "noic" || cmd.args == "noignorecase") {
} else if (cmd.args == _("noic") || cmd.args == _("noignorecase")) {
// :set noic
setActionChecked(Find::Constants::CASE_SENSITIVE, true);
} else {
*handled = false; // Let the handler see it as well.
}
} else if (cmd.matches("n", "next")) {
} else if (cmd.matches(_("n"), _("next"))) {
// :n[ext]
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]
switchToFile(currentFile() - cmd.count);
} else if (cmd.matches("bn", "bnext")) {
} else if (cmd.matches(_("bn"), _("bnext"))) {
// :bn[ext]
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]
switchToFile(currentFile() - cmd.count);
} else if (cmd.matches("on", "only")) {
} else if (cmd.matches(_("on"), _("only"))) {
// :on[ly]
//triggerAction(Core::Constants::REMOVE_ALL_SPLITS);
triggerAction(Core::Constants::REMOVE_CURRENT_SPLIT);
} else if (cmd.cmd == "AS") {
} else if (cmd.cmd == _("AS")) {
triggerAction(Core::Constants::SPLIT);
triggerAction(CppTools::Constants::SWITCH_HEADER_SOURCE);
} else if (cmd.cmd == "AV") {
} else if (cmd.cmd == _("AV")) {
triggerAction(Core::Constants::SPLIT_SIDE_BY_SIDE);
triggerAction(CppTools::Constants::SWITCH_HEADER_SOURCE);
} else {
......@@ -2018,12 +2018,12 @@ void FakeVimPlugin::extensionsInitialized()
#ifdef WITH_TESTS
void FakeVimPlugin::setupTest(QString *title, FakeVimHandler **handler, QWidget **edit)
{
*title = QString("test.cpp");
*title = QString::fromLatin1("test.cpp");
Core::IEditor *iedit = Core::EditorManager::openEditorWithContents(Core::Id(), title);
Core::EditorManager::activateEditor(iedit);
*edit = iedit->widget();
*handler = d->m_editorToHandler.value(iedit, 0);
(*handler)->handleCommand("set startofline");
(*handler)->handleCommand(_("set startofline"));
// *handler = 0;
// m_statusMessage.clear();
......@@ -2053,7 +2053,7 @@ void FakeVimPlugin::setupTest(QString *title, FakeVimHandler **handler, QWidget
// this, SLOT(changeStatusData(QString)));
// 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
......
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