diff options
author | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2013-06-21 13:13:03 +0200 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2013-06-25 16:21:03 +0200 |
commit | 195d3c6f9e1524171bacc0b3e3d415ce8c88c766 (patch) | |
tree | c9332ddd48d5841610088d364b8566f897f95d7a /src | |
parent | 012924ec46662d79c189c28f9d370d41b19a8ad0 (diff) | |
download | qt-creator-195d3c6f9e1524171bacc0b3e3d415ce8c88c766.tar.gz |
CppTools: "Switch Header/Source" checks also other projects
...and not only the current one as fallback.
E.g. if the projects qtcreator and qtbase are open and you navigate into
qdir.h of your include path from the qtcreator project and trigger
"Switch Header/Source", then "qdir.cpp" will be found in the qtbase
source dir.
Task-number: QTCREATORBUG-3789
Change-Id: Ibd73c37bb626f8f7ee80cd8be3ef1244883ccf5e
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/cpptools/cpptoolsplugin.cpp | 72 |
1 files changed, 49 insertions, 23 deletions
diff --git a/src/plugins/cpptools/cpptoolsplugin.cpp b/src/plugins/cpptools/cpptoolsplugin.cpp index 93b2a80482..7f2bdbd24c 100644 --- a/src/plugins/cpptools/cpptoolsplugin.cpp +++ b/src/plugins/cpptools/cpptoolsplugin.cpp @@ -237,6 +237,35 @@ static int commonStringLength(const QString &s1, const QString &s2) return length; } +static QString correspondingHeaderOrSourceInProject(const QFileInfo &fileInfo, + const QStringList &candidateFileNames, + const ProjectExplorer::Project *project) +{ + QString bestFileName; + int compareValue = 0; + const QString filePath = fileInfo.filePath(); + foreach (const QString &candidateFileName, candidateFileNames) { + const QStringList projectFiles = findFilesInProject(candidateFileName, project); + // Find the file having the most common path with fileName + foreach (const QString &projectFile, projectFiles) { + int value = commonStringLength(filePath, projectFile); + if (value > compareValue) { + compareValue = value; + bestFileName = projectFile; + } + } + } + if (!bestFileName.isEmpty()) { + const QFileInfo candidateFi(bestFileName); + QTC_ASSERT(candidateFi.isFile(), return QString()); + m_headerSourceMapping[fileInfo.absoluteFilePath()] = candidateFi.absoluteFilePath(); + m_headerSourceMapping[candidateFi.absoluteFilePath()] = fileInfo.absoluteFilePath(); + return candidateFi.absoluteFilePath(); + } + + return QString(); +} + } // namespace Internal QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader) @@ -287,29 +316,26 @@ QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader) } } - // Find files in the project - ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::currentProject(); - if (project) { - QString bestFileName; - int compareValue = 0; - foreach (const QString &candidateFileName, candidateFileNames) { - const QStringList projectFiles = findFilesInProject(candidateFileName, project); - // Find the file having the most common path with fileName - foreach (const QString &projectFile, projectFiles) { - int value = commonStringLength(fileName, projectFile); - if (value > compareValue) { - compareValue = value; - bestFileName = projectFile; - } - } - } - if (!bestFileName.isEmpty()) { - const QFileInfo candidateFi(bestFileName); - QTC_ASSERT(candidateFi.isFile(), return QString()); - m_headerSourceMapping[fi.absoluteFilePath()] = candidateFi.absoluteFilePath(); - m_headerSourceMapping[candidateFi.absoluteFilePath()] = fi.absoluteFilePath(); - return candidateFi.absoluteFilePath(); - } + // Find files in the current project + ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectExplorerPlugin::currentProject(); + if (currentProject) { + const QString path = correspondingHeaderOrSourceInProject(fi, candidateFileNames, + currentProject); + if (!path.isEmpty()) + return path; + } + + // Find files in other projects + CppModelManager *modelManager = CppModelManager::instance(); + QList<CppModelManagerInterface::ProjectInfo> projectInfos = modelManager->projectInfos(); + foreach (const CppModelManagerInterface::ProjectInfo &projectInfo, projectInfos) { + const ProjectExplorer::Project *project = projectInfo.project().data(); + if (project == currentProject) + continue; // We have already checked the current project. + + const QString path = correspondingHeaderOrSourceInProject(fi, candidateFileNames, project); + if (!path.isEmpty()) + return path; } return QString(); |