forked from qt-creator/qt-creator
TextEditor: Remove one stack of EditorWidget constructors
There are conceptually only two: one that operates a new document, and one that shares one. Being explicit makes moving data over to the Editor hierarchy easier. Convenience can be re-added there, later. Change-Id: I9b34ff26628c99ffff01201dcf99332d5e7253e9 Reviewed-by: Christian Stenger <christian.stenger@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
@@ -104,7 +104,7 @@ public:
|
||||
// Open file
|
||||
auto textDocument = new TextEditor::BaseTextDocument;
|
||||
textDocument->setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
|
||||
TextEditor::BaseTextEditorWidget editorWidget(textDocument);
|
||||
TextEditor::BaseTextEditorWidget editorWidget(textDocument, 0);
|
||||
editorWidget.setupAsPlainEditor();
|
||||
QString error;
|
||||
editorWidget.open(&error, document->fileName(), document->fileName());
|
||||
|
||||
@@ -101,7 +101,7 @@ private:
|
||||
};
|
||||
|
||||
DescriptionEditorWidget::DescriptionEditorWidget(QWidget *parent)
|
||||
: BaseTextEditorWidget(parent)
|
||||
: BaseTextEditorWidget(new BaseTextDocument, parent)
|
||||
{
|
||||
DisplaySettings settings = displaySettings();
|
||||
settings.m_textWrapping = false;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "selectabletexteditorwidget.h"
|
||||
#include <texteditor/basetextdocument.h>
|
||||
|
||||
#include <QPainter>
|
||||
#include <QTextBlock>
|
||||
@@ -35,7 +36,7 @@
|
||||
namespace DiffEditor {
|
||||
|
||||
SelectableTextEditorWidget::SelectableTextEditorWidget(QWidget *parent)
|
||||
: BaseTextEditorWidget(parent)
|
||||
: BaseTextEditorWidget(new TextEditor::BaseTextDocument, parent)
|
||||
{
|
||||
setFrameStyle(QFrame::NoFrame);
|
||||
}
|
||||
|
||||
@@ -64,9 +64,9 @@ ProjectFilesFactory::ProjectFilesFactory(Manager *manager)
|
||||
|
||||
Core::IEditor *ProjectFilesFactory::createEditor()
|
||||
{
|
||||
ProjectFilesEditorWidget *ed = new ProjectFilesEditorWidget();
|
||||
TextEditorSettings::initializeEditor(ed);
|
||||
return ed->editor();
|
||||
auto widget = new ProjectFilesEditorWidget(new BaseTextDocument, 0);
|
||||
TextEditorSettings::initializeEditor(widget);
|
||||
return widget->editor();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -85,10 +85,9 @@ ProjectFilesEditor::ProjectFilesEditor(ProjectFilesEditorWidget *editor)
|
||||
|
||||
Core::IEditor *ProjectFilesEditor::duplicate()
|
||||
{
|
||||
ProjectFilesEditorWidget *editor = new ProjectFilesEditorWidget(
|
||||
qobject_cast<ProjectFilesEditorWidget *>(editorWidget()));
|
||||
TextEditorSettings::initializeEditor(editor);
|
||||
return editor->editor();
|
||||
auto widget = new ProjectFilesEditorWidget(editorWidget());
|
||||
TextEditorSettings::initializeEditor(widget);
|
||||
return widget->editor();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -97,12 +96,12 @@ Core::IEditor *ProjectFilesEditor::duplicate()
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ProjectFilesEditorWidget::ProjectFilesEditorWidget(QWidget *parent)
|
||||
: BaseTextEditorWidget(parent)
|
||||
ProjectFilesEditorWidget::ProjectFilesEditorWidget(BaseTextDocument *doc, QWidget *parent)
|
||||
: BaseTextEditorWidget(doc, parent)
|
||||
{
|
||||
}
|
||||
|
||||
ProjectFilesEditorWidget::ProjectFilesEditorWidget(ProjectFilesEditorWidget *other)
|
||||
ProjectFilesEditorWidget::ProjectFilesEditorWidget(BaseTextEditorWidget *other)
|
||||
: BaseTextEditorWidget(other)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -67,13 +67,10 @@ class ProjectFilesEditorWidget : public TextEditor::BaseTextEditorWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ProjectFilesEditorWidget(QWidget *parent = 0);
|
||||
ProjectFilesEditorWidget(ProjectFilesEditorWidget *other);
|
||||
ProjectFilesEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent);
|
||||
ProjectFilesEditorWidget(BaseTextEditorWidget *other);
|
||||
|
||||
TextEditor::BaseTextEditor *createEditor();
|
||||
|
||||
private:
|
||||
ProjectFilesEditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -140,11 +140,9 @@ void Document::addRange(const QTextCursor &cursor, GLSL::Scope *scope)
|
||||
_cursors.append(c);
|
||||
}
|
||||
|
||||
GlslEditorWidget::GlslEditorWidget(QWidget *parent)
|
||||
: TextEditor::BaseTextEditorWidget(parent)
|
||||
GlslEditorWidget::GlslEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent)
|
||||
: TextEditor::BaseTextEditorWidget(doc, parent)
|
||||
{
|
||||
baseTextDocument()->setId(GLSLEditor::Constants::C_GLSLEDITOR_ID);
|
||||
baseTextDocument()->setIndenter(new GLSLIndenter());
|
||||
ctor();
|
||||
}
|
||||
|
||||
@@ -180,10 +178,6 @@ void GlslEditorWidget::ctor()
|
||||
// }
|
||||
}
|
||||
|
||||
GlslEditorWidget::~GlslEditorWidget()
|
||||
{
|
||||
}
|
||||
|
||||
int GlslEditorWidget::editorRevision() const
|
||||
{
|
||||
//return document()->revision();
|
||||
|
||||
@@ -86,9 +86,8 @@ class GlslEditorWidget : public TextEditor::BaseTextEditorWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GlslEditorWidget(QWidget *parent = 0);
|
||||
GlslEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent);
|
||||
GlslEditorWidget(GlslEditorWidget *other);
|
||||
~GlslEditorWidget();
|
||||
|
||||
int editorRevision() const;
|
||||
bool isOutdated() const;
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "glsleditor.h"
|
||||
#include "glsleditorconstants.h"
|
||||
#include "glsleditorplugin.h"
|
||||
#include "glslindenter.h"
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <extensionsystem/pluginspec.h>
|
||||
@@ -65,7 +66,10 @@ GLSLEditorFactory::GLSLEditorFactory(QObject *parent)
|
||||
|
||||
Core::IEditor *GLSLEditorFactory::createEditor()
|
||||
{
|
||||
GlslEditorWidget *rc = new GlslEditorWidget();
|
||||
auto doc = new TextEditor::BaseTextDocument;
|
||||
doc->setId(C_GLSLEDITOR_ID);
|
||||
doc->setIndenter(new GLSLIndenter);
|
||||
GlslEditorWidget *rc = new GlslEditorWidget(doc, 0);
|
||||
TextEditor::TextEditorSettings::initializeEditor(rc);
|
||||
return rc->editor();
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "pythoneditorconstants.h"
|
||||
#include "pythoneditorwidget.h"
|
||||
#include "pythoneditorplugin.h"
|
||||
#include "tools/pythonindenter.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
@@ -39,6 +40,8 @@
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
using namespace TextEditor;
|
||||
|
||||
namespace PythonEditor {
|
||||
namespace Internal {
|
||||
|
||||
@@ -57,7 +60,10 @@ EditorFactory::EditorFactory(QObject *parent)
|
||||
|
||||
Core::IEditor *EditorFactory::createEditor()
|
||||
{
|
||||
PythonEditorWidget *widget = new PythonEditorWidget();
|
||||
auto doc = new BaseTextDocument;
|
||||
doc->setId(Constants::C_PYTHONEDITOR_ID);
|
||||
doc->setIndenter(new PythonIndenter);
|
||||
PythonEditorWidget *widget = new PythonEditorWidget(doc, 0);
|
||||
TextEditor::TextEditorSettings::initializeEditor(widget);
|
||||
|
||||
return widget->editor();
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
|
||||
#include "pythoneditorwidget.h"
|
||||
#include "tools/pythonhighlighter.h"
|
||||
#include "tools/pythonindenter.h"
|
||||
#include "pythoneditor.h"
|
||||
#include "pythoneditorconstants.h"
|
||||
|
||||
@@ -48,11 +47,9 @@
|
||||
namespace PythonEditor {
|
||||
namespace Internal {
|
||||
|
||||
PythonEditorWidget::PythonEditorWidget(QWidget *parent)
|
||||
: TextEditor::BaseTextEditorWidget(parent)
|
||||
PythonEditorWidget::PythonEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent)
|
||||
: TextEditor::BaseTextEditorWidget(doc, parent)
|
||||
{
|
||||
baseTextDocument()->setId(Constants::C_PYTHONEDITOR_ID);
|
||||
baseTextDocument()->setIndenter(new PythonIndenter());
|
||||
ctor();
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class PythonEditorWidget : public TextEditor::BaseTextEditorWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PythonEditorWidget(QWidget *parent = 0);
|
||||
PythonEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent);
|
||||
PythonEditorWidget(PythonEditorWidget *other);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -455,13 +455,6 @@ QString BaseTextEditorWidget::convertToPlainText(const QString &txt)
|
||||
|
||||
static const char kTextBlockMimeType[] = "application/vnd.qtcreator.blocktext";
|
||||
|
||||
BaseTextEditorWidget::BaseTextEditorWidget(QWidget *parent)
|
||||
: QPlainTextEdit(parent)
|
||||
{
|
||||
d = new BaseTextEditorWidgetPrivate(this);
|
||||
d->ctor(QSharedPointer<BaseTextDocument>(new BaseTextDocument));
|
||||
}
|
||||
|
||||
BaseTextEditorWidget::BaseTextEditorWidget(BaseTextDocument *doc, QWidget *parent)
|
||||
: QPlainTextEdit(parent)
|
||||
{
|
||||
|
||||
@@ -225,8 +225,7 @@ class TEXTEDITOR_EXPORT BaseTextEditorWidget : public QPlainTextEdit
|
||||
Q_PROPERTY(int verticalBlockSelectionLastColumn READ verticalBlockSelectionLastColumn)
|
||||
|
||||
public:
|
||||
BaseTextEditorWidget(QWidget *parent = 0);
|
||||
BaseTextEditorWidget(BaseTextDocument *doc, QWidget *parent = 0);
|
||||
BaseTextEditorWidget(BaseTextDocument *doc, QWidget *parent);
|
||||
BaseTextEditorWidget(BaseTextEditorWidget *other);
|
||||
~BaseTextEditorWidget();
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ Core::IEditor *PlainTextEditorFactory::createEditor()
|
||||
auto doc = new BaseTextDocument;
|
||||
doc->setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
|
||||
doc->setIndenter(new NormalIndenter);
|
||||
auto widget = new BaseTextEditorWidget(doc);
|
||||
auto widget = new BaseTextEditorWidget(doc, 0);
|
||||
widget->setupAsPlainEditor();
|
||||
TextEditorSettings::initializeEditor(widget);
|
||||
connect(widget, SIGNAL(configured(Core::IEditor*)),
|
||||
|
||||
@@ -49,7 +49,8 @@ SnippetEditor::SnippetEditor(SnippetEditorWidget *editor)
|
||||
setContext(Core::Context(Constants::SNIPPET_EDITOR_ID, Constants::C_TEXTEDITOR));
|
||||
}
|
||||
|
||||
SnippetEditorWidget::SnippetEditorWidget(QWidget *parent) : BaseTextEditorWidget(parent)
|
||||
SnippetEditorWidget::SnippetEditorWidget(QWidget *parent)
|
||||
: BaseTextEditorWidget(new BaseTextDocument, parent)
|
||||
{
|
||||
baseTextDocument()->setId(Constants::SNIPPET_EDITOR_ID);
|
||||
setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
|
||||
|
||||
@@ -648,7 +648,7 @@ QComboBox *VcsBaseEditorWidgetPrivate::entriesComboBox()
|
||||
*/
|
||||
|
||||
VcsBaseEditorWidget::VcsBaseEditorWidget(const VcsBaseEditorParameters *type, QWidget *parent)
|
||||
: BaseTextEditorWidget(parent),
|
||||
: BaseTextEditorWidget(new TextEditor::BaseTextDocument, parent),
|
||||
d(new Internal::VcsBaseEditorWidgetPrivate(this, type))
|
||||
{
|
||||
viewport()->setMouseTracking(true);
|
||||
|
||||
Reference in New Issue
Block a user