diff options
author | Eike Ziller <eike.ziller@digia.com> | 2013-07-04 11:35:56 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@digia.com> | 2013-07-09 10:21:58 +0200 |
commit | 99c383f3d06b93d79172a0bc3984b4f3332a8842 (patch) | |
tree | d47b752f0d82c6535a3fcaf29f19452073ff97a5 /src/plugins/resourceeditor | |
parent | 7dd81eca30b69b847709d00cb75fd432385c0917 (diff) |
Make IDocument::fileName a member with setter.
Instead of requiring subclasses to implement a method.
Also renames IDocument::rename to IDocument::setFileName,
since it doesn't really rename any files or such.
Change-Id: I1344025c24d2f74a6a983e04fb0a5245f1f37aad
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
Diffstat (limited to 'src/plugins/resourceeditor')
-rw-r--r-- | src/plugins/resourceeditor/resourceeditorw.cpp | 28 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourceeditorw.h | 5 |
2 files changed, 15 insertions, 18 deletions
diff --git a/src/plugins/resourceeditor/resourceeditorw.cpp b/src/plugins/resourceeditor/resourceeditorw.cpp index 1b49ad1e3ca..f7442cb7b9f 100644 --- a/src/plugins/resourceeditor/resourceeditorw.cpp +++ b/src/plugins/resourceeditor/resourceeditorw.cpp @@ -65,6 +65,7 @@ ResourceEditorDocument::ResourceEditorDocument(ResourceEditorW *parent) : m_mimeType(QLatin1String(ResourceEditor::Constants::C_RESOURCE_MIMETYPE)), m_parent(parent) { + setFileName(parent->m_resourceEditor->fileName()); if (debugResourceEditorW) qDebug() << "ResourceEditorFile::ResourceEditorFile()"; } @@ -142,7 +143,7 @@ bool ResourceEditorW::createNew(const QString &contents) return false; const bool rc = m_resourceEditor->load(saver.fileName()); - m_resourceEditor->setFileName(QString()); + m_resourceDocument->setFileName(QString()); m_shouldAutoSave = false; if (debugResourceEditorW) qDebug() << "ResourceEditorW::createNew: " << contents << " (" << saver.fileName() << ") returns " << rc; @@ -168,9 +169,8 @@ bool ResourceEditorW::open(QString *errorString, const QString &fileName, const return false; } - m_resourceEditor->setFileName(fileName); + m_resourceDocument->setFileName(fileName); m_resourceEditor->setDirty(fileName != realFileName); - setDisplayName(fi.fileName()); m_shouldAutoSave = false; m_diskIo = false; @@ -205,19 +205,22 @@ bool ResourceEditorDocument::save(QString *errorString, const QString &name, boo return true; } - m_parent->setDisplayName(QFileInfo(actualName).fileName()); + setFileName(actualName); m_parent->m_diskIo = false; emit changed(); return true; } -void ResourceEditorDocument::rename(const QString &newName) +void ResourceEditorDocument::setFileName(const QString &newName) { - const QString oldName = m_parent->m_resourceEditor->fileName(); - m_parent->m_resourceEditor->setFileName(newName); - emit fileNameChanged(oldName, newName); // TODO Are there other cases where the ressource file name changes? - emit changed(); + if (newName != m_parent->m_resourceEditor->fileName()) + m_parent->m_resourceEditor->setFileName(newName); + if (newName.isEmpty()) + m_parent->setDisplayName(m_parent->tr("untitled")); + else + m_parent->setDisplayName(QFileInfo(newName).fileName()); + IDocument::setFileName(newName); } Core::Id ResourceEditorW::id() const @@ -230,11 +233,6 @@ QWidget *ResourceEditorW::toolBar() return m_toolBar; } -QString ResourceEditorDocument::fileName() const -{ - return m_parent->m_resourceEditor->fileName(); -} - bool ResourceEditorDocument::shouldAutoSave() const { return m_parent->m_shouldAutoSave; @@ -258,7 +256,7 @@ bool ResourceEditorDocument::reload(QString *errorString, ReloadFlag flag, Chang emit changed(); } else { emit aboutToReload(); - QString fn = m_parent->m_resourceEditor->fileName(); + QString fn = fileName(); const bool success = m_parent->open(errorString, fn, fn); emit reloadFinished(success); return success; diff --git a/src/plugins/resourceeditor/resourceeditorw.h b/src/plugins/resourceeditor/resourceeditorw.h index 22d71f69c88..ef174ed5c7d 100644 --- a/src/plugins/resourceeditor/resourceeditorw.h +++ b/src/plugins/resourceeditor/resourceeditorw.h @@ -55,15 +55,14 @@ public: //IDocument bool save(QString *errorString, const QString &fileName, bool autoSave); - QString fileName() const; bool shouldAutoSave() const; bool isModified() const; bool isSaveAsAllowed() const; bool reload(QString *errorString, ReloadFlag flag, ChangeType type); QString defaultPath() const; QString suggestedFileName() const; - virtual QString mimeType() const; - virtual void rename(const QString &newName); + QString mimeType() const; + void setFileName(const QString &newName); private: const QString m_mimeType; |