forked from qt-creator/qt-creator
CppEditor: Remember project in preprocessor dialog.
Change-Id: If226707541b1fd4d5c22de2795fb39bc333cfa49 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
@@ -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()) {
|
||||
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();
|
||||
const QString &projectFile = projectParts.first()->projectFile;
|
||||
updater->setEditorDefines(ProjectExplorer::SessionManager::value(
|
||||
projectFile + QLatin1Char(',') + filePath).toByteArray());
|
||||
}
|
||||
updater->setEditorDefines(additionalDirectives);
|
||||
|
||||
BaseTextEditorWidget::setMimeType(mt);
|
||||
setObjCEnabled(mt == QLatin1String(CppTools::Constants::OBJECTIVE_C_SOURCE_MIMETYPE)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user