From d326779dc4e912fb5eb8439cfeb0ae17e356dfb4 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 2 May 2019 14:28:07 +0200 Subject: [PATCH] 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 --- src/plugins/resourceeditor/resourcenode.cpp | 46 ++++----------------- 1 file changed, 9 insertions(+), 37 deletions(-) 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; }