Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tobias Hunger
qt-creator
Commits
73320a43
Commit
73320a43
authored
Oct 05, 2009
by
Roberto Raggi
Browse files
Added `Find Usages' of a Symbol.
parent
d38f654d
Changes
10
Hide whitespace changes
Inline
Side-by-side
src/plugins/cppeditor/cppeditor.cpp
View file @
73320a43
...
...
@@ -862,7 +862,21 @@ CPlusPlus::Symbol *CPPEditor::findCanonicalSymbol(const QTextCursor &cursor,
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
;
...
...
@@ -896,7 +910,7 @@ void CPPEditor::findReferences()
setExtraSelections
(
CodeSemanticsSelection
,
selections
);
m_modelManager
->
findReferenc
es
(
canonicalSymbol
);
m_modelManager
->
renameUsag
es
(
canonicalSymbol
);
}
}
}
...
...
@@ -920,7 +934,7 @@ void CPPEditor::renameSymbolUnderCursor()
}
if
(
m_renameSelections
.
isEmpty
())
findReferenc
es
();
renameUsag
es
();
}
void
CPPEditor
::
onContentsChanged
(
int
position
,
int
charsRemoved
,
int
charsAdded
)
...
...
src/plugins/cppeditor/cppeditor.h
View file @
73320a43
...
...
@@ -197,7 +197,8 @@ public Q_SLOTS:
void
switchDeclarationDefinition
();
void
jumpToDefinition
();
void
renameSymbolUnderCursor
();
void
findReferences
();
void
renameUsages
();
void
findUsages
();
void
moveToPreviousToken
();
void
moveToNextToken
();
...
...
src/plugins/cppeditor/cppeditorconstants.h
View file @
73320a43
...
...
@@ -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
SWITCH_DECLARATION_DEFINITION
=
"CppEditor.SwitchDeclarationDefinition"
;
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
FIND_REFERENCES
=
"CppEditor.FindReferences"
;
const
char
*
const
JUMP_TO_DEFINITION
=
"CppEditor.JumpToDefinition"
;
...
...
src/plugins/cppeditor/cppplugin.cpp
View file @
73320a43
...
...
@@ -212,6 +212,12 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
contextMenu
->
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
);
cmd
=
am
->
registerAction
(
renameSymbolUnderCursorAction
,
Constants
::
RENAME_SYMBOL_UNDER_CURSOR
,
context
);
...
...
@@ -286,4 +292,12 @@ void CppPlugin::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
)
src/plugins/cppeditor/cppplugin.h
View file @
73320a43
...
...
@@ -74,6 +74,7 @@ private slots:
void
switchDeclarationDefinition
();
void
jumpToDefinition
();
void
renameSymbolUnderCursor
();
void
findUsages
();
private:
Core
::
IEditor
*
createEditor
(
QWidget
*
parent
);
...
...
src/plugins/cpptools/cppfindreferences.cpp
View file @
73320a43
...
...
@@ -532,10 +532,21 @@ static void find_helper(QFutureInterface<Utils::FileSearchResult> &future,
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
->
setShowReplaceUI
(
true
);
findAll_helper
(
symbol
);
}
void
CppFindReferences
::
findAll_helper
(
Symbol
*
symbol
)
{
_resultWindow
->
popup
(
true
);
const
Snapshot
snapshot
=
_modelManager
->
snapshot
();
...
...
src/plugins/cpptools/cppfindreferences.h
View file @
73320a43
...
...
@@ -62,13 +62,17 @@ Q_SIGNALS:
void
changed
();
public:
void
findAll
(
CPlusPlus
::
Symbol
*
symbol
);
void
findUsages
(
CPlusPlus
::
Symbol
*
symbol
);
void
renameUsages
(
CPlusPlus
::
Symbol
*
symbol
);
private
Q_SLOTS
:
void
displayResult
(
int
);
void
searchFinished
();
void
openEditor
(
const
QString
&
,
int
,
int
);
private:
void
findAll_helper
(
CPlusPlus
::
Symbol
*
symbol
);
private:
QPointer
<
CppModelManager
>
_modelManager
;
Find
::
SearchResultWindow
*
_resultWindow
;
...
...
src/plugins/cpptools/cppmodelmanager.cpp
View file @
73320a43
...
...
@@ -755,10 +755,16 @@ QList<int> CppModelManager::references(CPlusPlus::Symbol *symbol,
return
m_findReferences
->
references
(
LookupContext
::
canonicalSymbol
(
symbol
),
doc
,
snapshot
);
}
void
CppModelManager
::
find
Referenc
es
(
CPlusPlus
::
Symbol
*
symbol
)
void
CppModelManager
::
find
Usag
es
(
CPlusPlus
::
Symbol
*
symbol
)
{
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
()
...
...
src/plugins/cpptools/cppmodelmanager.h
View file @
73320a43
...
...
@@ -106,7 +106,8 @@ public:
CPlusPlus
::
Document
::
Ptr
doc
,
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
)
{
m_headerSuffixes
=
suffixes
;
}
...
...
src/plugins/cpptools/cppmodelmanagerinterface.h
View file @
73320a43
...
...
@@ -101,7 +101,8 @@ public:
CPlusPlus
::
Document
::
Ptr
doc
,
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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment