diff --git a/src/plugins/cppeditor/cppeditorconstants.h b/src/plugins/cppeditor/cppeditorconstants.h index 44c1d2674be..4df974e1262 100644 --- a/src/plugins/cppeditor/cppeditorconstants.h +++ b/src/plugins/cppeditor/cppeditorconstants.h @@ -34,7 +34,6 @@ const char CPPEDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("OpenWith::Editors", "C+ const char SWITCH_DECLARATION_DEFINITION[] = "CppEditor.SwitchDeclarationDefinition"; const char OPEN_DECLARATION_DEFINITION_IN_NEXT_SPLIT[] = "CppEditor.OpenDeclarationDefinitionInNextSplit"; const char RENAME_SYMBOL_UNDER_CURSOR[] = "CppEditor.RenameSymbolUnderCursor"; -const char FIND_USAGES[] = "CppEditor.FindUsages"; const char OPEN_PREPROCESSOR_DIALOG[] = "CppEditor.OpenPreprocessorDialog"; const char ERRORS_IN_HEADER_FILES[] = "CppEditor.ErrorsInHeaderFiles"; const char MULTIPLE_PARSE_CONTEXTS_AVAILABLE[] = "CppEditor.MultipleParseContextsAvailable"; diff --git a/src/plugins/cppeditor/cppeditorplugin.cpp b/src/plugins/cppeditor/cppeditorplugin.cpp index 5f2e9a703df..3ad268ca34f 100644 --- a/src/plugins/cppeditor/cppeditorplugin.cpp +++ b/src/plugins/cppeditor/cppeditorplugin.cpp @@ -118,7 +118,6 @@ public: void inspectCppCodeModel(); QAction *m_renameSymbolUnderCursorAction = nullptr; - QAction *m_findUsagesAction = nullptr; QAction *m_reparseExternallyChangedFiles = nullptr; QAction *m_openTypeHierarchyAction = nullptr; QAction *m_openIncludeHierarchyAction = nullptr; @@ -215,10 +214,7 @@ bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err this, &CppEditorPlugin::openDeclarationDefinitionInNextSplit); cppToolsMenu->addAction(cmd); - d->m_findUsagesAction = new QAction(tr("Find Usages"), this); - cmd = ActionManager::registerAction(d->m_findUsagesAction, Constants::FIND_USAGES, context); - cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+U"))); - connect(d->m_findUsagesAction, &QAction::triggered, this, &CppEditorPlugin::findUsages); + cmd = ActionManager::command(TextEditor::Constants::FIND_USAGES); contextMenu->addAction(cmd); cppToolsMenu->addAction(cmd); @@ -328,12 +324,6 @@ void CppEditorPlugin::renameSymbolUnderCursor() editorWidget->renameSymbolUnderCursor(); } -void CppEditorPlugin::findUsages() -{ - if (CppEditorWidget *editorWidget = currentCppEditorWidget()) - editorWidget->findUsages(); -} - void CppEditorPlugin::showPreProcessorDialog() { if (CppEditorWidget *editorWidget = currentCppEditorWidget()) @@ -344,7 +334,7 @@ void CppEditorPluginPrivate::onTaskStarted(Id type) { if (type == CppTools::Constants::TASK_INDEX) { m_renameSymbolUnderCursorAction->setEnabled(false); - m_findUsagesAction->setEnabled(false); + ActionManager::command(TextEditor::Constants::FIND_USAGES)->action()->setEnabled(false); m_reparseExternallyChangedFiles->setEnabled(false); m_openTypeHierarchyAction->setEnabled(false); m_openIncludeHierarchyAction->setEnabled(false); @@ -355,7 +345,7 @@ void CppEditorPluginPrivate::onAllTasksFinished(Id type) { if (type == CppTools::Constants::TASK_INDEX) { m_renameSymbolUnderCursorAction->setEnabled(true); - m_findUsagesAction->setEnabled(true); + ActionManager::command(TextEditor::Constants::FIND_USAGES)->action()->setEnabled(true); m_reparseExternallyChangedFiles->setEnabled(true); m_openTypeHierarchyAction->setEnabled(true); m_openIncludeHierarchyAction->setEnabled(true); diff --git a/src/plugins/cppeditor/cppeditorplugin.h b/src/plugins/cppeditor/cppeditorplugin.h index c4fb3b720b0..263af42a123 100644 --- a/src/plugins/cppeditor/cppeditorplugin.h +++ b/src/plugins/cppeditor/cppeditorplugin.h @@ -58,7 +58,6 @@ public: void openDeclarationDefinitionInNextSplit(); void openTypeHierarchy(); void openIncludeHierarchy(); - void findUsages(); void showPreProcessorDialog(); void renameSymbolUnderCursor(); void switchDeclarationDefinition(); diff --git a/src/plugins/cppeditor/cppeditorwidget.cpp b/src/plugins/cppeditor/cppeditorwidget.cpp index 1a5fa099ac3..e01a1a71c17 100644 --- a/src/plugins/cppeditor/cppeditorwidget.cpp +++ b/src/plugins/cppeditor/cppeditorwidget.cpp @@ -431,10 +431,13 @@ static void findRenameCallback(CppEditorWidget *widget, search->popup(); } +void CppEditorWidget::findUsages() +{ + findUsages(textCursor()); +} + void CppEditorWidget::findUsages(QTextCursor cursor) { - if (cursor.isNull()) - cursor = textCursor(); // 'this' in cursorInEditor is never used (and must never be used) asynchronously. const CppTools::CursorInEditor cursorInEditor{cursor, textDocument()->filePath(), this}; QPointer cppEditorWidget = this; diff --git a/src/plugins/cppeditor/cppeditorwidget.h b/src/plugins/cppeditor/cppeditorwidget.h index d5538e63bf9..e00f5666c78 100644 --- a/src/plugins/cppeditor/cppeditorwidget.h +++ b/src/plugins/cppeditor/cppeditorwidget.h @@ -78,7 +78,8 @@ public: void switchDeclarationDefinition(bool inNextSplit); void showPreProcessorWidget() override; - void findUsages(QTextCursor cursor = QTextCursor()); + void findUsages() override; + void findUsages(QTextCursor cursor); void renameUsages(const QString &replacement = QString(), QTextCursor cursor = QTextCursor()); void renameSymbolUnderCursor(); diff --git a/src/plugins/cppeditor/fileandtokenactions_test.cpp b/src/plugins/cppeditor/fileandtokenactions_test.cpp index 89275d3d6ab..02c1314d7d9 100644 --- a/src/plugins/cppeditor/fileandtokenactions_test.cpp +++ b/src/plugins/cppeditor/fileandtokenactions_test.cpp @@ -372,12 +372,12 @@ class FindUsagesTokenAction : public TestActionsTestCase::AbstractAction { public: /// Find Usages on each token - void run(CppEditorWidget *); + void run(CppEditorWidget *editor); }; -void FindUsagesTokenAction::run(CppEditorWidget *) +void FindUsagesTokenAction::run(CppEditorWidget *editor) { - CppEditorPlugin::instance()->findUsages(); + editor->findUsages(); QApplication::processEvents(); } diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index 1b2767d43ea..251ab2a8177 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -74,7 +74,7 @@ public: void inspectElementUnderCursor() const; - void findUsages(); + void findUsages() override; void renameUsages(); void showContextPane(); diff --git a/src/plugins/qmljseditor/qmljseditorconstants.h b/src/plugins/qmljseditor/qmljseditorconstants.h index 624d3b0b169..ac13c9add5a 100644 --- a/src/plugins/qmljseditor/qmljseditorconstants.h +++ b/src/plugins/qmljseditor/qmljseditorconstants.h @@ -41,7 +41,6 @@ const char C_QMLJSEDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("OpenWith::Editors", const char TASK_SEARCH[] = "QmlJSEditor.TaskSearch"; const char SETTINGS_CATEGORY_QML[] = "J.QtQuick"; -const char FIND_USAGES[] = "QmlJSEditor.FindUsages"; const char RENAME_USAGES[] = "QmlJSEditor.RenameUsages"; const char RUN_SEMANTIC_SCAN[] = "QmlJSEditor.RunSemanticScan"; const char REFORMAT_FILE[] = "QmlJSEditor.ReformatFile"; diff --git a/src/plugins/qmljseditor/qmljseditorplugin.cpp b/src/plugins/qmljseditor/qmljseditorplugin.cpp index 474e2642ffb..318575956eb 100644 --- a/src/plugins/qmljseditor/qmljseditorplugin.cpp +++ b/src/plugins/qmljseditor/qmljseditorplugin.cpp @@ -81,7 +81,6 @@ public: Command *addToolAction(QAction *a, Context &context, Id id, ActionContainer *c1, const QString &keySequence); - void findUsages(); void renameUsages(); void reformatFile(); void showContextPane(); @@ -157,10 +156,7 @@ QmlJSEditorPluginPrivate::QmlJSEditorPluginPrivate() contextMenu->addAction(cmd); qmlToolsMenu->addAction(cmd); - QAction *findUsagesAction = new QAction(QmlJSEditorPlugin::tr("Find Usages"), this); - cmd = ActionManager::registerAction(findUsagesAction, Constants::FIND_USAGES, context); - cmd->setDefaultKeySequence(QKeySequence(QmlJSEditorPlugin::tr("Ctrl+Shift+U"))); - connect(findUsagesAction, &QAction::triggered, this, &QmlJSEditorPluginPrivate::findUsages); + cmd = ActionManager::command(TextEditor::Constants::FIND_USAGES); contextMenu->addAction(cmd); qmlToolsMenu->addAction(cmd); @@ -243,12 +239,6 @@ QuickToolBar *QmlJSEditorPlugin::quickToolBar() return &m_instance->d->m_quickToolBar; } -void QmlJSEditorPluginPrivate::findUsages() -{ - if (QmlJSEditorWidget *editor = qobject_cast(EditorManager::currentEditor()->widget())) - editor->findUsages(); -} - void QmlJSEditorPluginPrivate::renameUsages() { if (QmlJSEditorWidget *editor = qobject_cast(EditorManager::currentEditor()->widget())) diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 9f8fed1122f..c720e196a07 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -1872,6 +1872,11 @@ void TextEditorWidget::openLinkUnderCursorInNextSplit() }, true, openInNextSplit); } +void TextEditorWidget::findUsages() +{ + emit requestUsages(textCursor()); +} + void TextEditorWidget::abortAssist() { d->m_codeAssistant.destroyContext(); diff --git a/src/plugins/texteditor/texteditor.h b/src/plugins/texteditor/texteditor.h index ef2c8065f11..8615f152955 100644 --- a/src/plugins/texteditor/texteditor.h +++ b/src/plugins/texteditor/texteditor.h @@ -443,6 +443,8 @@ public: void openLinkUnderCursor(); void openLinkUnderCursorInNextSplit(); + virtual void findUsages(); + /// Abort code assistant if it is running. void abortAssist(); @@ -475,6 +477,7 @@ signals: void requestLinkAt(const QTextCursor &cursor, Utils::ProcessLinkCallback &callback, bool resolveTarget, bool inNextSplit); + void requestUsages(const QTextCursor &cursor); protected: QTextBlock blockForVisibleRow(int row) const; diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp index e8599f3836f..e34ac19dee0 100644 --- a/src/plugins/texteditor/texteditoractionhandler.cpp +++ b/src/plugins/texteditor/texteditoractionhandler.cpp @@ -181,6 +181,7 @@ public: QAction *m_unindentAction = nullptr; QAction *m_followSymbolAction = nullptr; QAction *m_followSymbolInNextSplitAction = nullptr; + QAction *m_findUsageAction = nullptr; QAction *m_jumpToFileAction = nullptr; QAction *m_jumpToFileInNextSplitAction = nullptr; QList m_modifyingActions; @@ -288,6 +289,9 @@ void TextEditorActionHandlerPrivate::createActions() m_followSymbolInNextSplitAction = registerAction(FOLLOW_SYMBOL_UNDER_CURSOR_IN_NEXT_SPLIT, [] (TextEditorWidget *w) { w->openLinkUnderCursorInNextSplit(); }, true, tr("Follow Symbol Under Cursor in Next Split"), QKeySequence(Utils::HostOsInfo::isMacHost() ? tr("Meta+E, F2") : tr("Ctrl+E, F2"))); + m_findUsageAction = registerAction(FIND_USAGES, + [] (TextEditorWidget *w) { w->findUsages(); }, true, tr("Find References to Symbol Under Cursor"), + QKeySequence(tr("Ctrl+Shift+U"))); m_jumpToFileAction = registerAction(JUMP_TO_FILE_UNDER_CURSOR, [] (TextEditorWidget *w) { w->openLinkUnderCursor(); }, true, tr("Jump to File Under Cursor"), QKeySequence(Qt::Key_F2)); diff --git a/src/plugins/texteditor/texteditorconstants.h b/src/plugins/texteditor/texteditorconstants.h index 56678f18126..22fa68d83bd 100644 --- a/src/plugins/texteditor/texteditorconstants.h +++ b/src/plugins/texteditor/texteditorconstants.h @@ -196,6 +196,7 @@ const char INDENT[] = "TextEditor.Indent"; const char UNINDENT[] = "TextEditor.Unindent"; const char FOLLOW_SYMBOL_UNDER_CURSOR[] = "TextEditor.FollowSymbolUnderCursor"; const char FOLLOW_SYMBOL_UNDER_CURSOR_IN_NEXT_SPLIT[] = "TextEditor.FollowSymbolUnderCursorInNextSplit"; +const char FIND_USAGES[] = "TextEditor.FindUsages"; const char JUMP_TO_FILE_UNDER_CURSOR[] = "TextEditor.JumpToFileUnderCursor"; const char JUMP_TO_FILE_UNDER_CURSOR_IN_NEXT_SPLIT[] = "TextEditor.JumpToFileUnderCursorInNextSplit";