forked from qt-creator/qt-creator
Fixed a problem with adding files when final newline is missing
When there was no final newline in the .files file, the name of the first new file would get appended to the name of the last file. This patch fixes that by simply rewriting the whole file. Also switched to writing out native line endings.
This commit is contained in:
@@ -170,18 +170,22 @@ static QStringList readLines(const QString &absoluteFileName)
|
||||
|
||||
bool GenericProject::addFiles(const QStringList &filePaths)
|
||||
{
|
||||
// Make sure we can open the file for writing
|
||||
QFile file(filesFileName());
|
||||
if (file.open(QFile::Append)) {
|
||||
QTextStream stream(&file);
|
||||
QDir baseDir(QFileInfo(m_fileName).dir());
|
||||
foreach (const QString &filePath, filePaths) {
|
||||
stream << baseDir.relativeFilePath(filePath) << "\n";
|
||||
}
|
||||
file.close();
|
||||
refresh(GenericProject::Files);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
return false;
|
||||
|
||||
QStringList newFileList = m_files;
|
||||
newFileList.append(filePaths);
|
||||
|
||||
QTextStream stream(&file);
|
||||
QDir baseDir(QFileInfo(m_fileName).dir());
|
||||
foreach (const QString &filePath, newFileList)
|
||||
stream << baseDir.relativeFilePath(filePath) << QLatin1Char('\n');
|
||||
|
||||
file.close();
|
||||
refresh(GenericProject::Files);
|
||||
return true;
|
||||
}
|
||||
|
||||
void GenericProject::parseProject(RefreshOptions options)
|
||||
|
Reference in New Issue
Block a user