FakeVim: Remove a few uses of QObject::sender()

Considered bad style...

Change-Id: Idc1d39bd55fa30dfa854bbc99094f5f6ec9afc4d
Reviewed-by: Lukas Holecek <hluk@email.cz>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
hjk
2017-01-23 18:34:17 +01:00
parent b25a70bf03
commit ef80d060e7
4 changed files with 176 additions and 214 deletions

View File

@@ -1871,7 +1871,7 @@ public:
m_cursor.movePosition(Right, KeepAnchor, n); m_cursor.movePosition(Right, KeepAnchor, n);
} }
if (atEndOfLine()) if (atEndOfLine())
emit q->fold(1, false); emit q->fold(q, 1, false);
setTargetColumn(); setTargetColumn();
} }
void moveLeft(int n = 1) { void moveLeft(int n = 1) {
@@ -3187,9 +3187,9 @@ void FakeVimHandler::Private::commitCursor()
updateCursorShape(); updateCursorShape();
if (isVisualBlockMode()) { if (isVisualBlockMode()) {
emit q->requestSetBlockSelection(tc); emit q->requestSetBlockSelection(q, tc);
} else { } else {
emit q->requestDisableBlockSelection(); emit q->requestDisableBlockSelection(q);
if (editor()) if (editor())
EDITOR(setTextCursor(tc)); EDITOR(setTextCursor(tc));
} }
@@ -3205,10 +3205,10 @@ void FakeVimHandler::Private::pullCursor()
QTextCursor oldCursor = m_cursor; QTextCursor oldCursor = m_cursor;
bool visualBlockMode = false; bool visualBlockMode = false;
emit q->requestHasBlockSelection(&visualBlockMode); emit q->requestHasBlockSelection(q, &visualBlockMode);
if (visualBlockMode) if (visualBlockMode)
q->requestBlockSelection(&m_cursor); q->requestBlockSelection(q, &m_cursor);
else if (editor()) else if (editor())
m_cursor = editorCursor(); m_cursor = editorCursor();
@@ -3325,7 +3325,7 @@ void FakeVimHandler::Private::moveToEndOfLineVisually(QTextCursor *tc)
void FakeVimHandler::Private::moveBehindEndOfLine() void FakeVimHandler::Private::moveBehindEndOfLine()
{ {
emit q->fold(1, false); emit q->fold(q, 1, false);
int pos = qMin(block().position() + block().length() - 1, int pos = qMin(block().position() + block().length() - 1,
lastPositionInDocument() + 1); lastPositionInDocument() + 1);
setPosition(pos); setPosition(pos);
@@ -3599,7 +3599,7 @@ void FakeVimHandler::Private::updateSelection()
} }
} }
//qDebug() << "SELECTION: " << selections; //qDebug() << "SELECTION: " << selections;
emit q->selectionChanged(selections); emit q->selectionChanged(q, selections);
} }
void FakeVimHandler::Private::updateHighlights() void FakeVimHandler::Private::updateHighlights()
@@ -3614,7 +3614,7 @@ void FakeVimHandler::Private::updateHighlights()
return; return;
} }
emit q->highlightMatches(m_highlighted); emit q->highlightMatches(q, m_highlighted);
} }
void FakeVimHandler::Private::updateMiniBuffer() void FakeVimHandler::Private::updateMiniBuffer()
@@ -3682,7 +3682,7 @@ void FakeVimHandler::Private::updateMiniBuffer()
if (g.isRecording && msg.startsWith("--")) if (g.isRecording && msg.startsWith("--"))
msg.append(' ').append("Recording"); msg.append(' ').append("Recording");
emit q->commandBufferChanged(msg, cursorPos, anchorPos, messageLevel, q); emit q->commandBufferChanged(q, msg, cursorPos, anchorPos, messageLevel);
int linesInDoc = linesInDocument(); int linesInDoc = linesInDocument();
int l = cursorLine(); int l = cursorLine();
@@ -3694,7 +3694,7 @@ void FakeVimHandler::Private::updateMiniBuffer()
status = Tr::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 else
status = Tr::tr("%1All").arg(pos, -10); status = Tr::tr("%1All").arg(pos, -10);
emit q->statusDataChanged(status); emit q->statusDataChanged(q, status);
} }
void FakeVimHandler::Private::showMessage(MessageLevel level, const QString &msg) void FakeVimHandler::Private::showMessage(MessageLevel level, const QString &msg)
@@ -3776,7 +3776,7 @@ bool FakeVimHandler::Private::handleCommandSubSubMode(const Input &input)
handled = false; handled = false;
if (input.is('j') || input.is('k')) { if (input.is('j') || input.is('k')) {
int pos = position(); int pos = position();
emit q->foldGoTo(input.is('j') ? count() : -count(), false); emit q->foldGoTo(q, input.is('j') ? count() : -count(), false);
if (pos != position()) { if (pos != position()) {
handled = true; handled = true;
finishMovement(QString("%1z%2") finishMovement(QString("%1z%2")
@@ -3803,7 +3803,7 @@ bool FakeVimHandler::Private::handleCommandSubSubMode(const Input &input)
else if (input.is(']') && g.subsubmode == CloseSquareSubSubMode) else if (input.is(']') && g.subsubmode == CloseSquareSubSubMode)
bracketSearchForward(&m_cursor, "^\\{", count(), g.submode != NoSubMode); bracketSearchForward(&m_cursor, "^\\{", count(), g.submode != NoSubMode);
else if (input.is('z')) else if (input.is('z'))
emit q->foldGoTo(g.subsubmode == OpenSquareSubSubMode ? -count() : count(), true); emit q->foldGoTo(q, g.subsubmode == OpenSquareSubSubMode ? -count() : count(), true);
handled = pos != position(); handled = pos != position();
if (handled) { if (handled) {
if (lineForPosition(pos) != lineForPosition(position())) if (lineForPosition(pos) != lineForPosition(position()))
@@ -3870,7 +3870,7 @@ bool FakeVimHandler::Private::handleMovement(const Input &input)
m_findStartPosition = position(); m_findStartPosition = position();
g.movetype = MoveExclusive; g.movetype = MoveExclusive;
setAnchor(); // clear selection: otherwise, search is restricted to selection setAnchor(); // clear selection: otherwise, search is restricted to selection
emit q->findRequested(!g.lastSearchForward); emit q->findRequested(q, !g.lastSearchForward);
} else { } else {
// FIXME: make core find dialog sufficiently flexible to // FIXME: make core find dialog sufficiently flexible to
// produce the "default vi" behaviour too. For now, roll our own. // produce the "default vi" behaviour too. For now, roll our own.
@@ -4042,10 +4042,10 @@ bool FakeVimHandler::Private::handleMovement(const Input &input)
if (hasConfig(ConfigUseCoreSearch)) { if (hasConfig(ConfigUseCoreSearch)) {
bool forward = (input.is('n')) ? g.lastSearchForward : !g.lastSearchForward; bool forward = (input.is('n')) ? g.lastSearchForward : !g.lastSearchForward;
int pos = position(); int pos = position();
emit q->findNextRequested(!forward); emit q->findNextRequested(q, !forward);
if (forward && pos == m_cursor.selectionStart()) { if (forward && pos == m_cursor.selectionStart()) {
// if cursor is already positioned at the start of a find result, this is returned // if cursor is already positioned at the start of a find result, this is returned
emit q->findNextRequested(false); emit q->findNextRequested(q, false);
} }
setPosition(m_cursor.selectionStart()); setPosition(m_cursor.selectionStart());
} else { } else {
@@ -4383,7 +4383,7 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
if (block().blockNumber() > 0) { if (block().blockNumber() > 0) {
moveUp(); moveUp();
if (line != lineNumber(block())) if (line != lineNumber(block()))
emit q->fold(1, true); emit q->fold(q, 1, true);
moveDown(); moveDown();
} }
} else if (input.isControl('o')) { } else if (input.isControl('o')) {
@@ -4660,7 +4660,7 @@ bool FakeVimHandler::Private::handleWindowSubMode(const Input &input)
leaveVisualMode(); leaveVisualMode();
leaveCurrentMode(); leaveCurrentMode();
emit q->windowCommandRequested(input.toString(), count()); emit q->windowCommandRequested(q, input.toString(), count());
return true; return true;
} }
@@ -4686,21 +4686,21 @@ bool FakeVimHandler::Private::handleZSubMode(const Input &input)
} else if (input.is('o') || input.is('c')) { } else if (input.is('o') || input.is('c')) {
// Open/close current fold. // Open/close current fold.
foldMaybeClosed = input.is('c'); foldMaybeClosed = input.is('c');
emit q->fold(count(), foldMaybeClosed); emit q->fold(q, count(), foldMaybeClosed);
} else if (input.is('O') || input.is('C')) { } else if (input.is('O') || input.is('C')) {
// Recursively open/close current fold. // Recursively open/close current fold.
foldMaybeClosed = input.is('C'); foldMaybeClosed = input.is('C');
emit q->fold(-1, foldMaybeClosed); emit q->fold(q, -1, foldMaybeClosed);
} else if (input.is('a') || input.is('A')) { } else if (input.is('a') || input.is('A')) {
// Toggle current fold. // Toggle current fold.
foldMaybeClosed = true; foldMaybeClosed = true;
emit q->foldToggle(input.is('a') ? count() : -1); emit q->foldToggle(q, input.is('a') ? count() : -1);
} else if (input.is('R') || input.is('M')) { } else if (input.is('R') || input.is('M')) {
// Open/close all folds in document. // Open/close all folds in document.
foldMaybeClosed = input.is('M'); foldMaybeClosed = input.is('M');
emit q->foldAll(foldMaybeClosed); emit q->foldAll(q, foldMaybeClosed);
} else if (input.is('j') || input.is('k')) { } else if (input.is('j') || input.is('k')) {
emit q->foldGoTo(input.is('j') ? count() : -count(), false); emit q->foldGoTo(q, input.is('j') ? count() : -count(), false);
} else { } else {
handled = false; handled = false;
} }
@@ -5079,7 +5079,7 @@ void FakeVimHandler::Private::handleInsertMode(const Input &input)
moveToNextWordStart(1, false, false); moveToNextWordStart(1, false, false);
QString str = selectText(Range(position(), tc.position())); QString str = selectText(Range(position(), tc.position()));
m_cursor = tc; m_cursor = tc;
emit q->simpleCompletionRequested(str, input.isControl('n')); emit q->simpleCompletionRequested(q, str, input.isControl('n'));
} else if (input.isShift(Qt::Key_Insert)) { } else if (input.isShift(Qt::Key_Insert)) {
// Insert text from clipboard. // Insert text from clipboard.
QClipboard *clipboard = QApplication::clipboard(); QClipboard *clipboard = QApplication::clipboard();
@@ -5668,7 +5668,7 @@ bool FakeVimHandler::Private::handleExHistoryCommand(const ExCommand &cmd)
++i; ++i;
info += QString("%1 %2\n").arg(i, -8).arg(item); info += QString("%1 %2\n").arg(i, -8).arg(item);
} }
emit q->extraInformationChanged(info); emit q->extraInformationChanged(q, info);
} else { } else {
notImplementedYet(); notImplementedYet();
} }
@@ -5698,7 +5698,7 @@ bool FakeVimHandler::Private::handleExRegisterCommand(const ExCommand &cmd)
QString value = quoteUnprintable(registerContents(reg)); QString value = quoteUnprintable(registerContents(reg));
info += QString("\"%1 %2\n").arg(reg).arg(value); info += QString("\"%1 %2\n").arg(reg).arg(value);
} }
emit q->extraInformationChanged(info); emit q->extraInformationChanged(q, info);
return true; return true;
} }
@@ -6017,7 +6017,7 @@ bool FakeVimHandler::Private::handleExBangCommand(const ExCommand &cmd) // :!
showMessage(MessageInfo, Tr::tr("%n lines filtered.", 0, showMessage(MessageInfo, Tr::tr("%n lines filtered.", 0,
input.count('\n'))); input.count('\n')));
} else if (!result.isEmpty()) { } else if (!result.isEmpty()) {
emit q->extraInformationChanged(result); emit q->extraInformationChanged(q, result);
} }
return true; return true;
@@ -6221,7 +6221,7 @@ bool FakeVimHandler::Private::handleExPluginCommand(const ExCommand &cmd)
bool handled = false; bool handled = false;
int pos = m_cursor.position(); int pos = m_cursor.position();
commitCursor(); commitCursor();
emit q->handleExCommandRequested(&handled, cmd); emit q->handleExCommandRequested(q, &handled, cmd);
//qDebug() << "HANDLER REQUEST: " << cmd.cmd << handled; //qDebug() << "HANDLER REQUEST: " << cmd.cmd << handled;
if (handled && (m_textedit || m_plaintextedit)) { if (handled && (m_textedit || m_plaintextedit)) {
pullCursor(); pullCursor();
@@ -6435,14 +6435,14 @@ void FakeVimHandler::Private::indentText(const Range &range, QChar typedChar)
// Don't remember current indentation in last text insertion. // Don't remember current indentation in last text insertion.
const QString lastInsertion = m_buffer->lastInsertion; const QString lastInsertion = m_buffer->lastInsertion;
emit q->indentRegion(beginBlock, endBlock, typedChar); emit q->indentRegion(q, beginBlock, endBlock, typedChar);
m_buffer->lastInsertion = lastInsertion; m_buffer->lastInsertion = lastInsertion;
} }
bool FakeVimHandler::Private::isElectricCharacter(QChar c) const bool FakeVimHandler::Private::isElectricCharacter(QChar c) const
{ {
bool result = false; bool result = false;
emit q->checkForElectricCharacter(&result, c); emit q->checkForElectricCharacter(q, &result, c);
return result; return result;
} }
@@ -6566,7 +6566,7 @@ void FakeVimHandler::Private::miniBufferTextEdited(const QString &text, int curs
// update command/search buffer // update command/search buffer
cmdBuf.setContents(buffer.mid(1), pos - 1, anchor - 1); cmdBuf.setContents(buffer.mid(1), pos - 1, anchor - 1);
if (pos != cursorPos || anchor != anchorPos || buffer != text) if (pos != cursorPos || anchor != anchorPos || buffer != text)
emit q->commandBufferChanged(buffer, pos, anchor, 0, q); emit q->commandBufferChanged(q, buffer, pos, anchor, 0);
// update search expression // update search expression
if (g.subsubmode == SearchSubSubMode) { if (g.subsubmode == SearchSubSubMode) {
updateFind(false); updateFind(false);
@@ -6753,7 +6753,7 @@ void FakeVimHandler::Private::moveToMatchingParanthesis()
if (tc.atBlockEnd()) if (tc.atBlockEnd())
tc = m_cursor; tc = m_cursor;
emit q->moveToMatchingParenthesis(&moved, &forward, &tc); emit q->moveToMatchingParenthesis(q, &moved, &forward, &tc);
if (moved) { if (moved) {
if (forward) if (forward)
tc.movePosition(Left, KeepAnchor, 1); tc.movePosition(Left, KeepAnchor, 1);
@@ -7320,7 +7320,7 @@ bool FakeVimHandler::Private::handleInsertInEditor(const Input &input)
bool FakeVimHandler::Private::passEventToEditor(QEvent &event, QTextCursor &tc) bool FakeVimHandler::Private::passEventToEditor(QEvent &event, QTextCursor &tc)
{ {
removeEventFilter(); removeEventFilter();
emit q->requestDisableBlockSelection(); emit q->requestDisableBlockSelection(q);
setThinCursor(); setThinCursor();
EDITOR(setTextCursor(tc)); EDITOR(setTextCursor(tc));
@@ -7663,7 +7663,7 @@ void FakeVimHandler::Private::onContentsChanged(int position, int charsRemoved,
} }
if (!m_highlighted.isEmpty()) if (!m_highlighted.isEmpty())
emit q->highlightMatches(m_highlighted); emit q->highlightMatches(q, m_highlighted);
} }
void FakeVimHandler::Private::onCursorPositionChanged() void FakeVimHandler::Private::onCursorPositionChanged()
@@ -8429,7 +8429,7 @@ bool FakeVimHandler::Private::jumpToMark(QChar mark, bool backTickMode)
return false; return false;
} }
if (!m.isLocal(m_currentFileName)) { if (!m.isLocal(m_currentFileName)) {
emit q->jumpToGlobalMark(mark, backTickMode, m.fileName()); emit q->jumpToGlobalMark(q, mark, backTickMode, m.fileName());
return false; return false;
} }

View File

@@ -132,31 +132,31 @@ public:
bool eventFilter(QObject *ob, QEvent *ev); bool eventFilter(QObject *ob, QEvent *ev);
signals: signals:
void commandBufferChanged(const QString &msg, int cursorPos, int anchorPos, void commandBufferChanged(FakeVimHandler *self, const QString &msg, int cursorPos, int anchorPos,
int messageLevel, FakeVimHandler *eventFilter); int messageLevel);
void statusDataChanged(const QString &msg); void statusDataChanged(FakeVimHandler *self, const QString &msg);
void extraInformationChanged(const QString &msg); void extraInformationChanged(FakeVimHandler *self, const QString &msg);
void selectionChanged(const QList<QTextEdit::ExtraSelection> &selection); void selectionChanged(FakeVimHandler *self, const QList<QTextEdit::ExtraSelection> &selection);
void highlightMatches(const QString &needle); void highlightMatches(FakeVimHandler *self, const QString &needle);
void writeAllRequested(QString *error); void writeAllRequested(FakeVimHandler *self, QString *error);
void moveToMatchingParenthesis(bool *moved, bool *forward, QTextCursor *cursor); void moveToMatchingParenthesis(FakeVimHandler *self, bool *moved, bool *forward, QTextCursor *cursor);
void checkForElectricCharacter(bool *result, QChar c); void checkForElectricCharacter(FakeVimHandler *self, bool *result, QChar c);
void indentRegion(int beginLine, int endLine, QChar typedChar); void indentRegion(FakeVimHandler *self, int beginLine, int endLine, QChar typedChar);
void completionRequested(); void completionRequested(FakeVimHandler *self);
void simpleCompletionRequested(const QString &needle, bool forward); void simpleCompletionRequested(FakeVimHandler *self, const QString &needle, bool forward);
void windowCommandRequested(const QString &key, int count); void windowCommandRequested(FakeVimHandler *self, const QString &key, int count);
void findRequested(bool reverse); void findRequested(FakeVimHandler *self, bool reverse);
void findNextRequested(bool reverse); void findNextRequested(FakeVimHandler *self, bool reverse);
void handleExCommandRequested(bool *handled, const ExCommand &cmd); void handleExCommandRequested(FakeVimHandler *self, bool *handled, const ExCommand &cmd);
void requestDisableBlockSelection(); void requestDisableBlockSelection(FakeVimHandler *self);
void requestSetBlockSelection(const QTextCursor&); void requestSetBlockSelection(FakeVimHandler *self, const QTextCursor &cursor);
void requestBlockSelection(QTextCursor*); void requestBlockSelection(FakeVimHandler *self, QTextCursor *cursor);
void requestHasBlockSelection(bool *on); void requestHasBlockSelection(FakeVimHandler *self, bool *on);
void foldToggle(int depth); void foldToggle(FakeVimHandler *self, int depth);
void foldAll(bool fold); void foldAll(FakeVimHandler *self, bool fold);
void fold(int depth, bool fold); void fold(FakeVimHandler *self, int depth, bool fold);
void foldGoTo(int count, bool current); void foldGoTo(FakeVimHandler *self, int count, bool current);
void jumpToGlobalMark(QChar mark, bool backTickMode, const QString &fileName); void jumpToGlobalMark(FakeVimHandler *handler, QChar mark, bool backTickMode, const QString &fileName);
public: public:
class Private; class Private;

View File

@@ -1044,33 +1044,33 @@ private:
void setUseFakeVim(const QVariant &value); void setUseFakeVim(const QVariant &value);
void setUseFakeVimInternal(bool on); void setUseFakeVimInternal(bool on);
void quitFakeVim(); void quitFakeVim();
void triggerCompletions(); void triggerCompletions(FakeVimHandler *handler);
void triggerSimpleCompletions(const QString &needle, bool forward); void triggerSimpleCompletions(FakeVimHandler *handler, const QString &needle, bool forward);
void windowCommand(const QString &key, int count); void windowCommand(FakeVimHandler *handler, const QString &key, int count);
void find(bool reverse); void find(bool reverse);
void findNext(bool reverse); void findNext(bool reverse);
void foldToggle(int depth); void foldToggle(FakeVimHandler *handler, int depth);
void foldAll(bool fold); void foldAll(FakeVimHandler *handler, bool fold);
void fold(int depth, bool fold); void fold(FakeVimHandler *handler, int depth, bool fold);
void foldGoTo(int count, bool current); void foldGoTo(FakeVimHandler *handler, int count, bool current);
void jumpToGlobalMark(QChar mark, bool backTickMode, const QString &fileName); void jumpToGlobalMark(FakeVimHandler *, QChar mark, bool backTickMode, const QString &fileName);
void maybeReadVimRc(); void maybeReadVimRc();
void disableBlockSelection(); void disableBlockSelection(FakeVimHandler *handler);
void setBlockSelection(const QTextCursor&); void setBlockSelection(FakeVimHandler *handler, const QTextCursor &cursor);
void blockSelection(QTextCursor *); void blockSelection(FakeVimHandler *handler, QTextCursor *cursor);
void hasBlockSelection(bool*); void hasBlockSelection(FakeVimHandler *handler, bool *on);
void setShowRelativeLineNumbers(const QVariant &value); void setShowRelativeLineNumbers(const QVariant &value);
void resetCommandBuffer(); void resetCommandBuffer();
void showCommandBuffer(const QString &contents, int cursorPos, int anchorPos, void showCommandBuffer(FakeVimHandler *handler, const QString &contents,
int messageLevel, FakeVimHandler *eventFilter); int cursorPos, int anchorPos, int messageLevel);
void showExtraInformation(const QString &msg); void showExtraInformation(const QString &msg);
void changeSelection(const QList<QTextEdit::ExtraSelection> &selections); void changeSelection(FakeVimHandler *handler, const QList<QTextEdit::ExtraSelection> &selections);
void highlightMatches(const QString &needle); void highlightMatches(FakeVimHandler *handler, const QString &needle);
void moveToMatchingParenthesis(bool *moved, bool *forward, QTextCursor *cursor); void moveToMatchingParenthesis(FakeVimHandler *handler, bool *moved, bool *forward, QTextCursor *cursor);
void checkForElectricCharacter(bool *result, QChar c); void checkForElectricCharacter(FakeVimHandler *handler, bool *result, QChar c);
void indentRegion(int beginBlock, int endBlock, QChar typedChar); void indentRegion(FakeVimHandler *handler, int beginBlock, int endBlock, QChar typedChar);
void handleExCommand(bool *handled, const ExCommand &cmd); void handleExCommand(FakeVimHandler *handler, bool *handled, const ExCommand &cmd);
void writeSettings(); void writeSettings();
void readSettings(); void readSettings();
@@ -1099,7 +1099,7 @@ private:
void setActionChecked(Id id, bool check); void setActionChecked(Id id, bool check);
typedef int (*DistFunction)(const QRect &cursor, const QRect &other); typedef int (*DistFunction)(const QRect &cursor, const QRect &other);
void moveSomewhere(DistFunction f, int count); void moveSomewhere(FakeVimHandler *handler, DistFunction f, int count);
void keepOnlyWindow(); // :only void keepOnlyWindow(); // :only
@@ -1470,7 +1470,7 @@ static int moveDownWeight(const QRect &cursor, const QRect &other)
return w; return w;
} }
void FakeVimPluginPrivate::windowCommand(const QString &map, int count) void FakeVimPluginPrivate::windowCommand(FakeVimHandler *handler, const QString &map, int count)
{ {
// normalize mapping // normalize mapping
const QString key = map.toUpper(); const QString key = map.toUpper();
@@ -1490,31 +1490,31 @@ void FakeVimPluginPrivate::windowCommand(const QString &map, int count)
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(handler, &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(handler, &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(handler, &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(handler, &moveDownWeight, key == "<S-J>" ? -1 : count);
else else
qDebug() << "UNKNOWN WINDOW COMMAND: <C-W>" << map; qDebug() << "UNKNOWN WINDOW COMMAND: <C-W>" << map;
} }
void FakeVimPluginPrivate::moveSomewhere(DistFunction f, int count) void FakeVimPluginPrivate::moveSomewhere(FakeVimHandler *handler, DistFunction f, int count)
{ {
IEditor *currentEditor = EditorManager::currentEditor(); QTC_ASSERT(handler, return);
QWidget *w = currentEditor->widget(); QWidget *w = handler->widget();
QPlainTextEdit *pe = qobject_cast<QPlainTextEdit *>(w); QPlainTextEdit *pe = qobject_cast<QPlainTextEdit *>(w);
QTC_ASSERT(pe, return); QTC_ASSERT(pe, return);
QRect rc = pe->cursorRect(); QRect rc = pe->cursorRect();
QRect cursorRect(w->mapToGlobal(rc.topLeft()), QRect cursorRect(w->mapToGlobal(rc.topLeft()), w->mapToGlobal(rc.bottomRight()));
w->mapToGlobal(rc.bottomRight()));
//qDebug() << "\nCURSOR: " << cursorRect; //qDebug() << "\nCURSOR: " << cursorRect;
IEditor *bestEditor = 0; IEditor *bestEditor = 0;
int repeat = count; int repeat = count;
IEditor *currentEditor = EditorManager::currentEditor();
QList<IEditor *> editors = EditorManager::visibleEditors(); QList<IEditor *> editors = EditorManager::visibleEditors();
while (repeat < 0 || repeat-- > 0) { while (repeat < 0 || repeat-- > 0) {
editors.removeOne(currentEditor); editors.removeOne(currentEditor);
@@ -1572,28 +1572,21 @@ void FakeVimPluginPrivate::findNext(bool reverse)
triggerAction(Core::Constants::FIND_NEXT); triggerAction(Core::Constants::FIND_NEXT);
} }
void FakeVimPluginPrivate::foldToggle(int depth) void FakeVimPluginPrivate::foldToggle(FakeVimHandler *handler, int depth)
{ {
IEditor *ieditor = EditorManager::currentEditor(); QTC_ASSERT(handler, return);
FakeVimHandler *handler = m_editorToHandler.value(ieditor, 0);
QTC_ASSERT(handler != 0, return);
QTextBlock block = handler->textCursor().block(); QTextBlock block = handler->textCursor().block();
fold(depth, !TextDocumentLayout::isFolded(block)); fold(handler, depth, !TextDocumentLayout::isFolded(block));
} }
void FakeVimPluginPrivate::foldAll(bool fold) void FakeVimPluginPrivate::foldAll(FakeVimHandler *handler, bool fold)
{ {
IEditor *ieditor = EditorManager::currentEditor(); QTC_ASSERT(handler, return);
TextEditorWidget *editor = qobject_cast<TextEditorWidget *>(ieditor->widget()); QTextDocument *document = handler->textCursor().document();
QTC_ASSERT(editor != 0, return); auto documentLayout = qobject_cast<TextDocumentLayout*>(document->documentLayout());
QTextDocument *doc = editor->document();
TextDocumentLayout *documentLayout =
qobject_cast<TextDocumentLayout*>(doc->documentLayout());
QTC_ASSERT(documentLayout != 0, return); QTC_ASSERT(documentLayout != 0, return);
QTextBlock block = editor->document()->firstBlock(); QTextBlock block = document->firstBlock();
while (block.isValid()) { while (block.isValid()) {
TextDocumentLayout::doFoldOrUnfold(block, !fold); TextDocumentLayout::doFoldOrUnfold(block, !fold);
block = block.next(); block = block.next();
@@ -1603,18 +1596,13 @@ void FakeVimPluginPrivate::foldAll(bool fold)
documentLayout->emitDocumentSizeChanged(); documentLayout->emitDocumentSizeChanged();
} }
void FakeVimPluginPrivate::fold(int depth, bool fold) void FakeVimPluginPrivate::fold(FakeVimHandler *handler, int depth, bool fold)
{ {
IEditor *ieditor = EditorManager::currentEditor(); QTC_ASSERT(handler, return);
FakeVimHandler *handler = m_editorToHandler.value(ieditor, 0); QTextDocument *doc = handler->textCursor().document();
QTC_ASSERT(handler != 0, return); QTC_ASSERT(doc, return);
TextEditorWidget *editor = qobject_cast<TextEditorWidget *>(ieditor->widget()); auto documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
QTC_ASSERT(editor != 0, return); QTC_ASSERT(documentLayout, return);
QTextDocument *doc = editor->document();
TextDocumentLayout *documentLayout =
qobject_cast<TextDocumentLayout*>(doc->documentLayout());
QTC_ASSERT(documentLayout != 0, return);
QTextBlock block = handler->textCursor().block(); QTextBlock block = handler->textCursor().block();
int indent = TextDocumentLayout::foldingIndent(block); int indent = TextDocumentLayout::foldingIndent(block);
@@ -1664,12 +1652,9 @@ void FakeVimPluginPrivate::fold(int depth, bool fold)
documentLayout->emitDocumentSizeChanged(); documentLayout->emitDocumentSizeChanged();
} }
void FakeVimPluginPrivate::foldGoTo(int count, bool current) void FakeVimPluginPrivate::foldGoTo(FakeVimHandler *handler, int count, bool current)
{ {
IEditor *ieditor = EditorManager::currentEditor(); QTC_ASSERT(handler, return);
FakeVimHandler *handler = m_editorToHandler.value(ieditor, 0);
QTC_ASSERT(handler != 0, return);
QTextCursor tc = handler->textCursor(); QTextCursor tc = handler->textCursor();
QTextBlock block = tc.block(); QTextBlock block = tc.block();
@@ -1721,8 +1706,8 @@ void FakeVimPluginPrivate::foldGoTo(int count, bool current)
} }
} }
void FakeVimPluginPrivate::jumpToGlobalMark(QChar mark, bool backTickMode, void FakeVimPluginPrivate::jumpToGlobalMark(FakeVimHandler *,
const QString &fileName) QChar mark, bool backTickMode, const QString &fileName)
{ {
IEditor *iedit = EditorManager::openEditor(fileName); IEditor *iedit = EditorManager::openEditor(fileName);
if (!iedit) if (!iedit)
@@ -1899,55 +1884,46 @@ void FakeVimPluginPrivate::setUseFakeVimInternal(bool on)
} }
} }
void FakeVimPluginPrivate::triggerCompletions() void FakeVimPluginPrivate::triggerCompletions(FakeVimHandler *handler)
{ {
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender()); QTC_ASSERT(handler, return);
if (!handler)
return;
if (TextEditorWidget *editor = qobject_cast<TextEditorWidget *>(handler->widget())) if (TextEditorWidget *editor = qobject_cast<TextEditorWidget *>(handler->widget()))
editor->invokeAssist(Completion, m_wordProvider); editor->invokeAssist(Completion, m_wordProvider);
// CompletionSupport::instance()->complete(editor->editor(), TextCompletion, false); // CompletionSupport::instance()->complete(editor->editor(), TextCompletion, false);
} }
void FakeVimPluginPrivate::triggerSimpleCompletions(const QString &needle, bool forward) void FakeVimPluginPrivate::triggerSimpleCompletions(FakeVimHandler *handler, const QString &needle, bool forward)
{ {
// m_wordCompletion->setActive(needle, forward, qobject_cast<FakeVimHandler *>(sender())); QTC_ASSERT(handler, return);
m_wordProvider->setActive(needle, forward, qobject_cast<FakeVimHandler *>(sender())); // m_wordCompletion->setActive(needle, forward, handler);
m_wordProvider->setActive(needle, forward, handler);
} }
void FakeVimPluginPrivate::disableBlockSelection() void FakeVimPluginPrivate::disableBlockSelection(FakeVimHandler *handler)
{ {
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender()); QTC_ASSERT(handler, return);
if (!handler)
return;
if (TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget())) if (TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget()))
bt->setBlockSelection(false); bt->setBlockSelection(false);
} }
void FakeVimPluginPrivate::setBlockSelection(const QTextCursor &cursor) void FakeVimPluginPrivate::setBlockSelection(FakeVimHandler *handler, const QTextCursor &cursor)
{ {
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender()); QTC_ASSERT(handler, return);
if (!handler)
return;
if (TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget())) if (TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget()))
bt->setBlockSelection(cursor); bt->setBlockSelection(cursor);
} }
void FakeVimPluginPrivate::blockSelection(QTextCursor *cursor) void FakeVimPluginPrivate::blockSelection(FakeVimHandler *handler, QTextCursor *cursor)
{ {
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender()); QTC_ASSERT(handler, return);
if (!handler)
return;
if (TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget())) if (TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget()))
if (cursor) if (cursor)
*cursor = bt->blockSelection(); *cursor = bt->blockSelection();
} }
void FakeVimPluginPrivate::hasBlockSelection(bool *on) void FakeVimPluginPrivate::hasBlockSelection(FakeVimHandler *handler, bool *on)
{ {
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender()); QTC_ASSERT(handler, return);
if (!handler)
return;
if (TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget())) if (TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget()))
*on = bt->hasBlockSelection(); *on = bt->hasBlockSelection();
} }
@@ -1960,26 +1936,21 @@ void FakeVimPluginPrivate::setShowRelativeLineNumbers(const QVariant &value)
} }
} }
void FakeVimPluginPrivate::checkForElectricCharacter(bool *result, QChar c) void FakeVimPluginPrivate::checkForElectricCharacter(FakeVimHandler *handler, bool *result, QChar c)
{ {
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender()); QTC_ASSERT(handler, return);
if (!handler)
return;
if (TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget())) if (TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget()))
*result = bt->textDocument()->indenter()->isElectricCharacter(c); *result = bt->textDocument()->indenter()->isElectricCharacter(c);
} }
void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd) void FakeVimPluginPrivate::handleExCommand(FakeVimHandler *handler, bool *handled, const ExCommand &cmd)
{ {
QTC_ASSERT(handler, return);
using namespace Core; using namespace Core;
//qDebug() << "PLUGIN HANDLE: " << cmd.cmd << cmd.count; //qDebug() << "PLUGIN HANDLE: " << cmd.cmd << cmd.count;
*handled = false; *handled = false;
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
if (!handler)
return;
// Focus editor first so actions can be executed in correct context. // Focus editor first so actions can be executed in correct context.
QWidget *editor = handler->widget(); QWidget *editor = handler->widget();
if (editor) if (editor)
@@ -2095,7 +2066,7 @@ void FakeVimPluginPrivate::handleDelayedQuitAll(bool forced)
EditorManager::closeAllEditors(!forced); EditorManager::closeAllEditors(!forced);
} }
void FakeVimPluginPrivate::moveToMatchingParenthesis(bool *moved, bool *forward, void FakeVimPluginPrivate::moveToMatchingParenthesis(FakeVimHandler *, bool *moved, bool *forward,
QTextCursor *cursor) QTextCursor *cursor)
{ {
*moved = false; *moved = false;
@@ -2131,12 +2102,10 @@ void FakeVimPluginPrivate::moveToMatchingParenthesis(bool *moved, bool *forward,
} }
} }
void FakeVimPluginPrivate::indentRegion(int beginBlock, int endBlock, void FakeVimPluginPrivate::indentRegion(FakeVimHandler *handler,
QChar typedChar) int beginBlock, int endBlock, QChar typedChar)
{ {
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender()); QTC_ASSERT(handler, return);
if (!handler)
return;
TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget()); TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget());
if (!bt) if (!bt)
@@ -2176,15 +2145,15 @@ void FakeVimPluginPrivate::quitFakeVim()
void FakeVimPluginPrivate::resetCommandBuffer() void FakeVimPluginPrivate::resetCommandBuffer()
{ {
showCommandBuffer(QString(), -1, -1, 0, 0); showCommandBuffer(nullptr, QString(), -1, -1, 0);
} }
void FakeVimPluginPrivate::showCommandBuffer(const QString &contents, int cursorPos, int anchorPos, void FakeVimPluginPrivate::showCommandBuffer(FakeVimHandler *handler, const QString &contents, int cursorPos, int anchorPos,
int messageLevel, FakeVimHandler *eventFilter) int messageLevel)
{ {
//qDebug() << "SHOW COMMAND BUFFER" << contents; //qDebug() << "SHOW COMMAND BUFFER" << contents;
if (MiniBuffer *w = qobject_cast<MiniBuffer *>(m_statusBar->widget())) if (MiniBuffer *w = qobject_cast<MiniBuffer *>(m_statusBar->widget()))
w->setContents(contents, cursorPos, anchorPos, messageLevel, eventFilter); w->setContents(contents, cursorPos, anchorPos, messageLevel, handler);
} }
void FakeVimPluginPrivate::showExtraInformation(const QString &text) void FakeVimPluginPrivate::showExtraInformation(const QString &text)
@@ -2198,14 +2167,14 @@ void FakeVimPluginPrivate::showExtraInformation(const QString &text)
handler->handleCommand("0"); handler->handleCommand("0");
} }
void FakeVimPluginPrivate::changeSelection(const QList<QTextEdit::ExtraSelection> &selection) void FakeVimPluginPrivate::changeSelection(FakeVimHandler *handler, const QList<QTextEdit::ExtraSelection> &selection)
{ {
if (FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender())) QTC_ASSERT(handler, return);
if (TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget())) if (TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget()))
bt->setExtraSelections(TextEditorWidget::FakeVimSelection, selection); bt->setExtraSelections(TextEditorWidget::FakeVimSelection, selection);
} }
void FakeVimPluginPrivate::highlightMatches(const QString &needle) void FakeVimPluginPrivate::highlightMatches(FakeVimHandler *, const QString &needle)
{ {
foreach (IEditor *editor, EditorManager::visibleEditors()) { foreach (IEditor *editor, EditorManager::visibleEditors()) {
QWidget *w = editor->widget(); QWidget *w = editor->widget();

View File

@@ -36,8 +36,6 @@
using namespace FakeVim::Internal; using namespace FakeVim::Internal;
typedef QLatin1String _;
/** /**
* Simple editor widget. * Simple editor widget.
* @tparam TextEdit QTextEdit or QPlainTextEdit as base class * @tparam TextEdit QTextEdit or QPlainTextEdit as base class
@@ -46,9 +44,10 @@ template <typename TextEdit>
class Editor : public TextEdit class Editor : public TextEdit
{ {
public: public:
Editor(QWidget *parent = 0) : TextEdit(parent) Editor()
{ {
TextEdit::setCursorWidth(0); TextEdit::setCursorWidth(0);
TextEdit::setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
} }
void paintEvent(QPaintEvent *e) void paintEvent(QPaintEvent *e)
@@ -62,7 +61,7 @@ public:
if ( TextEdit::overwriteMode() ) { if ( TextEdit::overwriteMode() ) {
QFontMetrics fm(TextEdit::font()); QFontMetrics fm(TextEdit::font());
rect.setWidth(fm.width(QLatin1Char('m'))); rect.setWidth(fm.width('m'));
painter.setPen(Qt::NoPen); painter.setPen(Qt::NoPen);
painter.setBrush(TextEdit::palette().color(QPalette::Base)); painter.setBrush(TextEdit::palette().color(QPalette::Base));
painter.setCompositionMode(QPainter::CompositionMode_Difference); painter.setCompositionMode(QPainter::CompositionMode_Difference);
@@ -80,27 +79,29 @@ class Proxy : public QObject
Q_OBJECT Q_OBJECT
public: public:
Proxy(QWidget *widget, QMainWindow *mw, QObject *parent = 0) Proxy(QMainWindow *mw)
: QObject(parent), m_widget(widget), m_mainWindow(mw) : m_mainWindow(mw)
{} {}
void changeSelection(const QList<QTextEdit::ExtraSelection> &s) void changeSelection(FakeVimHandler *handler, const QList<QTextEdit::ExtraSelection> &s)
{ {
if (QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(m_widget)) QWidget *widget = handler->widget();
if (auto ed = qobject_cast<QPlainTextEdit *>(widget))
ed->setExtraSelections(s); ed->setExtraSelections(s);
else if (QTextEdit *ed = qobject_cast<QTextEdit *>(m_widget)) else if (auto ed = qobject_cast<QTextEdit *>(widget))
ed->setExtraSelections(s); ed->setExtraSelections(s);
} }
void changeStatusData(const QString &info) void changeStatusData(FakeVimHandler *, const QString &info)
{ {
m_statusData = info; m_statusData = info;
updateStatusBar(); updateStatusBar();
} }
void highlightMatches(const QString &pattern) void highlightMatches(FakeVimHandler *handler, const QString &pattern)
{ {
QTextEdit *ed = qobject_cast<QTextEdit *>(m_widget); QWidget *widget = handler->widget();
auto ed = qobject_cast<QTextEdit *>(widget);
if (!ed) if (!ed)
return; return;
@@ -136,39 +137,36 @@ public:
} }
} }
void changeStatusMessage(const QString &contents, int cursorPos) void changeStatusMessage(FakeVimHandler *, const QString &contents, int cursorPos)
{ {
m_statusMessage = cursorPos == -1 ? contents m_statusMessage = cursorPos == -1 ? contents
: contents.left(cursorPos) + QChar(10073) + contents.mid(cursorPos); : contents.left(cursorPos) + QChar(10073) + contents.mid(cursorPos);
updateStatusBar(); updateStatusBar();
} }
void changeExtraInformation(const QString &info) void changeExtraInformation(FakeVimHandler *handler, const QString &info)
{ {
QMessageBox::information(m_widget, tr("Information"), info); QMessageBox::information(handler->widget(), tr("Information"), info);
} }
void updateStatusBar() void updateStatusBar()
{ {
int slack = 80 - m_statusMessage.size() - m_statusData.size(); int slack = 80 - m_statusMessage.size() - m_statusData.size();
QString msg = m_statusMessage + QString(slack, QLatin1Char(' ')) + m_statusData; QString msg = m_statusMessage + QString(slack, ' ') + m_statusData;
m_mainWindow->statusBar()->showMessage(msg); m_mainWindow->statusBar()->showMessage(msg);
} }
void handleExCommand(bool *handled, const ExCommand &cmd) void handleExCommand(FakeVimHandler *, bool *handled, const ExCommand &cmd)
{ {
if (cmd.matches(_("q"), _("quit")) || cmd.matches(_("qa"), _("qall"))) { if (cmd.matches("q", "quit") || cmd.matches("qa", "qall")) {
QApplication::quit(); QApplication::quit();
*handled = true;
} else { } else {
*handled = false; *handled = false;
return;
} }
*handled = true;
} }
private: private:
QWidget *m_widget;
QMainWindow *m_mainWindow; QMainWindow *m_mainWindow;
QString m_statusMessage; QString m_statusMessage;
QString m_statusData; QString m_statusData;
@@ -177,16 +175,11 @@ private:
QWidget *createEditorWidget(bool usePlainTextEdit) QWidget *createEditorWidget(bool usePlainTextEdit)
{ {
QWidget *editor = 0; QWidget *editor = 0;
if (usePlainTextEdit) { if (usePlainTextEdit)
Editor<QPlainTextEdit> *w = new Editor<QPlainTextEdit>; editor = new Editor<QPlainTextEdit>;
w->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); else
editor = w; editor = new Editor<QTextEdit>;
} else { editor->setObjectName("Editor");
Editor<QTextEdit> *w = new Editor<QTextEdit>;
w->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
editor = w;
}
editor->setObjectName(_("Editor"));
editor->setFocus(); editor->setFocus();
return editor; return editor;
@@ -195,13 +188,13 @@ QWidget *createEditorWidget(bool usePlainTextEdit)
void initHandler(FakeVimHandler &handler) void initHandler(FakeVimHandler &handler)
{ {
// Set some Vim options. // Set some Vim options.
handler.handleCommand(_("set expandtab")); handler.handleCommand("set expandtab");
handler.handleCommand(_("set shiftwidth=8")); handler.handleCommand("set shiftwidth=8");
handler.handleCommand(_("set tabstop=16")); handler.handleCommand("set tabstop=16");
handler.handleCommand(_("set autoindent")); handler.handleCommand("set autoindent");
// Try to source file "fakevimrc" from current directory. // Try to source file "fakevimrc" from current directory.
handler.handleCommand(_("source fakevimrc")); handler.handleCommand("source fakevimrc");
handler.installEventFilter(); handler.installEventFilter();
handler.setupWidget(); handler.setupWidget();
@@ -209,7 +202,7 @@ void initHandler(FakeVimHandler &handler)
void initMainWindow(QMainWindow &mainWindow, QWidget *centralWidget, const QString &title) void initMainWindow(QMainWindow &mainWindow, QWidget *centralWidget, const QString &title)
{ {
mainWindow.setWindowTitle(QString(_("FakeVim (%1)")).arg(title)); mainWindow.setWindowTitle(QString("FakeVim (%1)").arg(title));
mainWindow.setCentralWidget(centralWidget); mainWindow.setCentralWidget(centralWidget);
mainWindow.resize(600, 650); mainWindow.resize(600, 650);
mainWindow.move(0, 0); mainWindow.move(0, 0);
@@ -217,14 +210,14 @@ void initMainWindow(QMainWindow &mainWindow, QWidget *centralWidget, const QStri
// Set monospace font for editor and status bar. // Set monospace font for editor and status bar.
QFont font = QApplication::font(); QFont font = QApplication::font();
font.setFamily(_("Monospace")); font.setFamily("Monospace");
centralWidget->setFont(font); centralWidget->setFont(font);
mainWindow.statusBar()->setFont(font); mainWindow.statusBar()->setFont(font);
} }
void readFile(FakeVimHandler &handler, const QString &editFileName) void readFile(FakeVimHandler &handler, const QString &editFileName)
{ {
handler.handleCommand(QString(_("r %1")).arg(editFileName)); handler.handleCommand("r " + editFileName);
} }
void connectSignals(FakeVimHandler &handler, Proxy &proxy) void connectSignals(FakeVimHandler &handler, Proxy &proxy)
@@ -252,20 +245,20 @@ int main(int argc, char *argv[])
// If first argument is present use QPlainTextEdit instead on QTextEdit; // If first argument is present use QPlainTextEdit instead on QTextEdit;
bool usePlainTextEdit = args.size() > 1; bool usePlainTextEdit = args.size() > 1;
// Second argument is path to file to edit. // Second argument is path to file to edit.
const QString editFileName = args.value(2, QString(_("/usr/share/vim/vim73/tutor/tutor"))); const QString editFileName = args.value(2, "/usr/share/vim/vim73/tutor/tutor");
// Create editor widget. // Create editor widget.
QWidget *editor = createEditorWidget(usePlainTextEdit); QWidget *editor = createEditorWidget(usePlainTextEdit);
// Create FakeVimHandler instance which will emulate Vim behavior in editor widget. // Create FakeVimHandler instance which will emulate Vim behavior in editor widget.
FakeVimHandler handler(editor, 0); FakeVimHandler handler(editor, nullptr);
// Create main window. // Create main window.
QMainWindow mainWindow; QMainWindow mainWindow;
initMainWindow(mainWindow, editor, usePlainTextEdit ? _("QPlainTextEdit") : _("QTextEdit")); initMainWindow(mainWindow, editor, usePlainTextEdit ? "QPlainTextEdit" : "QTextEdit");
// Connect slots to FakeVimHandler signals. // Connect slots to FakeVimHandler signals.
Proxy proxy(editor, &mainWindow); Proxy proxy(&mainWindow);
connectSignals(handler, proxy); connectSignals(handler, proxy);
// Initialize FakeVimHandler. // Initialize FakeVimHandler.