Commit d3dd264c authored by Friedemann Kleint's avatar Friedemann Kleint

Resource editor: Fix paste.

Add a "plainText" property to the resource editor's document
similar to the diff editor (see
f268d0f8 ).

Task-number: QTCREATORBUG-13458
Change-Id: Icd11134432f796b37090a16bbaa13f075fa8c2bd
Reviewed-by: default avatarDaniel Teske <daniel.teske@theqtcompany.com>
parent de34e0e3
...@@ -136,6 +136,11 @@ bool QrcEditor::save() ...@@ -136,6 +136,11 @@ bool QrcEditor::save()
return m_treeview->save(); return m_treeview->save();
} }
QString QrcEditor::contents() const
{
return m_treeview->contents();
}
bool QrcEditor::isDirty() bool QrcEditor::isDirty()
{ {
return m_treeview->isDirty(); return m_treeview->isDirty();
......
...@@ -49,6 +49,7 @@ public: ...@@ -49,6 +49,7 @@ public:
bool load(const QString &fileName); bool load(const QString &fileName);
bool save(); bool save();
QString contents() const;
QTreeView *treeView() { return m_treeview; } QTreeView *treeView() { return m_treeview; }
QString errorMessage() const { return m_treeview->errorMessage(); } QString errorMessage() const { return m_treeview->errorMessage(); }
......
...@@ -183,15 +183,8 @@ bool ResourceFile::load() ...@@ -183,15 +183,8 @@ bool ResourceFile::load()
return true; 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; QDomDocument doc;
QDomElement root = doc.createElement(QLatin1String("RCC")); QDomElement root = doc.createElement(QLatin1String("RCC"));
doc.appendChild(root); doc.appendChild(root);
...@@ -222,11 +215,19 @@ bool ResourceFile::save() ...@@ -222,11 +215,19 @@ bool ResourceFile::save()
felt.setAttribute(QLatin1String("threshold"), file.threshold); felt.setAttribute(QLatin1String("threshold"), file.threshold);
} }
} }
return doc.toString(4);
}
QString data = doc.toString(4); bool ResourceFile::save()
if (!m_textFileFormat.writeFile(m_file_name, data, &m_error_message)) {
m_error_message.clear();
if (m_file_name.isEmpty()) {
m_error_message = tr("The file name is empty.");
return false; return false;
return true; }
return m_textFileFormat.writeFile(m_file_name, contents(), &m_error_message);
} }
void ResourceFile::refresh() void ResourceFile::refresh()
......
...@@ -139,6 +139,7 @@ public: ...@@ -139,6 +139,7 @@ public:
QString fileName() const { return m_file_name; } QString fileName() const { return m_file_name; }
bool load(); bool load();
bool save(); bool save();
QString contents() const;
QString errorMessage() const { return m_error_message; } QString errorMessage() const { return m_error_message; }
void refresh(); void refresh();
...@@ -252,6 +253,8 @@ private: ...@@ -252,6 +253,8 @@ private:
public: public:
virtual bool reload(); virtual bool reload();
virtual bool save(); virtual bool save();
QString contents() const { return m_resource_file.contents(); }
// QString errorMessage() const { return m_resource_file.errorMessage(); } // QString errorMessage() const { return m_resource_file.errorMessage(); }
bool dirty() const { return m_dirty; } bool dirty() const { return m_dirty; }
......
...@@ -381,6 +381,11 @@ bool ResourceView::save() ...@@ -381,6 +381,11 @@ bool ResourceView::save()
return m_qrcModel->save(); return m_qrcModel->save();
} }
QString ResourceView::contents() const
{
return m_qrcModel->contents();
}
QString ResourceView::currentAlias() const QString ResourceView::currentAlias() const
{ {
const QModelIndex current = currentIndex(); const QModelIndex current = currentIndex();
......
...@@ -85,6 +85,7 @@ public: ...@@ -85,6 +85,7 @@ public:
bool load(const QString &fileName); bool load(const QString &fileName);
bool save(); bool save();
QString contents() const;
QString errorMessage() const { return m_qrcFile.errorMessage(); } QString errorMessage() const { return m_qrcFile.errorMessage(); }
QString fileName() const; QString fileName() const;
void setFileName(const QString &fileName); void setFileName(const QString &fileName);
......
...@@ -187,6 +187,11 @@ bool ResourceEditorDocument::save(QString *errorString, const QString &name, boo ...@@ -187,6 +187,11 @@ bool ResourceEditorDocument::save(QString *errorString, const QString &name, boo
return true; return true;
} }
QString ResourceEditorDocument::plainText() const
{
return m_parent->m_resourceEditor->contents();
}
bool ResourceEditorDocument::setContents(const QByteArray &contents) bool ResourceEditorDocument::setContents(const QByteArray &contents)
{ {
Utils::TempFileSaver saver; Utils::TempFileSaver saver;
......
...@@ -50,12 +50,14 @@ class ResourceEditorDocument ...@@ -50,12 +50,14 @@ class ResourceEditorDocument
: public Core::IDocument : public Core::IDocument
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString plainText READ plainText STORED false) // For access by code pasters
public: public:
ResourceEditorDocument(ResourceEditorW *parent = 0); ResourceEditorDocument(ResourceEditorW *parent = 0);
//IDocument //IDocument
bool save(QString *errorString, const QString &fileName, bool autoSave); bool save(QString *errorString, const QString &fileName, bool autoSave);
QString plainText() const;
bool setContents(const QByteArray &contents); bool setContents(const QByteArray &contents);
bool shouldAutoSave() const; bool shouldAutoSave() const;
bool isModified() const; bool isModified() const;
......
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