Commit a3608f59 authored by Eike Ziller's avatar Eike Ziller
Browse files

Editors: Remove BaseTextEditorWidget::setBaseTextDocument



First step in never changing the text document after construction,
because that is actually not really supported.
Second step will be to fix that for the editor duplicate() methods too.

Change-Id: I3d112ba0895e7ee7ac6dd8ae2318f0de7d2cebc9
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 498d1981
...@@ -96,14 +96,12 @@ Project *androidProject(const QString &file) ...@@ -96,14 +96,12 @@ Project *androidProject(const QString &file)
} // anonymous namespace } // anonymous namespace
AndroidManifestEditorWidget::AndroidManifestEditorWidget(QWidget *parent) AndroidManifestEditorWidget::AndroidManifestEditorWidget(QWidget *parent)
: TextEditor::PlainTextEditorWidget(parent), : TextEditor::PlainTextEditorWidget(new AndroidManifestDocument(this), parent),
m_dirty(false), m_dirty(false),
m_stayClean(false), m_stayClean(false),
m_setAppName(false), m_setAppName(false),
m_appNameInStringsXml(false) m_appNameInStringsXml(false)
{ {
setBaseTextDocument(QSharedPointer<AndroidManifestDocument>(new AndroidManifestDocument(this)));
configure(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE)); configure(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE));
initializePage(); initializePage();
...@@ -126,7 +124,6 @@ TextEditor::BaseTextEditor *AndroidManifestEditorWidget::createEditor() ...@@ -126,7 +124,6 @@ TextEditor::BaseTextEditor *AndroidManifestEditorWidget::createEditor()
return new AndroidManifestEditor(this); return new AndroidManifestEditor(this);
} }
void AndroidManifestEditorWidget::initializePage() void AndroidManifestEditorWidget::initializePage()
{ {
QWidget *mainWidget = new QWidget(this); QWidget *mainWidget = new QWidget(this);
......
...@@ -116,10 +116,8 @@ void CMakeEditor::build() ...@@ -116,10 +116,8 @@ void CMakeEditor::build()
// //
CMakeEditorWidget::CMakeEditorWidget(QWidget *parent) CMakeEditorWidget::CMakeEditorWidget(QWidget *parent)
: BaseTextEditorWidget(parent) : BaseTextEditorWidget(new CMakeDocument(), parent)
{ {
setBaseTextDocument(QSharedPointer<CMakeDocument>(new CMakeDocument));
baseTextDocument()->setSyntaxHighlighter(new CMakeHighlighter); baseTextDocument()->setSyntaxHighlighter(new CMakeHighlighter);
m_commentDefinition.clearCommentStyles(); m_commentDefinition.clearCommentStyles();
......
...@@ -104,7 +104,7 @@ public: ...@@ -104,7 +104,7 @@ public:
// Open file // Open file
QScopedPointer<TextEditor::BaseTextEditorWidget> editorWidget( QScopedPointer<TextEditor::BaseTextEditorWidget> editorWidget(
new TextEditor::PlainTextEditorWidget(0)); new TextEditor::PlainTextEditorWidget);
QString error; QString error;
editorWidget->open(&error, document->fileName(), document->fileName()); editorWidget->open(&error, document->fileName(), document->fileName());
QVERIFY(error.isEmpty()); QVERIFY(error.isEmpty());
......
...@@ -39,13 +39,11 @@ namespace Internal { ...@@ -39,13 +39,11 @@ namespace Internal {
DesignerXmlEditorWidget::DesignerXmlEditorWidget(QDesignerFormWindowInterface *form, DesignerXmlEditorWidget::DesignerXmlEditorWidget(QDesignerFormWindowInterface *form,
QWidget *parent) : QWidget *parent) :
TextEditor::PlainTextEditorWidget(parent), TextEditor::PlainTextEditorWidget(new FormWindowFile(form, this), parent),
m_file(new FormWindowFile(form, this)),
m_designerEditor(new FormWindowEditor(this)) m_designerEditor(new FormWindowEditor(this))
{ {
setBaseTextDocument(m_file);
setReadOnly(true); setReadOnly(true);
configure(m_file->mimeType()); configure(baseTextDocument()->mimeType());
} }
TextEditor::BaseTextEditor *DesignerXmlEditorWidget::createEditor() TextEditor::BaseTextEditor *DesignerXmlEditorWidget::createEditor()
...@@ -62,7 +60,7 @@ FormWindowEditor *DesignerXmlEditorWidget::designerEditor() const ...@@ -62,7 +60,7 @@ FormWindowEditor *DesignerXmlEditorWidget::designerEditor() const
Internal::FormWindowFile *DesignerXmlEditorWidget::formWindowFile() const Internal::FormWindowFile *DesignerXmlEditorWidget::formWindowFile() const
{ {
return m_file.data(); return qobject_cast<FormWindowFile *>(baseTextDocument());
} }
} // namespace Internal } // namespace Internal
......
...@@ -67,7 +67,6 @@ protected: ...@@ -67,7 +67,6 @@ protected:
virtual TextEditor::BaseTextEditor *createEditor(); virtual TextEditor::BaseTextEditor *createEditor();
private: private:
QSharedPointer<Internal::FormWindowFile> m_file;
FormWindowEditor *m_designerEditor; FormWindowEditor *m_designerEditor;
}; };
......
...@@ -109,8 +109,6 @@ Core::IEditor *ProjectFilesEditor::duplicate() ...@@ -109,8 +109,6 @@ Core::IEditor *ProjectFilesEditor::duplicate()
ProjectFilesEditorWidget::ProjectFilesEditorWidget(QWidget *parent) ProjectFilesEditorWidget::ProjectFilesEditorWidget(QWidget *parent)
: BaseTextEditorWidget(parent) : BaseTextEditorWidget(parent)
{ {
QSharedPointer<BaseTextDocument> doc(new BaseTextDocument());
setBaseTextDocument(doc);
} }
BaseTextEditor *ProjectFilesEditorWidget::createEditor() BaseTextEditor *ProjectFilesEditorWidget::createEditor()
......
...@@ -83,11 +83,8 @@ TextEditor::CompletionAssistProvider *ProFileEditor::completionAssistProvider() ...@@ -83,11 +83,8 @@ TextEditor::CompletionAssistProvider *ProFileEditor::completionAssistProvider()
// //
ProFileEditorWidget::ProFileEditorWidget(ProFileEditorFactory *factory, QWidget *parent) ProFileEditorWidget::ProFileEditorWidget(ProFileEditorFactory *factory, QWidget *parent)
: BaseTextEditorWidget(parent), m_factory(factory) : BaseTextEditorWidget(new ProFileDocument(), parent), m_factory(factory)
{ {
QSharedPointer<ProFileDocument> doc(new ProFileDocument());
setBaseTextDocument(doc);
baseTextDocument()->setSyntaxHighlighter(new ProFileHighlighter); baseTextDocument()->setSyntaxHighlighter(new ProFileHighlighter);
m_commentDefinition.clearCommentStyles(); m_commentDefinition.clearCommentStyles();
m_commentDefinition.singleLine = QLatin1Char('#'); m_commentDefinition.singleLine = QLatin1Char('#');
......
...@@ -188,9 +188,19 @@ QString BaseTextEditorWidget::convertToPlainText(const QString &txt) ...@@ -188,9 +188,19 @@ QString BaseTextEditorWidget::convertToPlainText(const QString &txt)
static const char kTextBlockMimeType[] = "application/vnd.qtcreator.blocktext"; static const char kTextBlockMimeType[] = "application/vnd.qtcreator.blocktext";
static const char kVerticalTextBlockMimeType[] = "application/vnd.qtcreator.vblocktext"; static const char kVerticalTextBlockMimeType[] = "application/vnd.qtcreator.vblocktext";
BaseTextEditorWidget::BaseTextEditorWidget(QWidget *parent) BaseTextEditorWidget::BaseTextEditorWidget(QWidget *parent)
: QPlainTextEdit(parent) : QPlainTextEdit(parent)
{
ctor(QSharedPointer<BaseTextDocument>(new BaseTextDocument));
}
BaseTextEditorWidget::BaseTextEditorWidget(BaseTextDocument *doc, QWidget *parent)
: QPlainTextEdit(parent)
{
ctor(QSharedPointer<BaseTextDocument>(doc));
}
void BaseTextEditorWidget::ctor(const QSharedPointer<BaseTextDocument> &doc)
{ {
d = new BaseTextEditorWidgetPrivate; d = new BaseTextEditorWidgetPrivate;
d->q = this; d->q = this;
...@@ -203,6 +213,7 @@ BaseTextEditorWidget::BaseTextEditorWidget(QWidget *parent) ...@@ -203,6 +213,7 @@ BaseTextEditorWidget::BaseTextEditorWidget(QWidget *parent)
d->m_searchResultOverlay = new TextEditorOverlay(this); d->m_searchResultOverlay = new TextEditorOverlay(this);
d->m_refactorOverlay = new RefactorOverlay(this); d->m_refactorOverlay = new RefactorOverlay(this);
d->m_document = doc;
d->setupDocumentSignals(d->m_document); d->setupDocumentSignals(d->m_document);
d->m_lastScrollPos = -1; d->m_lastScrollPos = -1;
...@@ -2079,14 +2090,6 @@ void BaseTextEditorWidget::duplicateFrom(BaseTextEditorWidget *widget) ...@@ -2079,14 +2090,6 @@ void BaseTextEditorWidget::duplicateFrom(BaseTextEditorWidget *widget)
d->m_document = widget->d->m_document; d->m_document = widget->d->m_document;
} }
void BaseTextEditorWidget::setBaseTextDocument(const QSharedPointer<BaseTextDocument> &doc)
{
if (!doc.isNull()) {
d->setupDocumentSignals(doc);
d->m_document = doc;
}
}
void BaseTextEditorWidget::documentAboutToBeReloaded() void BaseTextEditorWidget::documentAboutToBeReloaded()
{ {
//memorize cursor position //memorize cursor position
...@@ -2405,7 +2408,6 @@ BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate() ...@@ -2405,7 +2408,6 @@ BaseTextEditorWidgetPrivate::BaseTextEditorWidgetPrivate()
q(0), q(0),
m_contentsChanged(false), m_contentsChanged(false),
m_lastCursorChangeWasInteresting(false), m_lastCursorChangeWasInteresting(false),
m_document(new BaseTextDocument),
m_parenthesesMatchingEnabled(false), m_parenthesesMatchingEnabled(false),
m_updateTimer(0), m_updateTimer(0),
m_formatRange(false), m_formatRange(false),
......
...@@ -130,7 +130,8 @@ class TEXTEDITOR_EXPORT BaseTextEditorWidget : public QPlainTextEdit ...@@ -130,7 +130,8 @@ class TEXTEDITOR_EXPORT BaseTextEditorWidget : public QPlainTextEdit
Q_PROPERTY(int verticalBlockSelectionLastColumn READ verticalBlockSelectionLastColumn) Q_PROPERTY(int verticalBlockSelectionLastColumn READ verticalBlockSelectionLastColumn)
public: public:
BaseTextEditorWidget(QWidget *parent); BaseTextEditorWidget(QWidget *parent = 0);
BaseTextEditorWidget(BaseTextDocument *doc, QWidget *parent = 0);
~BaseTextEditorWidget(); ~BaseTextEditorWidget();
const Utils::ChangeSet &changeSet() const; const Utils::ChangeSet &changeSet() const;
...@@ -359,8 +360,6 @@ public: ...@@ -359,8 +360,6 @@ public:
void duplicateFrom(BaseTextEditorWidget *editor); void duplicateFrom(BaseTextEditorWidget *editor);
protected: protected:
void setBaseTextDocument(const QSharedPointer<BaseTextDocument> &doc);
void setDefaultPath(const QString &defaultPath); void setDefaultPath(const QString &defaultPath);
virtual BaseTextEditor *createEditor() = 0; virtual BaseTextEditor *createEditor() = 0;
...@@ -538,6 +537,7 @@ signals: ...@@ -538,6 +537,7 @@ signals:
void requestBlockUpdate(const QTextBlock &); void requestBlockUpdate(const QTextBlock &);
private: private:
void ctor(const QSharedPointer<BaseTextDocument> &doc);
void indentOrUnindent(bool doIndent); void indentOrUnindent(bool doIndent);
void handleHomeKey(bool anchor); void handleHomeKey(bool anchor);
void handleBackspaceKey(); void handleBackspaceKey();
......
...@@ -58,9 +58,20 @@ PlainTextEditor::PlainTextEditor(PlainTextEditorWidget *editor) ...@@ -58,9 +58,20 @@ PlainTextEditor::PlainTextEditor(PlainTextEditorWidget *editor)
} }
PlainTextEditorWidget::PlainTextEditorWidget(QWidget *parent) PlainTextEditorWidget::PlainTextEditorWidget(QWidget *parent)
: BaseTextEditorWidget(parent), : BaseTextEditorWidget(parent)
m_isMissingSyntaxDefinition(false)
{ {
ctor();
}
PlainTextEditorWidget::PlainTextEditorWidget(BaseTextDocument *doc, QWidget *parent)
: BaseTextEditorWidget(doc, parent)
{
ctor();
}
void PlainTextEditorWidget::ctor()
{
m_isMissingSyntaxDefinition = false;
setRevisionsVisible(true); setRevisionsVisible(true);
setMarksVisible(true); setMarksVisible(true);
setLineSeparatorsAllowed(true); setLineSeparatorsAllowed(true);
......
...@@ -60,6 +60,7 @@ class TEXTEDITOR_EXPORT PlainTextEditorWidget : public BaseTextEditorWidget ...@@ -60,6 +60,7 @@ class TEXTEDITOR_EXPORT PlainTextEditorWidget : public BaseTextEditorWidget
public: public:
PlainTextEditorWidget(QWidget *parent = 0); PlainTextEditorWidget(QWidget *parent = 0);
PlainTextEditorWidget(BaseTextDocument *doc, QWidget *parent = 0);
void configure(const QString& mimeType); void configure(const QString& mimeType);
void configure(const Core::MimeType &mimeType); void configure(const Core::MimeType &mimeType);
...@@ -80,6 +81,8 @@ protected: ...@@ -80,6 +81,8 @@ protected:
virtual BaseTextEditor *createEditor() { return new PlainTextEditor(this); } virtual BaseTextEditor *createEditor() { return new PlainTextEditor(this); }
private: private:
void ctor();
bool m_isMissingSyntaxDefinition; bool m_isMissingSyntaxDefinition;
Utils::CommentDefinition m_commentDefinition; Utils::CommentDefinition m_commentDefinition;
}; };
......
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