[Bf-blender-cvs] [ee013f44b52] asset-browser-grid-view: Show asset catalog tree-view in navigation sidebar
Julian Eisel
noreply at git.blender.org
Mon Feb 7 18:58:45 CET 2022
Commit: ee013f44b52dc2a41a81951a0705cd019fbb62f9
Author: Julian Eisel
Date: Mon Feb 7 17:18:08 2022 +0100
Branches: asset-browser-grid-view
https://developer.blender.org/rBee013f44b52dc2a41a81951a0705cd019fbb62f9
Show asset catalog tree-view in navigation sidebar
Selecting catalogs doesn't work yet.
Includes some temporary changes needed to avoid conflicts between old
File/Asset Browser and new Asset Browser code.
===================================================================
M release/scripts/startup/bl_ui/space_assets.py
M source/blender/editors/asset/ED_asset_list.h
M source/blender/editors/asset/intern/asset_list.cc
M source/blender/editors/space_assets/CMakeLists.txt
M source/blender/editors/space_assets/asset_browser_intern.hh
A source/blender/editors/space_assets/asset_browser_panels.cc
A source/blender/editors/space_assets/asset_catalog_tree_view.cc
M source/blender/editors/space_assets/space_assets.cc
M source/blender/editors/space_file/asset_catalog_tree_view.cc
M source/blender/makesdna/DNA_space_types.h
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_assets.py b/release/scripts/startup/bl_ui/space_assets.py
index 707c7b3e78d..eb42de2addb 100644
--- a/release/scripts/startup/bl_ui/space_assets.py
+++ b/release/scripts/startup/bl_ui/space_assets.py
@@ -29,8 +29,6 @@ class ASSETBROWSER_HT_header(Header):
layout.template_header()
- layout.prop(space, "asset_library_ref", text="")
-
classes = (
ASSETBROWSER_HT_header,
diff --git a/source/blender/editors/asset/ED_asset_list.h b/source/blender/editors/asset/ED_asset_list.h
index eb094a6f1c0..454323bd31e 100644
--- a/source/blender/editors/asset/ED_asset_list.h
+++ b/source/blender/editors/asset/ED_asset_list.h
@@ -26,6 +26,7 @@ extern "C" {
struct AssetFilterSettings;
struct AssetHandle;
+struct AssetLibrary;
struct AssetLibraryReference;
struct ID;
struct bContext;
@@ -63,6 +64,9 @@ void ED_assetlist_storage_exit(void);
struct ImBuf *ED_assetlist_asset_image_get(const AssetHandle *asset_handle);
const char *ED_assetlist_library_path(const struct AssetLibraryReference *library_reference);
+struct AssetLibrary *ED_assetlist_library_get(
+ const struct AssetLibraryReference *library_reference);
+
/**
* \return True if the region needs a UI redraw.
*/
diff --git a/source/blender/editors/asset/intern/asset_list.cc b/source/blender/editors/asset/intern/asset_list.cc
index 79a8d316173..7456d507817 100644
--- a/source/blender/editors/asset/intern/asset_list.cc
+++ b/source/blender/editors/asset/intern/asset_list.cc
@@ -133,6 +133,7 @@ class AssetList : NonCopyable {
int size() const;
void tagMainDataDirty() const;
void remapID(ID *id_old, ID *id_new) const;
+ AssetLibrary &asset_library() const;
StringRef filepath() const;
};
@@ -315,6 +316,11 @@ StringRef AssetList::filepath() const
return filelist_dir(filelist_);
}
+AssetLibrary &AssetList::asset_library() const
+{
+ return *filelist_asset_library(filelist_);
+}
+
/** \} */
/* -------------------------------------------------------------------- */
@@ -526,6 +532,15 @@ const char *ED_assetlist_library_path(const AssetLibraryReference *library_refer
return nullptr;
}
+AssetLibrary *ED_assetlist_library_get(const AssetLibraryReference *library_reference)
+{
+ AssetList *list = AssetListStorage::lookup_list(*library_reference);
+ if (list) {
+ return &list->asset_library();
+ }
+ return nullptr;
+}
+
bool ED_assetlist_listen(const AssetLibraryReference *library_reference,
const wmNotifier *notifier)
{
diff --git a/source/blender/editors/space_assets/CMakeLists.txt b/source/blender/editors/space_assets/CMakeLists.txt
index dd36ea03895..37da8593b72 100644
--- a/source/blender/editors/space_assets/CMakeLists.txt
+++ b/source/blender/editors/space_assets/CMakeLists.txt
@@ -32,6 +32,8 @@ set(INC
set(SRC
asset_browser_draw.cc
asset_browser_ops.cc
+ asset_browser_panels.cc
+ asset_catalog_tree_view.cc
asset_view.cc
space_assets.cc
diff --git a/source/blender/editors/space_assets/asset_browser_intern.hh b/source/blender/editors/space_assets/asset_browser_intern.hh
index 46248b83cea..fdcea02d71c 100644
--- a/source/blender/editors/space_assets/asset_browser_intern.hh
+++ b/source/blender/editors/space_assets/asset_browser_intern.hh
@@ -23,6 +23,16 @@
void asset_browser_operatortypes();
struct ARegion;
+struct ARegionType;
+struct AssetLibrary;
struct bContext;
+struct SpaceAssets;
+struct uiLayout;
void asset_browser_main_region_draw(const bContext *C, ARegion *region);
+
+void asset_browser_navigation_region_panels_register(ARegionType *art);
+
+void asset_brower_create_catalog_tree_view_in_layout(::AssetLibrary *asset_library,
+ uiLayout *layout,
+ SpaceAssets *assets_space);
diff --git a/source/blender/editors/space_assets/asset_browser_panels.cc b/source/blender/editors/space_assets/asset_browser_panels.cc
new file mode 100644
index 00000000000..12d30be404e
--- /dev/null
+++ b/source/blender/editors/space_assets/asset_browser_panels.cc
@@ -0,0 +1,91 @@
+/*
+ * 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.
+ */
+
+/** \file
+ * \ingroup spassets
+ */
+
+#include <cstring>
+
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+
+#include "BKE_screen.h"
+
+#include "BLI_listbase.h"
+
+#include "BLT_translation.h"
+
+#include "ED_asset.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "WM_api.h"
+
+#include "asset_browser_intern.hh"
+
+static void assets_panel_asset_catalog_buttons_draw(const bContext *C, Panel *panel)
+{
+ bScreen *screen = CTX_wm_screen(C);
+ SpaceAssets *assets_space = CTX_wm_space_assets(C);
+
+ uiLayout *col = uiLayoutColumn(panel->layout, false);
+ uiLayout *row = uiLayoutRow(col, true);
+
+ PointerRNA assets_space_ptr;
+ RNA_pointer_create(&screen->id, &RNA_SpaceAssets, assets_space, &assets_space_ptr);
+
+ uiItemR(row, &assets_space_ptr, "asset_library_ref", 0, "", ICON_NONE);
+ if (assets_space->asset_library_ref.type == ASSET_LIBRARY_LOCAL) {
+ bContext *mutable_ctx = CTX_copy(C);
+ if (WM_operator_name_poll(mutable_ctx, "asset.bundle_install")) {
+ uiItemS(col);
+ uiItemMenuEnumO(col,
+ mutable_ctx,
+ "asset.bundle_install",
+ "asset_library_ref",
+ "Copy Bundle to Asset Library...",
+ ICON_IMPORT);
+ }
+ CTX_free(mutable_ctx);
+ }
+ else {
+ uiItemO(row, "", ICON_FILE_REFRESH, "ASSET_OT_library_refresh");
+ }
+
+ uiItemS(col);
+
+ AssetLibrary *library = ED_assetlist_library_get(&assets_space->asset_library_ref);
+ asset_brower_create_catalog_tree_view_in_layout(library, col, assets_space);
+}
+
+void asset_browser_navigation_region_panels_register(ARegionType *art)
+{
+ PanelType *pt;
+
+ pt = MEM_cnew<PanelType>("asset browser 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->draw = assets_panel_asset_catalog_buttons_draw;
+ BLI_addtail(&art->paneltypes, pt);
+}
diff --git a/source/blender/editors/space_file/asset_catalog_tree_view.cc b/source/blender/editors/space_assets/asset_catalog_tree_view.cc
similarity index 90%
copy from source/blender/editors/space_file/asset_catalog_tree_view.cc
copy to source/blender/editors/space_assets/asset_catalog_tree_view.cc
index 4107669630f..72626e38214 100644
--- a/source/blender/editors/space_file/asset_catalog_tree_view.cc
+++ b/source/blender/editors/space_assets/asset_catalog_tree_view.cc
@@ -18,7 +18,7 @@
*/
/** \file
- * \ingroup spfile
+ * \ingroup spassets
*/
#include "DNA_space_types.h"
@@ -32,7 +32,6 @@
#include "BLT_translation.h"
#include "ED_asset.h"
-#include "ED_fileselect.h"
#include "ED_undo.h"
#include "RNA_access.h"
@@ -45,8 +44,7 @@
#include "WM_api.h"
#include "WM_types.h"
-#include "file_intern.h"
-#include "filelist.h"
+#include "asset_browser_intern.hh"
using namespace blender;
using namespace blender::bke;
@@ -59,17 +57,14 @@ class AssetCatalogTreeView : public ui::AbstractTreeView {
::AssetLibrary *asset_library_;
/** The asset catalog tree this tree-view represents. */
bke::AssetCatalogTree *catalog_tree_;
- FileAssetSelectParams *params_;
- SpaceFile &space_file_;
+ AssetCatalogFilterSettings &catalog_filter_;
friend class AssetCatalogTreeViewItem;
friend class AssetCatalogDropController;
friend class AssetCatalogTreeViewAllItem;
public:
- AssetCatalogTreeView(::AssetLibrary *library,
- FileAssetSelectParams *params,
- SpaceFile &space_file);
+ AssetCatalogTreeView(::AssetLibrary *library, AssetCatalogFilterSettings *catalog_filter);
void build_tree() override;
@@ -186,13 +181,14 @@ class AssetCatalogTreeViewUnassignedItem : public ui::BasicTreeViewItem {
/* ---------------------------------------------------------------------- */
AssetCatalogTreeView::AssetCatalogTreeView(::AssetLibrary *library,
- FileAssetSelectParams *params,
- SpaceFile &space_file)
+ AssetCatalogFilterSettings *catalog_filter)
: asset_library_(library),
catalog_tree_(BKE_asset_library_get_catalog_tree(library)),
- params_(params),
- space_file_(space_file)
+ catalog_filter_(*catalog_filter)
{
+ if (!catalog_filter) {
+ throw "Catalog filter should never be null";
+ }
}
void AssetCatalogTreeView::build_tree()
@@ -226,44 +222,43 @@ ui::BasicTreeViewItem &AssetCatalogTreeView::build_catalog_items_recursive(
AssetCatalogTreeViewAllItem &AssetCatalogTreeView::add_all_item()
{
- FileAssetSelectParams *params = params_;
-
AssetCatalogTreeViewAllItem &item = add_tree_item<AssetCatalogTreeViewAllItem>(IFACE_("All"));
- item.set_on_activate_fn([params](ui::BasicTreeViewItem & /*item*/) {
- params->asset_catalog_visibility = FILE_SHOW_ASSETS_ALL_CATALOGS;
- WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
+ item.set_on_activate_fn([this](ui::BasicTreeViewItem & /*item*/) {
+ catalog_filter_.filter_mode = FILE_SHOW_ASSETS_ALL_CATALOGS;
+ /* TODO */
+ // WM_main_add_notifier(NC_SPACE |
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list