[Bf-blender-cvs] [536109b4ec3] master: Fix possibly wrong matching of tree-view item buttons

Julian Eisel noreply at git.blender.org
Wed Oct 6 16:36:57 CEST 2021


Commit: 536109b4ec336e86de5a7e22e51804584bca74f5
Author: Julian Eisel
Date:   Wed Oct 6 16:15:12 2021 +0200
Branches: master
https://developer.blender.org/rB536109b4ec336e86de5a7e22e51804584bca74f5

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.

===================================================================

M	source/blender/editors/include/UI_tree_view.hh
M	source/blender/editors/interface/tree_view.cc

===================================================================

diff --git a/source/blender/editors/include/UI_tree_view.hh b/source/blender/editors/include/UI_tree_view.hh
index 51737067648..8f8681896fe 100644
--- a/source/blender/editors/include/UI_tree_view.hh
+++ b/source/blender/editors/include/UI_tree_view.hh
@@ -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:
   /**
diff --git a/source/blender/editors/interface/tree_view.cc b/source/blender/editors/interface/tree_view.cc
index 8f272143b2c..d2971f791c2 100644
--- a/source/blender/editors/interface/tree_view.cc
+++ b/source/blender/editors/interface/tree_view.cc
@@ -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)



More information about the Bf-blender-cvs mailing list