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; ...@@ -49,8 +49,7 @@ using namespace Android::Internal;
// JavaEditor // JavaEditor
// //
JavaEditor::JavaEditor(JavaEditorWidget *editor) JavaEditor::JavaEditor()
: BaseTextEditor(editor)
{ {
setContext(Core::Context(Constants::C_JAVA_EDITOR, setContext(Core::Context(Constants::C_JAVA_EDITOR,
TextEditor::Constants::C_TEXTEDITOR)); TextEditor::Constants::C_TEXTEDITOR));
...@@ -78,7 +77,7 @@ JavaEditorWidget::JavaEditorWidget() ...@@ -78,7 +77,7 @@ JavaEditorWidget::JavaEditorWidget()
TextEditor::BaseTextEditor *JavaEditorWidget::createEditor() TextEditor::BaseTextEditor *JavaEditorWidget::createEditor()
{ {
return new JavaEditor(this); return new JavaEditor;
} }
// //
...@@ -86,7 +85,6 @@ TextEditor::BaseTextEditor *JavaEditorWidget::createEditor() ...@@ -86,7 +85,6 @@ TextEditor::BaseTextEditor *JavaEditorWidget::createEditor()
// //
JavaDocument::JavaDocument() JavaDocument::JavaDocument()
: TextEditor::BaseTextDocument()
{ {
setId(Constants::JAVA_EDITOR_ID); setId(Constants::JAVA_EDITOR_ID);
setMimeType(QLatin1String(Constants::JAVA_MIMETYPE)); setMimeType(QLatin1String(Constants::JAVA_MIMETYPE));
......
...@@ -38,14 +38,13 @@ namespace Android { ...@@ -38,14 +38,13 @@ namespace Android {
namespace Internal { namespace Internal {
class JavaEditorFactory; class JavaEditorFactory;
class JavaEditorWidget;
class JavaEditor : public TextEditor::BaseTextEditor class JavaEditor : public TextEditor::BaseTextEditor
{ {
Q_OBJECT Q_OBJECT
public: public:
JavaEditor(JavaEditorWidget *); JavaEditor();
Core::IEditor *duplicate(); Core::IEditor *duplicate();
TextEditor::CompletionAssistProvider *completionAssistProvider(); TextEditor::CompletionAssistProvider *completionAssistProvider();
......
...@@ -57,15 +57,13 @@ using namespace CMakeProjectManager::Internal; ...@@ -57,15 +57,13 @@ using namespace CMakeProjectManager::Internal;
// ProFileEditorEditable // ProFileEditorEditable
// //
CMakeEditor::CMakeEditor(CMakeEditorWidget *editor) CMakeEditor::CMakeEditor()
: BaseTextEditor(editor)
{ {
setContext(Core::Context(CMakeProjectManager::Constants::C_CMAKEEDITOR, setContext(Core::Context(CMakeProjectManager::Constants::C_CMAKEEDITOR,
TextEditor::Constants::C_TEXTEDITOR)); TextEditor::Constants::C_TEXTEDITOR));
setDuplicateSupported(true); setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::HashStyle); setCommentStyle(Utils::CommentDefinition::HashStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<CMakeFileCompletionAssistProvider>()); setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<CMakeFileCompletionAssistProvider>());
connect(document(), SIGNAL(changed()), this, SLOT(markAsChanged()));
} }
Core::IEditor *CMakeEditor::duplicate() Core::IEditor *CMakeEditor::duplicate()
...@@ -157,7 +155,9 @@ CMakeEditorWidget::CMakeEditorWidget() ...@@ -157,7 +155,9 @@ CMakeEditorWidget::CMakeEditorWidget()
TextEditor::BaseTextEditor *CMakeEditorWidget::createEditor() 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) void CMakeEditorWidget::contextMenuEvent(QContextMenuEvent *e)
......
...@@ -50,12 +50,13 @@ class CMakeEditor : public TextEditor::BaseTextEditor ...@@ -50,12 +50,13 @@ class CMakeEditor : public TextEditor::BaseTextEditor
Q_OBJECT Q_OBJECT
public: public:
CMakeEditor(CMakeEditorWidget *); CMakeEditor();
Core::IEditor *duplicate(); Core::IEditor *duplicate();
QString contextHelpId() const; QString contextHelpId() const;
friend class CMakeEditorWidget;
private slots: private slots:
void markAsChanged(); void markAsChanged();
void build(); void build();
......
...@@ -105,8 +105,7 @@ QTimer *newSingleShotTimer(QObject *parent, int msecInterval) ...@@ -105,8 +105,7 @@ QTimer *newSingleShotTimer(QObject *parent, int msecInterval)
namespace CppEditor { namespace CppEditor {
namespace Internal { namespace Internal {
CPPEditor::CPPEditor(CppEditorWidget *editor) CPPEditor::CPPEditor()
: BaseTextEditor(editor)
{ {
m_context.add(CppEditor::Constants::C_CPPEDITOR); m_context.add(CppEditor::Constants::C_CPPEDITOR);
m_context.add(ProjectExplorer::Constants::LANG_CXX); m_context.add(ProjectExplorer::Constants::LANG_CXX);
...@@ -263,7 +262,7 @@ CppEditorOutline *CppEditorWidget::outline() const ...@@ -263,7 +262,7 @@ CppEditorOutline *CppEditorWidget::outline() const
TextEditor::BaseTextEditor *CppEditorWidget::createEditor() TextEditor::BaseTextEditor *CppEditorWidget::createEditor()
{ {
return new CPPEditor(this); return new CPPEditor;
} }
void CppEditorWidget::paste() void CppEditorWidget::paste()
......
...@@ -50,7 +50,6 @@ namespace CppEditor { ...@@ -50,7 +50,6 @@ namespace CppEditor {
namespace Internal { namespace Internal {
class CppEditorOutline; class CppEditorOutline;
class CppEditorWidget;
class CppEditorWidgetPrivate; class CppEditorWidgetPrivate;
class FollowSymbolUnderCursor; class FollowSymbolUnderCursor;
...@@ -59,7 +58,7 @@ class CPPEditor : public TextEditor::BaseTextEditor ...@@ -59,7 +58,7 @@ class CPPEditor : public TextEditor::BaseTextEditor
Q_OBJECT Q_OBJECT
public: public:
CPPEditor(CppEditorWidget *); CPPEditor();
Core::IEditor *duplicate() QTC_OVERRIDE; Core::IEditor *duplicate() QTC_OVERRIDE;
......
...@@ -50,10 +50,10 @@ struct FormWindowEditorPrivate ...@@ -50,10 +50,10 @@ struct FormWindowEditorPrivate
Internal::DesignerXmlEditorWidget *m_widget; Internal::DesignerXmlEditorWidget *m_widget;
}; };
FormWindowEditor::FormWindowEditor(Internal::DesignerXmlEditorWidget *editor) : FormWindowEditor::FormWindowEditor(Internal::DesignerXmlEditorWidget *editor)
TextEditor::BaseTextEditor(editor), : d(new FormWindowEditorPrivate)
d(new FormWindowEditorPrivate)
{ {
setEditorWidget(editor);
d->m_widget = editor; d->m_widget = editor;
setDuplicateSupported(true); setDuplicateSupported(true);
setContext(Core::Context(Designer::Constants::K_DESIGNER_XML_EDITOR_ID, setContext(Core::Context(Designer::Constants::K_DESIGNER_XML_EDITOR_ID,
......
...@@ -83,12 +83,7 @@ public slots: ...@@ -83,12 +83,7 @@ public slots:
void setDisplaySettings(const DisplaySettings &ds); void setDisplaySettings(const DisplaySettings &ds);
protected: protected:
BaseTextEditor *createEditor() BaseTextEditor *createEditor() { return new BaseTextEditor; }
{
BaseTextEditor *editor = new BaseTextEditor(this);
editor->document()->setId("DiffEditor.DescriptionEditor");
return editor;
}
void mouseMoveEvent(QMouseEvent *e); void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e); void mouseReleaseEvent(QMouseEvent *e);
...@@ -103,7 +98,7 @@ private: ...@@ -103,7 +98,7 @@ private:
DescriptionEditorWidget::DescriptionEditorWidget(QWidget *parent) DescriptionEditorWidget::DescriptionEditorWidget(QWidget *parent)
: BaseTextEditorWidget(parent) : BaseTextEditorWidget(parent)
{ {
setTextDocument(BaseTextDocumentPtr(new BaseTextDocument)); setSimpleTextDocument("DiffEditor.DescriptionEditor");
DisplaySettings settings = displaySettings(); DisplaySettings settings = displaySettings();
settings.m_textWrapping = false; settings.m_textWrapping = false;
settings.m_displayLineNumbers = false; settings.m_displayLineNumbers = false;
......
...@@ -63,7 +63,6 @@ public: ...@@ -63,7 +63,6 @@ public:
public: public:
DiffEditorController *controller() const; DiffEditorController *controller() const;
// Core::IEditor
Core::IEditor *duplicate(); Core::IEditor *duplicate();
bool open(QString *errorString, bool open(QString *errorString,
......
...@@ -38,13 +38,12 @@ namespace DiffEditor { ...@@ -38,13 +38,12 @@ namespace DiffEditor {
SelectableTextEditorWidget::SelectableTextEditorWidget(QWidget *parent) SelectableTextEditorWidget::SelectableTextEditorWidget(QWidget *parent)
: BaseTextEditorWidget(parent) : BaseTextEditorWidget(parent)
{ {
setTextDocument(TextEditor::BaseTextDocumentPtr(new TextEditor::BaseTextDocument)); setSimpleTextDocument("DiffEditor.UnifiedDiffEditor");
setFrameStyle(QFrame::NoFrame); setFrameStyle(QFrame::NoFrame);
} }
SelectableTextEditorWidget::~SelectableTextEditorWidget() SelectableTextEditorWidget::~SelectableTextEditorWidget()
{ {
} }
void SelectableTextEditorWidget::paintEvent(QPaintEvent *e) void SelectableTextEditorWidget::paintEvent(QPaintEvent *e)
......
...@@ -54,8 +54,7 @@ class DIFFEDITOR_EXPORT SelectableTextEditorWidget ...@@ -54,8 +54,7 @@ class DIFFEDITOR_EXPORT SelectableTextEditorWidget
public: public:
SelectableTextEditorWidget(QWidget *parent = 0); SelectableTextEditorWidget(QWidget *parent = 0);
~SelectableTextEditorWidget(); ~SelectableTextEditorWidget();
void setSelections(const QMap<int, void setSelections(const QMap<int, QList<DiffSelection> > &selections) {
QList<DiffSelection> > &selections) {
m_selections = selections; m_selections = selections;
} }
......
...@@ -78,10 +78,8 @@ class SideDiffEditor : public BaseTextEditor ...@@ -78,10 +78,8 @@ class SideDiffEditor : public BaseTextEditor
{ {
Q_OBJECT Q_OBJECT
public: public:
SideDiffEditor(BaseTextEditorWidget *editorWidget) SideDiffEditor()
: BaseTextEditor(editorWidget)
{ {
document()->setId("DiffEditor.SideDiffEditor");
connect(this, SIGNAL(tooltipRequested(TextEditor::BaseTextEditor*,QPoint,int)), connect(this, SIGNAL(tooltipRequested(TextEditor::BaseTextEditor*,QPoint,int)),
this, SLOT(slotTooltipRequested(TextEditor::BaseTextEditor*,QPoint,int))); this, SLOT(slotTooltipRequested(TextEditor::BaseTextEditor*,QPoint,int)));
} }
...@@ -170,7 +168,7 @@ protected: ...@@ -170,7 +168,7 @@ protected:
return SelectableTextEditorWidget::extraAreaWidth(markWidthPtr); return SelectableTextEditorWidget::extraAreaWidth(markWidthPtr);
} }
void applyFontSettings(); void applyFontSettings();
BaseTextEditor *createEditor() { return new SideDiffEditor(this); } BaseTextEditor *createEditor() { return new SideDiffEditor; }
virtual QString lineNumber(int blockNumber) const; virtual QString lineNumber(int blockNumber) const;
virtual int lineNumberDigits() const; virtual int lineNumberDigits() const;
virtual bool selectionVisible(int blockNumber) const; virtual bool selectionVisible(int blockNumber) const;
...@@ -326,6 +324,7 @@ SideDiffEditorWidget::SideDiffEditorWidget(QWidget *parent) ...@@ -326,6 +324,7 @@ SideDiffEditorWidget::SideDiffEditorWidget(QWidget *parent)
m_lineNumberDigits(1), m_lineNumberDigits(1),
m_inPaintEvent(false) m_inPaintEvent(false)
{ {
textDocument()->setId("DiffEditor.SideDiffEditor");
DisplaySettings settings = displaySettings(); DisplaySettings settings = displaySettings();
settings.m_textWrapping = false; settings.m_textWrapping = false;
settings.m_displayLineNumbers = true; settings.m_displayLineNumbers = true;
......
...@@ -71,16 +71,6 @@ using namespace TextEditor; ...@@ -71,16 +71,6 @@ using namespace TextEditor;
namespace DiffEditor { namespace DiffEditor {
class UnifiedDiffEditor : public BaseTextEditor
{
Q_OBJECT
public:
UnifiedDiffEditor(BaseTextEditorWidget *editorWidget)
: BaseTextEditor(editorWidget) {
document()->setId("DiffEditor.UnifiedDiffEditor");
}
};
UnifiedDiffEditorWidget::UnifiedDiffEditorWidget(QWidget *parent) UnifiedDiffEditorWidget::UnifiedDiffEditorWidget(QWidget *parent)
: SelectableTextEditorWidget(parent) : SelectableTextEditorWidget(parent)
, m_guiController(0) , m_guiController(0)
...@@ -389,7 +379,7 @@ void UnifiedDiffEditorWidget::patch(int diffFileIndex, int chunkIndex, bool reve ...@@ -389,7 +379,7 @@ void UnifiedDiffEditorWidget::patch(int diffFileIndex, int chunkIndex, bool reve
TextEditor::BaseTextEditor *UnifiedDiffEditorWidget::createEditor() TextEditor::BaseTextEditor *UnifiedDiffEditorWidget::createEditor()
{ {
return new UnifiedDiffEditor(this); return new BaseTextEditor;
} }
void UnifiedDiffEditorWidget::clear(const QString &message) void UnifiedDiffEditorWidget::clear(const QString &message)
...@@ -844,5 +834,3 @@ void UnifiedDiffEditorWidget::setCurrentDiffFileIndex(int diffFileIndex) ...@@ -844,5 +834,3 @@ void UnifiedDiffEditorWidget::setCurrentDiffFileIndex(int diffFileIndex)
} }
} // namespace DiffEditor } // namespace DiffEditor
#include "unifieddiffeditorwidget.moc"
...@@ -65,7 +65,7 @@ ProjectFilesFactory::ProjectFilesFactory(Manager *manager) ...@@ -65,7 +65,7 @@ ProjectFilesFactory::ProjectFilesFactory(Manager *manager)
Core::IEditor *ProjectFilesFactory::createEditor() Core::IEditor *ProjectFilesFactory::createEditor()
{ {
auto widget = new ProjectFilesEditorWidget; auto widget = new ProjectFilesEditorWidget;
widget->setTextDocument(BaseTextDocumentPtr(new BaseTextDocument)); widget->setSimpleTextDocument(Constants::FILES_EDITOR_ID);
TextEditorSettings::initializeEditor(widget); TextEditorSettings::initializeEditor(widget);
return widget->editor(); return widget->editor();
} }
...@@ -76,10 +76,8 @@ Core::IEditor *ProjectFilesFactory::createEditor() ...@@ -76,10 +76,8 @@ Core::IEditor *ProjectFilesFactory::createEditor()
// //
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
ProjectFilesEditor::ProjectFilesEditor(ProjectFilesEditorWidget *editor) ProjectFilesEditor::ProjectFilesEditor()
: BaseTextEditor(editor)
{ {
document()->setId(Constants::FILES_EDITOR_ID);
setContext(Core::Context(Constants::C_FILESEDITOR)); setContext(Core::Context(Constants::C_FILESEDITOR));
setDuplicateSupported(true); setDuplicateSupported(true);
} }
...@@ -104,7 +102,7 @@ ProjectFilesEditorWidget::ProjectFilesEditorWidget() ...@@ -104,7 +102,7 @@ ProjectFilesEditorWidget::ProjectFilesEditorWidget()
BaseTextEditor *ProjectFilesEditorWidget::createEditor() BaseTextEditor *ProjectFilesEditorWidget::createEditor()
{ {
return new ProjectFilesEditor(this); return new ProjectFilesEditor;
} }
} // namespace Internal } // namespace Internal
......
...@@ -65,7 +65,7 @@ class ProjectFilesEditor : public TextEditor::BaseTextEditor ...@@ -65,7 +65,7 @@ class ProjectFilesEditor : public TextEditor::BaseTextEditor
Q_OBJECT Q_OBJECT
public: public:
ProjectFilesEditor(ProjectFilesEditorWidget *editorWidget); ProjectFilesEditor();
Core::IEditor *duplicate(); Core::IEditor *duplicate();
}; };
......
...@@ -232,7 +232,7 @@ QString GlslEditorWidget::wordUnderCursor() const ...@@ -232,7 +232,7 @@ QString GlslEditorWidget::wordUnderCursor() const
TextEditor::BaseTextEditor *GlslEditorWidget::createEditor() TextEditor::BaseTextEditor *GlslEditorWidget::createEditor()
{ {
return new GlslEditor(this); return new GlslEditor;
} }
void GlslEditorWidget::updateDocument() void GlslEditorWidget::updateDocument()
......
...@@ -41,8 +41,7 @@ ...@@ -41,8 +41,7 @@
namespace GLSLEditor { namespace GLSLEditor {
namespace Internal { namespace Internal {
GlslEditor::GlslEditor(GlslEditorWidget *editor) GlslEditor::GlslEditor()
: BaseTextEditor(editor)
{ {
setContext(Core::Context(GLSLEditor::Constants::C_GLSLEDITOR_ID, setContext(Core::Context(GLSLEditor::Constants::C_GLSLEDITOR_ID,
TextEditor::Constants::C_TEXTEDITOR)); TextEditor::Constants::C_TEXTEDITOR));
......
...@@ -35,14 +35,12 @@ ...@@ -35,14 +35,12 @@
namespace GLSLEditor { namespace GLSLEditor {
namespace Internal { namespace Internal {
class GlslEditorWidget;
class GlslEditor : public TextEditor::BaseTextEditor class GlslEditor : public TextEditor::BaseTextEditor
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GlslEditor(GlslEditorWidget *); GlslEditor();
Core::IEditor *duplicate(); Core::IEditor *duplicate();
bool open(QString *errorString, const QString &fileName, const QString &realFileName); bool open(QString *errorString, const QString &fileName, const QString &realFileName);
......
...@@ -47,8 +47,7 @@ ...@@ -47,8 +47,7 @@
namespace PythonEditor { namespace PythonEditor {
namespace Internal { namespace Internal {
PythonEditor::PythonEditor(PythonEditorWidget *editorWidget) PythonEditor::PythonEditor()
:BaseTextEditor(editorWidget)
{ {
setContext(Core::Context(Constants::C_PYTHONEDITOR_ID, setContext(Core::Context(Constants::C_PYTHONEDITOR_ID,
TextEditor::Constants::C_TEXTEDITOR)); TextEditor::Constants::C_TEXTEDITOR));
......
...@@ -35,14 +35,12 @@ ...@@ -35,14 +35,12 @@
namespace PythonEditor { namespace PythonEditor {
namespace Internal { namespace Internal {
class PythonEditorWidget;
class PythonEditor : public TextEditor::BaseTextEditor class PythonEditor : public TextEditor::BaseTextEditor
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit PythonEditor(PythonEditorWidget *editorWidget); PythonEditor();
Core::IEditor *duplicate(); Core::IEditor *duplicate();
......
...@@ -59,7 +59,7 @@ PythonEditorWidget::PythonEditorWidget(TextEditor::BaseTextDocumentPtr doc) ...@@ -59,7 +59,7 @@ PythonEditorWidget::PythonEditorWidget(TextEditor::BaseTextDocumentPtr doc)
TextEditor::BaseTextEditor *PythonEditorWidget::createEditor() TextEditor::BaseTextEditor *PythonEditorWidget::createEditor()
{ {
return new PythonEditor(this); return new PythonEditor;
} }
} // namespace Internal } // namespace Internal
......
...@@ -52,8 +52,7 @@ namespace Internal { ...@@ -52,8 +52,7 @@ namespace Internal {
// ProFileEditor // ProFileEditor
// //
ProFileEditor::ProFileEditor(ProFileEditorWidget *editor) ProFileEditor::ProFileEditor()
: BaseTextEditor(editor)
{ {
setContext(Core::Context(Constants::C_PROFILEEDITOR, setContext(Core::Context(Constants::C_PROFILEEDITOR,
TextEditor::Constants::C_TEXTEDITOR)); TextEditor::Constants::C_TEXTEDITOR));
...@@ -167,7 +166,7 @@ ProFileEditorWidget::Link ProFileEditorWidget::findLinkAt(const QTextCursor &cur ...@@ -167,7 +166,7 @@ ProFileEditorWidget::Link ProFileEditorWidget::findLinkAt(const QTextCursor &cur
TextEditor::BaseTextEditor *ProFileEditorWidget::createEditor() TextEditor::BaseTextEditor *ProFileEditorWidget::createEditor()
{ {
return new ProFileEditor(this); return new ProFileEditor;
} }
void ProFileEditorWidget::contextMenuEvent(QContextMenuEvent *e) void ProFileEditorWidget::contextMenuEvent(QContextMenuEvent *e)
...@@ -180,7 +179,6 @@ void ProFileEditorWidget::contextMenuEvent(QContextMenuEvent *e) ...@@ -180,7 +179,6 @@ void ProFileEditorWidget::contextMenuEvent(QContextMenuEvent *e)
// //
ProFileDocument::ProFileDocument() ProFileDocument::ProFileDocument()
: TextEditor::BaseTextDocument()
{ {
setId(Constants::PROFILE_EDITOR_ID); setId(Constants::PROFILE_EDITOR_ID);
setMimeType(QLatin1String(Constants::PROFILE_MIMETYPE)); setMimeType(QLatin1String(Constants::PROFILE_MIMETYPE));
......
...@@ -45,7 +45,7 @@ class ProFileEditor : public TextEditor::BaseTextEditor ...@@ -45,7 +45,7 @@ class ProFileEditor : public TextEditor::BaseTextEditor
Q_OBJECT Q_OBJECT
public: public:
ProFileEditor(ProFileEditorWidget *); ProFileEditor();
Core::IEditor *duplicate(); Core::IEditor *duplicate();
}; };
......
...@@ -98,7 +98,6 @@ namespace QmlJSEditor { ...@@ -98,7 +98,6 @@ namespace QmlJSEditor {
namespace Internal { namespace Internal {
QmlJSTextEditorWidget::QmlJSTextEditorWidget(TextEditor::BaseTextDocumentPtr doc) QmlJSTextEditorWidget::QmlJSTextEditorWidget(TextEditor::BaseTextDocumentPtr doc)
: TextEditor::BaseTextEditorWidget(0)
{ {
setTextDocument(doc); setTextDocument(doc);
...@@ -151,6 +150,7 @@ QmlJSTextEditorWidget::QmlJSTextEditorWidget(TextEditor::BaseTextDocumentPtr doc ...@@ -151,6 +150,7 @@ QmlJSTextEditorWidget::QmlJSTextEditorWidget(TextEditor::BaseTextDocumentPtr doc