Commit 068462e5 authored by hjk's avatar hjk

TextEditor: Replace PlainTextDocument by Base + a setup function

Change-Id: I1088062d0b74fd0dd69e92c55cc8bb80da61ae2d
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent d90bd094
......@@ -33,17 +33,15 @@
#include <coreplugin/editormanager/ieditor.h>
#include <QDir>
#include <QDomDocument>
#include <QFileInfo>
using namespace Android;
using namespace Android::Internal;
AndroidManifestDocument::AndroidManifestDocument(AndroidManifestEditorWidget *editorWidget)
: TextEditor::PlainTextDocument(),
m_editorWidget(editorWidget)
: m_editorWidget(editorWidget)
{
setupAsPlainTextDocument();
setId(Constants::ANDROID_MANIFEST_EDITOR_ID);
setMimeType(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE));
connect(editorWidget, SIGNAL(guiChanged()),
......
......@@ -30,14 +30,14 @@
#ifndef ANDROIDMANIFESTDOCUMENT_H
#define ANDROIDMANIFESTDOCUMENT_H
#include <coreplugin/textdocument.h>
#include <texteditor/plaintexteditor.h>
#include <texteditor/basetexteditor.h>
namespace Android {
namespace Internal {
class AndroidManifestEditorWidget;
class AndroidManifestDocument : public TextEditor::PlainTextDocument
class AndroidManifestDocument : public TextEditor::BaseTextDocument
{
public:
explicit AndroidManifestDocument(AndroidManifestEditorWidget *editorWidget);
......
......@@ -32,7 +32,9 @@
#include "cpptoolsplugin.h"
#include "cpptoolstestcase.h"
#include <texteditor/plaintexteditor.h>
#include <coreplugin/coreconstants.h>
#include <texteditor/basetexteditor.h>
#include <utils/fileutils.h>
......@@ -100,7 +102,10 @@ public:
QVERIFY(ast);
// Open file
TextEditor::BaseTextEditorWidget editorWidget(new TextEditor::PlainTextDocument);
auto textDocument = new TextEditor::BaseTextDocument;
textDocument->setupAsPlainTextDocument();
textDocument->setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
TextEditor::BaseTextEditorWidget editorWidget(textDocument);
editorWidget.setupAsPlainEditor();
QString error;
editorWidget.open(&error, document->fileName(), document->fileName());
......@@ -111,7 +116,7 @@ public:
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, cursorPosition);
editorWidget.setTextCursor(cursor);
QTextDocument *textDocument = editorWidget.document();
QTextDocument *qtextDocument = editorWidget.document();
CppRefactoringFilePtr cppRefactoringFile
= CppRefactoringChanges::file(&editorWidget, document);
......@@ -126,11 +131,11 @@ public:
Utils::ChangeSet change = formatter.format(ast); // ChangeSet may be empty.
// Apply change
QTextCursor changeCursor(textDocument);
QTextCursor changeCursor(qtextDocument);
change.apply(&changeCursor);
// Compare
QCOMPARE(textDocument->toPlainText(), expectedSource);
QCOMPARE(qtextDocument->toPlainText(), expectedSource);
}
};
......
......@@ -56,6 +56,7 @@ FormWindowFile::FormWindowFile(QDesignerFormWindowInterface *form, QObject *pare
m_formWindow(form),
m_isModified(false)
{
setupAsPlainTextDocument();
setMimeType(QLatin1String(Designer::Constants::FORM_MIMETYPE));
setParent(parent);
setId(Core::Id(Designer::Constants::K_DESIGNER_XML_EDITOR_ID));
......
......@@ -30,19 +30,18 @@
#ifndef FORMWINDOWFILE_H
#define FORMWINDOWFILE_H
#include <texteditor/plaintexteditor.h>
#include <texteditor/basetextdocument.h>
#include <QPointer>
QT_BEGIN_NAMESPACE
class QDesignerFormWindowInterface;
class QFile;
QT_END_NAMESPACE
namespace Designer {
namespace Internal {
class FormWindowFile : public TextEditor::PlainTextDocument
class FormWindowFile : public TextEditor::BaseTextDocument
{
Q_OBJECT
......
......@@ -41,12 +41,14 @@
#include "bardescriptoreditorpackageinformationwidget.h"
#include "bardescriptoreditorpermissionswidget.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
#include <projectexplorer/panelswidget.h>
#include <projectexplorer/propertiespanel.h>
#include <projectexplorer/task.h>
#include <projectexplorer/taskhub.h>
#include <texteditor/plaintexteditor.h>
#include <texteditor/basetextdocument.h>
#include <texteditor/basetexteditor.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/normalindenter.h>
......@@ -166,8 +168,11 @@ void BarDescriptorEditorWidget::initAssetsPage()
void BarDescriptorEditorWidget::initSourcePage()
{
auto doc = new TextEditor::PlainTextDocument;
auto doc = new TextEditor::BaseTextDocument;
doc->setupAsPlainTextDocument();
doc->setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID); // FIXME: This looks odd.
doc->setIndenter(new TextEditor::NormalIndenter);
m_xmlSourceWidget = new TextEditor::BaseTextEditorWidget(doc, this);
m_xmlSourceWidget->setupAsPlainEditor();
addWidget(m_xmlSourceWidget);
......
......@@ -40,6 +40,7 @@
#include "tabsettings.h"
#include "texteditorconstants.h"
#include "typingsettings.h"
#include <texteditor/generichighlighter/highlighter.h>
#include <QApplication>
#include <QDir>
......@@ -49,6 +50,7 @@
#include <QStringList>
#include <QTextCodec>
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <utils/qtcassert.h>
......@@ -80,6 +82,7 @@ public:
public slots:
void onModificationChanged(bool modified);
void updateTabSettings();
public:
QString m_defaultPath;
......@@ -197,6 +200,12 @@ void BaseTextDocumentPrivate::onModificationChanged(bool modified)
updateRevisions();
}
void BaseTextDocumentPrivate::updateTabSettings()
{
if (Highlighter *highlighter = qobject_cast<Highlighter *>(m_highlighter))
highlighter->setTabSettings(m_tabSettings);
}
///////////////////////////////////////////////////////////////////////
//
......@@ -318,6 +327,11 @@ void BaseTextDocument::triggerPendingUpdates()
applyFontSettings();
}
void BaseTextDocument::setupAsPlainTextDocument()
{
connect(this, SIGNAL(tabSettingsChanged()), d, SLOT(updateTabSettings()));
}
void BaseTextDocument::applyFontSettings()
{
d->m_fontSettingsNeedsApply = false;
......
......@@ -128,6 +128,8 @@ public:
virtual void triggerPendingUpdates();
void setupAsPlainTextDocument();
public slots:
void setTabSettings(const TextEditor::TabSettings &tabSettings);
void setFontSettings(const TextEditor::FontSettings &fontSettings);
......
......@@ -74,16 +74,4 @@ IEditor *PlainTextEditor::duplicate()
return newWidget->editor();
}
PlainTextDocument::PlainTextDocument()
{
setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
connect(this, SIGNAL(tabSettingsChanged()), this, SLOT(updateTabSettings()));
}
void PlainTextDocument::updateTabSettings()
{
if (Highlighter *highlighter = qobject_cast<Highlighter *>(syntaxHighlighter()))
highlighter->setTabSettings(tabSettings());
}
} // namespace TextEditor
......@@ -43,15 +43,6 @@ public:
Core::IEditor *duplicate();
};
class TEXTEDITOR_EXPORT PlainTextDocument : public BaseTextDocument
{
Q_OBJECT
public:
PlainTextDocument();
private slots:
void updateTabSettings();
};
} // namespace TextEditor
#endif // PLAINTEXTEDITOR_H
......@@ -61,7 +61,9 @@ PlainTextEditorFactory::PlainTextEditorFactory(QObject *parent)
Core::IEditor *PlainTextEditorFactory::createEditor()
{
auto doc = new PlainTextDocument;
auto doc = new BaseTextDocument;
doc->setupAsPlainTextDocument();
doc->setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
doc->setIndenter(new NormalIndenter);
auto widget = new BaseTextEditorWidget(doc);
widget->setupAsPlainEditor();
......
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