Fix collapse all disable state and functionality when partially collapsed.
Fix being able to collapse empty groups with double-click.
This commit is contained in:
@@ -122,6 +122,7 @@ private:
|
|||||||
GUIGroupList groups; ///< List of groups
|
GUIGroupList groups; ///< List of groups
|
||||||
uint tiny_step_height; ///< Step height for the group list
|
uint tiny_step_height; ///< Step height for the group list
|
||||||
Scrollbar *group_sb;
|
Scrollbar *group_sb;
|
||||||
|
SmallVector<GroupID, 16> all_groups; ///< List of all groups, including hidden ones
|
||||||
SmallVector<GroupID, 16> collapsed_groups; ///< List of collapsed groups
|
SmallVector<GroupID, 16> collapsed_groups; ///< List of collapsed groups
|
||||||
SmallVector<GroupID, 16> collapsable_groups; ///< List of collapsable groups
|
SmallVector<GroupID, 16> collapsable_groups; ///< List of collapsable groups
|
||||||
|
|
||||||
@@ -130,18 +131,21 @@ private:
|
|||||||
Dimension column_size[VGC_END]; ///< Size of the columns in the group list.
|
Dimension column_size[VGC_END]; ///< Size of the columns in the group list.
|
||||||
|
|
||||||
/** return true if group has children */
|
/** return true if group has children */
|
||||||
bool AddParents(GUIGroupList *source, GroupID parent, int indent)
|
bool AddParents(GUIGroupList *source, GroupID parent, int indent, bool parent_collapsed)
|
||||||
{
|
{
|
||||||
bool is_collapsed = this->collapsed_groups.Contains(parent);
|
bool is_collapsed = this->collapsed_groups.Contains(parent);
|
||||||
|
bool overall_collapsed = is_collapsed || parent_collapsed;
|
||||||
bool has_children = false;
|
bool has_children = false;
|
||||||
|
|
||||||
for (const Group **g = source->Begin(); g != source->End(); g++) {
|
for (const Group **g = source->Begin(); g != source->End(); g++) {
|
||||||
if ((*g)->parent == parent) {
|
if ((*g)->parent == parent) {
|
||||||
has_children = true;
|
has_children = true;
|
||||||
if (is_collapsed) return has_children;
|
*this->all_groups.Append() = (*g)->index;
|
||||||
|
if (!overall_collapsed) {
|
||||||
*this->groups.Append() = *g;
|
*this->groups.Append() = *g;
|
||||||
*this->indents.Append() = indent;
|
*this->indents.Append() = indent;
|
||||||
bool child_has_children = AddParents(source, (*g)->index, indent + 1);
|
}
|
||||||
|
bool child_has_children = AddParents(source, (*g)->index, indent + 1, overall_collapsed);
|
||||||
if (child_has_children) *this->collapsable_groups.Append() = (*g)->index;
|
if (child_has_children) *this->collapsable_groups.Append() = (*g)->index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,7 +179,9 @@ private:
|
|||||||
{
|
{
|
||||||
GroupID *item = this->collapsed_groups.Find(group);
|
GroupID *item = this->collapsed_groups.Find(group);
|
||||||
if (item == this->collapsed_groups.End()) {
|
if (item == this->collapsed_groups.End()) {
|
||||||
|
if (this->collapsable_groups.Find(group) != this->collapsable_groups.End()) {
|
||||||
*(this->collapsed_groups.Append()) = group;
|
*(this->collapsed_groups.Append()) = group;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this->collapsed_groups.Erase(item);
|
this->collapsed_groups.Erase(item);
|
||||||
}
|
}
|
||||||
@@ -190,6 +196,7 @@ private:
|
|||||||
{
|
{
|
||||||
if (!this->groups.NeedRebuild()) return;
|
if (!this->groups.NeedRebuild()) return;
|
||||||
|
|
||||||
|
this->all_groups.Clear();
|
||||||
this->groups.Clear();
|
this->groups.Clear();
|
||||||
this->indents.Clear();
|
this->indents.Clear();
|
||||||
this->collapsable_groups.Clear();
|
this->collapsable_groups.Clear();
|
||||||
@@ -206,7 +213,7 @@ private:
|
|||||||
list.ForceResort();
|
list.ForceResort();
|
||||||
list.Sort(&GroupNameSorter);
|
list.Sort(&GroupNameSorter);
|
||||||
|
|
||||||
AddParents(&list, INVALID_GROUP, 0);
|
AddParents(&list, INVALID_GROUP, 0, false);
|
||||||
|
|
||||||
this->groups.Compact();
|
this->groups.Compact();
|
||||||
this->groups.RebuildDone();
|
this->groups.RebuildDone();
|
||||||
@@ -720,8 +727,8 @@ public:
|
|||||||
|
|
||||||
case WID_GL_COLLAPSE_ALL_GROUPS: {
|
case WID_GL_COLLAPSE_ALL_GROUPS: {
|
||||||
this->collapsed_groups.Clear();
|
this->collapsed_groups.Clear();
|
||||||
for (const Group **group = this->groups.Begin(); group != this->groups.End(); ++group) {
|
for (const GroupID *gid = this->all_groups.Begin(); gid != this->all_groups.End(); ++gid) {
|
||||||
GroupID id = (*group)->index;
|
GroupID id = *gid;
|
||||||
if (id != ALL_GROUP && id != DEFAULT_GROUP && id != INVALID_GROUP && this->collapsable_groups.Contains(id)) {
|
if (id != ALL_GROUP && id != DEFAULT_GROUP && id != INVALID_GROUP && this->collapsable_groups.Contains(id)) {
|
||||||
*this->collapsed_groups.Append() = id;
|
*this->collapsed_groups.Append() = id;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user