forked from qt-creator/qt-creator
CppEditor: Do not reimplement BaseTextEditorWidget::setMimeType
It's not necessary, since we have signals for that. And it's wrong to handle the additional preprocessor directives there anyway. The update if the editor supports objective-c/c++ is now done in a mimeTypeChanged signal handler, the update of the additional preprocessor directives on filePathChanged. Change-Id: If88c70f5321c2bc21a21673e96be2598dc9ecf04 Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -576,6 +576,13 @@ void CPPEditorWidget::ctor()
|
||||
SIGNAL(commentsSettingsChanged(CppTools::CommentsSettings)),
|
||||
this,
|
||||
SLOT(onCommentsSettingsChanged(CppTools::CommentsSettings)));
|
||||
|
||||
connect(baseTextDocument(), SIGNAL(filePathChanged(QString,QString)),
|
||||
this, SLOT(onFilePathChanged()));
|
||||
connect(baseTextDocument(), SIGNAL(mimeTypeChanged()),
|
||||
this, SLOT(onMimeTypeChanged()));
|
||||
onFilePathChanged();
|
||||
onMimeTypeChanged();
|
||||
}
|
||||
|
||||
CPPEditorWidget::~CPPEditorWidget()
|
||||
@@ -718,27 +725,6 @@ void CPPEditorWidget::selectAll()
|
||||
BaseTextEditorWidget::selectAll();
|
||||
}
|
||||
|
||||
void CPPEditorWidget::setMimeType(const QString &mt)
|
||||
{
|
||||
const QString &filePath = editor()->document()->filePath();
|
||||
const QString &projectFile = ProjectExplorer::SessionManager::value(
|
||||
QLatin1String(Constants::CPP_PREPROCESSOR_PROJECT_PREFIX) + filePath).toString();
|
||||
const QByteArray &additionalDirectives = ProjectExplorer::SessionManager::value(
|
||||
projectFile + QLatin1Char(',') + filePath).toString().toUtf8();
|
||||
|
||||
QSharedPointer<SnapshotUpdater> updater
|
||||
= m_modelManager->cppEditorSupport(editor())->snapshotUpdater();
|
||||
updater->setProjectPart(m_modelManager->projectPartForProjectFile(projectFile));
|
||||
updater->setEditorDefines(additionalDirectives);
|
||||
|
||||
m_preprocessorButton->setProperty("highlightWidget", !additionalDirectives.trimmed().isEmpty());
|
||||
m_preprocessorButton->update();
|
||||
|
||||
BaseTextEditorWidget::setMimeType(mt);
|
||||
setObjCEnabled(mt == QLatin1String(CppTools::Constants::OBJECTIVE_C_SOURCE_MIMETYPE)
|
||||
|| mt == QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE));
|
||||
}
|
||||
|
||||
void CPPEditorWidget::setObjCEnabled(bool onoff)
|
||||
{
|
||||
m_objcEnabled = onoff;
|
||||
@@ -1862,6 +1848,33 @@ void CPPEditorWidget::onFunctionDeclDefLinkFound(QSharedPointer<FunctionDeclDefL
|
||||
|
||||
}
|
||||
|
||||
void CPPEditorWidget::onFilePathChanged()
|
||||
{
|
||||
QTC_ASSERT(m_modelManager, return);
|
||||
QByteArray additionalDirectives;
|
||||
const QString &filePath = baseTextDocument()->filePath();
|
||||
if (!filePath.isEmpty()) {
|
||||
const QString &projectFile = ProjectExplorer::SessionManager::value(
|
||||
QLatin1String(Constants::CPP_PREPROCESSOR_PROJECT_PREFIX) + filePath).toString();
|
||||
additionalDirectives = ProjectExplorer::SessionManager::value(
|
||||
projectFile + QLatin1Char(',') + filePath).toString().toUtf8();
|
||||
|
||||
QSharedPointer<SnapshotUpdater> updater
|
||||
= m_modelManager->cppEditorSupport(editor())->snapshotUpdater();
|
||||
updater->setProjectPart(m_modelManager->projectPartForProjectFile(projectFile));
|
||||
updater->setEditorDefines(additionalDirectives);
|
||||
}
|
||||
m_preprocessorButton->setProperty("highlightWidget", !additionalDirectives.trimmed().isEmpty());
|
||||
m_preprocessorButton->update();
|
||||
}
|
||||
|
||||
void CPPEditorWidget::onMimeTypeChanged()
|
||||
{
|
||||
const QString &mt = baseTextDocument()->mimeType();
|
||||
setObjCEnabled(mt == QLatin1String(CppTools::Constants::OBJECTIVE_C_SOURCE_MIMETYPE)
|
||||
|| mt == QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE));
|
||||
}
|
||||
|
||||
void CPPEditorWidget::applyDeclDefLinkChanges(bool jumpToMatch)
|
||||
{
|
||||
if (!m_declDefLink)
|
||||
|
||||
Reference in New Issue
Block a user