FakeVim: Modernize plugin connections.

Change-Id: Ia704aa975e64cc8942b4e5717f812b7c1a788096
Reviewed-by: Lukas Holecek <hluk@email.cz>
Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
hjk
2015-02-18 17:22:18 +01:00
parent db8b2e8512
commit 61cca902ad

View File

@@ -57,6 +57,7 @@
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <texteditor/displaysettings.h>
#include <texteditor/textdocumentlayout.h> #include <texteditor/textdocumentlayout.h>
#include <texteditor/texteditor.h> #include <texteditor/texteditor.h>
#include <texteditor/textmark.h> #include <texteditor/textmark.h>
@@ -126,9 +127,9 @@ public:
, m_eventFilter(0) , m_eventFilter(0)
, m_lastMessageLevel(MessageMode) , m_lastMessageLevel(MessageMode)
{ {
connect(m_edit, SIGNAL(textEdited(QString)), SLOT(changed())); connect(m_edit, &QLineEdit::textEdited, this, &MiniBuffer::changed);
connect(m_edit, SIGNAL(cursorPositionChanged(int,int)), SLOT(changed())); connect(m_edit, &QLineEdit::cursorPositionChanged, this, &MiniBuffer::changed);
connect(m_edit, SIGNAL(selectionChanged()), SLOT(changed())); connect(m_edit, &QLineEdit::selectionChanged, this, &MiniBuffer::changed);
m_label->setTextInteractionFlags(Qt::TextSelectableByMouse); m_label->setTextInteractionFlags(Qt::TextSelectableByMouse);
addWidget(m_label); addWidget(m_label);
@@ -136,7 +137,7 @@ public:
m_hideTimer.setSingleShot(true); m_hideTimer.setSingleShot(true);
m_hideTimer.setInterval(8000); m_hideTimer.setInterval(8000);
connect(&m_hideTimer, SIGNAL(timeout()), SLOT(hide())); connect(&m_hideTimer, &QTimer::timeout, this, &QWidget::hide);
} }
void setContents(const QString &contents, int cursorPos, int anchorPos, void setContents(const QString &contents, int cursorPos, int anchorPos,
@@ -212,7 +213,7 @@ public:
signals: signals:
void edited(const QString &text, int cursorPos, int anchorPos); void edited(const QString &text, int cursorPos, int anchorPos);
private slots: private:
void changed() void changed()
{ {
const int cursorPos = m_edit->cursorPosition(); const int cursorPos = m_edit->cursorPosition();
@@ -222,7 +223,6 @@ private slots:
emit edited(m_edit->text(), cursorPos, anchorPos); emit edited(m_edit->text(), cursorPos, anchorPos);
} }
private:
QLabel *m_label; QLabel *m_label;
QLineEdit *m_edit; QLineEdit *m_edit;
QObject *m_eventFilter; QObject *m_eventFilter;
@@ -245,12 +245,18 @@ public:
m_timerUpdate.setSingleShot(true); m_timerUpdate.setSingleShot(true);
m_timerUpdate.setInterval(0); m_timerUpdate.setInterval(0);
connect(&m_timerUpdate, SIGNAL(timeout()), SLOT(followEditorLayout())); connect(&m_timerUpdate, &QTimer::timeout,
updateOnSignal(m_editor, SIGNAL(cursorPositionChanged())); this, &RelativeNumbersColumn::followEditorLayout);
updateOnSignal(m_editor->verticalScrollBar(), SIGNAL(valueChanged(int)));
updateOnSignal(m_editor->document(), SIGNAL(contentsChanged())); auto start = static_cast<void(QTimer::*)()>(&QTimer::start);
updateOnSignal(TextEditorSettings::instance(), connect(m_editor, &QPlainTextEdit::cursorPositionChanged,
SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings))); &m_timerUpdate, start);
connect(m_editor->verticalScrollBar(), &QAbstractSlider::valueChanged,
&m_timerUpdate, start);
connect(m_editor->document(), &QTextDocument::contentsChanged,
&m_timerUpdate, start);
connect(TextEditorSettings::instance(), &TextEditorSettings::displaySettingsChanged,
&m_timerUpdate, start);
m_editor->installEventFilter(this); m_editor->installEventFilter(this);
@@ -339,11 +345,6 @@ private slots:
update(); update();
} }
void updateOnSignal(QObject *object, const char *signal)
{
connect(object, signal, &m_timerUpdate, SLOT(start()));
}
private: private:
int m_currentPos; int m_currentPos;
int m_lineSpacing; int m_lineSpacing;
@@ -458,14 +459,14 @@ QWidget *FakeVimOptionPage::widget()
m_group.insert(theFakeVimSetting(ConfigRelativeNumber), m_group.insert(theFakeVimSetting(ConfigRelativeNumber),
m_ui.checkBoxRelativeNumber); m_ui.checkBoxRelativeNumber);
connect(m_ui.pushButtonCopyTextEditorSettings, SIGNAL(clicked()), connect(m_ui.pushButtonCopyTextEditorSettings, &QAbstractButton::clicked,
SLOT(copyTextEditorSettings())); this, &FakeVimOptionPage::copyTextEditorSettings);
connect(m_ui.pushButtonSetQtStyle, SIGNAL(clicked()), connect(m_ui.pushButtonSetQtStyle, &QAbstractButton::clicked,
SLOT(setQtStyle())); this, &FakeVimOptionPage::setQtStyle);
connect(m_ui.pushButtonSetPlainStyle, SIGNAL(clicked()), connect(m_ui.pushButtonSetPlainStyle, &QAbstractButton::clicked,
SLOT(setPlainStyle())); this, &FakeVimOptionPage::setPlainStyle);
connect(m_ui.checkBoxReadVimRc, SIGNAL(stateChanged(int)), connect(m_ui.checkBoxReadVimRc, &QCheckBox::stateChanged,
SLOT(updateVimRcWidgets())); this, &FakeVimOptionPage::updateVimRcWidgets);
updateVimRcWidgets(); updateVimRcWidgets();
} }
@@ -1039,7 +1040,7 @@ private slots:
void handleDelayedQuitAll(bool forced); void handleDelayedQuitAll(bool forced);
void handleDelayedQuit(bool forced, Core::IEditor *editor); void handleDelayedQuit(bool forced, Core::IEditor *editor);
void userActionTriggered(); void userActionTriggered(int key);
void switchToFile(int n); void switchToFile(int n);
int currentFile() const; int currentFile() const;
@@ -1157,8 +1158,8 @@ FakeVimPluginPrivate::~FakeVimPluginPrivate()
void FakeVimPluginPrivate::onCoreAboutToClose() void FakeVimPluginPrivate::onCoreAboutToClose()
{ {
// Don't attach to editors anymore. // Don't attach to editors anymore.
disconnect(EditorManager::instance(), SIGNAL(editorOpened(Core::IEditor*)), disconnect(EditorManager::instance(), &EditorManager::editorOpened,
this, SLOT(editorOpened(Core::IEditor*))); this, &FakeVimPluginPrivate::editorOpened);
} }
void FakeVimPluginPrivate::aboutToShutdown() void FakeVimPluginPrivate::aboutToShutdown()
@@ -1205,41 +1206,41 @@ bool FakeVimPluginPrivate::initialize()
const Id base = "FakeVim.UserAction"; const Id base = "FakeVim.UserAction";
for (int i = 1; i < 10; ++i) { for (int i = 1; i < 10; ++i) {
QAction *act = new QAction(this); auto act = new QAction(this);
act->setText(Tr::tr("Execute User Action #%1").arg(i)); act->setText(Tr::tr("Execute User Action #%1").arg(i));
act->setData(i);
cmd = ActionManager::registerAction(act, base.withSuffix(i), globalcontext); cmd = ActionManager::registerAction(act, base.withSuffix(i), globalcontext);
cmd->setDefaultKeySequence(QKeySequence((UseMacShortcuts ? Tr::tr("Meta+V,%1") : Tr::tr("Alt+V,%1")).arg(i))); cmd->setDefaultKeySequence(QKeySequence((UseMacShortcuts ? Tr::tr("Meta+V,%1") : Tr::tr("Alt+V,%1")).arg(i)));
connect(act, SIGNAL(triggered()), SLOT(userActionTriggered())); connect(act, &QAction::triggered, this, [this, i] { userActionTriggered(i); });
} }
connect(ICore::instance(), SIGNAL(coreAboutToClose()), this, SLOT(onCoreAboutToClose())); connect(ICore::instance(), &ICore::coreAboutToClose,
this, &FakeVimPluginPrivate::onCoreAboutToClose);
// EditorManager // EditorManager
connect(EditorManager::instance(), SIGNAL(editorAboutToClose(Core::IEditor*)), connect(EditorManager::instance(), &EditorManager::editorAboutToClose,
this, SLOT(editorAboutToClose(Core::IEditor*))); this, &FakeVimPluginPrivate::editorAboutToClose);
connect(EditorManager::instance(), SIGNAL(editorOpened(Core::IEditor*)), connect(EditorManager::instance(), &EditorManager::editorOpened,
this, SLOT(editorOpened(Core::IEditor*))); this, &FakeVimPluginPrivate::editorOpened);
connect(DocumentManager::instance(), SIGNAL(allDocumentsRenamed(QString,QString)), connect(DocumentManager::instance(), &DocumentManager::allDocumentsRenamed,
this, SLOT(allDocumentsRenamed(QString,QString))); this, &FakeVimPluginPrivate::allDocumentsRenamed);
connect(DocumentManager::instance(), SIGNAL(documentRenamed(Core::IDocument*,QString,QString)), connect(DocumentManager::instance(), &DocumentManager::documentRenamed,
this, SLOT(documentRenamed(Core::IDocument*,QString,QString))); this, &FakeVimPluginPrivate::documentRenamed);
connect(theFakeVimSetting(ConfigUseFakeVim), SIGNAL(valueChanged(QVariant)), connect(theFakeVimSetting(ConfigUseFakeVim), &Utils::SavedAction::valueChanged,
this, SLOT(setUseFakeVim(QVariant))); this, &FakeVimPluginPrivate::setUseFakeVim);
connect(theFakeVimSetting(ConfigReadVimRc), SIGNAL(valueChanged(QVariant)), connect(theFakeVimSetting(ConfigReadVimRc), &Utils::SavedAction::valueChanged,
this, SLOT(maybeReadVimRc())); this, &FakeVimPluginPrivate::maybeReadVimRc);
connect(theFakeVimSetting(ConfigVimRcPath), SIGNAL(valueChanged(QVariant)), connect(theFakeVimSetting(ConfigVimRcPath), &Utils::SavedAction::valueChanged,
this, SLOT(maybeReadVimRc())); this, &FakeVimPluginPrivate::maybeReadVimRc);
connect(theFakeVimSetting(ConfigRelativeNumber), SIGNAL(valueChanged(QVariant)), connect(theFakeVimSetting(ConfigRelativeNumber), &Utils::SavedAction::valueChanged,
this, SLOT(setShowRelativeLineNumbers(QVariant))); this, &FakeVimPluginPrivate::setShowRelativeLineNumbers);
// Delayed operations. // Delayed operations.
connect(this, SIGNAL(delayedQuitRequested(bool,Core::IEditor*)), connect(this, &FakeVimPluginPrivate::delayedQuitRequested,
this, SLOT(handleDelayedQuit(bool,Core::IEditor*)), Qt::QueuedConnection); this, &FakeVimPluginPrivate::handleDelayedQuit, Qt::QueuedConnection);
connect(this, SIGNAL(delayedQuitAllRequested(bool)), connect(this, &FakeVimPluginPrivate::delayedQuitAllRequested,
this, SLOT(handleDelayedQuitAll(bool)), Qt::QueuedConnection); this, &FakeVimPluginPrivate::handleDelayedQuitAll, Qt::QueuedConnection);
// Vimrc can break test so don't source it if running tests. // Vimrc can break test so don't source it if running tests.
if (!ExtensionSystem::PluginManager::testRunRequested()) if (!ExtensionSystem::PluginManager::testRunRequested())
@@ -1249,14 +1250,8 @@ bool FakeVimPluginPrivate::initialize()
return true; return true;
} }
void FakeVimPluginPrivate::userActionTriggered() void FakeVimPluginPrivate::userActionTriggered(int key)
{ {
QAction *act = qobject_cast<QAction *>(sender());
if (!act)
return;
const int key = act->data().toInt();
if (!key)
return;
IEditor *editor = EditorManager::currentEditor(); IEditor *editor = EditorManager::currentEditor();
FakeVimHandler *handler = m_editorToHandler[editor]; FakeVimHandler *handler = m_editorToHandler[editor];
if (handler) { if (handler) {
@@ -1277,10 +1272,10 @@ void FakeVimPluginPrivate::createRelativeNumberWidget(IEditor *editor)
{ {
if (TextEditorWidget *textEditor = qobject_cast<TextEditorWidget *>(editor->widget())) { if (TextEditorWidget *textEditor = qobject_cast<TextEditorWidget *>(editor->widget())) {
RelativeNumbersColumn *relativeNumbers = new RelativeNumbersColumn(textEditor); RelativeNumbersColumn *relativeNumbers = new RelativeNumbersColumn(textEditor);
connect(theFakeVimSetting(ConfigRelativeNumber), SIGNAL(valueChanged(QVariant)), connect(theFakeVimSetting(ConfigRelativeNumber), &Utils::SavedAction::valueChanged,
relativeNumbers, SLOT(deleteLater())); relativeNumbers, &QObject::deleteLater);
connect(theFakeVimSetting(ConfigUseFakeVim), SIGNAL(valueChanged(QVariant)), connect(theFakeVimSetting(ConfigUseFakeVim), &Utils::SavedAction::valueChanged,
relativeNumbers, SLOT(deleteLater())); relativeNumbers, &QObject::deleteLater);
relativeNumbers->show(); relativeNumbers->show();
} }
} }
@@ -1761,54 +1756,54 @@ void FakeVimPluginPrivate::editorOpened(IEditor *editor)
new DeferredDeleter(widget, handler); new DeferredDeleter(widget, handler);
m_editorToHandler[editor] = handler; m_editorToHandler[editor] = handler;
connect(handler, SIGNAL(extraInformationChanged(QString)), connect(handler, &FakeVimHandler::extraInformationChanged,
SLOT(showExtraInformation(QString))); this, &FakeVimPluginPrivate::showExtraInformation);
connect(handler, SIGNAL(commandBufferChanged(QString,int,int,int,QObject*)), connect(handler, &FakeVimHandler::commandBufferChanged,
SLOT(showCommandBuffer(QString,int,int,int,QObject*))); this, &FakeVimPluginPrivate::showCommandBuffer);
connect(handler, SIGNAL(selectionChanged(QList<QTextEdit::ExtraSelection>)), connect(handler, &FakeVimHandler::selectionChanged,
SLOT(changeSelection(QList<QTextEdit::ExtraSelection>))); this, &FakeVimPluginPrivate::changeSelection);
connect(handler, SIGNAL(highlightMatches(QString)), connect(handler, &FakeVimHandler::highlightMatches,
SLOT(highlightMatches(QString))); this, &FakeVimPluginPrivate::highlightMatches);
connect(handler, SIGNAL(moveToMatchingParenthesis(bool*,bool*,QTextCursor*)), connect(handler, &FakeVimHandler::moveToMatchingParenthesis,
SLOT(moveToMatchingParenthesis(bool*,bool*,QTextCursor*)), Qt::DirectConnection); this, &FakeVimPluginPrivate::moveToMatchingParenthesis, Qt::DirectConnection);
connect(handler, SIGNAL(indentRegion(int,int,QChar)), connect(handler, &FakeVimHandler::indentRegion,
SLOT(indentRegion(int,int,QChar))); this, &FakeVimPluginPrivate::indentRegion);
connect(handler, SIGNAL(checkForElectricCharacter(bool*,QChar)), connect(handler, &FakeVimHandler::checkForElectricCharacter,
SLOT(checkForElectricCharacter(bool*,QChar)), Qt::DirectConnection); this, &FakeVimPluginPrivate::checkForElectricCharacter, Qt::DirectConnection);
connect(handler, SIGNAL(requestDisableBlockSelection()), connect(handler, &FakeVimHandler::requestDisableBlockSelection,
SLOT(disableBlockSelection())); this, &FakeVimPluginPrivate::disableBlockSelection);
connect(handler, SIGNAL(requestSetBlockSelection(QTextCursor)), connect(handler, &FakeVimHandler::requestSetBlockSelection,
SLOT(setBlockSelection(QTextCursor))); this, &FakeVimPluginPrivate::setBlockSelection);
connect(handler, SIGNAL(requestBlockSelection(QTextCursor*)), connect(handler, &FakeVimHandler::requestBlockSelection,
SLOT(blockSelection(QTextCursor*)), Qt::DirectConnection); this, &FakeVimPluginPrivate::blockSelection, Qt::DirectConnection);
connect(handler, SIGNAL(requestHasBlockSelection(bool*)), connect(handler, &FakeVimHandler::requestHasBlockSelection,
SLOT(hasBlockSelection(bool*)), Qt::DirectConnection); this, &FakeVimPluginPrivate::hasBlockSelection, Qt::DirectConnection);
connect(handler, SIGNAL(completionRequested()), connect(handler, &FakeVimHandler::completionRequested,
SLOT(triggerCompletions())); this, &FakeVimPluginPrivate::triggerCompletions);
connect(handler, SIGNAL(simpleCompletionRequested(QString,bool)), connect(handler, &FakeVimHandler::simpleCompletionRequested,
SLOT(triggerSimpleCompletions(QString,bool))); this, &FakeVimPluginPrivate::triggerSimpleCompletions);
connect(handler, SIGNAL(windowCommandRequested(QString,int)), connect(handler, &FakeVimHandler::windowCommandRequested,
SLOT(windowCommand(QString,int))); this, &FakeVimPluginPrivate::windowCommand);
connect(handler, SIGNAL(findRequested(bool)), connect(handler, &FakeVimHandler::findRequested,
SLOT(find(bool))); this, &FakeVimPluginPrivate::find);
connect(handler, SIGNAL(findNextRequested(bool)), connect(handler, &FakeVimHandler::findNextRequested,
SLOT(findNext(bool))); this, &FakeVimPluginPrivate::findNext);
connect(handler, SIGNAL(foldToggle(int)), connect(handler, &FakeVimHandler::foldToggle,
SLOT(foldToggle(int))); this, &FakeVimPluginPrivate::foldToggle);
connect(handler, SIGNAL(foldAll(bool)), connect(handler, &FakeVimHandler::foldAll,
SLOT(foldAll(bool))); this, &FakeVimPluginPrivate::foldAll);
connect(handler, SIGNAL(fold(int,bool)), connect(handler, &FakeVimHandler::fold,
SLOT(fold(int,bool))); this, &FakeVimPluginPrivate::fold);
connect(handler, SIGNAL(foldGoTo(int,bool)), connect(handler, &FakeVimHandler::foldGoTo,
SLOT(foldGoTo(int,bool))); this, &FakeVimPluginPrivate::foldGoTo);
connect(handler, SIGNAL(jumpToGlobalMark(QChar,bool,QString)), connect(handler, &FakeVimHandler::jumpToGlobalMark,
SLOT(jumpToGlobalMark(QChar,bool,QString))); this, &FakeVimPluginPrivate::jumpToGlobalMark);
connect(handler, SIGNAL(handleExCommandRequested(bool*,ExCommand)), connect(handler, &FakeVimHandler::handleExCommandRequested,
SLOT(handleExCommand(bool*,ExCommand)), Qt::DirectConnection); this, &FakeVimPluginPrivate::handleExCommand, Qt::DirectConnection);
connect(ICore::instance(), SIGNAL(saveSettingsRequested()), connect(ICore::instance(), &ICore::saveSettingsRequested,
SLOT(writeSettings())); this, &FakeVimPluginPrivate::writeSettings);
handler->setCurrentFileName(editor->document()->filePath().toString()); handler->setCurrentFileName(editor->document()->filePath().toString());
handler->installEventFilter(); handler->installEventFilter();