2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-12 14:39:51 +01:00
|
|
|
#include "cpptoolsplugin.h"
|
2008-12-12 16:36:33 +01:00
|
|
|
#include "completionsettingspage.h"
|
2009-03-18 16:43:01 +01:00
|
|
|
#include "cppfilesettingspage.h"
|
2011-02-03 15:48:14 +01:00
|
|
|
#include "cppcodestylesettingspage.h"
|
2008-11-28 15:36:54 +01:00
|
|
|
#include "cppclassesfilter.h"
|
2008-12-09 17:15:00 +01:00
|
|
|
#include "cppfunctionsfilter.h"
|
2009-05-14 21:08:08 +02:00
|
|
|
#include "cppcurrentdocumentfilter.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cppmodelmanager.h"
|
|
|
|
|
#include "cpptoolsconstants.h"
|
2009-10-16 10:55:58 +02:00
|
|
|
#include "cpplocatorfilter.h"
|
2010-07-19 14:46:53 +02:00
|
|
|
#include "symbolsfindfilter.h"
|
2011-02-03 15:48:14 +01:00
|
|
|
#include "cpptoolssettings.h"
|
2012-10-10 21:00:48 +02:00
|
|
|
#include "cpptoolsreuse.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-06-02 14:56:03 +02:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/mimedatabase.h>
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
2009-01-13 13:39:31 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2011-09-05 16:10:37 +02:00
|
|
|
#include <coreplugin/id.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2009-06-02 14:56:03 +02:00
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
2009-11-11 14:32:54 +01:00
|
|
|
#include <coreplugin/vcsmanager.h>
|
2012-02-14 16:43:51 +01:00
|
|
|
#include <coreplugin/documentmanager.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <cppeditor/cppeditorconstants.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QtConcurrentRun>
|
|
|
|
|
#include <QFutureSynchronizer>
|
2012-02-09 09:35:03 +01:00
|
|
|
#include <utils/runextensions.h>
|
2009-06-02 14:56:03 +02:00
|
|
|
|
|
|
|
|
#include <find/ifindfilter.h>
|
|
|
|
|
#include <find/searchresultwindow.h>
|
|
|
|
|
#include <utils/filesearch.h>
|
2012-01-23 17:44:49 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2009-06-02 14:56:03 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QtPlugin>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QAction>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-06-02 14:56:03 +02:00
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
using namespace CPlusPlus;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-10-10 21:00:48 +02:00
|
|
|
namespace CppTools {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
enum { debug = 0 };
|
|
|
|
|
|
2011-07-06 17:34:45 +02:00
|
|
|
static CppToolsPlugin *m_instance = 0;
|
2012-10-10 21:00:48 +02:00
|
|
|
static QHash<QString, QString> m_headerSourceMapping;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-04-29 09:04:59 +02:00
|
|
|
CppToolsPlugin::CppToolsPlugin() :
|
|
|
|
|
m_fileSettings(new CppFileSettings)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
m_instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CppToolsPlugin::~CppToolsPlugin()
|
|
|
|
|
{
|
|
|
|
|
m_instance = 0;
|
2012-10-15 16:38:56 +02:00
|
|
|
delete CppModelManager::instance();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-20 11:52:04 +01:00
|
|
|
bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(arguments)
|
|
|
|
|
Q_UNUSED(error)
|
2011-05-27 09:35:47 +02:00
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
m_settings = new CppToolsSettings(this); // force registration of cpp tools settings
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// Objects
|
2012-10-15 16:38:56 +02:00
|
|
|
CppModelManager *modelManager = CppModelManager::instance();
|
2012-01-24 15:36:40 +01:00
|
|
|
Core::VcsManager *vcsManager = Core::ICore::vcsManager();
|
2009-11-11 14:32:54 +01:00
|
|
|
connect(vcsManager, SIGNAL(repositoryChanged(QString)),
|
2012-10-15 16:38:56 +02:00
|
|
|
modelManager, SLOT(updateModifiedSourceFiles()));
|
2012-02-14 16:43:51 +01:00
|
|
|
connect(Core::DocumentManager::instance(), SIGNAL(filesChangedInternally(QStringList)),
|
2012-10-15 16:38:56 +02:00
|
|
|
modelManager, SLOT(updateSourceFiles(QStringList)));
|
2009-06-09 13:52:27 +02:00
|
|
|
|
2012-10-15 16:38:56 +02:00
|
|
|
addAutoReleasedObject(new CppLocatorFilter(modelManager));
|
|
|
|
|
addAutoReleasedObject(new CppClassesFilter(modelManager));
|
|
|
|
|
addAutoReleasedObject(new CppFunctionsFilter(modelManager));
|
|
|
|
|
addAutoReleasedObject(new CppCurrentDocumentFilter(modelManager, Core::ICore::editorManager()));
|
2009-04-29 09:04:59 +02:00
|
|
|
addAutoReleasedObject(new CppFileSettingsPage(m_fileSettings));
|
2012-10-15 16:38:56 +02:00
|
|
|
addAutoReleasedObject(new SymbolsFindFilter(modelManager));
|
2011-02-03 15:48:14 +01:00
|
|
|
addAutoReleasedObject(new CppCodeStyleSettingsPage);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// Menus
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionContainer *mtools = Core::ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
|
|
|
|
Core::ActionContainer *mcpptools = Core::ActionManager::createMenu(CppTools::Constants::M_TOOLS_CPP);
|
2008-12-02 12:01:29 +01:00
|
|
|
QMenu *menu = mcpptools->menu();
|
|
|
|
|
menu->setTitle(tr("&C++"));
|
|
|
|
|
menu->setEnabled(true);
|
|
|
|
|
mtools->addMenu(mcpptools);
|
|
|
|
|
|
|
|
|
|
// Actions
|
2010-06-25 17:37:59 +02:00
|
|
|
Core::Context context(CppEditor::Constants::C_CPPEDITOR);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QAction *switchAction = new QAction(tr("Switch Header/Source"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::Command *command = Core::ActionManager::registerAction(switchAction, Constants::SWITCH_HEADER_SOURCE, context, true);
|
2008-12-02 12:01:29 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(Qt::Key_F4));
|
|
|
|
|
mcpptools->addAction(command);
|
|
|
|
|
connect(switchAction, SIGNAL(triggered()), this, SLOT(switchHeaderSource()));
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppToolsPlugin::extensionsInitialized()
|
|
|
|
|
{
|
2009-04-29 09:04:59 +02:00
|
|
|
// The Cpp editor plugin, which is loaded later on, registers the Cpp mime types,
|
|
|
|
|
// so, apply settings here
|
2012-01-24 15:36:40 +01:00
|
|
|
m_fileSettings->fromSettings(Core::ICore::settings());
|
2009-04-29 09:04:59 +02:00
|
|
|
if (!m_fileSettings->applySuffixesToMimeDB())
|
|
|
|
|
qWarning("Unable to apply cpp suffixes to mime database (cpp mime types not found).\n");
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-13 13:36:47 +02:00
|
|
|
ExtensionSystem::IPlugin::ShutdownFlag CppToolsPlugin::aboutToShutdown()
|
2008-12-12 16:36:33 +01:00
|
|
|
{
|
2010-07-13 13:36:47 +02:00
|
|
|
return SynchronousShutdown;
|
2008-12-12 16:36:33 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void CppToolsPlugin::switchHeaderSource()
|
|
|
|
|
{
|
2012-05-08 09:43:14 +02:00
|
|
|
Core::IEditor *editor = Core::EditorManager::currentEditor();
|
2012-02-14 16:43:51 +01:00
|
|
|
QString otherFile = correspondingHeaderOrSource(editor->document()->fileName());
|
2010-09-03 11:57:46 +02:00
|
|
|
if (!otherFile.isEmpty())
|
2012-05-08 09:43:14 +02:00
|
|
|
Core::EditorManager::openEditor(otherFile);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2012-01-06 22:23:15 +01:00
|
|
|
static QStringList findFilesInProject(const QString &name,
|
2011-09-28 10:35:21 +02:00
|
|
|
const ProjectExplorer::Project *project)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
if (debug)
|
2011-09-28 10:35:21 +02:00
|
|
|
qDebug() << Q_FUNC_INFO << name << project;
|
|
|
|
|
|
|
|
|
|
if (!project)
|
2012-01-06 22:23:15 +01:00
|
|
|
return QStringList();
|
2011-09-28 10:35:21 +02:00
|
|
|
|
|
|
|
|
QString pattern = QString(1, QLatin1Char('/'));
|
|
|
|
|
pattern += name;
|
|
|
|
|
const QStringList projectFiles = project->files(ProjectExplorer::Project::AllFiles);
|
|
|
|
|
const QStringList::const_iterator pcend = projectFiles.constEnd();
|
2012-01-06 22:23:15 +01:00
|
|
|
QStringList candidateList;
|
2011-09-28 10:35:21 +02:00
|
|
|
for (QStringList::const_iterator it = projectFiles.constBegin(); it != pcend; ++it) {
|
|
|
|
|
if (it->endsWith(pattern))
|
2012-01-06 22:23:15 +01:00
|
|
|
candidateList.append(*it);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2012-01-06 22:23:15 +01:00
|
|
|
return candidateList;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Figure out file type
|
2008-12-12 16:36:33 +01:00
|
|
|
enum FileType {
|
|
|
|
|
HeaderFile,
|
|
|
|
|
C_SourceFile,
|
|
|
|
|
CPP_SourceFile,
|
2009-05-04 17:11:10 +02:00
|
|
|
ObjectiveCPP_SourceFile,
|
2008-12-12 16:36:33 +01:00
|
|
|
UnknownType
|
|
|
|
|
};
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
static inline FileType fileType(const Core::MimeDatabase *mimeDatase, const QFileInfo & fi)
|
|
|
|
|
{
|
|
|
|
|
const Core::MimeType mimeType = mimeDatase->findByFile(fi);
|
|
|
|
|
if (!mimeType)
|
|
|
|
|
return UnknownType;
|
|
|
|
|
const QString typeName = mimeType.type();
|
|
|
|
|
if (typeName == QLatin1String(CppTools::Constants::C_SOURCE_MIMETYPE))
|
|
|
|
|
return C_SourceFile;
|
|
|
|
|
if (typeName == QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE))
|
|
|
|
|
return CPP_SourceFile;
|
2009-05-04 17:11:10 +02:00
|
|
|
if (typeName == QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE))
|
|
|
|
|
return ObjectiveCPP_SourceFile;
|
2008-12-02 12:01:29 +01:00
|
|
|
if (typeName == QLatin1String(CppTools::Constants::C_HEADER_MIMETYPE)
|
|
|
|
|
|| typeName == QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE))
|
|
|
|
|
return HeaderFile;
|
|
|
|
|
return UnknownType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return the suffixes that should be checked when trying to find a
|
|
|
|
|
// source belonging to a header and vice versa
|
|
|
|
|
static QStringList matchingCandidateSuffixes(const Core::MimeDatabase *mimeDatase, FileType type)
|
|
|
|
|
{
|
|
|
|
|
switch (type) {
|
|
|
|
|
case UnknownType:
|
|
|
|
|
break;
|
|
|
|
|
case HeaderFile: // Note that C/C++ headers are undistinguishable
|
2009-05-04 17:11:10 +02:00
|
|
|
return mimeDatase->findByType(QLatin1String(CppTools::Constants::C_SOURCE_MIMETYPE)).suffixes()
|
|
|
|
|
+ mimeDatase->findByType(QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE)).suffixes()
|
|
|
|
|
+ mimeDatase->findByType(QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE)).suffixes();
|
2008-12-02 12:01:29 +01:00
|
|
|
case C_SourceFile:
|
|
|
|
|
return mimeDatase->findByType(QLatin1String(CppTools::Constants::C_HEADER_MIMETYPE)).suffixes();
|
|
|
|
|
case CPP_SourceFile:
|
2009-05-04 17:11:10 +02:00
|
|
|
case ObjectiveCPP_SourceFile:
|
2008-12-02 12:01:29 +01:00
|
|
|
return mimeDatase->findByType(QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE)).suffixes();
|
|
|
|
|
}
|
|
|
|
|
return QStringList();
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-28 10:35:21 +02:00
|
|
|
static QStringList baseNameWithAllSuffixes(const QString &baseName, const QStringList &suffixes)
|
|
|
|
|
{
|
|
|
|
|
QStringList result;
|
|
|
|
|
const QChar dot = QLatin1Char('.');
|
|
|
|
|
foreach (const QString &suffix, suffixes) {
|
|
|
|
|
QString fileName = baseName;
|
|
|
|
|
fileName += dot;
|
|
|
|
|
fileName += suffix;
|
|
|
|
|
result += fileName;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-06 22:23:15 +01:00
|
|
|
static int commonStringLength(const QString &s1, const QString &s2)
|
|
|
|
|
{
|
|
|
|
|
int length = qMin(s1.length(), s2.length());
|
|
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
|
if (s1[i] != s2[i])
|
|
|
|
|
return i;
|
|
|
|
|
return length;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-10 21:00:48 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
|
|
|
|
|
QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-10-10 21:00:48 +02:00
|
|
|
using namespace Internal;
|
2012-01-08 16:00:32 +01:00
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
const Core::MimeDatabase *mimeDatase = Core::ICore::mimeDatabase();
|
2012-10-10 21:00:48 +02:00
|
|
|
const QFileInfo fi(fileName);
|
|
|
|
|
if (m_headerSourceMapping.contains(fi.absoluteFilePath())) {
|
|
|
|
|
if (wasHeader)
|
|
|
|
|
*wasHeader = fileType(mimeDatase, fi) == HeaderFile;
|
|
|
|
|
return m_headerSourceMapping.value(fi.absoluteFilePath());
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-10-10 21:00:48 +02:00
|
|
|
FileType type = fileType(mimeDatase, fi);
|
|
|
|
|
if (wasHeader)
|
|
|
|
|
*wasHeader = type == HeaderFile;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << fileName << type;
|
|
|
|
|
|
|
|
|
|
if (type == UnknownType)
|
|
|
|
|
return QString();
|
|
|
|
|
|
2009-03-16 11:17:45 +01:00
|
|
|
const QString baseName = fi.completeBaseName();
|
2011-09-28 10:35:21 +02:00
|
|
|
const QString privateHeaderSuffix = QLatin1String("_p");
|
2008-12-02 12:01:29 +01:00
|
|
|
const QStringList suffixes = matchingCandidateSuffixes(mimeDatase, type);
|
|
|
|
|
|
2011-09-28 10:35:21 +02:00
|
|
|
QStringList candidateFileNames = baseNameWithAllSuffixes(baseName, suffixes);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (type == HeaderFile) {
|
|
|
|
|
if (baseName.endsWith(privateHeaderSuffix)) {
|
|
|
|
|
QString sourceBaseName = baseName;
|
|
|
|
|
sourceBaseName.truncate(sourceBaseName.size() - privateHeaderSuffix.size());
|
2011-09-28 10:35:21 +02:00
|
|
|
candidateFileNames += baseNameWithAllSuffixes(sourceBaseName, suffixes);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
2011-09-28 10:35:21 +02:00
|
|
|
QString privateHeaderBaseName = baseName;
|
|
|
|
|
privateHeaderBaseName.append(privateHeaderSuffix);
|
|
|
|
|
candidateFileNames += baseNameWithAllSuffixes(privateHeaderBaseName, suffixes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QDir absoluteDir = fi.absoluteDir();
|
|
|
|
|
|
|
|
|
|
// Try to find a file in the same directory first
|
2012-01-06 22:23:15 +01:00
|
|
|
foreach (const QString &candidateFileName, candidateFileNames) {
|
|
|
|
|
const QFileInfo candidateFi(absoluteDir, candidateFileName);
|
2012-01-08 16:00:32 +01:00
|
|
|
if (candidateFi.isFile()) {
|
|
|
|
|
m_headerSourceMapping[fi.absoluteFilePath()] = candidateFi.absoluteFilePath();
|
2012-06-21 20:55:17 -07:00
|
|
|
if (type != HeaderFile || !baseName.endsWith(privateHeaderSuffix))
|
|
|
|
|
m_headerSourceMapping[candidateFi.absoluteFilePath()] = fi.absoluteFilePath();
|
2011-09-28 10:35:21 +02:00
|
|
|
return candidateFi.absoluteFilePath();
|
2012-01-08 16:00:32 +01:00
|
|
|
}
|
2011-09-28 10:35:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find files in the project
|
2012-10-10 21:00:48 +02:00
|
|
|
ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::currentProject();
|
2011-09-28 10:35:21 +02:00
|
|
|
if (project) {
|
2012-01-06 22:23:15 +01:00
|
|
|
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);
|
2012-01-23 17:44:49 +01:00
|
|
|
QTC_ASSERT(candidateFi.isFile(), return QString());
|
2012-01-08 16:00:32 +01:00
|
|
|
m_headerSourceMapping[fi.absoluteFilePath()] = candidateFi.absoluteFilePath();
|
|
|
|
|
m_headerSourceMapping[candidateFi.absoluteFilePath()] = fi.absoluteFilePath();
|
2012-01-06 22:23:15 +01:00
|
|
|
return candidateFi.absoluteFilePath();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
2011-09-28 10:35:21 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-10 21:00:48 +02:00
|
|
|
} // namespace CppTools
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-10-10 21:00:48 +02:00
|
|
|
Q_EXPORT_PLUGIN(CppTools::Internal::CppToolsPlugin)
|