diff options
-rw-r--r-- | src/plugins/cppeditor/cppeditor.cpp | 19 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppeditorconstants.h | 2 | ||||
-rw-r--r-- | src/plugins/cppeditor/cpppreprocessordialog.cpp | 15 |
3 files changed, 23 insertions, 13 deletions
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 90e65c0f07..0604edde96 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -702,17 +702,14 @@ void CPPEditorWidget::selectAll() void CPPEditorWidget::setMimeType(const QString &mt) { const QString &filePath = editor()->document()->filePath(); - // Check if this editor belongs to a project - QList<ProjectPart::Ptr> projectParts = m_modelManager->projectPart(filePath); - if (projectParts.isEmpty()) - projectParts = m_modelManager->projectPartFromDependencies(filePath); - if (!projectParts.isEmpty()) { - QSharedPointer<SnapshotUpdater> updater - = m_modelManager->cppEditorSupport(editor())->snapshotUpdater(); - const QString &projectFile = projectParts.first()->projectFile; - updater->setEditorDefines(ProjectExplorer::SessionManager::value( - projectFile + QLatin1Char(',') + filePath).toByteArray()); - } + const QString &projectFile = ProjectExplorer::SessionManager::value( + QLatin1String(Constants::CPP_PREPROCESSOR_PROJECT_PREFIX) + filePath).toString(); + const QByteArray &additionalDirectives = ProjectExplorer::SessionManager::value( + projectFile + QLatin1Char(',') + filePath).toByteArray(); + + QSharedPointer<SnapshotUpdater> updater + = m_modelManager->cppEditorSupport(editor())->snapshotUpdater(); + updater->setEditorDefines(additionalDirectives); BaseTextEditorWidget::setMimeType(mt); setObjCEnabled(mt == QLatin1String(CppTools::Constants::OBJECTIVE_C_SOURCE_MIMETYPE) diff --git a/src/plugins/cppeditor/cppeditorconstants.h b/src/plugins/cppeditor/cppeditorconstants.h index 672c732149..378789f911 100644 --- a/src/plugins/cppeditor/cppeditorconstants.h +++ b/src/plugins/cppeditor/cppeditorconstants.h @@ -63,6 +63,8 @@ const char WIZARD_TR_CATEGORY[] = QT_TRANSLATE_NOOP("CppEditor", "C++"); const char CPP_SNIPPETS_GROUP_ID[] = "C++"; +const char CPP_PREPROCESSOR_PROJECT_PREFIX[] = "CppPreprocessorProject-"; + } // namespace Constants } // namespace CppEditor diff --git a/src/plugins/cppeditor/cpppreprocessordialog.cpp b/src/plugins/cppeditor/cpppreprocessordialog.cpp index 37b400cbf7..e964962555 100644 --- a/src/plugins/cppeditor/cpppreprocessordialog.cpp +++ b/src/plugins/cppeditor/cpppreprocessordialog.cpp @@ -31,6 +31,7 @@ #include "ui_cpppreprocessordialog.h" #include "cppeditor.h" +#include "cppeditorconstants.h" #include "cppsnippetprovider.h" #include <projectexplorer/session.h> @@ -57,6 +58,10 @@ CppPreProcessorDialog::CppPreProcessorDialog(CPPEditorWidget *editorWidget, CppSnippetProvider().decorateEditor(m_ui->editWidget); + const QString ¤tProjectFile = ProjectExplorer::SessionManager::value( + QLatin1String(Constants::CPP_PREPROCESSOR_PROJECT_PREFIX) + m_filePath).toString(); + int currentIndex = 0; + QList<CppTools::ProjectPart::Ptr> sortedProjectParts(projectParts); qStableSort(sortedProjectParts.begin(), sortedProjectParts.end(), projectPartLessThan); @@ -66,12 +71,14 @@ CppPreProcessorDialog::CppPreProcessorDialog(CPPEditorWidget *editorWidget, addition.projectPart = projectPart; addition.additionalDirectives = ProjectExplorer::SessionManager::value( projectPart->projectFile + QLatin1Char(',') + m_filePath).toString(); + if (projectPart->projectFile == currentProjectFile) + currentIndex = m_ui->projectComboBox->count() - 1; m_partAdditions << addition; } if (m_ui->projectComboBox->count() <= 1) m_ui->projectComboBox->setEnabled(false); - m_ui->editWidget->setPlainText( - m_partAdditions.value(m_ui->projectComboBox->currentIndex()).additionalDirectives); + m_ui->projectComboBox->setCurrentIndex(currentIndex); + m_ui->editWidget->setPlainText(m_partAdditions.value(currentIndex).additionalDirectives); connect(m_ui->projectComboBox, SIGNAL(currentIndexChanged(int)), SLOT(projectChanged(int))); connect(m_ui->editWidget, SIGNAL(textChanged()), SLOT(textChanged())); @@ -87,6 +94,10 @@ int CppPreProcessorDialog::exec() if (QDialog::exec() == Rejected) return Rejected; + ProjectExplorer::SessionManager::setValue( + QLatin1String(Constants::CPP_PREPROCESSOR_PROJECT_PREFIX) + m_filePath, + m_partAdditions[m_ui->projectComboBox->currentIndex()].projectPart->projectFile); + foreach (ProjectPartAddition partAddition, m_partAdditions) { const QString &previousDirectives = ProjectExplorer::SessionManager::value( partAddition.projectPart->projectFile |