summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@theqtcompany.com>2015-06-02 17:14:48 +0200
committerEike Ziller <eike.ziller@theqtcompany.com>2015-06-10 11:21:17 +0000
commit4f927e4c87f07c4d50efcef5b61478df61cc9d3f (patch)
treea9bbeafa63ea92a5171990bdc8639f93282a7252 /src/plugins
parentc916d250b3c1ff28a4ad0c93ccbd6005c9ff9f42 (diff)
downloadqt-creator-4f927e4c87f07c4d50efcef5b61478df61cc9d3f.tar.gz
Move "open" from IEditor to IDocument
For non-editor documents it currently is not used, but for editors it makes more sense to have that on the document instead of the editor. Most actual implementations of "open" were done in the documents already anyhow, because it is needed for reloading. Change-Id: I29d4df2078995cbe80172b51a9bebeecb3afad3c Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/android/androidmanifesteditor.cpp5
-rw-r--r--src/plugins/android/androidmanifesteditor.h1
-rw-r--r--src/plugins/android/androidmanifesteditorwidget.cpp14
-rw-r--r--src/plugins/android/androidmanifesteditorwidget.h4
-rw-r--r--src/plugins/bineditor/bineditorplugin.cpp17
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager.cpp2
-rw-r--r--src/plugins/coreplugin/editormanager/ieditor.h1
-rw-r--r--src/plugins/coreplugin/idocument.cpp20
-rw-r--r--src/plugins/coreplugin/idocument.h3
-rw-r--r--src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp2
-rw-r--r--src/plugins/designer/formwindoweditor.cpp5
-rw-r--r--src/plugins/designer/formwindoweditor.h1
-rw-r--r--src/plugins/designer/formwindowfile.h4
-rw-r--r--src/plugins/diffeditor/diffeditor.cpp8
-rw-r--r--src/plugins/diffeditor/diffeditor.h5
-rw-r--r--src/plugins/diffeditor/diffeditordocument.cpp6
-rw-r--r--src/plugins/diffeditor/diffeditordocument.h2
-rw-r--r--src/plugins/git/giteditor.cpp4
-rw-r--r--src/plugins/git/giteditor.h2
-rw-r--r--src/plugins/imageviewer/imageviewer.cpp10
-rw-r--r--src/plugins/imageviewer/imageviewer.h1
-rw-r--r--src/plugins/imageviewer/imageviewerfile.cpp8
-rw-r--r--src/plugins/imageviewer/imageviewerfile.h2
-rw-r--r--src/plugins/resourceeditor/resourceeditorw.cpp5
-rw-r--r--src/plugins/resourceeditor/resourceeditorw.h3
-rw-r--r--src/plugins/tasklist/taskfile.cpp5
-rw-r--r--src/plugins/tasklist/taskfile.h2
-rw-r--r--src/plugins/tasklist/tasklistplugin.cpp2
-rw-r--r--src/plugins/texteditor/textdocument.cpp16
-rw-r--r--src/plugins/texteditor/textdocument.h5
-rw-r--r--src/plugins/texteditor/texteditor.cpp37
-rw-r--r--src/plugins/texteditor/texteditor.h4
-rw-r--r--src/plugins/vcsbase/submiteditorfile.cpp18
-rw-r--r--src/plugins/vcsbase/submiteditorfile.h1
-rw-r--r--src/plugins/vcsbase/vcsbasesubmiteditor.cpp18
-rw-r--r--src/plugins/vcsbase/vcsbasesubmiteditor.h2
36 files changed, 123 insertions, 122 deletions
diff --git a/src/plugins/android/androidmanifesteditor.cpp b/src/plugins/android/androidmanifesteditor.cpp
index 9349255b98..7df8b8c71c 100644
--- a/src/plugins/android/androidmanifesteditor.cpp
+++ b/src/plugins/android/androidmanifesteditor.cpp
@@ -65,11 +65,6 @@ AndroidManifestEditor::AndroidManifestEditor(AndroidManifestEditorWidget *editor
setWidget(editorWidget);
}
-bool AndroidManifestEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
-{
- return widget()->open(errorString, fileName, realFileName);
-}
-
QWidget *AndroidManifestEditor::toolBar()
{
return m_toolBar;
diff --git a/src/plugins/android/androidmanifesteditor.h b/src/plugins/android/androidmanifesteditor.h
index cef054567b..e413b02789 100644
--- a/src/plugins/android/androidmanifesteditor.h
+++ b/src/plugins/android/androidmanifesteditor.h
@@ -54,7 +54,6 @@ class AndroidManifestEditor : public Core::IEditor
public:
explicit AndroidManifestEditor(AndroidManifestEditorWidget *editorWidget);
- bool open(QString *errorString, const QString &fileName, const QString &realFileName) override;
QWidget *toolBar() override;
AndroidManifestEditorWidget *widget() const override;
Core::IDocument *document() override;
diff --git a/src/plugins/android/androidmanifesteditorwidget.cpp b/src/plugins/android/androidmanifesteditorwidget.cpp
index 487b808fdf..178c3fe4f1 100644
--- a/src/plugins/android/androidmanifesteditorwidget.cpp
+++ b/src/plugins/android/androidmanifesteditorwidget.cpp
@@ -123,6 +123,8 @@ AndroidManifestEditorWidget::AndroidManifestEditorWidget()
connect(m_textEditorWidget->document(), SIGNAL(contentsChanged()),
this, SLOT(startParseCheck()));
connect(m_textEditorWidget->textDocument(), &TextEditor::TextDocument::reloadFinished,
+ this, [this](bool success) { if (success) updateAfterFileLoad(); });
+ connect(m_textEditorWidget->textDocument(), &TextEditor::TextDocument::openFinishedSuccessfully,
this, &AndroidManifestEditorWidget::updateAfterFileLoad);
}
@@ -502,18 +504,8 @@ void AndroidManifestEditorWidget::updateTargetComboBox()
m_targetLineEdit->addItems(items);
}
-bool AndroidManifestEditorWidget::open(QString *errorString, const QString &fileName, const QString &realFileName)
+void AndroidManifestEditorWidget::updateAfterFileLoad()
{
- bool result = m_textEditorWidget->open(errorString, fileName, realFileName);
- updateAfterFileLoad(result);
- return result;
-}
-
-void AndroidManifestEditorWidget::updateAfterFileLoad(bool success)
-{
- if (!success)
- return;
-
QString error;
int errorLine;
int errorColumn;
diff --git a/src/plugins/android/androidmanifesteditorwidget.h b/src/plugins/android/androidmanifesteditorwidget.h
index 396eab4367..1bda68d201 100644
--- a/src/plugins/android/androidmanifesteditorwidget.h
+++ b/src/plugins/android/androidmanifesteditorwidget.h
@@ -96,8 +96,6 @@ public:
explicit AndroidManifestEditorWidget();
- bool open(QString *errorString, const QString &fileName, const QString &realFileName);
-
bool isModified() const;
EditorPage activePage() const;
@@ -135,7 +133,7 @@ private:
bool syncToWidgets();
void syncToWidgets(const QDomDocument &doc);
void syncToEditor();
- void updateAfterFileLoad(bool success);
+ void updateAfterFileLoad();
bool checkDocument(const QDomDocument &doc, QString *errorMessage,
int *errorLine, int *errorColumn);
diff --git a/src/plugins/bineditor/bineditorplugin.cpp b/src/plugins/bineditor/bineditorplugin.cpp
index e22e5f4e7a..0f15ba8cdb 100644
--- a/src/plugins/bineditor/bineditorplugin.cpp
+++ b/src/plugins/bineditor/bineditorplugin.cpp
@@ -265,7 +265,14 @@ public:
}
}
- bool open(QString *errorString, const QString &fileName, quint64 offset = 0) {
+ bool open(QString *errorString, const QString &fileName, const QString &realFileName)
+ {
+ QTC_CHECK(fileName == realFileName); // The bineditor can do no autosaving
+ return openImpl(errorString, fileName);
+ }
+
+ bool openImpl(QString *errorString, const QString &fileName, quint64 offset = 0)
+ {
QFile file(fileName);
if (file.open(QIODevice::ReadOnly)) {
file.close();
@@ -326,7 +333,7 @@ private slots:
void provideNewRange(quint64 offset)
{
- open(0, filePath().toString(), offset);
+ openImpl(0, filePath().toString(), offset);
}
public:
@@ -356,7 +363,7 @@ public:
emit aboutToReload();
int cPos = m_widget->cursorPosition();
m_widget->clear();
- const bool success = open(errorString, filePath().toString());
+ const bool success = openImpl(errorString, filePath().toString());
m_widget->setCursorPosition(cPos);
emit reloadFinished(success);
return success;
@@ -409,10 +416,6 @@ public:
delete m_widget;
}
- bool open(QString *errorString, const QString &fileName, const QString &realFileName) override {
- QTC_ASSERT(fileName == realFileName, return false); // The bineditor can do no autosaving
- return m_file->open(errorString, fileName);
- }
IDocument *document() override { return m_file; }
QWidget *toolBar() override { return m_toolBar; }
diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index b4b7f35817..a4bee8612d 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -612,7 +612,7 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileN
}
QString errorString;
- if (editor->open(&errorString, fn, realFn))
+ if (editor->document()->open(&errorString, fn, realFn))
break;
overrideCursor.reset();
diff --git a/src/plugins/coreplugin/editormanager/ieditor.h b/src/plugins/coreplugin/editormanager/ieditor.h
index e4cbb54a60..858a560694 100644
--- a/src/plugins/coreplugin/editormanager/ieditor.h
+++ b/src/plugins/coreplugin/editormanager/ieditor.h
@@ -51,7 +51,6 @@ public:
bool duplicateSupported() const;
void setDuplicateSupported(bool duplicateSupported);
- virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName) = 0;
virtual IDocument *document() = 0;
virtual IEditor *duplicate() { return 0; }
diff --git a/src/plugins/coreplugin/idocument.cpp b/src/plugins/coreplugin/idocument.cpp
index 1425aec53b..46b5924306 100644
--- a/src/plugins/coreplugin/idocument.cpp
+++ b/src/plugins/coreplugin/idocument.cpp
@@ -118,6 +118,26 @@ Id IDocument::id() const
}
/*!
+ * Used to load a file if this document is part of an IEditor implementation, when the editor
+ * is opened.
+ * If the editor is opened from an auto save file, \a realFileName is the name of the auto save
+ * that should be loaded, and \a fileName is the file name of the resulting file.
+ * In that case, the contents of the auto save file should be loaded, the file name of the
+ * IDocument should be set to \a fileName, and the document state be set to modified.
+ * If the editor is opened from a regular file, \a fileName and \a realFileName are the same.
+ * Use \a errorString to return an error message, if this document can not handle the
+ * file contents.
+ * Returns true on success, false if an error occurred.
+ */
+bool IDocument::open(QString *errorString, const QString &fileName, const QString &realFileName)
+{
+ Q_UNUSED(errorString)
+ Q_UNUSED(fileName)
+ Q_UNUSED(realFileName)
+ return false;
+}
+
+/*!
Used for example by EditorManager::openEditorWithContents() to set the contents
of this document.
Returns if setting the contents was successful.
diff --git a/src/plugins/coreplugin/idocument.h b/src/plugins/coreplugin/idocument.h
index d65f43fd3a..c9822004d1 100644
--- a/src/plugins/coreplugin/idocument.h
+++ b/src/plugins/coreplugin/idocument.h
@@ -85,6 +85,9 @@ public:
void setId(Id id);
Id id() const;
+ // required to be re-implemented for documents of IEditors
+ virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName);
+
virtual bool save(QString *errorString, const QString &fileName = QString(), bool autoSave = false) = 0;
virtual bool setContents(const QByteArray &contents);
diff --git a/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp b/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp
index 3f948bb580..691787473f 100644
--- a/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp
+++ b/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp
@@ -111,7 +111,7 @@ public:
QScopedPointer<TextEditor::BaseTextEditor> editor(
TextEditor::PlainTextEditorFactory::createPlainTextEditor());
QString error;
- editor->open(&error, document->fileName(), document->fileName());
+ editor->document()->open(&error, document->fileName(), document->fileName());
QVERIFY(error.isEmpty());
// Set cursor position
diff --git a/src/plugins/designer/formwindoweditor.cpp b/src/plugins/designer/formwindoweditor.cpp
index 5ad300f655..8898c325ed 100644
--- a/src/plugins/designer/formwindoweditor.cpp
+++ b/src/plugins/designer/formwindoweditor.cpp
@@ -53,11 +53,6 @@ FormWindowEditor::~FormWindowEditor()
{
}
-bool FormWindowEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
-{
- return formWindowFile()->open(errorString, fileName, realFileName);
-}
-
QWidget *FormWindowEditor::toolBar()
{
return 0;
diff --git a/src/plugins/designer/formwindoweditor.h b/src/plugins/designer/formwindoweditor.h
index 3c3a10b6d3..3c897ea081 100644
--- a/src/plugins/designer/formwindoweditor.h
+++ b/src/plugins/designer/formwindoweditor.h
@@ -54,7 +54,6 @@ public:
FormWindowEditor();
~FormWindowEditor() override;
- bool open(QString *errorString, const QString &fileName, const QString &realFileName) override;
QWidget *toolBar() override;
bool isDesignModePreferred() const override;
diff --git a/src/plugins/designer/formwindowfile.h b/src/plugins/designer/formwindowfile.h
index 6ba98dbb68..c5f9f158b6 100644
--- a/src/plugins/designer/formwindowfile.h
+++ b/src/plugins/designer/formwindowfile.h
@@ -52,9 +52,9 @@ public:
explicit FormWindowFile(QDesignerFormWindowInterface *form, QObject *parent = 0);
~FormWindowFile() override { }
- bool open(QString *errorString, const QString &fileName, const QString &realFileName) override;
-
// IDocument
+ bool open(QString *errorString, const QString &fileName,
+ const QString &realFileName) override;
bool save(QString *errorString, const QString &fileName, bool autoSave) override;
bool setContents(const QByteArray &contents) override;
bool shouldAutoSave() const override;
diff --git a/src/plugins/diffeditor/diffeditor.cpp b/src/plugins/diffeditor/diffeditor.cpp
index 5ca2a1f041..485f191f81 100644
--- a/src/plugins/diffeditor/diffeditor.cpp
+++ b/src/plugins/diffeditor/diffeditor.cpp
@@ -364,14 +364,6 @@ Core::IEditor *DiffEditor::duplicate()
return editor;
}
-bool DiffEditor::open(QString *errorString,
- const QString &fileName,
- const QString &realFileName)
-{
- Q_UNUSED(realFileName)
- return m_document->open(errorString, fileName);
-}
-
Core::IDocument *DiffEditor::document()
{
return m_document.data();
diff --git a/src/plugins/diffeditor/diffeditor.h b/src/plugins/diffeditor/diffeditor.h
index 350e657799..5011ee2163 100644
--- a/src/plugins/diffeditor/diffeditor.h
+++ b/src/plugins/diffeditor/diffeditor.h
@@ -63,12 +63,7 @@ public:
~DiffEditor() override;
Core::IEditor *duplicate() override;
-
- bool open(QString *errorString,
- const QString &fileName,
- const QString &realFileName) override;
Core::IDocument *document() override;
-
QWidget *toolBar() override;
private slots:
diff --git a/src/plugins/diffeditor/diffeditordocument.cpp b/src/plugins/diffeditor/diffeditordocument.cpp
index fc97985861..c0b96199ba 100644
--- a/src/plugins/diffeditor/diffeditordocument.cpp
+++ b/src/plugins/diffeditor/diffeditordocument.cpp
@@ -235,12 +235,14 @@ bool DiffEditorDocument::reload(QString *errorString, ReloadFlag flag, ChangeTyp
Q_UNUSED(type)
if (flag == FlagIgnore)
return true;
- return open(errorString, filePath().toString());
+ return open(errorString, filePath().toString(), filePath().toString());
}
-bool DiffEditorDocument::open(QString *errorString, const QString &fileName)
+bool DiffEditorDocument::open(QString *errorString, const QString &fileName,
+ const QString &realFileName)
{
QTC_ASSERT(errorString, return false);
+ QTC_ASSERT(fileName == realFileName, return false); // does not support autosave
beginReload();
QString patch;
if (read(fileName, &patch, errorString) != TextFileFormat::ReadSuccess)
diff --git a/src/plugins/diffeditor/diffeditordocument.h b/src/plugins/diffeditor/diffeditordocument.h
index 62d4376640..3bbf6e24a2 100644
--- a/src/plugins/diffeditor/diffeditordocument.h
+++ b/src/plugins/diffeditor/diffeditordocument.h
@@ -77,7 +77,7 @@ public:
bool save(QString *errorString, const QString &fileName, bool autoSave);
void reload();
bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
- bool open(QString *errorString, const QString &fileName);
+ bool open(QString *errorString, const QString &fileName, const QString &realFileName);
QString plainText() const;
diff --git a/src/plugins/git/giteditor.cpp b/src/plugins/git/giteditor.cpp
index bfff94ac05..2ec49b3de4 100644
--- a/src/plugins/git/giteditor.cpp
+++ b/src/plugins/git/giteditor.cpp
@@ -295,8 +295,9 @@ void GitEditorWidget::addDiffActions(QMenu *menu, const DiffChunk &chunk)
});
}
-bool GitEditorWidget::open(QString *errorString, const QString &fileName, const QString &realFileName)
+void GitEditorWidget::aboutToOpen(const QString &fileName, const QString &realFileName)
{
+ Q_UNUSED(realFileName)
Core::Id editorId = textDocument()->id();
if (editorId == Git::Constants::GIT_COMMIT_TEXT_EDITOR_ID
|| editorId == Git::Constants::GIT_REBASE_EDITOR_ID) {
@@ -306,7 +307,6 @@ bool GitEditorWidget::open(QString *errorString, const QString &fileName, const
textDocument()->setCodec(
GitPlugin::instance()->client()->encoding(gitPath, "i18n.commitEncoding"));
}
- return VcsBaseEditorWidget::open(errorString, fileName, realFileName);
}
QString GitEditorWidget::decorateVersion(const QString &revision) const
diff --git a/src/plugins/git/giteditor.h b/src/plugins/git/giteditor.h
index 3540c5e4aa..538946f76b 100644
--- a/src/plugins/git/giteditor.h
+++ b/src/plugins/git/giteditor.h
@@ -62,7 +62,7 @@ private:
void init() override;
void resetChange(const QByteArray &resetType);
void addDiffActions(QMenu *menu, const VcsBase::DiffChunk &chunk) override;
- bool open(QString *errorString, const QString &fileName, const QString &realFileName) override;
+ void aboutToOpen(const QString &fileName, const QString &realFileName) override;
QSet<QString> annotationChanges() const override;
QString changeUnderCursor(const QTextCursor &) const override;
VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes) const override;
diff --git a/src/plugins/imageviewer/imageviewer.cpp b/src/plugins/imageviewer/imageviewer.cpp
index 4bb53194e4..718435ef5e 100644
--- a/src/plugins/imageviewer/imageviewer.cpp
+++ b/src/plugins/imageviewer/imageviewer.cpp
@@ -142,6 +142,8 @@ void ImageViewer::ctor()
this, &ImageViewer::playToggled);
connect(d->file.data(), &ImageViewerFile::imageSizeChanged,
this, &ImageViewer::imageSizeUpdated);
+ connect(d->file.data(), &ImageViewerFile::openFinished,
+ d->imageView, &ImageView::createScene);
connect(d->file.data(), &ImageViewerFile::aboutToReload,
d->imageView, &ImageView::reset);
connect(d->file.data(), &ImageViewerFile::reloadFinished,
@@ -159,14 +161,6 @@ ImageViewer::~ImageViewer()
delete d;
}
-bool ImageViewer::open(QString *errorString, const QString &fileName, const QString &realFileName)
-{
- if (!d->file->open(errorString, fileName, realFileName))
- return false;
- d->imageView->createScene();
- return true;
-}
-
Core::IDocument *ImageViewer::document()
{
return d->file.data();
diff --git a/src/plugins/imageviewer/imageviewer.h b/src/plugins/imageviewer/imageviewer.h
index 5540a275cb..130573a4b6 100644
--- a/src/plugins/imageviewer/imageviewer.h
+++ b/src/plugins/imageviewer/imageviewer.h
@@ -55,7 +55,6 @@ public:
explicit ImageViewer(QWidget *parent = 0);
~ImageViewer() override;
- bool open(QString *errorString, const QString &fileName, const QString &realFileName) override;
Core::IDocument *document() override;
QWidget *toolBar() override;
diff --git a/src/plugins/imageviewer/imageviewerfile.cpp b/src/plugins/imageviewer/imageviewerfile.cpp
index 6a0599cbc1..92309678e2 100644
--- a/src/plugins/imageviewer/imageviewerfile.cpp
+++ b/src/plugins/imageviewer/imageviewerfile.cpp
@@ -88,7 +88,13 @@ ImageViewerFile::~ImageViewerFile()
bool ImageViewerFile::open(QString *errorString, const QString &fileName, const QString &realFileName)
{
QTC_CHECK(fileName == realFileName); // does not support auto save
+ bool success = openImpl(errorString, fileName);
+ emit openFinished(success);
+ return success;
+}
+bool ImageViewerFile::openImpl(QString *errorString, const QString &fileName)
+{
cleanUp();
m_type = TypeInvalid;
@@ -160,7 +166,7 @@ bool ImageViewerFile::reload(QString *errorString,
return true;
}
emit aboutToReload();
- bool success = open(errorString, filePath().toString(), filePath().toString());
+ bool success = openImpl(errorString, filePath().toString());
emit reloadFinished(success);
return success;
}
diff --git a/src/plugins/imageviewer/imageviewerfile.h b/src/plugins/imageviewer/imageviewerfile.h
index 77075bf399..fc0eee268e 100644
--- a/src/plugins/imageviewer/imageviewerfile.h
+++ b/src/plugins/imageviewer/imageviewerfile.h
@@ -87,11 +87,13 @@ public:
void updateVisibility();
signals:
+ void openFinished(bool success);
void imageSizeChanged(const QSize &size);
void isPausedChanged(bool paused);
private:
void cleanUp();
+ bool openImpl(QString *errorString, const QString &fileName);
ImageType m_type = TypeInvalid;
#ifndef QT_NO_SVG
diff --git a/src/plugins/resourceeditor/resourceeditorw.cpp b/src/plugins/resourceeditor/resourceeditorw.cpp
index a7f17447a8..e4e507f8a8 100644
--- a/src/plugins/resourceeditor/resourceeditorw.cpp
+++ b/src/plugins/resourceeditor/resourceeditorw.cpp
@@ -120,11 +120,6 @@ ResourceEditorW::~ResourceEditorW()
delete m_toolBar;
}
-bool ResourceEditorW::open(QString *errorString, const QString &fileName, const QString &realFileName)
-{
- return m_resourceDocument->open(errorString, fileName, realFileName);
-}
-
bool ResourceEditorDocument::open(QString *errorString, const QString &fileName,
const QString &realFileName)
{
diff --git a/src/plugins/resourceeditor/resourceeditorw.h b/src/plugins/resourceeditor/resourceeditorw.h
index 2e18032e78..ab6923c900 100644
--- a/src/plugins/resourceeditor/resourceeditorw.h
+++ b/src/plugins/resourceeditor/resourceeditorw.h
@@ -56,8 +56,8 @@ class ResourceEditorDocument
public:
ResourceEditorDocument(QObject *parent = 0);
- bool open(QString *errorString, const QString &fileName, const QString &realFileName);
//IDocument
+ bool open(QString *errorString, const QString &fileName, const QString &realFileName);
bool save(QString *errorString, const QString &fileName, bool autoSave);
QString plainText() const;
bool setContents(const QByteArray &contents);
@@ -95,7 +95,6 @@ public:
~ResourceEditorW() override;
// IEditor
- bool open(QString *errorString, const QString &fileName, const QString &realFileName) override;
Core::IDocument *document() override { return m_resourceDocument; }
QWidget *toolBar() override;
diff --git a/src/plugins/tasklist/taskfile.cpp b/src/plugins/tasklist/taskfile.cpp
index 5e1fcf60fd..c481079bdb 100644
--- a/src/plugins/tasklist/taskfile.cpp
+++ b/src/plugins/tasklist/taskfile.cpp
@@ -94,11 +94,12 @@ bool TaskFile::reload(QString *errorString, ReloadFlag flag, ChangeType type)
deleteLater();
return true;
}
- return open(errorString, filePath().toString());
+ return open(errorString, filePath().toString(), filePath().toString());
}
-bool TaskFile::open(QString *errorString, const QString &fileName)
+bool TaskFile::open(QString *errorString, const QString &fileName, const QString &realFileName)
{
+ Q_UNUSED(realFileName)
setFilePath(Utils::FileName::fromString(fileName));
return TaskListPlugin::loadFile(errorString, m_baseDir, fileName);
}
diff --git a/src/plugins/tasklist/taskfile.h b/src/plugins/tasklist/taskfile.h
index 6e701024c0..2550c94b1d 100644
--- a/src/plugins/tasklist/taskfile.h
+++ b/src/plugins/tasklist/taskfile.h
@@ -55,7 +55,7 @@ public:
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
- bool open(QString *errorString, const QString &fileName);
+ bool open(QString *errorString, const QString &fileName, const QString &realFileName);
QString baseDir() const;
void setBaseDir(const QString &base);
diff --git a/src/plugins/tasklist/tasklistplugin.cpp b/src/plugins/tasklist/tasklistplugin.cpp
index a272b07dca..c8921ad9d3 100644
--- a/src/plugins/tasklist/tasklistplugin.cpp
+++ b/src/plugins/tasklist/tasklistplugin.cpp
@@ -177,7 +177,7 @@ IDocument *TaskListPlugin::openTasks(const QString &base, const QString &fileNam
file->setBaseDir(base);
QString errorString;
- if (!file->open(&errorString, fileName)) {
+ if (!file->open(&errorString, fileName, fileName)) {
QMessageBox::critical(ICore::mainWindow(), tr("File Error"), errorString);
delete file;
return 0;
diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp
index 75e4ad4f08..4a7ad23be7 100644
--- a/src/plugins/texteditor/textdocument.cpp
+++ b/src/plugins/texteditor/textdocument.cpp
@@ -44,6 +44,7 @@
#include <texteditor/generichighlighter/highlighter.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/documentmodel.h>
+#include <utils/mimetypes/mimedatabase.h>
#include <QApplication>
#include <QDir>
@@ -559,6 +560,19 @@ void TextDocument::checkPermissions()
bool TextDocument::open(QString *errorString, const QString &fileName, const QString &realFileName)
{
+ emit aboutToOpen(fileName, realFileName);
+ bool success = openImpl(errorString, fileName, realFileName);
+ if (success) {
+ Utils::MimeDatabase mdb;
+ setMimeType(mdb.mimeTypeForFile(fileName).name());
+ emit openFinishedSuccessfully();
+ return true;
+ }
+ return false;
+}
+
+bool TextDocument::openImpl(QString *errorString, const QString &fileName, const QString &realFileName)
+{
QStringList content;
ReadResult readResult = Utils::TextFileFormat::ReadIOError;
@@ -620,7 +634,7 @@ bool TextDocument::reload(QString *errorString)
if (documentLayout)
marks = documentLayout->documentClosing(); // removes text marks non-permanently
- bool success = open(errorString, filePath().toString(), filePath().toString());
+ bool success = openImpl(errorString, filePath().toString(), filePath().toString());
if (documentLayout)
documentLayout->documentReloaded(marks, this); // re-adds text marks
diff --git a/src/plugins/texteditor/textdocument.h b/src/plugins/texteditor/textdocument.h
index 818059e80a..8deb19c62b 100644
--- a/src/plugins/texteditor/textdocument.h
+++ b/src/plugins/texteditor/textdocument.h
@@ -117,7 +117,7 @@ public:
void setDefaultPath(const QString &defaultPath);
void setSuggestedFileName(const QString &suggestedFileName);
- virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName);
+ bool open(QString *errorString, const QString &fileName, const QString &realFileName);
virtual bool reload(QString *errorString);
bool setPlainText(const QString &text);
@@ -138,6 +138,8 @@ public slots:
void setFontSettings(const TextEditor::FontSettings &fontSettings);
signals:
+ void aboutToOpen(const QString &fileName, const QString &realFileName);
+ void openFinishedSuccessfully();
void contentsChanged();
void tabSettingsChanged();
void fontSettingsChanged();
@@ -146,6 +148,7 @@ protected slots:
virtual void applyFontSettings();
private:
+ bool openImpl(QString *errorString, const QString &fileName, const QString &realFileName);
void cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument);
void ensureFinalNewLine(QTextCursor &cursor);
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp
index 5c0fcbf795..71b5ec4208 100644
--- a/src/plugins/texteditor/texteditor.cpp
+++ b/src/plugins/texteditor/texteditor.cpp
@@ -681,6 +681,10 @@ void TextEditorWidgetPrivate::ctor(const QSharedPointer<TextDocument> &doc)
updateCannotDecodeInfo();
+ QObject::connect(m_document.data(), &TextDocument::aboutToOpen,
+ q, &TextEditorWidget::aboutToOpen);
+ QObject::connect(m_document.data(), &TextDocument::openFinishedSuccessfully,
+ q, &TextEditorWidget::openFinishedSuccessfully);
connect(m_fileEncodingLabel, &LineColumnLabel::clicked,
q, &TextEditorWidget::selectEncoding);
connect(m_document->document(), &QTextDocument::modificationChanged,
@@ -972,17 +976,6 @@ void TextEditorWidgetPrivate::updateCannotDecodeInfo()
}
}
-bool TextEditorWidget::open(QString *errorString, const QString &fileName, const QString &realFileName)
-{
- if (d->m_document->open(errorString, fileName, realFileName)) {
- moveCursor(QTextCursor::Start);
- d->updateCannotDecodeInfo();
- updateTextCodecLabel();
- return true;
- }
- return false;
-}
-
/*
Collapses the first comment in a file, if there is only whitespace above
*/
@@ -1014,6 +1007,19 @@ TextDocument *TextEditorWidget::textDocument() const
return d->m_document.data();
}
+void TextEditorWidget::aboutToOpen(const QString &fileName, const QString &realFileName)
+{
+ Q_UNUSED(fileName)
+ Q_UNUSED(realFileName)
+}
+
+void TextEditorWidget::openFinishedSuccessfully()
+{
+ moveCursor(QTextCursor::Start);
+ d->updateCannotDecodeInfo();
+ updateTextCodecLabel();
+}
+
TextDocumentPtr TextEditorWidget::textDocumentPtr() const
{
return d->m_document;
@@ -7142,15 +7148,6 @@ QString TextEditorWidget::foldReplacementText(const QTextBlock &) const
return QLatin1String("...");
}
-bool BaseTextEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
-{
- if (!editorWidget()->open(errorString, fileName, realFileName))
- return false;
- Utils::MimeDatabase mdb;
- textDocument()->setMimeType(mdb.mimeTypeForFile(fileName).name());
- return true;
-}
-
QByteArray BaseTextEditor::saveState() const
{
return editorWidget()->saveState();
diff --git a/src/plugins/texteditor/texteditor.h b/src/plugins/texteditor/texteditor.h
index 30c2252496..183163232a 100644
--- a/src/plugins/texteditor/texteditor.h
+++ b/src/plugins/texteditor/texteditor.h
@@ -150,7 +150,6 @@ public:
// IEditor
Core::IDocument *document() override;
- bool open(QString *errorString, const QString &fileName, const QString &realFileName) override;
IEditor *duplicate() override;
@@ -211,8 +210,9 @@ public:
TextDocument *textDocument() const;
QSharedPointer<TextDocument> textDocumentPtr() const;
+ virtual void aboutToOpen(const QString &fileName, const QString &realFileName);
+ virtual void openFinishedSuccessfully();
// IEditor
- virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName);
QByteArray saveState() const;
bool restoreState(const QByteArray &state);
void gotoLine(int line, int column = 0, bool centerLine = true);
diff --git a/src/plugins/vcsbase/submiteditorfile.cpp b/src/plugins/vcsbase/submiteditorfile.cpp
index cc5175849e..0346b0a198 100644
--- a/src/plugins/vcsbase/submiteditorfile.cpp
+++ b/src/plugins/vcsbase/submiteditorfile.cpp
@@ -57,6 +57,24 @@ SubmitEditorFile::SubmitEditorFile(const VcsBaseSubmitEditorParameters *paramete
setTemporary(true);
}
+bool SubmitEditorFile::open(QString *errorString, const QString &fileName, const QString &realFileName)
+{
+ if (fileName.isEmpty())
+ return false;
+
+ FileReader reader;
+ if (!reader.fetch(realFileName, QIODevice::Text, errorString))
+ return false;
+
+ const QString text = QString::fromLocal8Bit(reader.data());
+ if (!m_editor->setFileContents(text.toUtf8()))
+ return false;
+
+ setFilePath(FileName::fromString(fileName));
+ setModified(fileName != realFileName);
+ return true;
+}
+
bool SubmitEditorFile::setContents(const QByteArray &contents)
{
return m_editor->setFileContents(contents);
diff --git a/src/plugins/vcsbase/submiteditorfile.h b/src/plugins/vcsbase/submiteditorfile.h
index 30fbd5d3e9..152f2bd689 100644
--- a/src/plugins/vcsbase/submiteditorfile.h
+++ b/src/plugins/vcsbase/submiteditorfile.h
@@ -47,6 +47,7 @@ public:
explicit SubmitEditorFile(const VcsBaseSubmitEditorParameters *parameters,
VcsBaseSubmitEditor *parent = 0);
+ bool open(QString *errorString, const QString &fileName, const QString &realFileName);
bool setContents(const QByteArray &contents);
QString defaultPath() const { return QString(); }
QString suggestedFileName() const { return QString(); }
diff --git a/src/plugins/vcsbase/vcsbasesubmiteditor.cpp b/src/plugins/vcsbase/vcsbasesubmiteditor.cpp
index b87c0f1d4d..fa76c8353a 100644
--- a/src/plugins/vcsbase/vcsbasesubmiteditor.cpp
+++ b/src/plugins/vcsbase/vcsbasesubmiteditor.cpp
@@ -362,24 +362,6 @@ void VcsBaseSubmitEditor::slotDescriptionChanged()
{
}
-bool VcsBaseSubmitEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
-{
- if (fileName.isEmpty())
- return false;
-
- FileReader reader;
- if (!reader.fetch(realFileName, QIODevice::Text, errorString))
- return false;
-
- const QString text = QString::fromLocal8Bit(reader.data());
- if (!setFileContents(text.toUtf8()))
- return false;
-
- d->m_file->setFilePath(FileName::fromString(fileName));
- d->m_file->setModified(fileName != realFileName);
- return true;
-}
-
Core::IDocument *VcsBaseSubmitEditor::document()
{
return d->m_file;
diff --git a/src/plugins/vcsbase/vcsbasesubmiteditor.h b/src/plugins/vcsbase/vcsbasesubmiteditor.h
index ec9aacdd1c..4748d92735 100644
--- a/src/plugins/vcsbase/vcsbasesubmiteditor.h
+++ b/src/plugins/vcsbase/vcsbasesubmiteditor.h
@@ -113,8 +113,6 @@ public:
QString checkScriptWorkingDirectory() const;
void setCheckScriptWorkingDirectory(const QString &);
- // Core::IEditor
- bool open(QString *errorString, const QString &fileName, const QString &realFileName) override;
Core::IDocument *document() override;
QWidget *toolBar() override;