forked from qt-creator/qt-creator
QmakeProjectManager: Preserve line endings
... when adding and removing files via the project tree. Fixes: QTCREATORBUG-2196 Change-Id: Ie4ee3a244c9089953cf414d9777fc65b6a8b9689 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -649,7 +649,7 @@ bool QmakePriFile::addDependencies(const QStringList &dependencies)
|
|||||||
if (qtDependencies.isEmpty())
|
if (qtDependencies.isEmpty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
const QPair<ProFile *, QStringList> pair = readProFile(filePath().toString());
|
const QPair<ProFile *, QStringList> pair = readProFile();
|
||||||
ProFile * const includeFile = pair.first;
|
ProFile * const includeFile = pair.first;
|
||||||
if (!includeFile)
|
if (!includeFile)
|
||||||
return false;
|
return false;
|
||||||
@@ -750,27 +750,30 @@ bool QmakePriFile::ensureWriteableProFile(const QString &file)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPair<ProFile *, QStringList> QmakePriFile::readProFile(const QString &file)
|
QPair<ProFile *, QStringList> QmakePriFile::readProFile()
|
||||||
{
|
{
|
||||||
QStringList lines;
|
QStringList lines;
|
||||||
ProFile *includeFile = nullptr;
|
ProFile *includeFile = nullptr;
|
||||||
{
|
{
|
||||||
QString contents;
|
QString contents;
|
||||||
{
|
{
|
||||||
FileReader reader;
|
QString errorMsg;
|
||||||
if (!reader.fetch(file, QIODevice::Text)) {
|
if (TextFileFormat::readFile(
|
||||||
QmakeProject::proFileParseError(reader.errorString());
|
filePath().toString(),
|
||||||
|
Core::EditorManager::defaultTextCodec(),
|
||||||
|
&contents,
|
||||||
|
&m_textFormat,
|
||||||
|
&errorMsg) != TextFileFormat::ReadSuccess) {
|
||||||
|
QmakeProject::proFileParseError(errorMsg);
|
||||||
return qMakePair(includeFile, lines);
|
return qMakePair(includeFile, lines);
|
||||||
}
|
}
|
||||||
const QTextCodec *codec = Core::EditorManager::defaultTextCodec();
|
lines = contents.split('\n');
|
||||||
contents = codec->toUnicode(reader.data());
|
|
||||||
lines = contents.split(QLatin1Char('\n'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QMakeVfs vfs;
|
QMakeVfs vfs;
|
||||||
QtSupport::ProMessageHandler handler;
|
QtSupport::ProMessageHandler handler;
|
||||||
QMakeParser parser(nullptr, &vfs, &handler);
|
QMakeParser parser(nullptr, &vfs, &handler);
|
||||||
includeFile = parser.parsedProBlock(QStringRef(&contents), 0, file, 1);
|
includeFile = parser.parsedProBlock(QStringRef(&contents), 0, filePath().toString(), 1);
|
||||||
}
|
}
|
||||||
return qMakePair(includeFile, lines);
|
return qMakePair(includeFile, lines);
|
||||||
}
|
}
|
||||||
@@ -788,7 +791,7 @@ bool QmakePriFile::renameFile(const QString &oldName,
|
|||||||
if (!prepareForChange())
|
if (!prepareForChange())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QPair<ProFile *, QStringList> pair = readProFile(filePath().toString());
|
QPair<ProFile *, QStringList> pair = readProFile();
|
||||||
ProFile *includeFile = pair.first;
|
ProFile *includeFile = pair.first;
|
||||||
QStringList lines = pair.second;
|
QStringList lines = pair.second;
|
||||||
|
|
||||||
@@ -834,7 +837,7 @@ void QmakePriFile::changeFiles(const QString &mimeType,
|
|||||||
if (!prepareForChange())
|
if (!prepareForChange())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QPair<ProFile *, QStringList> pair = readProFile(filePath().toString());
|
QPair<ProFile *, QStringList> pair = readProFile();
|
||||||
ProFile *includeFile = pair.first;
|
ProFile *includeFile = pair.first;
|
||||||
QStringList lines = pair.second;
|
QStringList lines = pair.second;
|
||||||
|
|
||||||
@@ -876,7 +879,7 @@ bool QmakePriFile::setProVariable(const QString &var, const QStringList &values,
|
|||||||
if (!prepareForChange())
|
if (!prepareForChange())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QPair<ProFile *, QStringList> pair = readProFile(filePath().toString());
|
QPair<ProFile *, QStringList> pair = readProFile();
|
||||||
ProFile *includeFile = pair.first;
|
ProFile *includeFile = pair.first;
|
||||||
QStringList lines = pair.second;
|
QStringList lines = pair.second;
|
||||||
|
|
||||||
@@ -895,11 +898,13 @@ bool QmakePriFile::setProVariable(const QString &var, const QStringList &values,
|
|||||||
void QmakePriFile::save(const QStringList &lines)
|
void QmakePriFile::save(const QStringList &lines)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
QTC_ASSERT(m_textFormat.codec, return);
|
||||||
FileChangeBlocker changeGuard(filePath().toString());
|
FileChangeBlocker changeGuard(filePath().toString());
|
||||||
FileSaver saver(filePath().toString(), QIODevice::Text);
|
QString errorMsg;
|
||||||
const QTextCodec *codec = Core::EditorManager::defaultTextCodec();
|
if (!m_textFormat.writeFile(filePath().toString(), lines.join('\n'), &errorMsg)) {
|
||||||
saver.write(codec->fromUnicode(lines.join(QLatin1Char('\n'))));
|
QMessageBox::critical(Core::ICore::mainWindow(), QCoreApplication::translate(
|
||||||
saver.finalize(Core::ICore::mainWindow());
|
"QmakePriFile", "File Error"), errorMsg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a hack.
|
// This is a hack.
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#include <coreplugin/idocument.h>
|
#include <coreplugin/idocument.h>
|
||||||
#include <cpptools/generatedcodemodelsupport.h>
|
#include <cpptools/generatedcodemodelsupport.h>
|
||||||
|
#include <utils/textfileformat.h>
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
@@ -202,7 +203,7 @@ private:
|
|||||||
|
|
||||||
bool prepareForChange();
|
bool prepareForChange();
|
||||||
static bool ensureWriteableProFile(const QString &file);
|
static bool ensureWriteableProFile(const QString &file);
|
||||||
static QPair<ProFile *, QStringList> readProFile(const QString &file);
|
QPair<ProFile *, QStringList> readProFile();
|
||||||
static QPair<ProFile *, QStringList> readProFileFromContents(const QString &contents);
|
static QPair<ProFile *, QStringList> readProFileFromContents(const QString &contents);
|
||||||
void save(const QStringList &lines);
|
void save(const QStringList &lines);
|
||||||
bool saveModifiedEditors();
|
bool saveModifiedEditors();
|
||||||
@@ -228,6 +229,7 @@ private:
|
|||||||
QVector<QmakePriFile *> m_children;
|
QVector<QmakePriFile *> m_children;
|
||||||
|
|
||||||
std::unique_ptr<Core::IDocument> m_priFileDocument;
|
std::unique_ptr<Core::IDocument> m_priFileDocument;
|
||||||
|
Utils::TextFileFormat m_textFormat;
|
||||||
|
|
||||||
// Memory is cheap...
|
// Memory is cheap...
|
||||||
QMap<ProjectExplorer::FileType, QSet<Utils::FilePath>> m_files;
|
QMap<ProjectExplorer::FileType, QSet<Utils::FilePath>> m_files;
|
||||||
|
Reference in New Issue
Block a user