CppEditor: Move isObjC property to document.

Change-Id: I2267c69001da6bc136d26d874331dd734c8693f5
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Eike Ziller
2014-02-10 12:42:41 +01:00
parent 13349331e8
commit e60f355f05
3 changed files with 32 additions and 25 deletions

View File

@@ -526,11 +526,11 @@ CPPEditorWidget::CPPEditorWidget(CPPEditorWidget *other)
void CPPEditorWidget::ctor() void CPPEditorWidget::ctor()
{ {
m_cppEditorDocument = qobject_cast<CPPEditorDocument *>(baseTextDocument());
m_currentRenameSelection = NoCurrentRenameSelection; m_currentRenameSelection = NoCurrentRenameSelection;
m_inRename = false; m_inRename = false;
m_inRenameChanged = false; m_inRenameChanged = false;
m_firstRenameChange = false; m_firstRenameChange = false;
m_objcEnabled = false;
m_commentsSettings = CppTools::CppToolsSettings::instance()->commentsSettings(); m_commentsSettings = CppTools::CppToolsSettings::instance()->commentsSettings();
m_followSymbolUnderCursor.reset(new FollowSymbolUnderCursor(this)); m_followSymbolUnderCursor.reset(new FollowSymbolUnderCursor(this));
m_preprocessorButton = 0; m_preprocessorButton = 0;
@@ -572,10 +572,7 @@ void CPPEditorWidget::ctor()
connect(baseTextDocument(), SIGNAL(filePathChanged(QString,QString)), connect(baseTextDocument(), SIGNAL(filePathChanged(QString,QString)),
this, SLOT(onFilePathChanged())); this, SLOT(onFilePathChanged()));
connect(baseTextDocument(), SIGNAL(mimeTypeChanged()),
this, SLOT(onMimeTypeChanged()));
onFilePathChanged(); onFilePathChanged();
onMimeTypeChanged();
} }
CPPEditorWidget::~CPPEditorWidget() CPPEditorWidget::~CPPEditorWidget()
@@ -584,6 +581,11 @@ CPPEditorWidget::~CPPEditorWidget()
m_modelManager->deleteCppEditorSupport(editor()); m_modelManager->deleteCppEditorSupport(editor());
} }
CPPEditorDocument *CPPEditorWidget::cppEditorDocument() const
{
return m_cppEditorDocument;
}
TextEditor::BaseTextEditor *CPPEditorWidget::createEditor() TextEditor::BaseTextEditor *CPPEditorWidget::createEditor()
{ {
CPPEditor *editable = new CPPEditor(this); CPPEditor *editable = new CPPEditor(this);
@@ -718,14 +720,6 @@ void CPPEditorWidget::selectAll()
BaseTextEditorWidget::selectAll(); BaseTextEditorWidget::selectAll();
} }
void CPPEditorWidget::setObjCEnabled(bool onoff)
{
m_objcEnabled = onoff;
}
bool CPPEditorWidget::isObjCEnabled() const
{ return m_objcEnabled; }
void CPPEditorWidget::startRename() void CPPEditorWidget::startRename()
{ {
m_inRenameChanged = false; m_inRenameChanged = false;
@@ -1822,13 +1816,6 @@ void CPPEditorWidget::onFilePathChanged()
m_preprocessorButton->update(); 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)
@@ -1985,7 +1972,15 @@ CPPEditorDocument::CPPEditorDocument()
{ {
connect(this, SIGNAL(tabSettingsChanged()), connect(this, SIGNAL(tabSettingsChanged()),
this, SLOT(invalidateFormatterCache())); this, SLOT(invalidateFormatterCache()));
connect(this, SIGNAL(mimeTypeChanged()),
this, SLOT(onMimeTypeChanged()));
setSyntaxHighlighter(new CppHighlighter); setSyntaxHighlighter(new CppHighlighter);
onMimeTypeChanged();
}
bool CPPEditorDocument::isObjCEnabled() const
{
return m_isObjCEnabled;
} }
void CPPEditorDocument::applyFontSettings() void CPPEditorDocument::applyFontSettings()
@@ -2008,4 +2003,11 @@ void CPPEditorDocument::invalidateFormatterCache()
formatter.invalidateCache(document()); formatter.invalidateCache(document());
} }
void CPPEditorDocument::onMimeTypeChanged()
{
const QString &mt = mimeType();
m_isObjCEnabled = (mt == QLatin1String(CppTools::Constants::OBJECTIVE_C_SOURCE_MIMETYPE)
|| mt == QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE));
}
#include <cppeditor.moc> #include <cppeditor.moc>

View File

@@ -77,11 +77,17 @@ class CPPEditorDocument : public TextEditor::BaseTextDocument
public: public:
CPPEditorDocument(); CPPEditorDocument();
bool isObjCEnabled() const;
protected: protected:
void applyFontSettings(); void applyFontSettings();
private slots: private slots:
void invalidateFormatterCache(); void invalidateFormatterCache();
void onMimeTypeChanged();
private:
bool m_isObjCEnabled;
}; };
class CPPEditor : public TextEditor::BaseTextEditor class CPPEditor : public TextEditor::BaseTextEditor
@@ -113,6 +119,9 @@ public:
CPPEditorWidget(QWidget *parent = 0); CPPEditorWidget(QWidget *parent = 0);
CPPEditorWidget(CPPEditorWidget *other); CPPEditorWidget(CPPEditorWidget *other);
~CPPEditorWidget(); ~CPPEditorWidget();
CPPEditorDocument *cppEditorDocument() const;
void unCommentSelection(); void unCommentSelection();
unsigned editorRevision() const; unsigned editorRevision() const;
@@ -126,9 +135,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
void setObjCEnabled(bool onoff);
bool isObjCEnabled() const;
bool openLink(const Link &link, bool inNextSplit) { return openCppEditorAt(link, inNextSplit); } bool openLink(const Link &link, bool inNextSplit) { return openCppEditorAt(link, inNextSplit); }
static Link linkToSymbol(CPlusPlus::Symbol *symbol); static Link linkToSymbol(CPlusPlus::Symbol *symbol);
@@ -182,7 +188,6 @@ private slots:
void updateFunctionDeclDefLinkNow(); void updateFunctionDeclDefLinkNow();
void onFunctionDeclDefLinkFound(QSharedPointer<FunctionDeclDefLink> link); void onFunctionDeclDefLinkFound(QSharedPointer<FunctionDeclDefLink> link);
void onFilePathChanged(); 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();
@@ -230,6 +235,7 @@ private:
QPointer<CppTools::CppModelManagerInterface> m_modelManager; QPointer<CppTools::CppModelManagerInterface> m_modelManager;
CPPEditorDocument *m_cppEditorDocument;
QComboBox *m_outlineCombo; QComboBox *m_outlineCombo;
CPlusPlus::OverviewModel *m_outlineModel; CPlusPlus::OverviewModel *m_outlineModel;
QModelIndex m_outlineModelIndex; QModelIndex m_outlineModelIndex;
@@ -250,7 +256,6 @@ private:
CppTools::SemanticInfo m_lastSemanticInfo; CppTools::SemanticInfo m_lastSemanticInfo;
QList<TextEditor::QuickFixOperation::Ptr> m_quickFixes; QList<TextEditor::QuickFixOperation::Ptr> m_quickFixes;
bool m_objcEnabled;
QScopedPointer<QFutureWatcher<TextEditor::HighlightingResult> > m_highlightWatcher; QScopedPointer<QFutureWatcher<TextEditor::HighlightingResult> > m_highlightWatcher;
unsigned m_highlightRevision; // the editor revision that requested the highlight unsigned m_highlightRevision; // the editor revision that requested the highlight

View File

@@ -1388,7 +1388,7 @@ void ConvertCStringToNSString::match(const CppQuickFixInterface &interface,
{ {
CppRefactoringFilePtr file = interface->currentFile(); CppRefactoringFilePtr file = interface->currentFile();
if (!interface->editor()->isObjCEnabled()) if (!interface->editor()->cppEditorDocument()->isObjCEnabled())
return; return;
WrapStringLiteral::Type type = WrapStringLiteral::TypeNone; WrapStringLiteral::Type type = WrapStringLiteral::TypeNone;