TextEditor: Replace PlainTextDocument by Base + a setup function

Change-Id: I1088062d0b74fd0dd69e92c55cc8bb80da61ae2d
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
hjk
2014-07-30 12:33:12 +02:00
parent d90bd09499
commit 068462e52d
11 changed files with 45 additions and 40 deletions

View File

@@ -33,17 +33,15 @@
#include <coreplugin/editormanager/ieditor.h> #include <coreplugin/editormanager/ieditor.h>
#include <QDir> #include <QFileInfo>
#include <QDomDocument>
using namespace Android; using namespace Android;
using namespace Android::Internal; using namespace Android::Internal;
AndroidManifestDocument::AndroidManifestDocument(AndroidManifestEditorWidget *editorWidget) AndroidManifestDocument::AndroidManifestDocument(AndroidManifestEditorWidget *editorWidget)
: TextEditor::PlainTextDocument(), : m_editorWidget(editorWidget)
m_editorWidget(editorWidget)
{ {
setupAsPlainTextDocument();
setId(Constants::ANDROID_MANIFEST_EDITOR_ID); setId(Constants::ANDROID_MANIFEST_EDITOR_ID);
setMimeType(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE)); setMimeType(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE));
connect(editorWidget, SIGNAL(guiChanged()), connect(editorWidget, SIGNAL(guiChanged()),

View File

@@ -30,14 +30,14 @@
#ifndef ANDROIDMANIFESTDOCUMENT_H #ifndef ANDROIDMANIFESTDOCUMENT_H
#define ANDROIDMANIFESTDOCUMENT_H #define ANDROIDMANIFESTDOCUMENT_H
#include <coreplugin/textdocument.h> #include <texteditor/basetexteditor.h>
#include <texteditor/plaintexteditor.h>
namespace Android { namespace Android {
namespace Internal { namespace Internal {
class AndroidManifestEditorWidget; class AndroidManifestEditorWidget;
class AndroidManifestDocument : public TextEditor::PlainTextDocument class AndroidManifestDocument : public TextEditor::BaseTextDocument
{ {
public: public:
explicit AndroidManifestDocument(AndroidManifestEditorWidget *editorWidget); explicit AndroidManifestDocument(AndroidManifestEditorWidget *editorWidget);

View File

@@ -32,7 +32,9 @@
#include "cpptoolsplugin.h" #include "cpptoolsplugin.h"
#include "cpptoolstestcase.h" #include "cpptoolstestcase.h"
#include <texteditor/plaintexteditor.h> #include <coreplugin/coreconstants.h>
#include <texteditor/basetexteditor.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
@@ -100,7 +102,10 @@ public:
QVERIFY(ast); QVERIFY(ast);
// Open file // 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(); editorWidget.setupAsPlainEditor();
QString error; QString error;
editorWidget.open(&error, document->fileName(), document->fileName()); editorWidget.open(&error, document->fileName(), document->fileName());
@@ -111,7 +116,7 @@ public:
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, cursorPosition); cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, cursorPosition);
editorWidget.setTextCursor(cursor); editorWidget.setTextCursor(cursor);
QTextDocument *textDocument = editorWidget.document(); QTextDocument *qtextDocument = editorWidget.document();
CppRefactoringFilePtr cppRefactoringFile CppRefactoringFilePtr cppRefactoringFile
= CppRefactoringChanges::file(&editorWidget, document); = CppRefactoringChanges::file(&editorWidget, document);
@@ -126,11 +131,11 @@ public:
Utils::ChangeSet change = formatter.format(ast); // ChangeSet may be empty. Utils::ChangeSet change = formatter.format(ast); // ChangeSet may be empty.
// Apply change // Apply change
QTextCursor changeCursor(textDocument); QTextCursor changeCursor(qtextDocument);
change.apply(&changeCursor); change.apply(&changeCursor);
// Compare // Compare
QCOMPARE(textDocument->toPlainText(), expectedSource); QCOMPARE(qtextDocument->toPlainText(), expectedSource);
} }
}; };

View File

@@ -56,6 +56,7 @@ FormWindowFile::FormWindowFile(QDesignerFormWindowInterface *form, QObject *pare
m_formWindow(form), m_formWindow(form),
m_isModified(false) m_isModified(false)
{ {
setupAsPlainTextDocument();
setMimeType(QLatin1String(Designer::Constants::FORM_MIMETYPE)); setMimeType(QLatin1String(Designer::Constants::FORM_MIMETYPE));
setParent(parent); setParent(parent);
setId(Core::Id(Designer::Constants::K_DESIGNER_XML_EDITOR_ID)); setId(Core::Id(Designer::Constants::K_DESIGNER_XML_EDITOR_ID));

View File

@@ -30,19 +30,18 @@
#ifndef FORMWINDOWFILE_H #ifndef FORMWINDOWFILE_H
#define FORMWINDOWFILE_H #define FORMWINDOWFILE_H
#include <texteditor/plaintexteditor.h> #include <texteditor/basetextdocument.h>
#include <QPointer> #include <QPointer>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QDesignerFormWindowInterface; class QDesignerFormWindowInterface;
class QFile;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Designer { namespace Designer {
namespace Internal { namespace Internal {
class FormWindowFile : public TextEditor::PlainTextDocument class FormWindowFile : public TextEditor::BaseTextDocument
{ {
Q_OBJECT Q_OBJECT

View File

@@ -41,12 +41,14 @@
#include "bardescriptoreditorpackageinformationwidget.h" #include "bardescriptoreditorpackageinformationwidget.h"
#include "bardescriptoreditorpermissionswidget.h" #include "bardescriptoreditorpermissionswidget.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <projectexplorer/panelswidget.h> #include <projectexplorer/panelswidget.h>
#include <projectexplorer/propertiespanel.h> #include <projectexplorer/propertiespanel.h>
#include <projectexplorer/task.h> #include <projectexplorer/task.h>
#include <projectexplorer/taskhub.h> #include <projectexplorer/taskhub.h>
#include <texteditor/plaintexteditor.h> #include <texteditor/basetextdocument.h>
#include <texteditor/basetexteditor.h>
#include <texteditor/texteditorsettings.h> #include <texteditor/texteditorsettings.h>
#include <texteditor/texteditorconstants.h> #include <texteditor/texteditorconstants.h>
#include <texteditor/normalindenter.h> #include <texteditor/normalindenter.h>
@@ -166,8 +168,11 @@ void BarDescriptorEditorWidget::initAssetsPage()
void BarDescriptorEditorWidget::initSourcePage() 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); doc->setIndenter(new TextEditor::NormalIndenter);
m_xmlSourceWidget = new TextEditor::BaseTextEditorWidget(doc, this); m_xmlSourceWidget = new TextEditor::BaseTextEditorWidget(doc, this);
m_xmlSourceWidget->setupAsPlainEditor(); m_xmlSourceWidget->setupAsPlainEditor();
addWidget(m_xmlSourceWidget); addWidget(m_xmlSourceWidget);

View File

@@ -40,6 +40,7 @@
#include "tabsettings.h" #include "tabsettings.h"
#include "texteditorconstants.h" #include "texteditorconstants.h"
#include "typingsettings.h" #include "typingsettings.h"
#include <texteditor/generichighlighter/highlighter.h>
#include <QApplication> #include <QApplication>
#include <QDir> #include <QDir>
@@ -49,6 +50,7 @@
#include <QStringList> #include <QStringList>
#include <QTextCodec> #include <QTextCodec>
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/progressmanager/progressmanager.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
@@ -80,6 +82,7 @@ public:
public slots: public slots:
void onModificationChanged(bool modified); void onModificationChanged(bool modified);
void updateTabSettings();
public: public:
QString m_defaultPath; QString m_defaultPath;
@@ -197,6 +200,12 @@ void BaseTextDocumentPrivate::onModificationChanged(bool modified)
updateRevisions(); updateRevisions();
} }
void BaseTextDocumentPrivate::updateTabSettings()
{
if (Highlighter *highlighter = qobject_cast<Highlighter *>(m_highlighter))
highlighter->setTabSettings(m_tabSettings);
}
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
// //
@@ -318,6 +327,11 @@ void BaseTextDocument::triggerPendingUpdates()
applyFontSettings(); applyFontSettings();
} }
void BaseTextDocument::setupAsPlainTextDocument()
{
connect(this, SIGNAL(tabSettingsChanged()), d, SLOT(updateTabSettings()));
}
void BaseTextDocument::applyFontSettings() void BaseTextDocument::applyFontSettings()
{ {
d->m_fontSettingsNeedsApply = false; d->m_fontSettingsNeedsApply = false;

View File

@@ -128,6 +128,8 @@ public:
virtual void triggerPendingUpdates(); virtual void triggerPendingUpdates();
void setupAsPlainTextDocument();
public slots: public slots:
void setTabSettings(const TextEditor::TabSettings &tabSettings); void setTabSettings(const TextEditor::TabSettings &tabSettings);
void setFontSettings(const TextEditor::FontSettings &fontSettings); void setFontSettings(const TextEditor::FontSettings &fontSettings);

View File

@@ -74,16 +74,4 @@ IEditor *PlainTextEditor::duplicate()
return newWidget->editor(); 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 } // namespace TextEditor

View File

@@ -43,15 +43,6 @@ public:
Core::IEditor *duplicate(); Core::IEditor *duplicate();
}; };
class TEXTEDITOR_EXPORT PlainTextDocument : public BaseTextDocument
{
Q_OBJECT
public:
PlainTextDocument();
private slots:
void updateTabSettings();
};
} // namespace TextEditor } // namespace TextEditor
#endif // PLAINTEXTEDITOR_H #endif // PLAINTEXTEDITOR_H

View File

@@ -61,7 +61,9 @@ PlainTextEditorFactory::PlainTextEditorFactory(QObject *parent)
Core::IEditor *PlainTextEditorFactory::createEditor() 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); doc->setIndenter(new NormalIndenter);
auto widget = new BaseTextEditorWidget(doc); auto widget = new BaseTextEditorWidget(doc);
widget->setupAsPlainEditor(); widget->setupAsPlainEditor();