[Bf-blender-cvs] [6da8a138209] temp-asset-browser-catalogs-ui: Very basic tree drawing in the Asset Browser sidebar

Julian Eisel noreply at git.blender.org
Thu Sep 2 17:28:29 CEST 2021


Commit: 6da8a138209d4d80f0811932f2b253216afa4199
Author: Julian Eisel
Date:   Thu Sep 2 17:23:45 2021 +0200
Branches: temp-asset-browser-catalogs-ui
https://developer.blender.org/rB6da8a138209d4d80f0811932f2b253216afa4199

Very basic tree drawing in the Asset Browser sidebar

Draws the catalogs in the Asset Browser sidebar with some dummy icons.
Also adds an "All" and a "Unassigned" item. Besides hover feedback,
interaction is not working yet.

Also removes the categories UI and makes sure all assets are drawn
always. Filtering by catalog needs to be implemented still.

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

M	release/scripts/startup/bl_ui/space_filebrowser.py
M	source/blender/blenkernel/BKE_asset_catalog.hh
M	source/blender/blenkernel/intern/asset_catalog.cc
M	source/blender/editors/space_file/CMakeLists.txt
A	source/blender/editors/space_file/asset_catalog_tree_view.cc
M	source/blender/editors/space_file/file_intern.h
M	source/blender/editors/space_file/file_panels.c
M	source/blender/editors/space_file/filelist.c
M	source/blender/editors/space_file/filelist.h
M	source/blender/editors/space_file/filesel.c
M	source/blender/editors/space_file/space_file.c
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/release/scripts/startup/bl_ui/space_filebrowser.py b/release/scripts/startup/bl_ui/space_filebrowser.py
index b789380e253..fdf081e0874 100644
--- a/release/scripts/startup/bl_ui/space_filebrowser.py
+++ b/release/scripts/startup/bl_ui/space_filebrowser.py
@@ -657,7 +657,8 @@ class ASSETBROWSER_PT_navigation_bar(asset_utils.AssetBrowserPanel, Panel):
     def poll(cls, context):
         return (
             asset_utils.AssetBrowserPanel.poll(context) and
-            context.preferences.experimental.use_extended_asset_browser
+            context.preferences.experimental.use_extended_asset_browser and
+            False
         )
 
     def draw(self, context):
diff --git a/source/blender/blenkernel/BKE_asset_catalog.hh b/source/blender/blenkernel/BKE_asset_catalog.hh
index 8ee7395af4c..3fc2145996f 100644
--- a/source/blender/blenkernel/BKE_asset_catalog.hh
+++ b/source/blender/blenkernel/BKE_asset_catalog.hh
@@ -119,6 +119,7 @@ class AssetCatalogTreeItem {
    * catalog path of its parent and a separator. */
   CatalogPath catalog_path() const;
   int count_parents() const;
+  bool has_children() const;
 
   static void foreach_item_recursive(const ChildSet &children_, const ItemIterFn callback);
 
diff --git a/source/blender/blenkernel/intern/asset_catalog.cc b/source/blender/blenkernel/intern/asset_catalog.cc
index 5e24ba30e55..84481d29a79 100644
--- a/source/blender/blenkernel/intern/asset_catalog.cc
+++ b/source/blender/blenkernel/intern/asset_catalog.cc
@@ -292,6 +292,11 @@ int AssetCatalogTreeItem::count_parents() const
   return i;
 }
 
+bool AssetCatalogTreeItem::has_children() const
+{
+  return !children_.empty();
+}
+
 void AssetCatalogTree::foreach_item(const AssetCatalogTreeItem::ItemIterFn callback) const
 {
   AssetCatalogTreeItem::foreach_item_recursive(children_, callback);
diff --git a/source/blender/editors/space_file/CMakeLists.txt b/source/blender/editors/space_file/CMakeLists.txt
index b60f9df82f6..2aad5f7b750 100644
--- a/source/blender/editors/space_file/CMakeLists.txt
+++ b/source/blender/editors/space_file/CMakeLists.txt
@@ -31,9 +31,11 @@ set(INC
   ../../../../intern/atomic
   ../../../../intern/glew-mx
   ../../../../intern/guardedalloc
+  ../../../../extern/ghc_filesystem
 )
 
 set(SRC
+  asset_catalog_tree_view.cc
   file_draw.c
   file_ops.c
   file_panels.c
diff --git a/source/blender/editors/space_file/asset_catalog_tree_view.cc b/source/blender/editors/space_file/asset_catalog_tree_view.cc
new file mode 100644
index 00000000000..ee6e7d13acf
--- /dev/null
+++ b/source/blender/editors/space_file/asset_catalog_tree_view.cc
@@ -0,0 +1,79 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2007 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup spfile
+ */
+
+#include "ED_fileselect.h"
+
+#include "DNA_space_types.h"
+
+#include "BKE_asset_catalog.hh"
+#include "BKE_asset_library.hh"
+
+#include "BLI_string_ref.hh"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "file_intern.h"
+
+using namespace blender;
+
+static uiBut *add_row_button(uiBlock *block, StringRef name, BIFIconID icon)
+{
+  return uiDefIconTextBut(block,
+                          UI_BTYPE_DATASETROW,
+                          0,
+                          icon,
+                          name.data(),
+                          0,
+                          0,
+                          UI_UNIT_X * 3,
+                          UI_UNIT_Y,
+                          nullptr,
+                          0,
+                          0,
+                          0,
+                          0,
+                          nullptr);
+}
+
+void file_draw_asset_catalog_tree_view_in_layout(::AssetLibrary *asset_library_c, uiLayout *layout)
+{
+  using namespace blender::bke;
+
+  uiBlock *block = uiLayoutGetBlock(layout);
+
+  add_row_button(block, "All", ICON_HOME);
+
+  if (asset_library_c) {
+    auto *asset_library = reinterpret_cast<blender::bke::AssetLibrary *>(asset_library_c);
+    AssetCatalogTree *catalog_tree = asset_library->catalog_service->get_catalog_tree();
+
+    catalog_tree->foreach_item([&](const AssetCatalogTreeItem &item) {
+      uiBut *but = add_row_button(
+          block, item.get_name(), item.has_children() ? ICON_TRIA_DOWN : ICON_BLANK1);
+      UI_but_datasetrow_indentation_set(but, item.count_parents());
+    });
+  }
+
+  add_row_button(block, "Unassigned", ICON_FILE_HIDDEN);
+}
diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h
index 905c0aeb8e0..85cc0bab760 100644
--- a/source/blender/editors/space_file/file_intern.h
+++ b/source/blender/editors/space_file/file_intern.h
@@ -23,12 +23,18 @@
 
 #pragma once
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* internal exports only */
 
 struct ARegion;
 struct ARegionType;
+struct AssetLibrary;
 struct FileSelectParams;
 struct SpaceFile;
+struct uiLayout;
 struct View2D;
 
 /* file_draw.c */
@@ -147,8 +153,18 @@ void file_on_reload_callback_register(struct SpaceFile *sfile,
 /* file_panels.c */
 void file_tool_props_region_panels_register(struct ARegionType *art);
 void file_execute_region_panels_register(struct ARegionType *art);
+void file_tools_region_panels_register(struct ARegionType *art);
 
 /* file_utils.c */
 void file_tile_boundbox(const ARegion *region, FileLayout *layout, const int file, rcti *r_bounds);
 
 void file_path_to_ui_path(const char *path, char *r_pathi, int max_size);
+
+/* asset_catalog_tree_view.cc */
+
+void file_draw_asset_catalog_tree_view_in_layout(struct AssetLibrary *asset_library,
+                                                 struct uiLayout *layout);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/editors/space_file/file_panels.c b/source/blender/editors/space_file/file_panels.c
index 7032d55b331..57e4ff12bd0 100644
--- a/source/blender/editors/space_file/file_panels.c
+++ b/source/blender/editors/space_file/file_panels.c
@@ -47,6 +47,7 @@
 #include "WM_types.h"
 
 #include "file_intern.h"
+#include "filelist.h"
 #include "fsmenu.h"
 
 #include <string.h>
@@ -57,6 +58,12 @@ static bool file_panel_operator_poll(const bContext *C, PanelType *UNUSED(pt))
   return (sfile && sfile->op);
 }
 
+static bool file_panel_asset_browsing_poll(const bContext *C, PanelType *UNUSED(pt))
+{
+  SpaceFile *sfile = CTX_wm_space_file(C);
+  return sfile && sfile->files && ED_fileselect_is_asset_browser(sfile);
+}
+
 static void file_panel_operator_header(const bContext *C, Panel *panel)
 {
   SpaceFile *sfile = CTX_wm_space_file(C);
@@ -222,3 +229,26 @@ void file_execute_region_panels_register(ARegionType *art)
   pt->draw = file_panel_execution_buttons_draw;
   BLI_addtail(&art->paneltypes, pt);
 }
+
+static void file_panel_asset_catalog_buttons_draw(const bContext *C, Panel *panel)
+{
+  SpaceFile *sfile = CTX_wm_space_file(C);
+  /* May be null! */
+  struct AssetLibrary *asset_library = filelist_asset_library(sfile->files);
+
+  file_draw_asset_catalog_tree_view_in_layout(asset_library, panel->layout);
+}
+
+void file_tools_region_panels_register(ARegionType *art)
+{
+  PanelType *pt;
+
+  pt = MEM_callocN(sizeof(PanelType), "spacetype file asset catalog buttons");
+  strcpy(pt->idname, "FILE_PT_asset_catalog_buttons");
+  strcpy(pt->label, N_("Asset Catalogs"));
+  strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
+  pt->flag = PANEL_TYPE_NO_HEADER;
+  pt->poll = file_panel_asset_browsing_poll;
+  pt->draw = file_panel_asset_catalog_buttons_draw;
+  BLI_addtail(&art->paneltypes, pt);
+}
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 1c178ada5a7..336c2a6d749 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -1795,6 +1795,11 @@ void filelist_free(struct FileList *filelist)
   filelist->flags &= ~(FL_NEED_SORTING | FL_NEED_FILTERING);
 }
 
+AssetLibrary *filelist_asset_library(FileList *filelist)
+{
+  return filelist->asset_library;
+}
+
 void filelist_freelib(struct FileList *filelist)
 {
   if (filelist->libfiledata) {
diff --git a/source/blender/editors/space_file/filelist.h b/source/blender/editors/space_file/filelist.h
index 1fb05e0f9ac..7c66cef16dc 100644
--- a/source/blender/editors/space_file/filelist.h
+++ b/source/blender/editors/space_file/filelist.h
@@ -141,6 +141,8 @@ void filelist_entry_parent_select_set(struct FileList *filelist,
 
 void filelist_setrecursion(struct FileList *filelist, const int recursion_level);
 
+struct AssetLibrary *filelist_asset_library(struct FileList *filelist);
+
 struct BlendHandle *filelist_lib(struct FileList *filelist);
 bool filelist_islibrary(struct FileList *filelist, char *dir, char **r_group);
 void filelist_freelib(struct FileList *filelist);
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index 4ab7014cf82..6b19c6b787e 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -126,13 +126,10 @@ static void fileselect_ensure_updated_asset_params(SpaceFile *sfile)
   FileSelectParams *base_params = &asset_params->base_params;
   base_params->file[0] = '\0';
   base_params->filter_glob[0] = '\0';
-  /* TODO: this way of using filters to form categories is notably slower than specifying a
-   * "group" to read. That's because all types are read and filtering is applied afterwards. Would
-   * be nice if we could lazy-re

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list