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)),
|
SIGNAL(commentsSettingsChanged(CppTools::CommentsSettings)),
|
||||||
this,
|
this,
|
||||||
SLOT(onCommentsSettingsChanged(CppTools::CommentsSettings)));
|
SLOT(onCommentsSettingsChanged(CppTools::CommentsSettings)));
|
||||||
|
|
||||||
|
connect(baseTextDocument(), SIGNAL(filePathChanged(QString,QString)),
|
||||||
|
this, SLOT(onFilePathChanged()));
|
||||||
|
connect(baseTextDocument(), SIGNAL(mimeTypeChanged()),
|
||||||
|
this, SLOT(onMimeTypeChanged()));
|
||||||
|
onFilePathChanged();
|
||||||
|
onMimeTypeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
CPPEditorWidget::~CPPEditorWidget()
|
CPPEditorWidget::~CPPEditorWidget()
|
||||||
@@ -718,27 +725,6 @@ void CPPEditorWidget::selectAll()
|
|||||||
BaseTextEditorWidget::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)
|
void CPPEditorWidget::setObjCEnabled(bool onoff)
|
||||||
{
|
{
|
||||||
m_objcEnabled = 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)
|
void CPPEditorWidget::applyDeclDefLinkChanges(bool jumpToMatch)
|
||||||
{
|
{
|
||||||
if (!m_declDefLink)
|
if (!m_declDefLink)
|
||||||
|
|||||||
@@ -113,8 +113,6 @@ public:
|
|||||||
virtual void cut(); // reimplemented from BaseTextEditorWidget
|
virtual void cut(); // reimplemented from BaseTextEditorWidget
|
||||||
virtual void selectAll(); // reimplemented from BaseTextEditorWidget
|
virtual void selectAll(); // reimplemented from BaseTextEditorWidget
|
||||||
|
|
||||||
virtual void setMimeType(const QString &mt);
|
|
||||||
|
|
||||||
void setObjCEnabled(bool onoff);
|
void setObjCEnabled(bool onoff);
|
||||||
bool isObjCEnabled() const;
|
bool isObjCEnabled() const;
|
||||||
|
|
||||||
@@ -173,6 +171,8 @@ private Q_SLOTS:
|
|||||||
void updateFunctionDeclDefLink();
|
void updateFunctionDeclDefLink();
|
||||||
void updateFunctionDeclDefLinkNow();
|
void updateFunctionDeclDefLinkNow();
|
||||||
void onFunctionDeclDefLinkFound(QSharedPointer<FunctionDeclDefLink> link);
|
void onFunctionDeclDefLinkFound(QSharedPointer<FunctionDeclDefLink> link);
|
||||||
|
void onFilePathChanged();
|
||||||
|
void onMimeTypeChanged();
|
||||||
void onDocumentUpdated();
|
void onDocumentUpdated();
|
||||||
void onContentsChanged(int position, int charsRemoved, int charsAdded);
|
void onContentsChanged(int position, int charsRemoved, int charsAdded);
|
||||||
void updatePreprocessorButtonTooltip();
|
void updatePreprocessorButtonTooltip();
|
||||||
|
|||||||
Reference in New Issue
Block a user