Commit c3d10509 authored by Eike Ziller's avatar Eike Ziller
Browse files

Qrc: Preserve line ending style



Change-Id: Ib8f57ee07fd5aff1089103cdeedbfec1003bf1cb
Task-number: QTCREATORBUG-6681
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 616ea2e5
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <QFile> #include <QFile>
#include <QMimeData> #include <QMimeData>
#include <QtAlgorithms> #include <QtAlgorithms>
#include <QTextCodec>
#include <QTextStream> #include <QTextStream>
#include <QIcon> #include <QIcon>
...@@ -124,6 +125,12 @@ bool ResourceFile::load() ...@@ -124,6 +125,12 @@ bool ResourceFile::load()
m_error_message = file.errorString(); m_error_message = file.errorString();
return false; return false;
} }
QByteArray data = file.readAll();
// Detect line ending style
m_textFileFormat = Utils::TextFileFormat::detect(data);
// we always write UTF-8 when saving
m_textFileFormat.codec = QTextCodec::codecForName("UTF-8");
file.close();
clearPrefixList(); clearPrefixList();
...@@ -131,7 +138,7 @@ bool ResourceFile::load() ...@@ -131,7 +138,7 @@ bool ResourceFile::load()
QString error_msg; QString error_msg;
int error_line, error_col; int error_line, error_col;
if (!doc.setContent(&file, &error_msg, &error_line, &error_col)) { if (!doc.setContent(data, &error_msg, &error_line, &error_col)) {
m_error_message = tr("XML error on line %1, col %2: %3") m_error_message = tr("XML error on line %1, col %2: %3")
.arg(error_line).arg(error_col).arg(error_msg); .arg(error_line).arg(error_col).arg(error_msg);
return false; return false;
...@@ -184,12 +191,6 @@ bool ResourceFile::save() ...@@ -184,12 +191,6 @@ bool ResourceFile::save()
return false; return false;
} }
QFile file(m_file_name);
if (!file.open(QIODevice::WriteOnly)) {
m_error_message = file.errorString();
return false;
}
QDomDocument doc; QDomDocument doc;
QDomElement root = doc.createElement(QLatin1String("RCC")); QDomElement root = doc.createElement(QLatin1String("RCC"));
doc.appendChild(root); doc.appendChild(root);
...@@ -221,13 +222,9 @@ bool ResourceFile::save() ...@@ -221,13 +222,9 @@ bool ResourceFile::save()
} }
} }
QTextStream stream(&file); QString data = doc.toString(4);
doc.save(stream, 4); if (!m_textFileFormat.writeFile(m_file_name, data, &m_error_message))
stream.flush();
if (stream.status() != QTextStream::Ok) {
m_error_message = tr("Cannot write file. Disk full?");
return false; return false;
}
return true; return true;
} }
......
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#include <QStringList> #include <QStringList>
#include <QIcon> #include <QIcon>
#include <utils/textfileformat.h>
namespace ResourceEditor { namespace ResourceEditor {
namespace Internal { namespace Internal {
...@@ -177,6 +179,7 @@ private: ...@@ -177,6 +179,7 @@ private:
PrefixList m_prefix_list; PrefixList m_prefix_list;
QString m_file_name; QString m_file_name;
QString m_error_message; QString m_error_message;
Utils::TextFileFormat m_textFileFormat;
public: public:
void * prefixPointer(int prefixIndex) const; void * prefixPointer(int prefixIndex) 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