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)
|
void CPPEditorWidget::setMimeType(const QString &mt)
|
||||||
{
|
{
|
||||||
const QString &filePath = editor()->document()->filePath();
|
const QString &filePath = editor()->document()->filePath();
|
||||||
// Check if this editor belongs to a project
|
const QString &projectFile = ProjectExplorer::SessionManager::value(
|
||||||
QList<ProjectPart::Ptr> projectParts = m_modelManager->projectPart(filePath);
|
QLatin1String(Constants::CPP_PREPROCESSOR_PROJECT_PREFIX) + filePath).toString();
|
||||||
if (projectParts.isEmpty())
|
const QByteArray &additionalDirectives = ProjectExplorer::SessionManager::value(
|
||||||
projectParts = m_modelManager->projectPartFromDependencies(filePath);
|
projectFile + QLatin1Char(',') + filePath).toByteArray();
|
||||||
if (!projectParts.isEmpty()) {
|
|
||||||
QSharedPointer<SnapshotUpdater> updater
|
QSharedPointer<SnapshotUpdater> updater
|
||||||
= m_modelManager->cppEditorSupport(editor())->snapshotUpdater();
|
= m_modelManager->cppEditorSupport(editor())->snapshotUpdater();
|
||||||
const QString &projectFile = projectParts.first()->projectFile;
|
updater->setEditorDefines(additionalDirectives);
|
||||||
updater->setEditorDefines(ProjectExplorer::SessionManager::value(
|
|
||||||
projectFile + QLatin1Char(',') + filePath).toByteArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
BaseTextEditorWidget::setMimeType(mt);
|
BaseTextEditorWidget::setMimeType(mt);
|
||||||
setObjCEnabled(mt == QLatin1String(CppTools::Constants::OBJECTIVE_C_SOURCE_MIMETYPE)
|
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_SNIPPETS_GROUP_ID[] = "C++";
|
||||||
|
|
||||||
|
const char CPP_PREPROCESSOR_PROJECT_PREFIX[] = "CppPreprocessorProject-";
|
||||||
|
|
||||||
} // namespace Constants
|
} // namespace Constants
|
||||||
} // namespace CppEditor
|
} // namespace CppEditor
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include "ui_cpppreprocessordialog.h"
|
#include "ui_cpppreprocessordialog.h"
|
||||||
|
|
||||||
#include "cppeditor.h"
|
#include "cppeditor.h"
|
||||||
|
#include "cppeditorconstants.h"
|
||||||
#include "cppsnippetprovider.h"
|
#include "cppsnippetprovider.h"
|
||||||
|
|
||||||
#include <projectexplorer/session.h>
|
#include <projectexplorer/session.h>
|
||||||
@@ -57,6 +58,10 @@ CppPreProcessorDialog::CppPreProcessorDialog(CPPEditorWidget *editorWidget,
|
|||||||
|
|
||||||
CppSnippetProvider().decorateEditor(m_ui->editWidget);
|
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);
|
QList<CppTools::ProjectPart::Ptr> sortedProjectParts(projectParts);
|
||||||
qStableSort(sortedProjectParts.begin(), sortedProjectParts.end(), projectPartLessThan);
|
qStableSort(sortedProjectParts.begin(), sortedProjectParts.end(), projectPartLessThan);
|
||||||
|
|
||||||
@@ -66,12 +71,14 @@ CppPreProcessorDialog::CppPreProcessorDialog(CPPEditorWidget *editorWidget,
|
|||||||
addition.projectPart = projectPart;
|
addition.projectPart = projectPart;
|
||||||
addition.additionalDirectives = ProjectExplorer::SessionManager::value(
|
addition.additionalDirectives = ProjectExplorer::SessionManager::value(
|
||||||
projectPart->projectFile + QLatin1Char(',') + m_filePath).toString();
|
projectPart->projectFile + QLatin1Char(',') + m_filePath).toString();
|
||||||
|
if (projectPart->projectFile == currentProjectFile)
|
||||||
|
currentIndex = m_ui->projectComboBox->count() - 1;
|
||||||
m_partAdditions << addition;
|
m_partAdditions << addition;
|
||||||
}
|
}
|
||||||
if (m_ui->projectComboBox->count() <= 1)
|
if (m_ui->projectComboBox->count() <= 1)
|
||||||
m_ui->projectComboBox->setEnabled(false);
|
m_ui->projectComboBox->setEnabled(false);
|
||||||
m_ui->editWidget->setPlainText(
|
m_ui->projectComboBox->setCurrentIndex(currentIndex);
|
||||||
m_partAdditions.value(m_ui->projectComboBox->currentIndex()).additionalDirectives);
|
m_ui->editWidget->setPlainText(m_partAdditions.value(currentIndex).additionalDirectives);
|
||||||
|
|
||||||
connect(m_ui->projectComboBox, SIGNAL(currentIndexChanged(int)), SLOT(projectChanged(int)));
|
connect(m_ui->projectComboBox, SIGNAL(currentIndexChanged(int)), SLOT(projectChanged(int)));
|
||||||
connect(m_ui->editWidget, SIGNAL(textChanged()), SLOT(textChanged()));
|
connect(m_ui->editWidget, SIGNAL(textChanged()), SLOT(textChanged()));
|
||||||
@@ -87,6 +94,10 @@ int CppPreProcessorDialog::exec()
|
|||||||
if (QDialog::exec() == Rejected)
|
if (QDialog::exec() == Rejected)
|
||||||
return 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) {
|
foreach (ProjectPartAddition partAddition, m_partAdditions) {
|
||||||
const QString &previousDirectives = ProjectExplorer::SessionManager::value(
|
const QString &previousDirectives = ProjectExplorer::SessionManager::value(
|
||||||
partAddition.projectPart->projectFile
|
partAddition.projectPart->projectFile
|
||||||
|
|||||||
Reference in New Issue
Block a user