diff --git a/src/plugins/resourceeditor/resourcenode.cpp b/src/plugins/resourceeditor/resourcenode.cpp index ae9d8c7d619..7c411a51269 100644 --- a/src/plugins/resourceeditor/resourcenode.cpp +++ b/src/plugins/resourceeditor/resourcenode.cpp @@ -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; }