ProjectExplorer: Don't hide empty resource files like empty directories

Task-number: QTCREATORBUG-18748
Change-Id: I4de59743c42b99ce0b402f814b4cd0ba5d299338
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Robert Loehning
2017-08-17 12:56:15 +02:00
parent 8353d76df4
commit b9167a192f
5 changed files with 16 additions and 2 deletions

View File

@@ -323,14 +323,15 @@ void FlatModel::addFolderNode(WrapperNode *parent, FolderNode *folderNode, QSet<
bool FlatModel::trimEmptyDirectories(WrapperNode *parent) bool FlatModel::trimEmptyDirectories(WrapperNode *parent)
{ {
if (!parent->m_node->asFolderNode()) const FolderNode *fn = parent->m_node->asFolderNode();
if (!fn)
return false; return false;
for (int i = parent->childCount() - 1; i >= 0; --i) { for (int i = parent->childCount() - 1; i >= 0; --i) {
if (trimEmptyDirectories(parent->childAt(i))) if (trimEmptyDirectories(parent->childAt(i)))
parent->removeChildAt(i); parent->removeChildAt(i);
} }
return parent->childCount() == 0; return parent->childCount() == 0 && !fn->showWhenEmpty();
} }
Qt::DropActions FlatModel::supportedDragActions() const Qt::DropActions FlatModel::supportedDragActions() const

View File

@@ -730,6 +730,11 @@ bool FolderNode::showInSimpleTree() const
return false; return false;
} }
bool FolderNode::showWhenEmpty() const
{
return false;
}
/*! /*!
\class ProjectExplorer::VirtualFolderNode \class ProjectExplorer::VirtualFolderNode

View File

@@ -272,6 +272,8 @@ public:
// determines if node will be shown in the flat view, by default folder and projects aren't shown // determines if node will be shown in the flat view, by default folder and projects aren't shown
virtual bool showInSimpleTree() const; virtual bool showInSimpleTree() const;
// determines if node will always be shown when hiding empty directories
virtual bool showWhenEmpty() const;
void addNode(Node *node); void addNode(Node *node);
void removeNode(Node *node); void removeNode(Node *node);

View File

@@ -492,6 +492,11 @@ bool ResourceTopLevelNode::showInSimpleTree() const
return true; return true;
} }
bool ResourceTopLevelNode::showWhenEmpty() const
{
return true;
}
ResourceFolderNode::ResourceFolderNode(const QString &prefix, const QString &lang, ResourceTopLevelNode *parent) ResourceFolderNode::ResourceFolderNode(const QString &prefix, const QString &lang, ResourceTopLevelNode *parent)
: FolderNode(FileName(parent->filePath()).appendPath(prefix)), : FolderNode(FileName(parent->filePath()).appendPath(prefix)),
// TOOD Why add existing directory doesn't work // TOOD Why add existing directory doesn't work

View File

@@ -51,6 +51,7 @@ public:
AddNewInformation addNewInformation(const QStringList &files, Node *context) const override; AddNewInformation addNewInformation(const QStringList &files, Node *context) const override;
bool showInSimpleTree() const override; bool showInSimpleTree() const override;
bool showWhenEmpty() const override;
bool removeNonExistingFiles(); bool removeNonExistingFiles();
QString contents() const { return m_contents; } QString contents() const { return m_contents; }