Fix possibly wrong matching of tree-view item buttons

The UI code to ensure consistent button state over redraws was just comparing
the name of the item, ignoring the parent names. So with multiple items of the
same name, there might have been glitches (didn't see any myself though).

There's a leftover to-do though, we don't check yet if the matched buttons are
actually from the same tree. Added TODO comment.
This commit is contained in:
Julian Eisel 2021-10-06 16:15:12 +02:00
parent 2012d541ae
commit 536109b4ec
2 changed files with 20 additions and 1 deletions

View File

@ -301,6 +301,7 @@ class AbstractTreeViewItem : public TreeViewItemContainer {
bool is_renaming() const;
void ensure_parents_uncollapsed();
bool matches_including_parents(const AbstractTreeViewItem &other) const;
protected:
/**

View File

@ -419,6 +419,23 @@ void AbstractTreeViewItem::ensure_parents_uncollapsed()
}
}
bool AbstractTreeViewItem::matches_including_parents(const AbstractTreeViewItem &other) const
{
if (!matches(other)) {
return false;
}
for (AbstractTreeViewItem *parent = parent_, *other_parent = other.parent_;
parent && other_parent;
parent = parent->parent_, other_parent = other_parent->parent_) {
if (!parent->matches(*other_parent)) {
return false;
}
}
return true;
}
void AbstractTreeViewItem::change_state_delayed()
{
if (is_active_fn_()) {
@ -538,7 +555,8 @@ bool UI_tree_view_item_matches(const uiTreeViewItemHandle *a_handle,
{
const AbstractTreeViewItem &a = reinterpret_cast<const AbstractTreeViewItem &>(*a_handle);
const AbstractTreeViewItem &b = reinterpret_cast<const AbstractTreeViewItem &>(*b_handle);
return a.matches(b);
/* TODO should match the tree-view as well. */
return a.matches_including_parents(b);
}
bool UI_tree_view_item_can_drop(const uiTreeViewItemHandle *item_, const wmDrag *drag)