Commit 3ad38766 authored by Eike Ziller's avatar Eike Ziller

TextEditors: Move indenter to document.

Change-Id: I8bdf7134562d007aa16cc63a34f5a15a708577ae
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent 8772e6e8
......@@ -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);
......
......@@ -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);
}
......@@ -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();
}
......
......@@ -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();
}
......
......@@ -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);
......
......@@ -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());
}
......
......@@ -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);
......
......@@ -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);
}
......@@ -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();
......
......@@ -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;
......
......@@ -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.
......
......@@ -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)
......
......@@ -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;
......
......@@ -227,7 +227,6 @@ public:
bool m_markDragging;
QScopedPointer<AutoCompleter> m_autoCompleter;
QScopedPointer<Indenter> m_indenter;
QScopedPointer<Internal::ClipboardAssistProvider> m_clipboardAssistProvider;
};
......
......@@ -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();
......
......@@ -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));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment