[Bf-blender-cvs] [487faed6d0a] master: Asset Browser: Ensure parent catalogs are expanded when adding child

Julian Eisel noreply at git.blender.org
Wed Oct 27 18:09:37 CEST 2021


Commit: 487faed6d0a1170a2f098552f794280fabe82186
Author: Julian Eisel
Date:   Wed Oct 27 17:38:59 2021 +0200
Branches: master
https://developer.blender.org/rB487faed6d0a1170a2f098552f794280fabe82186

Asset Browser: Ensure parent catalogs are expanded when adding child

When pressing the '+' icon to add a new child catalog, or when adding it
through the context menu, the new catalog should be visible. So the
this change makes sure the parent is uncollapsed if needed.

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

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 0d18eedeac9..77472979beb 100644
--- a/source/blender/editors/include/UI_tree_view.hh
+++ b/source/blender/editors/include/UI_tree_view.hh
@@ -196,6 +196,15 @@ class AbstractTreeView : public TreeViewItemContainer {
    * the actual state changes are done in a delayed manner through this function.
    */
   void change_state_delayed();
+  /**
+   * Typically when adding a new child from the UI, the parent should be expanded to make the new
+   * item visible. While this isn't totally bullet proof (items may be expanded where the child was
+   * added dynamically, not through user action), it should give the wanted behavior as needed in
+   * practice.
+   * "Focused" here means active or hovered, as a way to tell if the new item came from user
+   * interaction (on the row directly or through the context menu).
+   */
+  void unveil_new_items_in_focused_parent() const;
   void build_layout_from_tree(const TreeViewLayoutBuilder &builder);
 };
 
@@ -223,6 +232,8 @@ class AbstractTreeViewItem : public TreeViewItemContainer {
   bool is_open_ = false;
   bool is_active_ = false;
   bool is_renaming_ = false;
+  /* Could the item be identified from a previous redraw? */
+  bool is_new_ = true;
 
   IsActiveFn is_active_fn_;
 
diff --git a/source/blender/editors/interface/tree_view.cc b/source/blender/editors/interface/tree_view.cc
index c08fa51d5a5..d64f9d9c975 100644
--- a/source/blender/editors/interface/tree_view.cc
+++ b/source/blender/editors/interface/tree_view.cc
@@ -169,6 +169,21 @@ void AbstractTreeView::change_state_delayed()
   foreach_item([](AbstractTreeViewItem &item) { item.change_state_delayed(); });
 }
 
+void AbstractTreeView::unveil_new_items_in_focused_parent() const
+{
+  foreach_item([](AbstractTreeViewItem &item) {
+    if (!item.is_new_ || !item.parent_) {
+      return;
+    }
+    if (item.parent_->is_active() ||
+        /* Tree-row button is not created if a parent is collapsed. It's required for the
+         * hover-check. */
+        (item.parent_->tree_row_but_ && item.parent_->is_hovered())) {
+      item.parent_->set_collapsed(false);
+    }
+  });
+}
+
 /* ---------------------------------------------------------------------- */
 
 void AbstractTreeViewItem::tree_row_click_fn(struct bContext * /*C*/,
@@ -393,6 +408,7 @@ void AbstractTreeViewItem::update_from_old(const AbstractTreeViewItem &old)
   is_open_ = old.is_open_;
   is_active_ = old.is_active_;
   is_renaming_ = old.is_renaming_;
+  is_new_ = false;
 }
 
 bool AbstractTreeViewItem::matches(const AbstractTreeViewItem &other) const
@@ -569,6 +585,7 @@ void TreeViewBuilder::build_tree_view(AbstractTreeView &tree_view)
   tree_view.update_from_old(block_);
   tree_view.change_state_delayed();
   tree_view.build_layout_from_tree(TreeViewLayoutBuilder(block_));
+  tree_view.unveil_new_items_in_focused_parent();
 }
 
 /* ---------------------------------------------------------------------- */



More information about the Bf-blender-cvs mailing list