Commit c5fae0e8 authored by hjk's avatar hjk

TextEditor: Further *Editor/*EditorWidget disentangling

In most cases, the *Editor constructor does not need to
access the *EditorWidget.

Change-Id: I1f5c076a0f723d5d82b398e8c250c7bd1d47eb17
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent d2ec7d80
......@@ -49,8 +49,7 @@ using namespace Android::Internal;
// JavaEditor
//
JavaEditor::JavaEditor(JavaEditorWidget *editor)
: BaseTextEditor(editor)
JavaEditor::JavaEditor()
{
setContext(Core::Context(Constants::C_JAVA_EDITOR,
TextEditor::Constants::C_TEXTEDITOR));
......@@ -78,7 +77,7 @@ JavaEditorWidget::JavaEditorWidget()
TextEditor::BaseTextEditor *JavaEditorWidget::createEditor()
{
return new JavaEditor(this);
return new JavaEditor;
}
//
......@@ -86,7 +85,6 @@ TextEditor::BaseTextEditor *JavaEditorWidget::createEditor()
//
JavaDocument::JavaDocument()
: TextEditor::BaseTextDocument()
{
setId(Constants::JAVA_EDITOR_ID);
setMimeType(QLatin1String(Constants::JAVA_MIMETYPE));
......
......@@ -38,14 +38,13 @@ namespace Android {
namespace Internal {
class JavaEditorFactory;
class JavaEditorWidget;
class JavaEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
JavaEditor(JavaEditorWidget *);
JavaEditor();
Core::IEditor *duplicate();
TextEditor::CompletionAssistProvider *completionAssistProvider();
......
......@@ -57,15 +57,13 @@ using namespace CMakeProjectManager::Internal;
// ProFileEditorEditable
//
CMakeEditor::CMakeEditor(CMakeEditorWidget *editor)
: BaseTextEditor(editor)
CMakeEditor::CMakeEditor()
{
setContext(Core::Context(CMakeProjectManager::Constants::C_CMAKEEDITOR,
TextEditor::Constants::C_TEXTEDITOR));
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::HashStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<CMakeFileCompletionAssistProvider>());
connect(document(), SIGNAL(changed()), this, SLOT(markAsChanged()));
}
Core::IEditor *CMakeEditor::duplicate()
......@@ -157,7 +155,9 @@ CMakeEditorWidget::CMakeEditorWidget()
TextEditor::BaseTextEditor *CMakeEditorWidget::createEditor()
{
return new CMakeEditor(this);
auto editor = new CMakeEditor;
connect(textDocument(), &Core::IDocument::changed, editor, &CMakeEditor::markAsChanged);
return editor;
}
void CMakeEditorWidget::contextMenuEvent(QContextMenuEvent *e)
......
......@@ -50,12 +50,13 @@ class CMakeEditor : public TextEditor::BaseTextEditor
Q_OBJECT
public:
CMakeEditor(CMakeEditorWidget *);
CMakeEditor();
Core::IEditor *duplicate();
QString contextHelpId() const;
friend class CMakeEditorWidget;
private slots:
void markAsChanged();
void build();
......
......@@ -105,8 +105,7 @@ QTimer *newSingleShotTimer(QObject *parent, int msecInterval)
namespace CppEditor {
namespace Internal {
CPPEditor::CPPEditor(CppEditorWidget *editor)
: BaseTextEditor(editor)
CPPEditor::CPPEditor()
{
m_context.add(CppEditor::Constants::C_CPPEDITOR);
m_context.add(ProjectExplorer::Constants::LANG_CXX);
......@@ -263,7 +262,7 @@ CppEditorOutline *CppEditorWidget::outline() const
TextEditor::BaseTextEditor *CppEditorWidget::createEditor()
{
return new CPPEditor(this);
return new CPPEditor;
}
void CppEditorWidget::paste()
......
......@@ -50,7 +50,6 @@ namespace CppEditor {
namespace Internal {
class CppEditorOutline;
class CppEditorWidget;
class CppEditorWidgetPrivate;
class FollowSymbolUnderCursor;
......@@ -59,7 +58,7 @@ class CPPEditor : public TextEditor::BaseTextEditor
Q_OBJECT
public:
CPPEditor(CppEditorWidget *);
CPPEditor();
Core::IEditor *duplicate() QTC_OVERRIDE;
......
......@@ -50,10 +50,10 @@ struct FormWindowEditorPrivate
Internal::DesignerXmlEditorWidget *m_widget;
};
FormWindowEditor::FormWindowEditor(Internal::DesignerXmlEditorWidget *editor) :
TextEditor::BaseTextEditor(editor),
d(new FormWindowEditorPrivate)
FormWindowEditor::FormWindowEditor(Internal::DesignerXmlEditorWidget *editor)
: d(new FormWindowEditorPrivate)
{
setEditorWidget(editor);
d->m_widget = editor;
setDuplicateSupported(true);
setContext(Core::Context(Designer::Constants::K_DESIGNER_XML_EDITOR_ID,
......
......@@ -83,12 +83,7 @@ public slots:
void setDisplaySettings(const DisplaySettings &ds);
protected:
BaseTextEditor *createEditor()
{
BaseTextEditor *editor = new BaseTextEditor(this);
editor->document()->setId("DiffEditor.DescriptionEditor");
return editor;
}
BaseTextEditor *createEditor() { return new BaseTextEditor; }
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
......@@ -103,7 +98,7 @@ private:
DescriptionEditorWidget::DescriptionEditorWidget(QWidget *parent)
: BaseTextEditorWidget(parent)
{
setTextDocument(BaseTextDocumentPtr(new BaseTextDocument));
setSimpleTextDocument("DiffEditor.DescriptionEditor");
DisplaySettings settings = displaySettings();
settings.m_textWrapping = false;
settings.m_displayLineNumbers = false;
......
......@@ -63,7 +63,6 @@ public:
public:
DiffEditorController *controller() const;
// Core::IEditor
Core::IEditor *duplicate();
bool open(QString *errorString,
......
......@@ -38,13 +38,12 @@ namespace DiffEditor {
SelectableTextEditorWidget::SelectableTextEditorWidget(QWidget *parent)
: BaseTextEditorWidget(parent)
{
setTextDocument(TextEditor::BaseTextDocumentPtr(new TextEditor::BaseTextDocument));
setSimpleTextDocument("DiffEditor.UnifiedDiffEditor");
setFrameStyle(QFrame::NoFrame);
}
SelectableTextEditorWidget::~SelectableTextEditorWidget()
{
}
void SelectableTextEditorWidget::paintEvent(QPaintEvent *e)
......
......@@ -54,8 +54,7 @@ class DIFFEDITOR_EXPORT SelectableTextEditorWidget
public:
SelectableTextEditorWidget(QWidget *parent = 0);
~SelectableTextEditorWidget();
void setSelections(const QMap<int,
QList<DiffSelection> > &selections) {
void setSelections(const QMap<int, QList<DiffSelection> > &selections) {
m_selections = selections;
}
......
......@@ -78,10 +78,8 @@ class SideDiffEditor : public BaseTextEditor
{
Q_OBJECT
public:
SideDiffEditor(BaseTextEditorWidget *editorWidget)
: BaseTextEditor(editorWidget)
SideDiffEditor()
{
document()->setId("DiffEditor.SideDiffEditor");
connect(this, SIGNAL(tooltipRequested(TextEditor::BaseTextEditor*,QPoint,int)),
this, SLOT(slotTooltipRequested(TextEditor::BaseTextEditor*,QPoint,int)));
}
......@@ -170,7 +168,7 @@ protected:
return SelectableTextEditorWidget::extraAreaWidth(markWidthPtr);
}
void applyFontSettings();
BaseTextEditor *createEditor() { return new SideDiffEditor(this); }
BaseTextEditor *createEditor() { return new SideDiffEditor; }
virtual QString lineNumber(int blockNumber) const;
virtual int lineNumberDigits() const;
virtual bool selectionVisible(int blockNumber) const;
......@@ -326,6 +324,7 @@ SideDiffEditorWidget::SideDiffEditorWidget(QWidget *parent)
m_lineNumberDigits(1),
m_inPaintEvent(false)
{
textDocument()->setId("DiffEditor.SideDiffEditor");
DisplaySettings settings = displaySettings();
settings.m_textWrapping = false;
settings.m_displayLineNumbers = true;
......
......@@ -71,16 +71,6 @@ using namespace TextEditor;
namespace DiffEditor {
class UnifiedDiffEditor : public BaseTextEditor
{
Q_OBJECT
public:
UnifiedDiffEditor(BaseTextEditorWidget *editorWidget)
: BaseTextEditor(editorWidget) {
document()->setId("DiffEditor.UnifiedDiffEditor");
}
};
UnifiedDiffEditorWidget::UnifiedDiffEditorWidget(QWidget *parent)
: SelectableTextEditorWidget(parent)
, m_guiController(0)
......@@ -389,7 +379,7 @@ void UnifiedDiffEditorWidget::patch(int diffFileIndex, int chunkIndex, bool reve
TextEditor::BaseTextEditor *UnifiedDiffEditorWidget::createEditor()
{
return new UnifiedDiffEditor(this);
return new BaseTextEditor;
}
void UnifiedDiffEditorWidget::clear(const QString &message)
......@@ -844,5 +834,3 @@ void UnifiedDiffEditorWidget::setCurrentDiffFileIndex(int diffFileIndex)
}
} // namespace DiffEditor
#include "unifieddiffeditorwidget.moc"
......@@ -65,7 +65,7 @@ ProjectFilesFactory::ProjectFilesFactory(Manager *manager)
Core::IEditor *ProjectFilesFactory::createEditor()
{
auto widget = new ProjectFilesEditorWidget;
widget->setTextDocument(BaseTextDocumentPtr(new BaseTextDocument));
widget->setSimpleTextDocument(Constants::FILES_EDITOR_ID);
TextEditorSettings::initializeEditor(widget);
return widget->editor();
}
......@@ -76,10 +76,8 @@ Core::IEditor *ProjectFilesFactory::createEditor()
//
////////////////////////////////////////////////////////////////////////////////////////
ProjectFilesEditor::ProjectFilesEditor(ProjectFilesEditorWidget *editor)
: BaseTextEditor(editor)
ProjectFilesEditor::ProjectFilesEditor()
{
document()->setId(Constants::FILES_EDITOR_ID);
setContext(Core::Context(Constants::C_FILESEDITOR));
setDuplicateSupported(true);
}
......@@ -104,7 +102,7 @@ ProjectFilesEditorWidget::ProjectFilesEditorWidget()
BaseTextEditor *ProjectFilesEditorWidget::createEditor()
{
return new ProjectFilesEditor(this);
return new ProjectFilesEditor;
}
} // namespace Internal
......
......@@ -65,7 +65,7 @@ class ProjectFilesEditor : public TextEditor::BaseTextEditor
Q_OBJECT
public:
ProjectFilesEditor(ProjectFilesEditorWidget *editorWidget);
ProjectFilesEditor();
Core::IEditor *duplicate();
};
......
......@@ -232,7 +232,7 @@ QString GlslEditorWidget::wordUnderCursor() const
TextEditor::BaseTextEditor *GlslEditorWidget::createEditor()
{
return new GlslEditor(this);
return new GlslEditor;
}
void GlslEditorWidget::updateDocument()
......
......@@ -41,8 +41,7 @@
namespace GLSLEditor {
namespace Internal {
GlslEditor::GlslEditor(GlslEditorWidget *editor)
: BaseTextEditor(editor)
GlslEditor::GlslEditor()
{
setContext(Core::Context(GLSLEditor::Constants::C_GLSLEDITOR_ID,
TextEditor::Constants::C_TEXTEDITOR));
......
......@@ -35,14 +35,12 @@
namespace GLSLEditor {
namespace Internal {
class GlslEditorWidget;
class GlslEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
explicit GlslEditor(GlslEditorWidget *);
GlslEditor();
Core::IEditor *duplicate();
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
......
......@@ -47,8 +47,7 @@
namespace PythonEditor {
namespace Internal {
PythonEditor::PythonEditor(PythonEditorWidget *editorWidget)
:BaseTextEditor(editorWidget)
PythonEditor::PythonEditor()
{
setContext(Core::Context(Constants::C_PYTHONEDITOR_ID,
TextEditor::Constants::C_TEXTEDITOR));
......
......@@ -35,14 +35,12 @@
namespace PythonEditor {
namespace Internal {
class PythonEditorWidget;
class PythonEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
explicit PythonEditor(PythonEditorWidget *editorWidget);
PythonEditor();
Core::IEditor *duplicate();
......
......@@ -59,7 +59,7 @@ PythonEditorWidget::PythonEditorWidget(TextEditor::BaseTextDocumentPtr doc)
TextEditor::BaseTextEditor *PythonEditorWidget::createEditor()
{
return new PythonEditor(this);
return new PythonEditor;
}
} // namespace Internal
......
......@@ -52,8 +52,7 @@ namespace Internal {
// ProFileEditor
//
ProFileEditor::ProFileEditor(ProFileEditorWidget *editor)
: BaseTextEditor(editor)
ProFileEditor::ProFileEditor()
{
setContext(Core::Context(Constants::C_PROFILEEDITOR,
TextEditor::Constants::C_TEXTEDITOR));
......@@ -167,7 +166,7 @@ ProFileEditorWidget::Link ProFileEditorWidget::findLinkAt(const QTextCursor &cur
TextEditor::BaseTextEditor *ProFileEditorWidget::createEditor()
{
return new ProFileEditor(this);
return new ProFileEditor;
}
void ProFileEditorWidget::contextMenuEvent(QContextMenuEvent *e)
......@@ -180,7 +179,6 @@ void ProFileEditorWidget::contextMenuEvent(QContextMenuEvent *e)
//
ProFileDocument::ProFileDocument()
: TextEditor::BaseTextDocument()
{
setId(Constants::PROFILE_EDITOR_ID);
setMimeType(QLatin1String(Constants::PROFILE_MIMETYPE));
......
......@@ -45,7 +45,7 @@ class ProFileEditor : public TextEditor::BaseTextEditor
Q_OBJECT
public:
ProFileEditor(ProFileEditorWidget *);
ProFileEditor();
Core::IEditor *duplicate();
};
......
......@@ -98,7 +98,6 @@ namespace QmlJSEditor {
namespace Internal {
QmlJSTextEditorWidget::QmlJSTextEditorWidget(TextEditor::BaseTextDocumentPtr doc)
: TextEditor::BaseTextEditorWidget(0)
{
setTextDocument(doc);
......@@ -151,6 +150,7 @@ QmlJSTextEditorWidget::QmlJSTextEditorWidget(TextEditor::BaseTextDocumentPtr doc
SLOT(onRefactorMarkerClicked(TextEditor::RefactorMarker)));
setRequestMarkEnabled(true);
createToolBar();
}
QmlJSTextEditorWidget::~QmlJSTextEditorWidget()
......@@ -529,12 +529,10 @@ bool QmlJSTextEditorWidget::isClosingBrace(const QList<Token> &tokens) const
TextEditor::BaseTextEditor *QmlJSTextEditorWidget::createEditor()
{
QmlJSEditor *editable = new QmlJSEditor(this);
createToolBar(editable);
return editable;
return new QmlJSEditor;
}
void QmlJSTextEditorWidget::createToolBar(QmlJSEditor *editor)
void QmlJSTextEditorWidget::createToolBar()
{
m_outlineCombo = new QComboBox;
m_outlineCombo->setMinimumContentsLength(22);
......@@ -568,7 +566,7 @@ void QmlJSTextEditorWidget::createToolBar(QmlJSEditor *editor)
connect(this, SIGNAL(cursorPositionChanged()), m_updateOutlineIndexTimer, SLOT(start()));
editor->editorWidget()->insertExtraToolBarWidget(TextEditor::BaseTextEditorWidget::Left, m_outlineCombo);
insertExtraToolBarWidget(TextEditor::BaseTextEditorWidget::Left, m_outlineCombo);
}
TextEditor::BaseTextEditorWidget::Link QmlJSTextEditorWidget::findLinkAt(const QTextCursor &cursor,
......
......@@ -116,7 +116,7 @@ protected:
void scrollContentsBy(int dx, int dy);
void applyFontSettings();
TextEditor::BaseTextEditor *createEditor();
void createToolBar(QmlJSEditor *editable);
void createToolBar();
TextEditor::BaseTextEditorWidget::Link findLinkAt(const QTextCursor &cursor,
bool resolveTarget = true,
bool inNextSplit = false);
......
......@@ -48,8 +48,7 @@
namespace QmlJSEditor {
namespace Internal {
QmlJSEditor::QmlJSEditor(QmlJSTextEditorWidget *editor)
: BaseTextEditor(editor)
QmlJSEditor::QmlJSEditor()
{
m_context.add(Constants::C_QMLJSEDITOR_ID);
m_context.add(TextEditor::Constants::C_TEXTEDITOR);
......
......@@ -44,7 +44,7 @@ class QmlJSEditor : public TextEditor::BaseTextEditor
Q_OBJECT
public:
explicit QmlJSEditor(QmlJSTextEditorWidget *);
QmlJSEditor();
Core::IEditor *duplicate();
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
......
......@@ -205,7 +205,7 @@ void BaseTextDocumentPrivate::onModificationChanged(bool modified)
//
///////////////////////////////////////////////////////////////////////
BaseTextDocument::BaseTextDocument()
BaseTextDocument::BaseTextDocument(Id id)
: d(new BaseTextDocumentPrivate(this))
{
connect(d->m_document, SIGNAL(modificationChanged(bool)), d, SLOT(onModificationChanged(bool)));
......@@ -221,6 +221,9 @@ BaseTextDocument::BaseTextDocument()
d->m_document->setDefaultTextOption(opt);
BaseTextDocumentLayout *documentLayout = new BaseTextDocumentLayout(d->m_document);
d->m_document->setDocumentLayout(documentLayout);
if (id.isValid())
setId(id);
}
BaseTextDocument::~BaseTextDocument()
......
......@@ -32,6 +32,7 @@
#include "texteditor_global.h"
#include <coreplugin/id.h>
#include <coreplugin/textdocument.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
......@@ -64,7 +65,7 @@ class TEXTEDITOR_EXPORT BaseTextDocument : public Core::TextDocument
Q_OBJECT
public:
BaseTextDocument();
explicit BaseTextDocument(Core::Id id = Core::Id());
virtual ~BaseTextDocument();
static QMap<QString, QString> openedTextDocumentContents();
......
......@@ -662,6 +662,11 @@ BaseTextEditorWidget::~BaseTextEditorWidget()
d = 0;
}
void BaseTextEditorWidget::setSimpleTextDocument(Id id)
{
setTextDocument(BaseTextDocumentPtr(new BaseTextDocument(id)));
}
void BaseTextEditorWidget::print(QPrinter *printer)
{
const bool oldFullPage = printer->fullPage();
......@@ -874,7 +879,10 @@ int BaseTextEditorWidgetPrivate::visualIndent(const QTextBlock &block) const
BaseTextEditor *BaseTextEditorWidget::editor() const
{
if (!d->m_editor) {
d->m_editor = const_cast<BaseTextEditorWidget *>(this)->createEditor();
auto that = const_cast<BaseTextEditorWidget *>(this);
d->m_editor = that->createEditor();
if (!d->m_editor->widget())
d->m_editor->setEditorWidget(that);
d->m_codeAssistant->configure(d->m_editor);
}
return d->m_editor;
......@@ -6473,7 +6481,8 @@ QColor BaseTextEditorWidget::replacementPenColor(int blockNumber) const
BaseTextEditor *BaseTextEditorWidget::createEditor()
{
auto editor = new BaseTextEditor(this);
auto editor = new BaseTextEditor;
editor->setEditorWidget(this);
editor->setContext(Core::Context(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID,
TextEditor::Constants::C_TEXTEDITOR));
editor->setDuplicateSupported(true);
......@@ -6510,13 +6519,16 @@ void BaseTextEditorWidget::appendStandardContextMenuActions(QMenu *menu)
}
BaseTextEditor::BaseTextEditor(BaseTextEditorWidget *widget)
BaseTextEditor::BaseTextEditor()
: d(new BaseTextEditorPrivate)
{
d->m_completionAssistProvider = [] () -> CompletionAssistProvider * { return 0; };
}
void BaseTextEditor::setEditorWidget(BaseTextEditorWidget *widget)
{
setWidget(widget);
d->m_editorWidget = widget;
d->m_completionAssistProvider = [] () -> CompletionAssistProvider * { return 0; };
}
BaseTextEditor::~BaseTextEditor()
......
......@@ -117,9 +117,11 @@ public:
EndOfDoc = 5
};
BaseTextEditor(BaseTextEditorWidget *editorWidget);
BaseTextEditor();
~BaseTextEditor();
void setEditorWidget(BaseTextEditorWidget *editorWidget);
enum MarkRequestKind {
BreakpointRequest,
BookmarkRequest,
......@@ -216,6 +218,7 @@ public:
~BaseTextEditorWidget();
void setTextDocument(const BaseTextDocumentPtr &doc);
void setSimpleTextDocument(Core::Id id); // Convenience.
BaseTextDocument *textDocument() const;
BaseTextDocumentPtr textDocumentPtr() const;
......
......@@ -43,8 +43,7 @@ using namespace TextEditor;
\ingroup Snippets
*/
SnippetEditor::SnippetEditor(SnippetEditorWidget *editor)
: BaseTextEditor(editor)
SnippetEditor::SnippetEditor()
{
setContext(Core::Context(Constants::SNIPPET_EDITOR_ID, Constants::C_TEXTEDITOR));
}
......@@ -77,5 +76,5 @@ void SnippetEditorWidget::focusOutEvent(QFocusEvent *event)
BaseTextEditor *SnippetEditorWidget::createEditor()
{
return new SnippetEditor(this);
return new SnippetEditor;
}
......@@ -46,7 +46,7 @@ class TEXTEDITOR_EXPORT SnippetEditor : public BaseTextEditor
Q_OBJECT
public:
SnippetEditor(SnippetEditorWidget *editorWidget);
SnippetEditor();
Core::IEditor *duplicate() { return 0; }
};
......
......@@ -155,7 +155,7 @@ class VcsBaseEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
VcsBaseEditor(VcsBaseEditorWidget *, const VcsBaseEditorParameters *type);
explicit VcsBaseEditor(const VcsBaseEditorParameters *type);
signals:
void describeRequested(const QString &source, const QString &change);
......@@ -163,9 +163,7 @@ signals:
const QString &change, int line);
};
VcsBaseEditor::VcsBaseEditor(VcsBaseEditorWidget *widget,
const VcsBaseEditorParameters *type) :
BaseTextEditor(widget)