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

View File

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

View File

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

View File

@@ -36,8 +36,6 @@
using namespace FakeVim::Internal;
typedef QLatin1String _;
/**
* Simple editor widget.
* @tparam TextEdit QTextEdit or QPlainTextEdit as base class
@@ -46,9 +44,10 @@ template <typename TextEdit>
class Editor : public TextEdit
{
public:
Editor(QWidget *parent = 0) : TextEdit(parent)
Editor()
{
TextEdit::setCursorWidth(0);
TextEdit::setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
void paintEvent(QPaintEvent *e)
@@ -62,7 +61,7 @@ public:
if ( TextEdit::overwriteMode() ) {
QFontMetrics fm(TextEdit::font());
rect.setWidth(fm.width(QLatin1Char('m')));
rect.setWidth(fm.width('m'));
painter.setPen(Qt::NoPen);
painter.setBrush(TextEdit::palette().color(QPalette::Base));
painter.setCompositionMode(QPainter::CompositionMode_Difference);
@@ -80,27 +79,29 @@ class Proxy : public QObject
Q_OBJECT
public:
Proxy(QWidget *widget, QMainWindow *mw, QObject *parent = 0)
: QObject(parent), m_widget(widget), m_mainWindow(mw)
Proxy(QMainWindow *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);
else if (QTextEdit *ed = qobject_cast<QTextEdit *>(m_widget))
else if (auto ed = qobject_cast<QTextEdit *>(widget))
ed->setExtraSelections(s);
}
void changeStatusData(const QString &info)
void changeStatusData(FakeVimHandler *, const QString &info)
{
m_statusData = info;
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)
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
: contents.left(cursorPos) + QChar(10073) + contents.mid(cursorPos);
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()
{
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);
}
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();
*handled = true;
} else {
*handled = false;
return;
}
*handled = true;
}
private:
QWidget *m_widget;
QMainWindow *m_mainWindow;
QString m_statusMessage;
QString m_statusData;
@@ -177,16 +175,11 @@ private:
QWidget *createEditorWidget(bool usePlainTextEdit)
{
QWidget *editor = 0;
if (usePlainTextEdit) {
Editor<QPlainTextEdit> *w = new Editor<QPlainTextEdit>;
w->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
editor = w;
} else {
Editor<QTextEdit> *w = new Editor<QTextEdit>;
w->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
editor = w;
}
editor->setObjectName(_("Editor"));
if (usePlainTextEdit)
editor = new Editor<QPlainTextEdit>;
else
editor = new Editor<QTextEdit>;
editor->setObjectName("Editor");
editor->setFocus();
return editor;
@@ -195,13 +188,13 @@ QWidget *createEditorWidget(bool usePlainTextEdit)
void initHandler(FakeVimHandler &handler)
{
// Set some Vim options.
handler.handleCommand(_("set expandtab"));
handler.handleCommand(_("set shiftwidth=8"));
handler.handleCommand(_("set tabstop=16"));
handler.handleCommand(_("set autoindent"));
handler.handleCommand("set expandtab");
handler.handleCommand("set shiftwidth=8");
handler.handleCommand("set tabstop=16");
handler.handleCommand("set autoindent");
// Try to source file "fakevimrc" from current directory.
handler.handleCommand(_("source fakevimrc"));
handler.handleCommand("source fakevimrc");
handler.installEventFilter();
handler.setupWidget();
@@ -209,7 +202,7 @@ void initHandler(FakeVimHandler &handler)
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.resize(600, 650);
mainWindow.move(0, 0);
@@ -217,14 +210,14 @@ void initMainWindow(QMainWindow &mainWindow, QWidget *centralWidget, const QStri
// Set monospace font for editor and status bar.
QFont font = QApplication::font();
font.setFamily(_("Monospace"));
font.setFamily("Monospace");
centralWidget->setFont(font);
mainWindow.statusBar()->setFont(font);
}
void readFile(FakeVimHandler &handler, const QString &editFileName)
{
handler.handleCommand(QString(_("r %1")).arg(editFileName));
handler.handleCommand("r " + editFileName);
}
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;
bool usePlainTextEdit = args.size() > 1;
// 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.
QWidget *editor = createEditorWidget(usePlainTextEdit);
// Create FakeVimHandler instance which will emulate Vim behavior in editor widget.
FakeVimHandler handler(editor, 0);
FakeVimHandler handler(editor, nullptr);
// Create main window.
QMainWindow mainWindow;
initMainWindow(mainWindow, editor, usePlainTextEdit ? _("QPlainTextEdit") : _("QTextEdit"));
initMainWindow(mainWindow, editor, usePlainTextEdit ? "QPlainTextEdit" : "QTextEdit");
// Connect slots to FakeVimHandler signals.
Proxy proxy(editor, &mainWindow);
Proxy proxy(&mainWindow);
connectSignals(handler, proxy);
// Initialize FakeVimHandler.