Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2021-10-04 17:17:59 +0300
committerJulian Eisel <julian@blender.org>2021-10-04 18:03:12 +0300
commit2b6f2072f1eecd43080821bb7b55f5313f890ddb (patch)
tree54ec409e85c4322e5968a7cf3be457c29af897d0
parent4fd7ce321d7352570a5cbb08d66b1c635d234689 (diff)
UI Tree-View API: Enforce active item to be un-collapsed
Makes sure that the active item of a tree never has collapsed parent items, which can be confusing if it happens. E.g. for the asset catalogs UI, the active catalog decides which assets are visible. Having it hidden while being the main factor deciding which assets are visible is quite confusing. I think it makes sense to have this at the UI Tree-View level, rather than doing it manually in the asset catalog code for example. Seems like something you'd commonly want. We can make it optional in the API if needed. Renamed the `set_active()` function to make clear that it is more than a mere setter.
-rw-r--r--source/blender/editors/include/UI_tree_view.hh6
-rw-r--r--source/blender/editors/interface/tree_view.cc32
-rw-r--r--source/blender/editors/space_file/asset_catalog_tree_view.cc6
3 files changed, 33 insertions, 11 deletions
diff --git a/source/blender/editors/include/UI_tree_view.hh b/source/blender/editors/include/UI_tree_view.hh
index d36e688dd65..a82aae021f2 100644
--- a/source/blender/editors/include/UI_tree_view.hh
+++ b/source/blender/editors/include/UI_tree_view.hh
@@ -211,12 +211,16 @@ class AbstractTreeViewItem : public TreeViewItemContainer {
const AbstractTreeView &get_tree_view() const;
int count_parents() const;
- void set_active(bool value = true);
+ /** Activates this item, deactivates other items, calls the #AbstractTreeViewItem::on_activate()
+ * function and ensures this item's parents are not collapsed (so the item is visible). */
+ void activate();
+ void deactivate();
bool is_active() const;
void toggle_collapsed();
bool is_collapsed() const;
void set_collapsed(bool collapsed);
bool is_collapsible() const;
+ void ensure_parents_uncollapsed();
};
/** \} */
diff --git a/source/blender/editors/interface/tree_view.cc b/source/blender/editors/interface/tree_view.cc
index 0ea15a2a5bb..202e3dba2ab 100644
--- a/source/blender/editors/interface/tree_view.cc
+++ b/source/blender/editors/interface/tree_view.cc
@@ -184,14 +184,25 @@ int AbstractTreeViewItem::count_parents() const
return i;
}
-void AbstractTreeViewItem::set_active(bool value)
+void AbstractTreeViewItem::activate()
{
- if (value && !is_active()) {
- /* Deactivate other items in the tree. */
- get_tree_view().foreach_item([](auto &item) { item.set_active(false); });
- on_activate();
+ if (is_active()) {
+ return;
}
- is_active_ = value;
+
+ /* Deactivate other items in the tree. */
+ get_tree_view().foreach_item([](auto &item) { item.deactivate(); });
+
+ on_activate();
+ /* Make sure the active item is always visible. */
+ ensure_parents_uncollapsed();
+
+ is_active_ = true;
+}
+
+void AbstractTreeViewItem::deactivate()
+{
+ is_active_ = false;
}
bool AbstractTreeViewItem::is_active() const
@@ -219,6 +230,13 @@ bool AbstractTreeViewItem::is_collapsible() const
return !children_.is_empty();
}
+void AbstractTreeViewItem::ensure_parents_uncollapsed()
+{
+ for (AbstractTreeViewItem *parent = parent_; parent; parent = parent->parent_) {
+ parent->set_collapsed(false);
+ }
+}
+
/* ---------------------------------------------------------------------- */
TreeViewBuilder::TreeViewBuilder(uiBlock &block) : block_(block)
@@ -277,7 +295,7 @@ static void tree_row_click_fn(struct bContext *UNUSED(C), void *but_arg1, void *
if (tree_item.is_collapsed() || tree_item.is_active()) {
tree_item.toggle_collapsed();
}
- tree_item.set_active();
+ tree_item.activate();
}
void BasicTreeViewItem::build_row(uiLayout &row)
diff --git a/source/blender/editors/space_file/asset_catalog_tree_view.cc b/source/blender/editors/space_file/asset_catalog_tree_view.cc
index 883bc6d7890..657881bdb40 100644
--- a/source/blender/editors/space_file/asset_catalog_tree_view.cc
+++ b/source/blender/editors/space_file/asset_catalog_tree_view.cc
@@ -152,7 +152,7 @@ ui::BasicTreeViewItem &AssetCatalogTreeView::build_catalog_items_recursive(
ui::BasicTreeViewItem &view_item = view_parent_item.add_tree_item<AssetCatalogTreeViewItem>(
&catalog);
if (is_active_catalog(catalog.get_catalog_id())) {
- view_item.set_active();
+ view_item.activate();
}
catalog.foreach_child([&view_item, this](AssetCatalogTreeItem &child) {
@@ -171,7 +171,7 @@ void AssetCatalogTreeView::add_all_item()
WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
});
if (params->asset_catalog_visibility == FILE_SHOW_ASSETS_ALL_CATALOGS) {
- item.set_active();
+ item.activate();
}
}
@@ -185,7 +185,7 @@ void AssetCatalogTreeView::add_unassigned_item()
WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
});
if (params->asset_catalog_visibility == FILE_SHOW_ASSETS_WITHOUT_CATALOG) {
- item.set_active();
+ item.activate();
}
}