diff --git a/src/plugins/resourceeditor/qrceditor/qrceditor.cpp b/src/plugins/resourceeditor/qrceditor/qrceditor.cpp index 846f0136c60236c7e4d0cb18792772ed6b5e7f40..4afdf830cbb290b45ec2b5d826fa9a698152e91c 100644 --- a/src/plugins/resourceeditor/qrceditor/qrceditor.cpp +++ b/src/plugins/resourceeditor/qrceditor/qrceditor.cpp @@ -136,6 +136,11 @@ bool QrcEditor::save() return m_treeview->save(); } +QString QrcEditor::contents() const +{ + return m_treeview->contents(); +} + bool QrcEditor::isDirty() { return m_treeview->isDirty(); diff --git a/src/plugins/resourceeditor/qrceditor/qrceditor.h b/src/plugins/resourceeditor/qrceditor/qrceditor.h index 7a24d9653cbcc81a64cc248c377f053141a1f4e4..fbcafeb7e68b2802642a21f8c348b8994f9af142 100644 --- a/src/plugins/resourceeditor/qrceditor/qrceditor.h +++ b/src/plugins/resourceeditor/qrceditor/qrceditor.h @@ -49,6 +49,7 @@ public: bool load(const QString &fileName); bool save(); + QString contents() const; QTreeView *treeView() { return m_treeview; } QString errorMessage() const { return m_treeview->errorMessage(); } diff --git a/src/plugins/resourceeditor/qrceditor/resourcefile.cpp b/src/plugins/resourceeditor/qrceditor/resourcefile.cpp index e4a13ca8690adaaf61a33d85148a3d16ec48c594..ff57423cb5da273f7148a95b048d0d5f53d5f94f 100644 --- a/src/plugins/resourceeditor/qrceditor/resourcefile.cpp +++ b/src/plugins/resourceeditor/qrceditor/resourcefile.cpp @@ -183,15 +183,8 @@ bool ResourceFile::load() return true; } -bool ResourceFile::save() +QString ResourceFile::contents() const { - m_error_message.clear(); - - if (m_file_name.isEmpty()) { - m_error_message = tr("The file name is empty."); - return false; - } - QDomDocument doc; QDomElement root = doc.createElement(QLatin1String("RCC")); doc.appendChild(root); @@ -222,11 +215,19 @@ bool ResourceFile::save() felt.setAttribute(QLatin1String("threshold"), file.threshold); } } + return doc.toString(4); +} - QString data = doc.toString(4); - if (!m_textFileFormat.writeFile(m_file_name, data, &m_error_message)) +bool ResourceFile::save() +{ + m_error_message.clear(); + + if (m_file_name.isEmpty()) { + m_error_message = tr("The file name is empty."); return false; - return true; + } + + return m_textFileFormat.writeFile(m_file_name, contents(), &m_error_message); } void ResourceFile::refresh() diff --git a/src/plugins/resourceeditor/qrceditor/resourcefile_p.h b/src/plugins/resourceeditor/qrceditor/resourcefile_p.h index b60d5ca628a8f377b06c0a4bb49eba813c920039..598f80584454aec02dcc15287f253addf4f95798 100644 --- a/src/plugins/resourceeditor/qrceditor/resourcefile_p.h +++ b/src/plugins/resourceeditor/qrceditor/resourcefile_p.h @@ -139,6 +139,7 @@ public: QString fileName() const { return m_file_name; } bool load(); bool save(); + QString contents() const; QString errorMessage() const { return m_error_message; } void refresh(); @@ -252,6 +253,8 @@ private: public: virtual bool reload(); virtual bool save(); + QString contents() const { return m_resource_file.contents(); } + // QString errorMessage() const { return m_resource_file.errorMessage(); } bool dirty() const { return m_dirty; } diff --git a/src/plugins/resourceeditor/qrceditor/resourceview.cpp b/src/plugins/resourceeditor/qrceditor/resourceview.cpp index 4a7d7c905c52407290c1f55955ede4bb047c8a36..2b24dfa578aaf7647d0c8efc1d694d091e844dd7 100644 --- a/src/plugins/resourceeditor/qrceditor/resourceview.cpp +++ b/src/plugins/resourceeditor/qrceditor/resourceview.cpp @@ -381,6 +381,11 @@ bool ResourceView::save() return m_qrcModel->save(); } +QString ResourceView::contents() const +{ + return m_qrcModel->contents(); +} + QString ResourceView::currentAlias() const { const QModelIndex current = currentIndex(); diff --git a/src/plugins/resourceeditor/qrceditor/resourceview.h b/src/plugins/resourceeditor/qrceditor/resourceview.h index 840897e7a0ce5c1564ea03fab162cb7b18c004bb..96d2dadf9adae341090c6a0a47e4afc4a2283265 100644 --- a/src/plugins/resourceeditor/qrceditor/resourceview.h +++ b/src/plugins/resourceeditor/qrceditor/resourceview.h @@ -85,6 +85,7 @@ public: bool load(const QString &fileName); bool save(); + QString contents() const; QString errorMessage() const { return m_qrcFile.errorMessage(); } QString fileName() const; void setFileName(const QString &fileName); diff --git a/src/plugins/resourceeditor/resourceeditorw.cpp b/src/plugins/resourceeditor/resourceeditorw.cpp index 0b0dbd4e5616ae55dcf3dfcdf03716860818fe50..dc9fae45b104968fa39318a77512d51669046093 100644 --- a/src/plugins/resourceeditor/resourceeditorw.cpp +++ b/src/plugins/resourceeditor/resourceeditorw.cpp @@ -187,6 +187,11 @@ bool ResourceEditorDocument::save(QString *errorString, const QString &name, boo return true; } +QString ResourceEditorDocument::plainText() const +{ + return m_parent->m_resourceEditor->contents(); +} + bool ResourceEditorDocument::setContents(const QByteArray &contents) { Utils::TempFileSaver saver; diff --git a/src/plugins/resourceeditor/resourceeditorw.h b/src/plugins/resourceeditor/resourceeditorw.h index 2ddfba91a9ecc8fefeb7031f81faef342bef5152..908a93650610059c808678eb1c846a123dc8770f 100644 --- a/src/plugins/resourceeditor/resourceeditorw.h +++ b/src/plugins/resourceeditor/resourceeditorw.h @@ -50,12 +50,14 @@ class ResourceEditorDocument : public Core::IDocument { Q_OBJECT + Q_PROPERTY(QString plainText READ plainText STORED false) // For access by code pasters public: ResourceEditorDocument(ResourceEditorW *parent = 0); //IDocument bool save(QString *errorString, const QString &fileName, bool autoSave); + QString plainText() const; bool setContents(const QByteArray &contents); bool shouldAutoSave() const; bool isModified() const;