forked from qt-creator/qt-creator
ProjectExplorer: Fix renaming files in resources
This amends commit e161b5d1cd
, which fixed the problem only for top-
level entries in the resource file.
The underlying problem is that we have two different classes
ResourceFolderNode and SimpleResourceFolderNode, which look suspiciously
similar, with most of the latter's base class overrides being exact
copies of the former's. For now, we just get rid of these copies. At
some later point, we might want to drop one of these classes altogether.
Fixes: QTCREATORBUG-22313
Change-Id: I80094ca12f4e534daf40ca2f3cbf01a0ae4808d9
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -164,6 +164,7 @@ public:
|
||||
bool supportsAction(ProjectAction, const Node *node) const final;
|
||||
bool addFiles(const QStringList &filePaths, QStringList *notAdded) final;
|
||||
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved) final;
|
||||
bool canRenameFile(const QString &filePath, const QString &newFilePath) override;
|
||||
bool renameFile(const QString &filePath, const QString &newFilePath) final;
|
||||
|
||||
QString prefix() const { return m_prefix; }
|
||||
@@ -218,48 +219,17 @@ bool SimpleResourceFolderNode::addFiles(const QStringList &filePaths, QStringLis
|
||||
|
||||
bool SimpleResourceFolderNode::removeFiles(const QStringList &filePaths, QStringList *notRemoved)
|
||||
{
|
||||
if (notRemoved)
|
||||
*notRemoved = filePaths;
|
||||
ResourceFile file(m_topLevelNode->filePath().toString());
|
||||
if (file.load() != IDocument::OpenResult::Success)
|
||||
return false;
|
||||
int index = file.indexOfPrefix(m_prefix, m_lang);
|
||||
if (index == -1)
|
||||
return false;
|
||||
for (int j = 0; j < file.fileCount(index); ++j) {
|
||||
const QString fileName = file.file(index, j);
|
||||
if (!filePaths.contains(fileName))
|
||||
continue;
|
||||
if (notRemoved)
|
||||
notRemoved->removeOne(fileName);
|
||||
file.removeFile(index, j);
|
||||
--j;
|
||||
}
|
||||
FileChangeBlocker changeGuard(m_topLevelNode->filePath().toString());
|
||||
file.save();
|
||||
return prefixNode()->removeFiles(filePaths, notRemoved);
|
||||
}
|
||||
|
||||
return true;
|
||||
bool SimpleResourceFolderNode::canRenameFile(const QString &filePath, const QString &newFilePath)
|
||||
{
|
||||
return prefixNode()->canRenameFile(filePath, newFilePath);
|
||||
}
|
||||
|
||||
bool SimpleResourceFolderNode::renameFile(const QString &filePath, const QString &newFilePath)
|
||||
{
|
||||
ResourceFile file(m_topLevelNode->filePath().toString());
|
||||
if (file.load() != IDocument::OpenResult::Success)
|
||||
return false;
|
||||
int index = file.indexOfPrefix(m_prefix, m_lang);
|
||||
if (index == -1)
|
||||
return false;
|
||||
|
||||
for (int j = 0; j < file.fileCount(index); ++j) {
|
||||
if (file.file(index, j) == filePath) {
|
||||
file.replaceFile(index, j, newFilePath);
|
||||
FileChangeBlocker changeGuard(m_topLevelNode->filePath().toString());
|
||||
file.save();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return prefixNode()->renameFile(filePath, newFilePath);
|
||||
}
|
||||
|
||||
} // Internal
|
||||
@@ -544,6 +514,7 @@ bool ResourceFolderNode::removeFiles(const QStringList &filePaths, QStringList *
|
||||
file.removeFile(index, j);
|
||||
--j;
|
||||
}
|
||||
FileChangeBlocker changeGuard(m_topLevelNode->filePath().toString());
|
||||
file.save();
|
||||
|
||||
return true;
|
||||
@@ -582,6 +553,7 @@ bool ResourceFolderNode::renameFile(const QString &filePath, const QString &newF
|
||||
for (int j = 0; j < file.fileCount(index); ++j) {
|
||||
if (file.file(index, j) == filePath) {
|
||||
file.replaceFile(index, j, newFilePath);
|
||||
FileChangeBlocker changeGuard(m_topLevelNode->filePath().toString());
|
||||
file.save();
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user