Commit faa0e5b9 authored by hjk's avatar hjk

TextEditor: Replace PlainTextEditorWidget by Base + a setup function

Change-Id: I91a3bfb66a72e9234ca59f97d5260bbfc3ccb0d3
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent ce6f3477
......@@ -111,6 +111,7 @@ AndroidManifestEditorWidget::AndroidManifestEditorWidget()
m_appNameInStringsXml(false)
{
m_textEditorWidget = new AndroidManifestTextEditorWidget(this);
m_textEditorWidget->setupAsPlainEditor();
TextEditor::TextEditorSettings::initializeEditor(m_textEditorWidget);
initializePage();
......@@ -619,7 +620,7 @@ Core::IEditor *AndroidManifestEditorWidget::editor() const
return m_editor;
}
TextEditor::PlainTextEditorWidget *AndroidManifestEditorWidget::textEditorWidget() const
TextEditor::BaseTextEditorWidget *AndroidManifestEditorWidget::textEditorWidget() const
{
return m_textEditorWidget;
}
......@@ -1421,9 +1422,10 @@ int PermissionsModel::rowCount(const QModelIndex &parent) const
AndroidManifestTextEditorWidget::AndroidManifestTextEditorWidget(AndroidManifestEditorWidget *parent)
: TextEditor::PlainTextEditorWidget(new AndroidManifestDocument(parent), parent),
: TextEditor::BaseTextEditorWidget(new AndroidManifestDocument(parent), parent),
m_parent(parent)
{
setupAsPlainEditor();
baseTextDocument()->setMimeType(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE));
}
......@@ -80,7 +80,7 @@ private:
QStringList m_permissions;
};
class AndroidManifestTextEditorWidget : public TextEditor::PlainTextEditorWidget
class AndroidManifestTextEditorWidget : public TextEditor::BaseTextEditorWidget
{
public:
AndroidManifestTextEditorWidget(AndroidManifestEditorWidget *parent = 0);
......@@ -109,7 +109,7 @@ public:
void preSave();
Core::IEditor *editor() const;
TextEditor::PlainTextEditorWidget *textEditorWidget() const;
TextEditor::BaseTextEditorWidget *textEditorWidget() const;
public slots:
void setDirty(bool dirty = true);
......@@ -193,7 +193,7 @@ private:
QComboBox *m_permissionsComboBox;
QTimer m_timerParseCheck;
TextEditor::PlainTextEditorWidget *m_textEditorWidget;
TextEditor::BaseTextEditorWidget *m_textEditorWidget;
QStackedWidget *m_stackedWidget;
AndroidManifestEditor *m_editor;
};
......
......@@ -100,20 +100,20 @@ public:
QVERIFY(ast);
// Open file
QScopedPointer<TextEditor::BaseTextEditorWidget> editorWidget(
new TextEditor::PlainTextEditorWidget(new TextEditor::PlainTextDocument));
TextEditor::BaseTextEditorWidget editorWidget(new TextEditor::PlainTextDocument);
editorWidget.setupAsPlainEditor();
QString error;
editorWidget->open(&error, document->fileName(), document->fileName());
editorWidget.open(&error, document->fileName(), document->fileName());
QVERIFY(error.isEmpty());
// Set cursor position
QTextCursor cursor = editorWidget->textCursor();
QTextCursor cursor = editorWidget.textCursor();
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, cursorPosition);
editorWidget->setTextCursor(cursor);
editorWidget.setTextCursor(cursor);
QTextDocument *textDocument = editorWidget->document();
QTextDocument *textDocument = editorWidget.document();
CppRefactoringFilePtr cppRefactoringFile
= CppRefactoringChanges::file(editorWidget.data(), document);
= CppRefactoringChanges::file(&editorWidget, document);
// Prepare for formatting
Overview overview;
......
......@@ -39,9 +39,10 @@ namespace Internal {
DesignerXmlEditorWidget::DesignerXmlEditorWidget(QDesignerFormWindowInterface *form,
QWidget *parent) :
TextEditor::PlainTextEditorWidget(new FormWindowFile(form), parent),
TextEditor::BaseTextEditorWidget(new FormWindowFile(form), parent),
m_designerEditor(new FormWindowEditor(this))
{
setupAsPlainEditor();
setReadOnly(true);
configureMimeType(baseTextDocument()->mimeType());
}
......
......@@ -53,7 +53,7 @@ namespace Internal {
* Internally manages a FormWindowEditor and uses the plain text
* editable embedded in it. */
class DesignerXmlEditorWidget : public TextEditor::PlainTextEditorWidget
class DesignerXmlEditorWidget : public TextEditor::BaseTextEditorWidget
{
Q_OBJECT
public:
......
......@@ -168,7 +168,8 @@ void BarDescriptorEditorWidget::initSourcePage()
{
auto doc = new TextEditor::PlainTextDocument;
doc->setIndenter(new TextEditor::NormalIndenter);
m_xmlSourceWidget = new TextEditor::PlainTextEditorWidget(doc, this);
m_xmlSourceWidget = new TextEditor::BaseTextEditorWidget(doc, this);
m_xmlSourceWidget->setupAsPlainEditor();
addWidget(m_xmlSourceWidget);
TextEditor::TextEditorSettings::initializeEditor(m_xmlSourceWidget);
......
......@@ -40,10 +40,7 @@ namespace Core { class IEditor; }
namespace ProjectExplorer { class PanelsWidget; }
namespace TextEditor {
class PlainTextEditorWidget;
class BaseTextEditorWidget;
}
namespace TextEditor { class BaseTextEditorWidget; }
namespace Qnx {
namespace Internal {
......@@ -97,7 +94,7 @@ private:
BarDescriptorEditorAssetsWidget *m_assetsWidget;
TextEditor::PlainTextEditorWidget *m_xmlSourceWidget;
TextEditor::BaseTextEditorWidget *m_xmlSourceWidget;
};
......
......@@ -48,6 +48,7 @@
#include "circularclipboard.h"
#include "circularclipboardassist.h"
#include "highlighterutils.h"
#include "plaintexteditor.h"
#include <texteditor/codeassist/codeassistant.h>
#include <texteditor/codeassist/defaultassistinterface.h>
#include <texteditor/generichighlighter/context.h>
......@@ -6364,6 +6365,11 @@ QColor BaseTextEditorWidget::replacementPenColor(int blockNumber) const
return QColor();
}
BaseTextEditor *BaseTextEditorWidget::createEditor()
{
return new PlainTextEditor(this);
}
void BaseTextEditorWidget::appendStandardContextMenuActions(QMenu *menu)
{
menu->addSeparator();
......@@ -7001,6 +7007,20 @@ void BaseTextEditorWidget::configureMimeType()
configureMimeType(mimeType);
}
// The remnants of PlainTextEditor.
void BaseTextEditorWidget::setupAsPlainEditor()
{
setRevisionsVisible(true);
setMarksVisible(true);
setLineSeparatorsAllowed(true);
baseTextDocument()->setMimeType(QLatin1String(TextEditor::Constants::C_TEXTEDITOR_MIMETYPE_TEXT));
connect(baseTextDocument(), SIGNAL(filePathChanged(QString,QString)),
this, SLOT(configureMimeType()));
connect(Manager::instance(), SIGNAL(mimeTypesRegistered()), this, SLOT(configureMimeType()));
}
} // namespace TextEditor
......
......@@ -514,7 +514,7 @@ protected:
virtual bool replacementVisible(int blockNumber) const;
virtual QColor replacementPenColor(int blockNumber) const;
virtual BaseTextEditor *createEditor() = 0;
virtual BaseTextEditor *createEditor();
virtual void triggerPendingUpdates();
virtual void applyFontSettings();
......@@ -550,6 +550,8 @@ public:
QString selectedText() const;
void setupAsPlainEditor();
protected:
/*!
Reimplement this function to enable code navigation.
......
......@@ -58,7 +58,7 @@ using namespace TextEditor::Internal;
namespace TextEditor {
PlainTextEditor::PlainTextEditor(PlainTextEditorWidget *editor)
PlainTextEditor::PlainTextEditor(BaseTextEditorWidget *editor)
: BaseTextEditor(editor)
{
setContext(Core::Context(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID,
......@@ -66,35 +66,10 @@ PlainTextEditor::PlainTextEditor(PlainTextEditorWidget *editor)
setDuplicateSupported(true);
}
PlainTextEditorWidget::PlainTextEditorWidget(PlainTextDocument *doc, QWidget *parent)
: BaseTextEditorWidget(doc, parent)
{
ctor();
}
PlainTextEditorWidget::PlainTextEditorWidget(PlainTextEditorWidget *other)
: BaseTextEditorWidget(other)
{
ctor();
}
void PlainTextEditorWidget::ctor()
{
setRevisionsVisible(true);
setMarksVisible(true);
setLineSeparatorsAllowed(true);
baseTextDocument()->setMimeType(QLatin1String(TextEditor::Constants::C_TEXTEDITOR_MIMETYPE_TEXT));
connect(baseTextDocument(), SIGNAL(filePathChanged(QString,QString)),
this, SLOT(configureMimeType()));
connect(Manager::instance(), SIGNAL(mimeTypesRegistered()), this, SLOT(configureMimeType()));
}
IEditor *PlainTextEditor::duplicate()
{
PlainTextEditorWidget *newWidget = new PlainTextEditorWidget(
qobject_cast<PlainTextEditorWidget *>(editorWidget()));
auto newWidget = new BaseTextEditorWidget(editorWidget());
newWidget->setupAsPlainEditor();
TextEditorSettings::initializeEditor(newWidget);
return newWidget->editor();
}
......
......@@ -34,13 +34,11 @@
namespace TextEditor {
class PlainTextEditorWidget;
class TEXTEDITOR_EXPORT PlainTextEditor : public BaseTextEditor
{
Q_OBJECT
public:
PlainTextEditor(PlainTextEditorWidget *);
PlainTextEditor(BaseTextEditorWidget *);
Core::IEditor *duplicate();
};
......@@ -54,23 +52,6 @@ private slots:
void updateTabSettings();
};
class TEXTEDITOR_EXPORT PlainTextEditorWidget : public BaseTextEditorWidget
{
Q_OBJECT
public:
PlainTextEditorWidget(PlainTextDocument *doc, QWidget *parent = 0);
PlainTextEditorWidget(PlainTextEditorWidget *other);
protected:
virtual BaseTextEditor *createEditor() { return new PlainTextEditor(this); }
private:
PlainTextEditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity
PlainTextEditorWidget(BaseTextDocument *, QWidget *); //avoid stupidity
void ctor();
};
} // namespace TextEditor
#endif // PLAINTEXTEDITOR_H
......@@ -63,7 +63,8 @@ Core::IEditor *PlainTextEditorFactory::createEditor()
{
auto doc = new PlainTextDocument;
doc->setIndenter(new NormalIndenter);
auto widget = new PlainTextEditorWidget(doc);
auto widget = new BaseTextEditorWidget(doc);
widget->setupAsPlainEditor();
TextEditorSettings::initializeEditor(widget);
connect(widget, SIGNAL(configured(Core::IEditor*)),
this, SLOT(updateEditorInfoBar(Core::IEditor*)));
......
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