Skip to content
Snippets Groups Projects
Commit 7f031394 authored by Eike Ziller's avatar Eike Ziller
Browse files

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: default avatarEike Ziller <eike.ziller@digia.com>
parent cec4fac8
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -113,8 +113,6 @@ public:
virtual void cut(); // reimplemented from BaseTextEditorWidget
virtual void selectAll(); // reimplemented from BaseTextEditorWidget
virtual void setMimeType(const QString &mt);
void setObjCEnabled(bool onoff);
bool isObjCEnabled() const;
......@@ -173,6 +171,8 @@ private Q_SLOTS:
void updateFunctionDeclDefLink();
void updateFunctionDeclDefLinkNow();
void onFunctionDeclDefLinkFound(QSharedPointer<FunctionDeclDefLink> link);
void onFilePathChanged();
void onMimeTypeChanged();
void onDocumentUpdated();
void onContentsChanged(int position, int charsRemoved, int charsAdded);
void updatePreprocessorButtonTooltip();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment