Resolve ambiguous results of searches for relative file paths

Qt Creator extracts file names from the output of external processes in
various places, for instance from compilers during the build. It often
happens that such file names are not absolute, so they cannot be
directly opened in an editor when the user clicks on their
representation in some widget. That's why they are processed by the
FileInProjectFinder facility first.
This patch enhances the FileInProjectFinder to be able to return more
than one candidate for a relative file path, and allows the user to
choose between these candidates where possible. This way, we won't open
a random file anymore when a project contains more than one file with
the same name.

Fixes: QTCREATORBUG-13623
Change-Id: Id19c9eace3e6b3dbde89f6528e6d02b55872d747
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2019-02-25 17:45:39 +01:00
parent b0e125ac11
commit d0db212575
13 changed files with 133 additions and 79 deletions

View File

@@ -38,6 +38,7 @@
#include <coreplugin/icontext.h>
#include <utils/algorithm.h>
#include <utils/fileinprojectfinder.h>
#include <utils/qtcassert.h>
#include <utils/itemviews.h>
#include <utils/utilsicons.h>
@@ -498,6 +499,15 @@ void TaskWindow::triggerDefaultHandler(const QModelIndex &index)
if (task.isNull())
return;
if (!task.file.isEmpty() && !task.file.toFileInfo().isAbsolute()
&& !task.fileCandidates.empty()) {
const Utils::FileName userChoice = Utils::chooseFileFromList(task.fileCandidates);
if (!userChoice.isEmpty()) {
task.file = userChoice;
updatedTaskFileName(task.taskId, task.file.toString());
}
}
if (d->m_defaultHandler->canHandle(task)) {
d->m_defaultHandler->handle(task);
} else {