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
|
// Open file
|
||||||
auto textDocument = new TextEditor::BaseTextDocument;
|
auto textDocument = new TextEditor::BaseTextDocument;
|
||||||
textDocument->setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
|
textDocument->setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
|
||||||
TextEditor::BaseTextEditorWidget editorWidget(textDocument);
|
TextEditor::BaseTextEditorWidget editorWidget(textDocument, 0);
|
||||||
editorWidget.setupAsPlainEditor();
|
editorWidget.setupAsPlainEditor();
|
||||||
QString error;
|
QString error;
|
||||||
editorWidget.open(&error, document->fileName(), document->fileName());
|
editorWidget.open(&error, document->fileName(), document->fileName());
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
DescriptionEditorWidget::DescriptionEditorWidget(QWidget *parent)
|
DescriptionEditorWidget::DescriptionEditorWidget(QWidget *parent)
|
||||||
: BaseTextEditorWidget(parent)
|
: BaseTextEditorWidget(new BaseTextDocument, parent)
|
||||||
{
|
{
|
||||||
DisplaySettings settings = displaySettings();
|
DisplaySettings settings = displaySettings();
|
||||||
settings.m_textWrapping = false;
|
settings.m_textWrapping = false;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "selectabletexteditorwidget.h"
|
#include "selectabletexteditorwidget.h"
|
||||||
|
#include <texteditor/basetextdocument.h>
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
@@ -35,7 +36,7 @@
|
|||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
|
|
||||||
SelectableTextEditorWidget::SelectableTextEditorWidget(QWidget *parent)
|
SelectableTextEditorWidget::SelectableTextEditorWidget(QWidget *parent)
|
||||||
: BaseTextEditorWidget(parent)
|
: BaseTextEditorWidget(new TextEditor::BaseTextDocument, parent)
|
||||||
{
|
{
|
||||||
setFrameStyle(QFrame::NoFrame);
|
setFrameStyle(QFrame::NoFrame);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,9 +64,9 @@ ProjectFilesFactory::ProjectFilesFactory(Manager *manager)
|
|||||||
|
|
||||||
Core::IEditor *ProjectFilesFactory::createEditor()
|
Core::IEditor *ProjectFilesFactory::createEditor()
|
||||||
{
|
{
|
||||||
ProjectFilesEditorWidget *ed = new ProjectFilesEditorWidget();
|
auto widget = new ProjectFilesEditorWidget(new BaseTextDocument, 0);
|
||||||
TextEditorSettings::initializeEditor(ed);
|
TextEditorSettings::initializeEditor(widget);
|
||||||
return ed->editor();
|
return widget->editor();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -85,10 +85,9 @@ ProjectFilesEditor::ProjectFilesEditor(ProjectFilesEditorWidget *editor)
|
|||||||
|
|
||||||
Core::IEditor *ProjectFilesEditor::duplicate()
|
Core::IEditor *ProjectFilesEditor::duplicate()
|
||||||
{
|
{
|
||||||
ProjectFilesEditorWidget *editor = new ProjectFilesEditorWidget(
|
auto widget = new ProjectFilesEditorWidget(editorWidget());
|
||||||
qobject_cast<ProjectFilesEditorWidget *>(editorWidget()));
|
TextEditorSettings::initializeEditor(widget);
|
||||||
TextEditorSettings::initializeEditor(editor);
|
return widget->editor();
|
||||||
return editor->editor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -97,12 +96,12 @@ Core::IEditor *ProjectFilesEditor::duplicate()
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ProjectFilesEditorWidget::ProjectFilesEditorWidget(QWidget *parent)
|
ProjectFilesEditorWidget::ProjectFilesEditorWidget(BaseTextDocument *doc, QWidget *parent)
|
||||||
: BaseTextEditorWidget(parent)
|
: BaseTextEditorWidget(doc, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectFilesEditorWidget::ProjectFilesEditorWidget(ProjectFilesEditorWidget *other)
|
ProjectFilesEditorWidget::ProjectFilesEditorWidget(BaseTextEditorWidget *other)
|
||||||
: BaseTextEditorWidget(other)
|
: BaseTextEditorWidget(other)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,13 +67,10 @@ class ProjectFilesEditorWidget : public TextEditor::BaseTextEditorWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ProjectFilesEditorWidget(QWidget *parent = 0);
|
ProjectFilesEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent);
|
||||||
ProjectFilesEditorWidget(ProjectFilesEditorWidget *other);
|
ProjectFilesEditorWidget(BaseTextEditorWidget *other);
|
||||||
|
|
||||||
TextEditor::BaseTextEditor *createEditor();
|
TextEditor::BaseTextEditor *createEditor();
|
||||||
|
|
||||||
private:
|
|
||||||
ProjectFilesEditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -140,11 +140,9 @@ void Document::addRange(const QTextCursor &cursor, GLSL::Scope *scope)
|
|||||||
_cursors.append(c);
|
_cursors.append(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
GlslEditorWidget::GlslEditorWidget(QWidget *parent)
|
GlslEditorWidget::GlslEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent)
|
||||||
: TextEditor::BaseTextEditorWidget(parent)
|
: TextEditor::BaseTextEditorWidget(doc, parent)
|
||||||
{
|
{
|
||||||
baseTextDocument()->setId(GLSLEditor::Constants::C_GLSLEDITOR_ID);
|
|
||||||
baseTextDocument()->setIndenter(new GLSLIndenter());
|
|
||||||
ctor();
|
ctor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,10 +178,6 @@ void GlslEditorWidget::ctor()
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
GlslEditorWidget::~GlslEditorWidget()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int GlslEditorWidget::editorRevision() const
|
int GlslEditorWidget::editorRevision() const
|
||||||
{
|
{
|
||||||
//return document()->revision();
|
//return document()->revision();
|
||||||
|
|||||||
@@ -86,9 +86,8 @@ class GlslEditorWidget : public TextEditor::BaseTextEditorWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GlslEditorWidget(QWidget *parent = 0);
|
GlslEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent);
|
||||||
GlslEditorWidget(GlslEditorWidget *other);
|
GlslEditorWidget(GlslEditorWidget *other);
|
||||||
~GlslEditorWidget();
|
|
||||||
|
|
||||||
int editorRevision() const;
|
int editorRevision() const;
|
||||||
bool isOutdated() const;
|
bool isOutdated() const;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include "glsleditor.h"
|
#include "glsleditor.h"
|
||||||
#include "glsleditorconstants.h"
|
#include "glsleditorconstants.h"
|
||||||
#include "glsleditorplugin.h"
|
#include "glsleditorplugin.h"
|
||||||
|
#include "glslindenter.h"
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <extensionsystem/pluginspec.h>
|
#include <extensionsystem/pluginspec.h>
|
||||||
@@ -65,7 +66,10 @@ GLSLEditorFactory::GLSLEditorFactory(QObject *parent)
|
|||||||
|
|
||||||
Core::IEditor *GLSLEditorFactory::createEditor()
|
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);
|
TextEditor::TextEditorSettings::initializeEditor(rc);
|
||||||
return rc->editor();
|
return rc->editor();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include "pythoneditorconstants.h"
|
#include "pythoneditorconstants.h"
|
||||||
#include "pythoneditorwidget.h"
|
#include "pythoneditorwidget.h"
|
||||||
#include "pythoneditorplugin.h"
|
#include "pythoneditorplugin.h"
|
||||||
|
#include "tools/pythonindenter.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
@@ -39,6 +40,8 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
using namespace TextEditor;
|
||||||
|
|
||||||
namespace PythonEditor {
|
namespace PythonEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -57,7 +60,10 @@ EditorFactory::EditorFactory(QObject *parent)
|
|||||||
|
|
||||||
Core::IEditor *EditorFactory::createEditor()
|
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);
|
TextEditor::TextEditorSettings::initializeEditor(widget);
|
||||||
|
|
||||||
return widget->editor();
|
return widget->editor();
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
|
|
||||||
#include "pythoneditorwidget.h"
|
#include "pythoneditorwidget.h"
|
||||||
#include "tools/pythonhighlighter.h"
|
#include "tools/pythonhighlighter.h"
|
||||||
#include "tools/pythonindenter.h"
|
|
||||||
#include "pythoneditor.h"
|
#include "pythoneditor.h"
|
||||||
#include "pythoneditorconstants.h"
|
#include "pythoneditorconstants.h"
|
||||||
|
|
||||||
@@ -48,11 +47,9 @@
|
|||||||
namespace PythonEditor {
|
namespace PythonEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
PythonEditorWidget::PythonEditorWidget(QWidget *parent)
|
PythonEditorWidget::PythonEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent)
|
||||||
: TextEditor::BaseTextEditorWidget(parent)
|
: TextEditor::BaseTextEditorWidget(doc, parent)
|
||||||
{
|
{
|
||||||
baseTextDocument()->setId(Constants::C_PYTHONEDITOR_ID);
|
|
||||||
baseTextDocument()->setIndenter(new PythonIndenter());
|
|
||||||
ctor();
|
ctor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class PythonEditorWidget : public TextEditor::BaseTextEditorWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PythonEditorWidget(QWidget *parent = 0);
|
PythonEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent);
|
||||||
PythonEditorWidget(PythonEditorWidget *other);
|
PythonEditorWidget(PythonEditorWidget *other);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -455,13 +455,6 @@ QString BaseTextEditorWidget::convertToPlainText(const QString &txt)
|
|||||||
|
|
||||||
static const char kTextBlockMimeType[] = "application/vnd.qtcreator.blocktext";
|
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)
|
BaseTextEditorWidget::BaseTextEditorWidget(BaseTextDocument *doc, QWidget *parent)
|
||||||
: QPlainTextEdit(parent)
|
: QPlainTextEdit(parent)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -225,8 +225,7 @@ class TEXTEDITOR_EXPORT BaseTextEditorWidget : public QPlainTextEdit
|
|||||||
Q_PROPERTY(int verticalBlockSelectionLastColumn READ verticalBlockSelectionLastColumn)
|
Q_PROPERTY(int verticalBlockSelectionLastColumn READ verticalBlockSelectionLastColumn)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BaseTextEditorWidget(QWidget *parent = 0);
|
BaseTextEditorWidget(BaseTextDocument *doc, QWidget *parent);
|
||||||
BaseTextEditorWidget(BaseTextDocument *doc, QWidget *parent = 0);
|
|
||||||
BaseTextEditorWidget(BaseTextEditorWidget *other);
|
BaseTextEditorWidget(BaseTextEditorWidget *other);
|
||||||
~BaseTextEditorWidget();
|
~BaseTextEditorWidget();
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ Core::IEditor *PlainTextEditorFactory::createEditor()
|
|||||||
auto doc = new BaseTextDocument;
|
auto doc = new BaseTextDocument;
|
||||||
doc->setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
|
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, 0);
|
||||||
widget->setupAsPlainEditor();
|
widget->setupAsPlainEditor();
|
||||||
TextEditorSettings::initializeEditor(widget);
|
TextEditorSettings::initializeEditor(widget);
|
||||||
connect(widget, SIGNAL(configured(Core::IEditor*)),
|
connect(widget, SIGNAL(configured(Core::IEditor*)),
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ SnippetEditor::SnippetEditor(SnippetEditorWidget *editor)
|
|||||||
setContext(Core::Context(Constants::SNIPPET_EDITOR_ID, Constants::C_TEXTEDITOR));
|
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);
|
baseTextDocument()->setId(Constants::SNIPPET_EDITOR_ID);
|
||||||
setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
|
setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
|
||||||
|
|||||||
@@ -648,7 +648,7 @@ QComboBox *VcsBaseEditorWidgetPrivate::entriesComboBox()
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
VcsBaseEditorWidget::VcsBaseEditorWidget(const VcsBaseEditorParameters *type, QWidget *parent)
|
VcsBaseEditorWidget::VcsBaseEditorWidget(const VcsBaseEditorParameters *type, QWidget *parent)
|
||||||
: BaseTextEditorWidget(parent),
|
: BaseTextEditorWidget(new TextEditor::BaseTextDocument, parent),
|
||||||
d(new Internal::VcsBaseEditorWidgetPrivate(this, type))
|
d(new Internal::VcsBaseEditorWidgetPrivate(this, type))
|
||||||
{
|
{
|
||||||
viewport()->setMouseTracking(true);
|
viewport()->setMouseTracking(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user