diff options
author | Eike Ziller <eike.ziller@digia.com> | 2014-01-13 16:56:53 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@digia.com> | 2014-01-15 15:02:25 +0100 |
commit | 3ad38766112a6e0af67ad18c7244e251dc911f19 (patch) | |
tree | dee5c4e44b63113537d77a3b7f46963b1981441f /src/plugins | |
parent | 8772e6e85b2be4bd79cae4e21367e23a1ad94ed7 (diff) | |
download | qt-creator-3ad38766112a6e0af67ad18c7244e251dc911f19.tar.gz |
TextEditors: Move indenter to document.
Change-Id: I8bdf7134562d007aa16cc63a34f5a15a708577ae
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/cppeditor/cppeditor.cpp | 2 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppsnippetprovider.cpp | 2 | ||||
-rw-r--r-- | src/plugins/cpptools/cppcodestylesettingspage.cpp | 2 | ||||
-rw-r--r-- | src/plugins/fakevim/fakevimplugin.cpp | 4 | ||||
-rw-r--r-- | src/plugins/glsleditor/glsleditor.cpp | 2 | ||||
-rw-r--r-- | src/plugins/pythoneditor/pythoneditorwidget.cpp | 2 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljseditor.cpp | 1 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljssnippetprovider.cpp | 2 | ||||
-rw-r--r-- | src/plugins/qmljstools/qmljscodestylesettingspage.cpp | 4 | ||||
-rw-r--r-- | src/plugins/texteditor/basetextdocument.cpp | 25 | ||||
-rw-r--r-- | src/plugins/texteditor/basetextdocument.h | 12 | ||||
-rw-r--r-- | src/plugins/texteditor/basetexteditor.cpp | 25 | ||||
-rw-r--r-- | src/plugins/texteditor/basetexteditor.h | 3 | ||||
-rw-r--r-- | src/plugins/texteditor/basetexteditor_p.h | 1 | ||||
-rw-r--r-- | src/plugins/texteditor/codestyleeditor.cpp | 6 | ||||
-rw-r--r-- | src/plugins/texteditor/plaintexteditor.cpp | 3 |
16 files changed, 49 insertions, 47 deletions
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 6dc61e9349..7b73cf628f 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -514,6 +514,7 @@ Q_GLOBAL_STATIC(CppTools::SymbolFinder, symbolFinder) CPPEditorWidget::CPPEditorWidget(QWidget *parent) : TextEditor::BaseTextEditorWidget(parent) { + baseTextDocument()->setIndenter(new CppTools::CppQtStyleIndenter); ctor(); } @@ -539,7 +540,6 @@ void CPPEditorWidget::ctor() setParenthesesMatchingEnabled(true); setMarksVisible(true); setCodeFoldingSupported(true); - setIndenter(new CppTools::CppQtStyleIndenter); setAutoCompleter(new CppAutoCompleter); baseTextDocument()->setSyntaxHighlighter(new CppHighlighter); diff --git a/src/plugins/cppeditor/cppsnippetprovider.cpp b/src/plugins/cppeditor/cppsnippetprovider.cpp index 35c99a8b3b..4da115396f 100644 --- a/src/plugins/cppeditor/cppsnippetprovider.cpp +++ b/src/plugins/cppeditor/cppsnippetprovider.cpp @@ -64,6 +64,6 @@ QString CppSnippetProvider::displayName() const void CppSnippetProvider::decorateEditor(TextEditor::SnippetEditorWidget *editor) const { editor->setSyntaxHighlighter(new CppHighlighter); - editor->setIndenter(new CppTools::CppQtStyleIndenter); + editor->baseTextDocument()->setIndenter(new CppTools::CppQtStyleIndenter); editor->setAutoCompleter(new CppAutoCompleter); } diff --git a/src/plugins/cpptools/cppcodestylesettingspage.cpp b/src/plugins/cpptools/cppcodestylesettingspage.cpp index 2a5d889583..33504d3749 100644 --- a/src/plugins/cpptools/cppcodestylesettingspage.cpp +++ b/src/plugins/cpptools/cppcodestylesettingspage.cpp @@ -475,7 +475,7 @@ void CppCodeStylePreferencesWidget::updatePreview() QTextCursor tc = preview->textCursor(); tc.beginEditBlock(); while (block.isValid()) { - preview->indenter()->indentBlock(doc, block, QChar::Null, ts); + preview->baseTextDocument()->indenter()->indentBlock(doc, block, QChar::Null, ts); block = block.next(); } diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index ed48448b38..9055056c83 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -1752,7 +1752,7 @@ void FakeVimPluginPrivate::checkForElectricCharacter(bool *result, QChar c) if (!handler) return; if (BaseTextEditorWidget *bt = qobject_cast<BaseTextEditorWidget *>(handler->widget())) - *result = bt->indenter()->isElectricCharacter(c); + *result = bt->baseTextDocument()->indenter()->isElectricCharacter(c); } void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd) @@ -1947,7 +1947,7 @@ void FakeVimPluginPrivate::indentRegion(int beginBlock, int endBlock, while (!cursor.atBlockEnd()) cursor.deleteChar(); } else { - bt->indenter()->indentBlock(doc, block, typedChar, tabSettings); + bt->baseTextDocument()->indenter()->indentBlock(doc, block, typedChar, tabSettings); } block = block.next(); } diff --git a/src/plugins/glsleditor/glsleditor.cpp b/src/plugins/glsleditor/glsleditor.cpp index ad829c4780..9bc0913bbc 100644 --- a/src/plugins/glsleditor/glsleditor.cpp +++ b/src/plugins/glsleditor/glsleditor.cpp @@ -143,6 +143,7 @@ void Document::addRange(const QTextCursor &cursor, GLSL::Scope *scope) GLSLTextEditorWidget::GLSLTextEditorWidget(QWidget *parent) : TextEditor::BaseTextEditorWidget(parent) { + baseTextDocument()->setIndenter(new GLSLIndenter()); ctor(); } @@ -158,7 +159,6 @@ void GLSLTextEditorWidget::ctor() setParenthesesMatchingEnabled(true); setMarksVisible(true); setCodeFoldingSupported(true); - setIndenter(new GLSLIndenter()); setAutoCompleter(new GLSLCompleter()); m_updateDocumentTimer = new QTimer(this); diff --git a/src/plugins/pythoneditor/pythoneditorwidget.cpp b/src/plugins/pythoneditor/pythoneditorwidget.cpp index 4e5b119f3e..e5ee2521f2 100644 --- a/src/plugins/pythoneditor/pythoneditorwidget.cpp +++ b/src/plugins/pythoneditor/pythoneditorwidget.cpp @@ -50,6 +50,7 @@ namespace Internal { EditorWidget::EditorWidget(QWidget *parent) : TextEditor::BaseTextEditorWidget(parent) { + baseTextDocument()->setIndenter(new PythonIndenter()); ctor(); } @@ -69,7 +70,6 @@ void EditorWidget::ctor() setMarksVisible(true); setCodeFoldingSupported(true); - setIndenter(new PythonIndenter()); new PythonHighlighter(baseTextDocument()); } diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 8e66676d85..c8be9e23cf 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -476,7 +476,6 @@ void QmlJSTextEditorWidget::ctor() setParenthesesMatchingEnabled(true); setMarksVisible(true); setCodeFoldingSupported(true); - setIndenter(new Indenter); setAutoCompleter(new AutoCompleter); setLanguageSettingsId(QmlJSTools::Constants::QML_JS_SETTINGS_ID); diff --git a/src/plugins/qmljseditor/qmljssnippetprovider.cpp b/src/plugins/qmljseditor/qmljssnippetprovider.cpp index 31cbedbd19..746765700e 100644 --- a/src/plugins/qmljseditor/qmljssnippetprovider.cpp +++ b/src/plugins/qmljseditor/qmljssnippetprovider.cpp @@ -65,6 +65,6 @@ QString QmlJSSnippetProvider::displayName() const void QmlJSSnippetProvider::decorateEditor(TextEditor::SnippetEditorWidget *editor) const { editor->setSyntaxHighlighter(new Highlighter); - editor->setIndenter(new Indenter); + editor->baseTextDocument()->setIndenter(new Indenter); editor->setAutoCompleter(new AutoCompleter); } diff --git a/src/plugins/qmljstools/qmljscodestylesettingspage.cpp b/src/plugins/qmljstools/qmljscodestylesettingspage.cpp index a6ff258beb..e4094a3ac7 100644 --- a/src/plugins/qmljstools/qmljscodestylesettingspage.cpp +++ b/src/plugins/qmljstools/qmljscodestylesettingspage.cpp @@ -139,8 +139,8 @@ void QmlJSCodeStylePreferencesWidget::updatePreview() QTextCursor tc = m_ui->previewTextEdit->textCursor(); tc.beginEditBlock(); while (block.isValid()) { - m_ui->previewTextEdit->indenter()->indentBlock(doc, block, QChar::Null, ts); - + m_ui->previewTextEdit->baseTextDocument()->indenter() + ->indentBlock(doc, block, QChar::Null, ts); block = block.next(); } tc.endEditBlock(); diff --git a/src/plugins/texteditor/basetextdocument.cpp b/src/plugins/texteditor/basetextdocument.cpp index adba636f4f..b3b82d07ca 100644 --- a/src/plugins/texteditor/basetextdocument.cpp +++ b/src/plugins/texteditor/basetextdocument.cpp @@ -32,12 +32,13 @@ #include "basetextdocumentlayout.h" #include "basetexteditor.h" #include "convenience.h" -#include "typingsettings.h" -#include "storagesettings.h" -#include "tabsettings.h" #include "extraencodingsettings.h" +#include "indenter.h" +#include "storagesettings.h" #include "syntaxhighlighter.h" +#include "tabsettings.h" #include "texteditorconstants.h" +#include "typingsettings.h" #include <QApplication> #include <QDir> @@ -68,6 +69,7 @@ public: ExtraEncodingSettings m_extraEncodingSettings; QTextDocument *m_document; SyntaxHighlighter *m_highlighter; + QScopedPointer<Indenter> m_indenter; bool m_fileIsReadOnly; int m_autoSaveRevision; @@ -76,6 +78,7 @@ public: BaseTextDocumentPrivate::BaseTextDocumentPrivate(BaseTextDocument *q) : m_document(new QTextDocument(q)), m_highlighter(0), + m_indenter(new Indenter), m_fileIsReadOnly(false), m_autoSaveRevision(-1) { @@ -172,6 +175,22 @@ const ExtraEncodingSettings &BaseTextDocument::extraEncodingSettings() const return d->m_extraEncodingSettings; } +void BaseTextDocument::setIndenter(Indenter *indenter) +{ + // clear out existing code formatter data + for (QTextBlock it = document()->begin(); it.isValid(); it = it.next()) { + TextEditor::TextBlockUserData *userData = BaseTextDocumentLayout::testUserData(it); + if (userData) + userData->setCodeFormatterData(0); + } + d->m_indenter.reset(indenter); +} + +Indenter *BaseTextDocument::indenter() const +{ + return d->m_indenter.data(); +} + bool BaseTextDocument::isSaveAsAllowed() const { return true; diff --git a/src/plugins/texteditor/basetextdocument.h b/src/plugins/texteditor/basetextdocument.h index af6bb25333..443d4c51ee 100644 --- a/src/plugins/texteditor/basetextdocument.h +++ b/src/plugins/texteditor/basetextdocument.h @@ -41,13 +41,14 @@ QT_END_NAMESPACE namespace TextEditor { +class BaseTextDocumentPrivate; +class ExtraEncodingSettings; class ITextMarkable; -class TypingSettings; +class Indenter; class StorageSettings; -class TabSettings; -class ExtraEncodingSettings; class SyntaxHighlighter; -class BaseTextDocumentPrivate; +class TabSettings; +class TypingSettings; class TEXTEDITOR_EXPORT BaseTextDocument : public ITextEditorDocument { @@ -72,6 +73,9 @@ public: const TabSettings &tabSettings() const; const ExtraEncodingSettings &extraEncodingSettings() const; + void setIndenter(Indenter *indenter); + Indenter *indenter() const; + ITextMarkable *markableInterface() const; // IDocument implementation. diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index b75ed7afe1..868da2c262 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -1832,7 +1832,7 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e) QChar electricChar; if (d->m_document->typingSettings().m_autoIndent) { foreach (QChar c, text) { - if (d->m_indenter->isElectricCharacter(c)) { + if (d->m_document->indenter()->isElectricCharacter(c)) { electricChar = c; break; } @@ -2311,22 +2311,6 @@ int BaseTextEditorWidget::visibleWrapColumn() const return d->m_visibleWrapColumn; } -void BaseTextEditorWidget::setIndenter(Indenter *indenter) -{ - // clear out existing code formatter data - for (QTextBlock it = document()->begin(); it.isValid(); it = it.next()) { - TextEditor::TextBlockUserData *userData = BaseTextDocumentLayout::testUserData(it); - if (userData) - userData->setCodeFormatterData(0); - } - d->m_indenter.reset(indenter); -} - -Indenter *BaseTextEditorWidget::indenter() const -{ - return d->m_indenter.data(); -} - void BaseTextEditorWidget::setAutoCompleter(AutoCompleter *autoCompleter) { d->m_autoCompleter.reset(autoCompleter); @@ -2385,7 +2369,6 @@ BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate() m_cursorBlockNumber(-1), m_markDragging(false), m_autoCompleter(new AutoCompleter), - m_indenter(new Indenter), m_clipboardAssistProvider(new Internal::ClipboardAssistProvider) { } @@ -4446,7 +4429,7 @@ Core::Id BaseTextEditorWidget::languageSettingsId() const void BaseTextEditorWidget::setCodeStyle(ICodeStylePreferences *preferences) { - indenter()->setCodeStylePreferences(preferences); + baseTextDocument()->indenter()->setCodeStylePreferences(preferences); if (d->m_codeStylePreferences) { disconnect(d->m_codeStylePreferences, SIGNAL(currentTabSettingsChanged(TextEditor::TabSettings)), this, SLOT(setTabSettings(TextEditor::TabSettings))); @@ -4696,13 +4679,13 @@ void BaseTextEditorWidget::indentInsertedText(const QTextCursor &tc) void BaseTextEditorWidget::indent(QTextDocument *doc, const QTextCursor &cursor, QChar typedChar) { maybeClearSomeExtraSelections(cursor); - d->m_indenter->indent(doc, cursor, typedChar, tabSettings()); + d->m_document->indenter()->indent(doc, cursor, typedChar, tabSettings()); } void BaseTextEditorWidget::reindent(QTextDocument *doc, const QTextCursor &cursor) { maybeClearSomeExtraSelections(cursor); - d->m_indenter->reindent(doc, cursor, tabSettings()); + d->m_document->indenter()->reindent(doc, cursor, tabSettings()); } BaseTextEditorWidget::Link BaseTextEditorWidget::findLinkAt(const QTextCursor &, bool, bool) diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index d1105b3658..cf3dea8042 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -216,9 +216,6 @@ public: QRegion translatedLineRegion(int lineStart, int lineEnd) const; - void setIndenter(Indenter *indenter); - Indenter *indenter() const; - void setAutoCompleter(AutoCompleter *autoCompleter); AutoCompleter *autoCompleter() const; diff --git a/src/plugins/texteditor/basetexteditor_p.h b/src/plugins/texteditor/basetexteditor_p.h index 7af359af12..f0395db908 100644 --- a/src/plugins/texteditor/basetexteditor_p.h +++ b/src/plugins/texteditor/basetexteditor_p.h @@ -227,7 +227,6 @@ public: bool m_markDragging; QScopedPointer<AutoCompleter> m_autoCompleter; - QScopedPointer<Indenter> m_indenter; QScopedPointer<Internal::ClipboardAssistProvider> m_clipboardAssistProvider; }; diff --git a/src/plugins/texteditor/codestyleeditor.cpp b/src/plugins/texteditor/codestyleeditor.cpp index 838562b904..c9a738316c 100644 --- a/src/plugins/texteditor/codestyleeditor.cpp +++ b/src/plugins/texteditor/codestyleeditor.cpp @@ -93,14 +93,14 @@ void CodeStyleEditor::updatePreview() { QTextDocument *doc = m_preview->document(); - m_preview->indenter()->invalidateCache(doc); + m_preview->baseTextDocument()->indenter()->invalidateCache(doc); QTextBlock block = doc->firstBlock(); QTextCursor tc = m_preview->textCursor(); tc.beginEditBlock(); while (block.isValid()) { - m_preview->indenter()->indentBlock(doc, block, QChar::Null, m_codeStyle->currentTabSettings()); - + m_preview->baseTextDocument()->indenter() + ->indentBlock(doc, block, QChar::Null, m_codeStyle->currentTabSettings()); block = block.next(); } tc.endEditBlock(); diff --git a/src/plugins/texteditor/plaintexteditor.cpp b/src/plugins/texteditor/plaintexteditor.cpp index 2bb532df12..2beb3c538d 100644 --- a/src/plugins/texteditor/plaintexteditor.cpp +++ b/src/plugins/texteditor/plaintexteditor.cpp @@ -60,6 +60,8 @@ PlainTextEditor::PlainTextEditor(PlainTextEditorWidget *editor) PlainTextEditorWidget::PlainTextEditorWidget(QWidget *parent) : BaseTextEditorWidget(parent) { + // Currently only "normal" indentation is supported. + baseTextDocument()->setIndenter(new NormalIndenter); ctor(); } @@ -81,7 +83,6 @@ void PlainTextEditorWidget::ctor() setRevisionsVisible(true); setMarksVisible(true); setLineSeparatorsAllowed(true); - setIndenter(new NormalIndenter); // Currently only "normal" indentation is supported. baseTextDocument()->setMimeType(QLatin1String(TextEditor::Constants::C_TEXTEDITOR_MIMETYPE_TEXT)); |