From 3559af69db03529422443ff0cf35884a2d7e2511 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 6 May 2020 07:30:33 +0200 Subject: [PATCH] TextEditor: move rename symbol action to text editor Task-number: QTCREATORBUG-21578 Change-Id: I9a873dcd38bacb2287c45973b6be0091c3eb9480 Reviewed-by: Christian Stenger --- src/plugins/cppeditor/cppeditorconstants.h | 1 - src/plugins/cppeditor/cppeditorplugin.cpp | 23 ++++++------------- src/plugins/cppeditor/cppeditorwidget.cpp | 2 +- src/plugins/cppeditor/cppeditorwidget.h | 2 +- src/plugins/qmljseditor/qmljseditor.cpp | 9 ++++---- src/plugins/qmljseditor/qmljseditor.h | 2 +- src/plugins/qmljseditor/qmljseditorplugin.cpp | 7 ++---- src/plugins/texteditor/texteditor.cpp | 5 ++++ src/plugins/texteditor/texteditor.h | 2 ++ .../texteditor/texteditoractionhandler.cpp | 5 ++++ .../texteditor/texteditoractionhandler.h | 3 ++- src/plugins/texteditor/texteditorconstants.h | 2 ++ 12 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/plugins/cppeditor/cppeditorconstants.h b/src/plugins/cppeditor/cppeditorconstants.h index a6f3f9609f2..d1fb5f1706a 100644 --- a/src/plugins/cppeditor/cppeditorconstants.h +++ b/src/plugins/cppeditor/cppeditorconstants.h @@ -34,7 +34,6 @@ const char CPPEDITOR_ID[] = "CppEditor.C++Editor"; const char CPPEDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("OpenWith::Editors", "C++ Editor"); 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 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 1376843080b..8eae62faa49 100644 --- a/src/plugins/cppeditor/cppeditorplugin.cpp +++ b/src/plugins/cppeditor/cppeditorplugin.cpp @@ -103,9 +103,10 @@ public: setParenthesesMatchingEnabled(true); setEditorActionHandlers(TextEditorActionHandler::Format - | TextEditorActionHandler::UnCommentSelection - | TextEditorActionHandler::UnCollapseAll - | TextEditorActionHandler::FollowSymbolUnderCursor); + | TextEditorActionHandler::UnCommentSelection + | TextEditorActionHandler::UnCollapseAll + | TextEditorActionHandler::FollowSymbolUnderCursor + | TextEditorActionHandler::RenameSymbol); } }; @@ -118,7 +119,6 @@ public: void onAllTasksFinished(Core::Id type); void inspectCppCodeModel(); - QAction *m_renameSymbolUnderCursorAction = nullptr; QAction *m_reparseExternallyChangedFiles = nullptr; QAction *m_openTypeHierarchyAction = nullptr; QAction *m_openIncludeHierarchyAction = nullptr; @@ -245,16 +245,7 @@ bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err Command *sep = contextMenu->addSeparator(); sep->action()->setObjectName(QLatin1String(Constants::M_REFACTORING_MENU_INSERTION_POINT)); contextMenu->addSeparator(); - - d->m_renameSymbolUnderCursorAction = new QAction(tr("Rename Symbol Under Cursor"), - this); - cmd = ActionManager::registerAction(d->m_renameSymbolUnderCursorAction, - Constants::RENAME_SYMBOL_UNDER_CURSOR, - context); - cmd->setDefaultKeySequence(QKeySequence(tr("CTRL+SHIFT+R"))); - connect(d->m_renameSymbolUnderCursorAction, &QAction::triggered, - this, &CppEditorPlugin::renameSymbolUnderCursor); - cppToolsMenu->addAction(cmd); + cppToolsMenu->addAction(ActionManager::command(TextEditor::Constants::RENAME_SYMBOL)); // Update context in global context cppToolsMenu->addSeparator(Core::Constants::G_DEFAULT_THREE); @@ -342,8 +333,8 @@ void CppEditorPlugin::showPreProcessorDialog() void CppEditorPluginPrivate::onTaskStarted(Id type) { if (type == CppTools::Constants::TASK_INDEX) { - m_renameSymbolUnderCursorAction->setEnabled(false); ActionManager::command(TextEditor::Constants::FIND_USAGES)->action()->setEnabled(false); + ActionManager::command(TextEditor::Constants::RENAME_SYMBOL)->action()->setEnabled(false); m_reparseExternallyChangedFiles->setEnabled(false); m_openTypeHierarchyAction->setEnabled(false); m_openIncludeHierarchyAction->setEnabled(false); @@ -353,8 +344,8 @@ void CppEditorPluginPrivate::onTaskStarted(Id type) void CppEditorPluginPrivate::onAllTasksFinished(Id type) { if (type == CppTools::Constants::TASK_INDEX) { - m_renameSymbolUnderCursorAction->setEnabled(true); ActionManager::command(TextEditor::Constants::FIND_USAGES)->action()->setEnabled(true); + ActionManager::command(TextEditor::Constants::RENAME_SYMBOL)->action()->setEnabled(true); m_reparseExternallyChangedFiles->setEnabled(true); m_openTypeHierarchyAction->setEnabled(true); m_openIncludeHierarchyAction->setEnabled(true); diff --git a/src/plugins/cppeditor/cppeditorwidget.cpp b/src/plugins/cppeditor/cppeditorwidget.cpp index 2ce2c1092b5..f13d6d5a024 100644 --- a/src/plugins/cppeditor/cppeditorwidget.cpp +++ b/src/plugins/cppeditor/cppeditorwidget.cpp @@ -860,7 +860,7 @@ protected: QMenu *CppEditorWidget::createRefactorMenu(QWidget *parent) const { auto *menu = new QMenu(tr("&Refactor"), parent); - menu->addAction(ActionManager::command(Constants::RENAME_SYMBOL_UNDER_CURSOR)->action()); + menu->addAction(ActionManager::command(TextEditor::Constants::RENAME_SYMBOL)->action()); // ### enable // updateSemanticInfo(m_semanticHighlighter->semanticInfo(currentSource())); diff --git a/src/plugins/cppeditor/cppeditorwidget.h b/src/plugins/cppeditor/cppeditorwidget.h index 57fd9d0fd65..7bd9f4b4d3b 100644 --- a/src/plugins/cppeditor/cppeditorwidget.h +++ b/src/plugins/cppeditor/cppeditorwidget.h @@ -81,7 +81,7 @@ public: void findUsages(QTextCursor cursor); void renameUsages(const QString &replacement = QString(), QTextCursor cursor = QTextCursor()); - void renameSymbolUnderCursor(); + void renameSymbolUnderCursor() override; bool selectBlockUp() override; bool selectBlockDown() override; diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 16aaa6ec47f..f2de0347b81 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -844,7 +844,7 @@ void QmlJSEditorWidget::findUsages() m_findReferences->findUsages(textDocument()->filePath().toString(), textCursor().position()); } -void QmlJSEditorWidget::renameUsages() +void QmlJSEditorWidget::renameSymbolUnderCursor() { m_findReferences->renameUsages(textDocument()->filePath().toString(), textCursor().position()); } @@ -1098,9 +1098,10 @@ QmlJSEditorFactory::QmlJSEditorFactory(Core::Id _id) setCompletionAssistProvider(new QmlJSCompletionAssistProvider); setEditorActionHandlers(TextEditorActionHandler::Format - | TextEditorActionHandler::UnCommentSelection - | TextEditorActionHandler::UnCollapseAll - | TextEditorActionHandler::FollowSymbolUnderCursor); + | TextEditorActionHandler::UnCommentSelection + | TextEditorActionHandler::UnCollapseAll + | TextEditorActionHandler::FollowSymbolUnderCursor + | TextEditorActionHandler::RenameSymbol); } void QmlJSEditorFactory::decorateEditor(TextEditorWidget *editor) diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index cb5265e66ef..f13415f7f4a 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -74,7 +74,7 @@ public: void inspectElementUnderCursor() const; void findUsages() override; - void renameUsages(); + void renameSymbolUnderCursor() override; void showContextPane(); signals: diff --git a/src/plugins/qmljseditor/qmljseditorplugin.cpp b/src/plugins/qmljseditor/qmljseditorplugin.cpp index 4853c6840db..83e7e2ef488 100644 --- a/src/plugins/qmljseditor/qmljseditorplugin.cpp +++ b/src/plugins/qmljseditor/qmljseditorplugin.cpp @@ -162,10 +162,7 @@ QmlJSEditorPluginPrivate::QmlJSEditorPluginPrivate() contextMenu->addAction(cmd); qmlToolsMenu->addAction(cmd); - QAction *renameUsagesAction = new QAction(QmlJSEditorPlugin::tr("Rename Symbol Under Cursor"), this); - cmd = ActionManager::registerAction(renameUsagesAction, "QmlJSEditor.RenameUsages", context); - cmd->setDefaultKeySequence(QKeySequence(QmlJSEditorPlugin::tr("Ctrl+Shift+R"))); - connect(renameUsagesAction, &QAction::triggered, this, &QmlJSEditorPluginPrivate::renameUsages); + cmd = ActionManager::command(TextEditor::Constants::RENAME_SYMBOL); contextMenu->addAction(cmd); qmlToolsMenu->addAction(cmd); @@ -247,7 +244,7 @@ QuickToolBar *QmlJSEditorPlugin::quickToolBar() void QmlJSEditorPluginPrivate::renameUsages() { if (auto editor = qobject_cast(EditorManager::currentEditor()->widget())) - editor->renameUsages(); + editor->renameSymbolUnderCursor(); } void QmlJSEditorPluginPrivate::reformatFile() diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 0c8551ec46f..2c32af5b284 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -1965,6 +1965,11 @@ void TextEditorWidget::findUsages() emit requestUsages(textCursor()); } +void TextEditorWidget::renameSymbolUnderCursor() +{ + emit requestRename(textCursor()); +} + void TextEditorWidget::abortAssist() { d->m_codeAssistant.destroyContext(); diff --git a/src/plugins/texteditor/texteditor.h b/src/plugins/texteditor/texteditor.h index f7b69b48221..ad95abe3cdf 100644 --- a/src/plugins/texteditor/texteditor.h +++ b/src/plugins/texteditor/texteditor.h @@ -453,6 +453,7 @@ public: void openLinkUnderCursorInNextSplit(); virtual void findUsages(); + virtual void renameSymbolUnderCursor(); /// Abort code assistant if it is running. void abortAssist(); @@ -490,6 +491,7 @@ signals: void requestLinkAt(const QTextCursor &cursor, Utils::ProcessLinkCallback &callback, bool resolveTarget, bool inNextSplit); void requestUsages(const QTextCursor &cursor); + void requestRename(const QTextCursor &cursor); protected: QTextBlock blockForVisibleRow(int row) const; diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp index 67d58985092..10774178590 100644 --- a/src/plugins/texteditor/texteditoractionhandler.cpp +++ b/src/plugins/texteditor/texteditoractionhandler.cpp @@ -182,6 +182,7 @@ public: QAction *m_followSymbolAction = nullptr; QAction *m_followSymbolInNextSplitAction = nullptr; QAction *m_findUsageAction = nullptr; + QAction *m_renameSymbolAction = nullptr; QAction *m_jumpToFileAction = nullptr; QAction *m_jumpToFileInNextSplitAction = nullptr; QList m_modifyingActions; @@ -285,6 +286,9 @@ void TextEditorActionHandlerPrivate::createActions() m_findUsageAction = registerAction(FIND_USAGES, [] (TextEditorWidget *w) { w->findUsages(); }, true, tr("Find References to Symbol Under Cursor"), QKeySequence(tr("Ctrl+Shift+U"))); + m_renameSymbolAction = registerAction(RENAME_SYMBOL, + [] (TextEditorWidget *w) { w->renameSymbolUnderCursor(); }, true, tr("Rename Symbol Under Cursor"), + QKeySequence(tr("Ctrl+Shift+R"))); m_jumpToFileAction = registerAction(JUMP_TO_FILE_UNDER_CURSOR, [] (TextEditorWidget *w) { w->openLinkUnderCursor(); }, true, tr("Jump to File Under Cursor"), QKeySequence(Qt::Key_F2)); @@ -519,6 +523,7 @@ void TextEditorActionHandlerPrivate::createActions() m_jumpToFileAction->setEnabled(m_optionalActions & TextEditorActionHandler::JumpToFileUnderCursor); m_jumpToFileInNextSplitAction->setEnabled(m_optionalActions & TextEditorActionHandler::JumpToFileUnderCursor); m_unfoldAllAction->setEnabled(m_optionalActions & TextEditorActionHandler::UnCollapseAll); + m_renameSymbolAction->setEnabled(m_optionalActions & TextEditorActionHandler::RenameSymbol); } void TextEditorActionHandlerPrivate::updateActions() diff --git a/src/plugins/texteditor/texteditoractionhandler.h b/src/plugins/texteditor/texteditoractionhandler.h index f91ad7a8067..cfa684a13d6 100644 --- a/src/plugins/texteditor/texteditoractionhandler.h +++ b/src/plugins/texteditor/texteditoractionhandler.h @@ -55,7 +55,8 @@ public: UnCommentSelection = 2, UnCollapseAll = 4, FollowSymbolUnderCursor = 8, - JumpToFileUnderCursor = 16 + JumpToFileUnderCursor = 16, + RenameSymbol = 32, }; using TextEditorWidgetResolver = std::function; diff --git a/src/plugins/texteditor/texteditorconstants.h b/src/plugins/texteditor/texteditorconstants.h index 3435a713afb..c74bbfcde81 100644 --- a/src/plugins/texteditor/texteditorconstants.h +++ b/src/plugins/texteditor/texteditorconstants.h @@ -201,6 +201,8 @@ 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"; +// moved from CppEditor to TextEditor avoid breaking the setting by using the old key +const char RENAME_SYMBOL[] = "CppEditor.RenameSymbolUnderCursor"; const char JUMP_TO_FILE_UNDER_CURSOR[] = "TextEditor.JumpToFileUnderCursor"; const char JUMP_TO_FILE_UNDER_CURSOR_IN_NEXT_SPLIT[] = "TextEditor.JumpToFileUnderCursorInNextSplit";