Commit a3608f59 authored by Eike Ziller's avatar Eike Ziller

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