CppEditor: Use the project part chosen with CppPreProcessorDialog

...otherwise the CppPreProcessorDialog is only semi-useful.

Change-Id: I6b80967b05e7c9a51cd78ae064a3d78170948e32
Reviewed-by: David Schulz <david.schulz@digia.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Nikolai Kosjar
2013-12-02 15:23:13 +01:00
parent 3baa1b35e2
commit a8e7b6bd38
6 changed files with 22 additions and 2 deletions

View File

@@ -715,6 +715,7 @@ void CPPEditorWidget::setMimeType(const QString &mt)
QSharedPointer<SnapshotUpdater> updater
= m_modelManager->cppEditorSupport(editor())->snapshotUpdater();
updater->setProjectPart(m_modelManager->projectPartForProjectFile(projectFile));
updater->setEditorDefines(additionalDirectives);
m_preprocessorButton->setProperty("highlightWidget", !additionalDirectives.trimmed().isEmpty());
@@ -1994,6 +1995,7 @@ void CPPEditorWidget::showPreProcessorWidget()
QSharedPointer<SnapshotUpdater> updater
= m_modelManager->cppEditorSupport(editor())->snapshotUpdater();
const QString &additionals = preProcessorDialog.additionalPreProcessorDirectives();
updater->setProjectPart(preProcessorDialog.projectPart());
updater->setEditorDefines(additionals.toUtf8());
updater->update(m_modelManager->workingCopy());

View File

@@ -112,6 +112,11 @@ int CppPreProcessorDialog::exec()
return Accepted;
}
CppTools::ProjectPart::Ptr CppPreProcessorDialog::projectPart() const
{
return m_partAdditions[m_ui->projectComboBox->currentIndex()].projectPart;
}
QString CppPreProcessorDialog::additionalPreProcessorDirectives() const
{
return m_ui->editWidget->toPlainText();

View File

@@ -50,6 +50,8 @@ public:
~CppPreProcessorDialog();
int exec();
CppTools::ProjectPart::Ptr projectPart() const;
QString additionalPreProcessorDirectives() const;
private slots:

View File

@@ -689,12 +689,14 @@ private:
/// Make sure that m_projectMutex is locked when calling this.
void CppModelManager::recalculateFileToProjectParts()
{
m_projectFileToProjectPart.clear();
m_fileToProjectParts.clear();
foreach (const ProjectInfo &projectInfo, m_projectToProjectsInfo) {
foreach (const ProjectPart::Ptr &projectPart, projectInfo.projectParts()) {
foreach (const ProjectFile &cxxFile, projectPart->files) {
m_projectFileToProjectPart[projectPart->projectFile] = projectPart;
foreach (const ProjectFile &cxxFile, projectPart->files)
m_fileToProjectParts[cxxFile.path].append(projectPart);
}
}
}
}
@@ -774,6 +776,11 @@ QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo &newProjectIn
return updateSourceFiles(filesToReindex, ForcedProgressNotification);
}
ProjectPart::Ptr CppModelManager::projectPartForProjectFile(const QString &projectFile) const
{
return m_projectFileToProjectPart.value(projectFile);
}
QList<ProjectPart::Ptr> CppModelManager::projectPart(const QString &fileName) const
{
return m_fileToProjectParts.value(fileName);

View File

@@ -75,6 +75,8 @@ public:
virtual ProjectInfo projectInfo(ProjectExplorer::Project *project) const;
virtual QFuture<void> updateProjectInfo(const ProjectInfo &newProjectInfo);
/// \return The project part with the given project file
virtual ProjectPart::Ptr projectPartForProjectFile(const QString &projectFile) const;
/// \return All project parts that mention the given file name as one of the sources/headers.
virtual QList<ProjectPart::Ptr> projectPart(const QString &fileName) const;
/// This is a fall-back function: find all files that includes the file directly or indirectly,
@@ -199,6 +201,7 @@ private:
mutable QMutex m_projectMutex;
QMap<ProjectExplorer::Project *, ProjectInfo> m_projectToProjectsInfo;
QMap<QString, QList<CppTools::ProjectPart::Ptr> > m_fileToProjectParts;
QMap<QString, CppTools::ProjectPart::Ptr> m_projectFileToProjectPart;
// The members below are cached/(re)calculated from the projects and/or their project parts
bool m_dirty;
QStringList m_projectFiles;

View File

@@ -233,6 +233,7 @@ public:
virtual QList<ProjectInfo> projectInfos() const = 0;
virtual ProjectInfo projectInfo(ProjectExplorer::Project *project) const = 0;
virtual QFuture<void> updateProjectInfo(const ProjectInfo &pinfo) = 0;
virtual ProjectPart::Ptr projectPartForProjectFile(const QString &projectFile) const = 0;
virtual QList<ProjectPart::Ptr> projectPart(const QString &fileName) const = 0;
virtual QList<ProjectPart::Ptr> projectPartFromDependencies(const QString &fileName) const = 0;
virtual ProjectPart::Ptr fallbackProjectPart() const = 0;