forked from qt-creator/qt-creator
GenericProject: Keep file list sorted when adding or renaming files
Change-Id: I064e9a00039671fbf626efa5227678800615ff1d Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
committed by
André Hartmann
parent
04e222784b
commit
758544c058
@@ -46,6 +46,7 @@
|
|||||||
#include <projectexplorer/projectexplorerconstants.h>
|
#include <projectexplorer/projectexplorerconstants.h>
|
||||||
#include <qtsupport/baseqtversion.h>
|
#include <qtsupport/baseqtversion.h>
|
||||||
#include <qtsupport/qtkitinformation.h>
|
#include <qtsupport/qtkitinformation.h>
|
||||||
|
#include <utils/algorithm.h>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
@@ -171,14 +172,19 @@ bool GenericProject::saveRawList(const QStringList &rawList, const QString &file
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void insertSorted(QStringList *list, const QString &value)
|
||||||
|
{
|
||||||
|
int pos = Utils::indexOf(*list, [value](const QString &s) { return s > value; });
|
||||||
|
list->insert(pos, value);
|
||||||
|
}
|
||||||
|
|
||||||
bool GenericProject::addFiles(const QStringList &filePaths)
|
bool GenericProject::addFiles(const QStringList &filePaths)
|
||||||
{
|
{
|
||||||
QStringList newList = m_rawFileList;
|
QStringList newList = m_rawFileList;
|
||||||
|
|
||||||
QDir baseDir(projectDirectory().toString());
|
QDir baseDir(projectDirectory().toString());
|
||||||
foreach (const QString &filePath, filePaths)
|
foreach (const QString &filePath, filePaths)
|
||||||
newList.append(baseDir.relativeFilePath(filePath));
|
insertSorted(&newList, baseDir.relativeFilePath(filePath));
|
||||||
|
|
||||||
|
|
||||||
QSet<QString> includes = projectIncludePaths().toSet();
|
QSet<QString> includes = projectIncludePaths().toSet();
|
||||||
QSet<QString> toAdd;
|
QSet<QString> toAdd;
|
||||||
@@ -223,6 +229,7 @@ bool GenericProject::setFiles(const QStringList &filePaths)
|
|||||||
QDir baseDir(projectDirectory().toString());
|
QDir baseDir(projectDirectory().toString());
|
||||||
foreach (const QString &filePath, filePaths)
|
foreach (const QString &filePath, filePaths)
|
||||||
newList.append(baseDir.relativeFilePath(filePath));
|
newList.append(baseDir.relativeFilePath(filePath));
|
||||||
|
Utils::sort(newList);
|
||||||
|
|
||||||
return saveRawFileList(newList);
|
return saveRawFileList(newList);
|
||||||
}
|
}
|
||||||
@@ -236,7 +243,8 @@ bool GenericProject::renameFile(const QString &filePath, const QString &newFileP
|
|||||||
int index = newList.indexOf(i.value());
|
int index = newList.indexOf(i.value());
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
QDir baseDir(projectDirectory().toString());
|
QDir baseDir(projectDirectory().toString());
|
||||||
newList.replace(index, baseDir.relativeFilePath(newFilePath));
|
newList.removeAt(index);
|
||||||
|
insertSorted(&newList, baseDir.relativeFilePath(newFilePath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user