forked from qt-creator/qt-creator
ClassView: Simplify code
Change-Id: I7b69ff062222c44ac11c4961c3a221917df73df2 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
@@ -443,51 +443,34 @@ void Manager::gotoLocation(const QString &fileName, int line, int column)
|
|||||||
void Manager::gotoLocations(const QList<QVariant> &list)
|
void Manager::gotoLocations(const QList<QVariant> &list)
|
||||||
{
|
{
|
||||||
QSet<SymbolLocation> locations = Utils::roleToLocations(list);
|
QSet<SymbolLocation> locations = Utils::roleToLocations(list);
|
||||||
|
if (locations.size() == 0)
|
||||||
if (locations.count() == 0)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString fileName;
|
// Default to first known location
|
||||||
int line = 0;
|
SymbolLocation loc = *locations.constBegin();
|
||||||
int column = 0;
|
|
||||||
bool currentPositionAvailable = false;
|
|
||||||
|
|
||||||
// what is open now?
|
if (locations.size() > 1) {
|
||||||
if (IEditor *editor = EditorManager::currentEditor()) {
|
// The symbol has multiple locations. Check if we are already at one location,
|
||||||
// get current file name
|
// and if so, cycle to the "next" one
|
||||||
if (IDocument *document = editor->document())
|
auto textEditor = qobject_cast<TextEditor::BaseTextEditor *>(EditorManager::currentEditor());
|
||||||
fileName = document->filePath();
|
|
||||||
|
|
||||||
// if text file - what is current position?
|
|
||||||
TextEditor::BaseTextEditor *textEditor = qobject_cast<TextEditor::BaseTextEditor *>(editor);
|
|
||||||
if (textEditor) {
|
if (textEditor) {
|
||||||
// there is open currently text editor
|
// check if current cursor position is a known location of the symbol
|
||||||
int position = textEditor->position();
|
const QString fileName = textEditor->document()->filePath();
|
||||||
textEditor->convertPosition(position, &line, &column);
|
int line;
|
||||||
currentPositionAvailable = true;
|
int column;
|
||||||
|
textEditor->convertPosition(textEditor->position(), &line, &column);
|
||||||
|
SymbolLocation current(fileName, line, column);
|
||||||
|
QSet<SymbolLocation>::const_iterator it = locations.find(current);
|
||||||
|
QSet<SymbolLocation>::const_iterator end = locations.constEnd();
|
||||||
|
if (it != end) {
|
||||||
|
// we already are at the symbol, cycle to next location
|
||||||
|
++it;
|
||||||
|
if (it == end)
|
||||||
|
it = locations.begin();
|
||||||
|
loc = *it;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there is something open - try to check, is it currently activated symbol?
|
|
||||||
if (currentPositionAvailable) {
|
|
||||||
SymbolLocation current(fileName, line, column);
|
|
||||||
QSet<SymbolLocation>::const_iterator it = locations.find(current);
|
|
||||||
QSet<SymbolLocation>::const_iterator end = locations.constEnd();
|
|
||||||
// is it known location?
|
|
||||||
if (it != end) {
|
|
||||||
// found - do one additional step
|
|
||||||
++it;
|
|
||||||
if (it == end)
|
|
||||||
it = locations.begin();
|
|
||||||
const SymbolLocation &found = *it;
|
|
||||||
gotoLocation(found.fileName(), found.line(), found.column());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// no success - open first item in the list
|
|
||||||
const SymbolLocation loc = *locations.constBegin();
|
|
||||||
|
|
||||||
gotoLocation(loc.fileName(), loc.line(), loc.column());
|
gotoLocation(loc.fileName(), loc.line(), loc.column());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user