[Bf-blender-cvs] [375ae63ab34] temp-asset-browser-catalogs-ui: Add '+' icon for "All" item to allow adding top-level items

Julian Eisel noreply at git.blender.org
Mon Sep 27 17:23:53 CEST 2021


Commit: 375ae63ab347283e9e40ccca85fe19e29e7e1d18
Author: Julian Eisel
Date:   Mon Sep 27 17:22:54 2021 +0200
Branches: temp-asset-browser-catalogs-ui
https://developer.blender.org/rB375ae63ab347283e9e40ccca85fe19e29e7e1d18

Add '+' icon for "All" item to allow adding top-level items

Before this, there was no way to create a catalog tree from scratch, or
to add new top-level items.

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

M	source/blender/editors/space_file/asset_catalog_tree_view.cc

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

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 aa3edce7077..19e8a1094ae 100644
--- a/source/blender/editors/space_file/asset_catalog_tree_view.cc
+++ b/source/blender/editors/space_file/asset_catalog_tree_view.cc
@@ -108,6 +108,27 @@ class AssetCatalogTreeViewItem : public ui::BasicTreeViewItem {
   }
 };
 
+/** Only reason this isn't just `BasicTreeViewItem` is to add a '+' icon for adding a root level
+ * catalog. */
+class AssetCatalogTreeViewAllItem : public ui::BasicTreeViewItem {
+  using BasicTreeViewItem::BasicTreeViewItem;
+
+  void build_row(uiLayout &row) override
+  {
+    ui::BasicTreeViewItem::build_row(row);
+
+    if (!is_active()) {
+      return;
+    }
+
+    PointerRNA *props;
+    props = UI_but_extra_operator_icon_add(
+        button(), "ASSET_OT_catalog_new", WM_OP_INVOKE_DEFAULT, ICON_ADD);
+    /* No parent path to use the root level. */
+    RNA_string_set(props, "parent_path", nullptr);
+  }
+};
+
 AssetCatalogTreeView::AssetCatalogTreeView(bke::AssetLibrary *library,
                                            FileAssetSelectParams *params)
     : library_(library), params_(params)
@@ -118,7 +139,7 @@ void AssetCatalogTreeView::build_tree()
 {
   FileAssetSelectParams *params = params_;
 
-  add_tree_item<ui::BasicTreeViewItem>(
+  add_tree_item<AssetCatalogTreeViewAllItem>(
       IFACE_("All"), ICON_HOME, [params](ui::BasicTreeViewItem &) {
         params->asset_catalog_visibility = FILE_SHOW_ASSETS_ALL_CATALOGS;
         WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, NULL);



More information about the Bf-blender-cvs mailing list