forked from qt-creator/qt-creator
ResourceEditor: Simplify Resource tree construction
Instead of keeping track which nodes need to be created, create the tree on-the-fly directly. Change-Id: Iebb00c385f2abe42c7fd04547a7af85ad8f8f87b Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -27,15 +27,15 @@
|
||||
#include "resourceeditorconstants.h"
|
||||
#include "qrceditor/resourcefile_p.h"
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <coreplugin/documentmanager.h>
|
||||
#include <coreplugin/fileiconprovider.h>
|
||||
|
||||
#include <qmljstools/qmljstoolsconstants.h>
|
||||
|
||||
#include <utils/mimetypes/mimedatabase.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/mimetypes/mimedatabase.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
@@ -121,12 +121,10 @@ ResourceTopLevelNode::~ResourceTopLevelNode()
|
||||
|
||||
void ResourceTopLevelNode::addInternalNodes()
|
||||
{
|
||||
QMap<PrefixFolderLang, QList<ProjectExplorer::Node *>> nodesToAdd;
|
||||
QMap<PrefixFolderLang, QList<ProjectExplorer::FolderNode *>> foldersToAddToPrefix;
|
||||
|
||||
ResourceFile file(filePath().toString(), m_contents);
|
||||
if (file.load() == Core::IDocument::OpenResult::Success) {
|
||||
QMap<PrefixFolderLang, ProjectExplorer::FolderNode *> prefixNodes;
|
||||
if (file.load() != Core::IDocument::OpenResult::Success)
|
||||
return;
|
||||
|
||||
QMap<PrefixFolderLang, ProjectExplorer::FolderNode *> folderNodes;
|
||||
|
||||
int prfxcount = file.prefixCount();
|
||||
@@ -135,23 +133,25 @@ void ResourceTopLevelNode::addInternalNodes()
|
||||
const QString &lang = file.lang(i);
|
||||
// ensure that we don't duplicate prefixes
|
||||
PrefixFolderLang prefixId(prefix, QString(), lang);
|
||||
if (!prefixNodes.contains(prefixId)) {
|
||||
if (!folderNodes.contains(prefixId)) {
|
||||
ProjectExplorer::FolderNode *fn = new ResourceFolderNode(file.prefix(i), file.lang(i), this);
|
||||
addNode(fn);
|
||||
prefixNodes.insert(prefixId, fn);
|
||||
folderNodes.insert(prefixId, fn);
|
||||
}
|
||||
ResourceFolderNode *currentPrefixNode = static_cast<ResourceFolderNode*>(prefixNodes[prefixId]);
|
||||
ResourceFolderNode *currentPrefixNode = static_cast<ResourceFolderNode*>(folderNodes[prefixId]);
|
||||
|
||||
QSet<QString> fileNames;
|
||||
int filecount = file.fileCount(i);
|
||||
for (int j = 0; j < filecount; ++j) {
|
||||
const QString &fileName = file.file(i, j);
|
||||
QString alias = file.alias(i, j);
|
||||
if (fileNames.contains(fileName)) {
|
||||
// The file name is duplicated, skip it
|
||||
// Note: this is wrong, but the qrceditor doesn't allow it either
|
||||
// only aliases need to be unique
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
QString alias = file.alias(i, j);
|
||||
if (alias.isEmpty())
|
||||
alias = filePath().toFileInfo().absoluteDir().relativeFilePath(fileName);
|
||||
|
||||
@@ -183,14 +183,15 @@ void ResourceTopLevelNode::addInternalNodes()
|
||||
= new SimpleResourceFolderNode(folderName, pathElement,
|
||||
prefix, lang, folderPath,
|
||||
this, currentPrefixNode);
|
||||
if (parentIsPrefix) {
|
||||
foldersToAddToPrefix[prefixId] << newNode;
|
||||
nodesToAdd[prefixId] << newNode;
|
||||
} else {
|
||||
PrefixFolderLang parentFolderId(prefix, parentFolderName, lang);
|
||||
nodesToAdd[parentFolderId] << newNode;
|
||||
}
|
||||
folderNodes.insert(folderId, newNode);
|
||||
|
||||
PrefixFolderLang thisPrefixId = prefixId;
|
||||
if (!parentIsPrefix)
|
||||
thisPrefixId = PrefixFolderLang(prefix, parentFolderName, lang);
|
||||
FolderNode *fn = folderNodes[thisPrefixId];
|
||||
QTC_CHECK(fn);
|
||||
if (fn)
|
||||
fn->addNode(newNode);
|
||||
}
|
||||
parentIsPrefix = false;
|
||||
parentFolderName = folderName;
|
||||
@@ -198,25 +199,11 @@ void ResourceTopLevelNode::addInternalNodes()
|
||||
|
||||
const QString qrcPath = QDir::cleanPath(prefixWithSlash + alias);
|
||||
fileNames.insert(fileName);
|
||||
auto rn = new ResourceFileNode(Utils::FileName::fromString(fileName),
|
||||
qrcPath, displayName);
|
||||
nodesToAdd[folderId] << rn;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const QList<FolderNode *> fnodes = folderNodes();
|
||||
for (FolderNode *sfn : fnodes) {
|
||||
ResourceFolderNode *srn = static_cast<ResourceFolderNode *>(sfn);
|
||||
PrefixFolderLang folderId(srn->prefix(), QString(), srn->lang());
|
||||
const QList<ProjectExplorer::Node *> nodes = nodesToAdd[folderId];
|
||||
for (Node *n : nodes)
|
||||
srn->addNode(n);
|
||||
const QList<FolderNode *> sfnodes = sfn->folderNodes();
|
||||
for (FolderNode *ssfn : sfnodes) {
|
||||
SimpleResourceFolderNode *sssn = static_cast<SimpleResourceFolderNode *>(ssfn);
|
||||
sssn->addFilesAndSubfolders(nodesToAdd, srn->prefix(), srn->lang());
|
||||
FolderNode *fn = folderNodes[folderId];
|
||||
QTC_CHECK(fn);
|
||||
if (fn)
|
||||
fn->addNode(new ResourceFileNode(Utils::FileName::fromString(fileName),
|
||||
qrcPath, displayName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -651,14 +638,3 @@ ResourceFolderNode *SimpleResourceFolderNode::prefixNode() const
|
||||
{
|
||||
return m_prefixNode;
|
||||
}
|
||||
|
||||
void SimpleResourceFolderNode::addFilesAndSubfolders(const QMap<PrefixFolderLang, QList<Node *>> &nodesToAdd,
|
||||
const QString &prefix, const QString &lang)
|
||||
{
|
||||
for (Node *node : nodesToAdd.value(PrefixFolderLang(prefix, m_folderName, lang)))
|
||||
addNode(node);
|
||||
foreach (FolderNode* subNode, folderNodes()) {
|
||||
SimpleResourceFolderNode* sn = static_cast<SimpleResourceFolderNode*>(subNode);
|
||||
sn->addFilesAndSubfolders(nodesToAdd, prefix, lang);
|
||||
}
|
||||
}
|
||||
|
@@ -122,8 +122,6 @@ public:
|
||||
const QString &prefix, const QString &lang, Utils::FileName absolutePath,
|
||||
ResourceTopLevelNode *topLevel, ResourceFolderNode *prefixNode);
|
||||
QList<ProjectExplorer::ProjectAction> supportedActions(ProjectExplorer::Node *node) const;
|
||||
void addFilesAndSubfolders(const QMap<PrefixFolderLang, QList<Node *> > &nodesToAdd,
|
||||
const QString &prefix, const QString &lang);
|
||||
bool addFiles(const QStringList &filePaths, QStringList *notAdded);
|
||||
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved);
|
||||
bool renameFile(const QString &filePath, const QString &newFilePath);
|
||||
|
Reference in New Issue
Block a user