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

@@ -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();