forked from qt-creator/qt-creator
move find usages to TextEditor
In preperation for supporting find usages by the language client plugin Task-number: QTCREATORBUG-21577 Change-Id: I7a6da3a9d53478c1d486e0ddc5829c9ea09a2a20 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -58,7 +58,6 @@ public:
|
||||
void openDeclarationDefinitionInNextSplit();
|
||||
void openTypeHierarchy();
|
||||
void openIncludeHierarchy();
|
||||
void findUsages();
|
||||
void showPreProcessorDialog();
|
||||
void renameSymbolUnderCursor();
|
||||
void switchDeclarationDefinition();
|
||||
|
||||
@@ -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> cppEditorWidget = this;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ public:
|
||||
|
||||
void inspectElementUnderCursor() const;
|
||||
|
||||
void findUsages();
|
||||
void findUsages() override;
|
||||
void renameUsages();
|
||||
void showContextPane();
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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<QmlJSEditorWidget*>(EditorManager::currentEditor()->widget()))
|
||||
editor->findUsages();
|
||||
}
|
||||
|
||||
void QmlJSEditorPluginPrivate::renameUsages()
|
||||
{
|
||||
if (QmlJSEditorWidget *editor = qobject_cast<QmlJSEditorWidget*>(EditorManager::currentEditor()->widget()))
|
||||
|
||||
@@ -1872,6 +1872,11 @@ void TextEditorWidget::openLinkUnderCursorInNextSplit()
|
||||
}, true, openInNextSplit);
|
||||
}
|
||||
|
||||
void TextEditorWidget::findUsages()
|
||||
{
|
||||
emit requestUsages(textCursor());
|
||||
}
|
||||
|
||||
void TextEditorWidget::abortAssist()
|
||||
{
|
||||
d->m_codeAssistant.destroyContext();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<QAction *> 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));
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user