diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2019-05-02 14:28:07 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2019-05-02 13:22:11 +0000 |
commit | d326779dc4e912fb5eb8439cfeb0ae17e356dfb4 (patch) | |
tree | 9076cb2b712f42cf9420a7b2a14dd84f9408f024 /src/plugins/resourceeditor | |
parent | 66237a6e0401b0638e91c1fe3c8cefa7330db03d (diff) |
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>
Diffstat (limited to 'src/plugins/resourceeditor')
-rw-r--r-- | src/plugins/resourceeditor/resourcenode.cpp | 46 |
1 files changed, 9 insertions, 37 deletions
diff --git a/src/plugins/resourceeditor/resourcenode.cpp b/src/plugins/resourceeditor/resourcenode.cpp index ae9d8c7d61..7c411a5126 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; } |