forked from qt-creator/qt-creator
Added `Find Usages' of a Symbol.
This commit is contained in:
@@ -862,7 +862,21 @@ CPlusPlus::Symbol *CPPEditor::findCanonicalSymbol(const QTextCursor &cursor,
|
|||||||
return canonicalSymbol;
|
return canonicalSymbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPPEditor::findReferences()
|
|
||||||
|
void CPPEditor::findUsages()
|
||||||
|
{
|
||||||
|
updateSemanticInfo(m_semanticHighlighter->semanticInfo(currentSource()));
|
||||||
|
|
||||||
|
SemanticInfo info = m_lastSemanticInfo;
|
||||||
|
|
||||||
|
if (! info.doc)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (Symbol *canonicalSymbol = findCanonicalSymbol(textCursor(), info.doc, info.snapshot))
|
||||||
|
m_modelManager->findUsages(canonicalSymbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPPEditor::renameUsages()
|
||||||
{
|
{
|
||||||
m_currentRenameSelection = -1;
|
m_currentRenameSelection = -1;
|
||||||
|
|
||||||
@@ -896,7 +910,7 @@ void CPPEditor::findReferences()
|
|||||||
|
|
||||||
setExtraSelections(CodeSemanticsSelection, selections);
|
setExtraSelections(CodeSemanticsSelection, selections);
|
||||||
|
|
||||||
m_modelManager->findReferences(canonicalSymbol);
|
m_modelManager->renameUsages(canonicalSymbol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -920,7 +934,7 @@ void CPPEditor::renameSymbolUnderCursor()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_renameSelections.isEmpty())
|
if (m_renameSelections.isEmpty())
|
||||||
findReferences();
|
renameUsages();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPPEditor::onContentsChanged(int position, int charsRemoved, int charsAdded)
|
void CPPEditor::onContentsChanged(int position, int charsRemoved, int charsAdded)
|
||||||
|
|||||||
@@ -197,7 +197,8 @@ public Q_SLOTS:
|
|||||||
void switchDeclarationDefinition();
|
void switchDeclarationDefinition();
|
||||||
void jumpToDefinition();
|
void jumpToDefinition();
|
||||||
void renameSymbolUnderCursor();
|
void renameSymbolUnderCursor();
|
||||||
void findReferences();
|
void renameUsages();
|
||||||
|
void findUsages();
|
||||||
|
|
||||||
void moveToPreviousToken();
|
void moveToPreviousToken();
|
||||||
void moveToNextToken();
|
void moveToNextToken();
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ const char * const C_CPPEDITOR = "C++ Editor";
|
|||||||
const char * const CPPEDITOR_KIND = QT_TRANSLATE_NOOP("OpenWith::Editors", "C++ Editor");
|
const char * const CPPEDITOR_KIND = QT_TRANSLATE_NOOP("OpenWith::Editors", "C++ Editor");
|
||||||
const char * const SWITCH_DECLARATION_DEFINITION = "CppEditor.SwitchDeclarationDefinition";
|
const char * const SWITCH_DECLARATION_DEFINITION = "CppEditor.SwitchDeclarationDefinition";
|
||||||
const char * const RENAME_SYMBOL_UNDER_CURSOR = "CppEditor.RenameSymbolUnderCursor";
|
const char * const RENAME_SYMBOL_UNDER_CURSOR = "CppEditor.RenameSymbolUnderCursor";
|
||||||
|
const char * const FIND_USAGES = "CppEditor.FindUsages";
|
||||||
const char * const SEPARATOR = "CppEditor.Separator";
|
const char * const SEPARATOR = "CppEditor.Separator";
|
||||||
const char * const FIND_REFERENCES = "CppEditor.FindReferences";
|
const char * const FIND_REFERENCES = "CppEditor.FindReferences";
|
||||||
const char * const JUMP_TO_DEFINITION = "CppEditor.JumpToDefinition";
|
const char * const JUMP_TO_DEFINITION = "CppEditor.JumpToDefinition";
|
||||||
|
|||||||
@@ -212,6 +212,12 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
|
|||||||
contextMenu->addAction(cmd);
|
contextMenu->addAction(cmd);
|
||||||
am->actionContainer(CppTools::Constants::M_TOOLS_CPP)->addAction(cmd);
|
am->actionContainer(CppTools::Constants::M_TOOLS_CPP)->addAction(cmd);
|
||||||
|
|
||||||
|
QAction *findUsagesAction = new QAction(tr("Find Usages"), this);
|
||||||
|
cmd = am->registerAction(findUsagesAction, Constants::FIND_USAGES, context);
|
||||||
|
connect(findUsagesAction, SIGNAL(triggered()), this, SLOT(findUsages()));
|
||||||
|
contextMenu->addAction(cmd);
|
||||||
|
am->actionContainer(CppTools::Constants::M_TOOLS_CPP)->addAction(cmd);
|
||||||
|
|
||||||
QAction *renameSymbolUnderCursorAction = new QAction(tr("Rename Symbol under Cursor"), this);
|
QAction *renameSymbolUnderCursorAction = new QAction(tr("Rename Symbol under Cursor"), this);
|
||||||
cmd = am->registerAction(renameSymbolUnderCursorAction,
|
cmd = am->registerAction(renameSymbolUnderCursorAction,
|
||||||
Constants::RENAME_SYMBOL_UNDER_CURSOR, context);
|
Constants::RENAME_SYMBOL_UNDER_CURSOR, context);
|
||||||
@@ -286,4 +292,12 @@ void CppPlugin::renameSymbolUnderCursor()
|
|||||||
editor->renameSymbolUnderCursor();
|
editor->renameSymbolUnderCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CppPlugin::findUsages()
|
||||||
|
{
|
||||||
|
Core::EditorManager *em = Core::EditorManager::instance();
|
||||||
|
CPPEditor *editor = qobject_cast<CPPEditor*>(em->currentEditor()->widget());
|
||||||
|
if (editor)
|
||||||
|
editor->findUsages();
|
||||||
|
}
|
||||||
|
|
||||||
Q_EXPORT_PLUGIN(CppPlugin)
|
Q_EXPORT_PLUGIN(CppPlugin)
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ private slots:
|
|||||||
void switchDeclarationDefinition();
|
void switchDeclarationDefinition();
|
||||||
void jumpToDefinition();
|
void jumpToDefinition();
|
||||||
void renameSymbolUnderCursor();
|
void renameSymbolUnderCursor();
|
||||||
|
void findUsages();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Core::IEditor *createEditor(QWidget *parent);
|
Core::IEditor *createEditor(QWidget *parent);
|
||||||
|
|||||||
@@ -532,10 +532,21 @@ static void find_helper(QFutureInterface<Utils::FileSearchResult> &future,
|
|||||||
future.setProgressValue(files.size());
|
future.setProgressValue(files.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppFindReferences::findAll(Symbol *symbol)
|
void CppFindReferences::findUsages(Symbol *symbol)
|
||||||
|
{
|
||||||
|
_resultWindow->clearContents();
|
||||||
|
findAll_helper(symbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CppFindReferences::renameUsages(Symbol *symbol)
|
||||||
{
|
{
|
||||||
_resultWindow->clearContents();
|
_resultWindow->clearContents();
|
||||||
_resultWindow->setShowReplaceUI(true);
|
_resultWindow->setShowReplaceUI(true);
|
||||||
|
findAll_helper(symbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CppFindReferences::findAll_helper(Symbol *symbol)
|
||||||
|
{
|
||||||
_resultWindow->popup(true);
|
_resultWindow->popup(true);
|
||||||
|
|
||||||
const Snapshot snapshot = _modelManager->snapshot();
|
const Snapshot snapshot = _modelManager->snapshot();
|
||||||
|
|||||||
@@ -62,13 +62,17 @@ Q_SIGNALS:
|
|||||||
void changed();
|
void changed();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void findAll(CPlusPlus::Symbol *symbol);
|
void findUsages(CPlusPlus::Symbol *symbol);
|
||||||
|
void renameUsages(CPlusPlus::Symbol *symbol);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void displayResult(int);
|
void displayResult(int);
|
||||||
void searchFinished();
|
void searchFinished();
|
||||||
void openEditor(const QString&, int, int);
|
void openEditor(const QString&, int, int);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void findAll_helper(CPlusPlus::Symbol *symbol);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<CppModelManager> _modelManager;
|
QPointer<CppModelManager> _modelManager;
|
||||||
Find::SearchResultWindow *_resultWindow;
|
Find::SearchResultWindow *_resultWindow;
|
||||||
|
|||||||
@@ -755,10 +755,16 @@ QList<int> CppModelManager::references(CPlusPlus::Symbol *symbol,
|
|||||||
return m_findReferences->references(LookupContext::canonicalSymbol(symbol), doc, snapshot);
|
return m_findReferences->references(LookupContext::canonicalSymbol(symbol), doc, snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppModelManager::findReferences(CPlusPlus::Symbol *symbol)
|
void CppModelManager::findUsages(CPlusPlus::Symbol *symbol)
|
||||||
{
|
{
|
||||||
if (symbol->identifier())
|
if (symbol->identifier())
|
||||||
m_findReferences->findAll(symbol);
|
m_findReferences->findUsages(symbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CppModelManager::renameUsages(CPlusPlus::Symbol *symbol)
|
||||||
|
{
|
||||||
|
if (symbol->identifier())
|
||||||
|
m_findReferences->renameUsages(symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString, QString> CppModelManager::buildWorkingCopyList()
|
QMap<QString, QString> CppModelManager::buildWorkingCopyList()
|
||||||
|
|||||||
@@ -106,7 +106,8 @@ public:
|
|||||||
CPlusPlus::Document::Ptr doc,
|
CPlusPlus::Document::Ptr doc,
|
||||||
const CPlusPlus::Snapshot &snapshot);
|
const CPlusPlus::Snapshot &snapshot);
|
||||||
|
|
||||||
virtual void findReferences(CPlusPlus::Symbol *symbol);
|
virtual void findUsages(CPlusPlus::Symbol *symbol);
|
||||||
|
virtual void renameUsages(CPlusPlus::Symbol *symbol);
|
||||||
|
|
||||||
void setHeaderSuffixes(const QStringList &suffixes)
|
void setHeaderSuffixes(const QStringList &suffixes)
|
||||||
{ m_headerSuffixes = suffixes; }
|
{ m_headerSuffixes = suffixes; }
|
||||||
|
|||||||
@@ -101,7 +101,8 @@ public:
|
|||||||
CPlusPlus::Document::Ptr doc,
|
CPlusPlus::Document::Ptr doc,
|
||||||
const CPlusPlus::Snapshot &snapshot) = 0;
|
const CPlusPlus::Snapshot &snapshot) = 0;
|
||||||
|
|
||||||
virtual void findReferences(CPlusPlus::Symbol *symbol) = 0;
|
virtual void renameUsages(CPlusPlus::Symbol *symbol) = 0;
|
||||||
|
virtual void findUsages(CPlusPlus::Symbol *symbol) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CPPTOOLS_EXPORT AbstractEditorSupport
|
class CPPTOOLS_EXPORT AbstractEditorSupport
|
||||||
|
|||||||
Reference in New Issue
Block a user