CPPEditor: Rework preprocessor addition tooltip.

Change the preprocessor popup to a dialog.
Save the additional preprocessor directives to the session instead of the
.pro.user file.

Change-Id: I0d08c5684cfb21e822cde0a965c9cf14e5d6d47d
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
David Schulz
2013-10-17 11:19:26 +02:00
parent 04cd026582
commit f30bd48b58
11 changed files with 258 additions and 358 deletions

View File

@@ -34,7 +34,7 @@
#include "cppeditorplugin.h"
#include "cppfollowsymbolundercursor.h"
#include "cpphighlighter.h"
#include "cpppreprocessoradditionwidget.h"
#include "cpppreprocessordialog.h"
#include "cppquickfixassistant.h"
#include <coreplugin/actionmanager/actioncontainer.h>
@@ -701,18 +701,17 @@ void CPPEditorWidget::selectAll()
void CPPEditorWidget::setMimeType(const QString &mt)
{
const QString &fileName = editor()->document()->filePath();
const QString &filePath = editor()->document()->filePath();
// Check if this editor belongs to a project
QList<ProjectPart::Ptr> projectParts = m_modelManager->projectPart(fileName);
QList<ProjectPart::Ptr> projectParts = m_modelManager->projectPart(filePath);
if (projectParts.isEmpty())
projectParts = m_modelManager->projectPartFromDependencies(fileName);
projectParts = m_modelManager->projectPartFromDependencies(filePath);
if (!projectParts.isEmpty()) {
if (ProjectExplorer::Project *project = projectParts.first()->project) {
QByteArray additionalDefines = project->additionalCppDefines()
.value(projectParts.first()->projectFile).toByteArray();
m_modelManager->cppEditorSupport(editor())->snapshotUpdater()->setEditorDefines(
additionalDefines);
}
QSharedPointer<SnapshotUpdater> updater
= m_modelManager->cppEditorSupport(editor())->snapshotUpdater();
const QString &projectFile = projectParts.first()->projectFile;
updater->setEditorDefines(ProjectExplorer::SessionManager::value(
projectFile + QLatin1Char(',') + filePath).toByteArray());
}
BaseTextEditorWidget::setMimeType(mt);
@@ -1968,28 +1967,21 @@ void CPPEditorWidget::onCommentsSettingsChanged(const CppTools::CommentsSettings
void CPPEditorWidget::showPreProcessorWidget()
{
const QString &fileName = editor()->document()->filePath();
// Check if this editor belongs to a project
// Check if this editor belongs to a project
QList<ProjectPart::Ptr> projectParts = m_modelManager->projectPart(fileName);
if (projectParts.isEmpty())
projectParts = m_modelManager->projectPartFromDependencies(fileName);
if (projectParts.isEmpty())
projectParts << m_modelManager->fallbackProjectPart();
PreProcessorAdditionPopUp::instance()->show(this, projectParts);
connect(PreProcessorAdditionPopUp::instance(),
SIGNAL(finished(QByteArray)),
SLOT(preProcessorWidgetFinished(QByteArray)));
}
void CPPEditorWidget::preProcessorWidgetFinished(const QByteArray &additionalDefines)
{
PreProcessorAdditionPopUp::instance()->disconnect(this);
QSharedPointer<SnapshotUpdater> updater
= m_modelManager->cppEditorSupport(editor())->snapshotUpdater();
updater->setEditorDefines(additionalDefines);
updater->update(m_modelManager->workingCopy());
CppPreProcessorDialog preProcessorDialog(this, projectParts);
if (preProcessorDialog.exec() == QDialog::Accepted) {
QSharedPointer<SnapshotUpdater> updater
= m_modelManager->cppEditorSupport(editor())->snapshotUpdater();
updater->setEditorDefines(preProcessorDialog.additionalPreProcessorDirectives().toLatin1());
updater->update(m_modelManager->workingCopy());
}
}
#include <cppeditor.moc>