[Bf-blender-cvs] [9f8cc981647] asset-browser-poselib: Add button to refresh the asset list from the asset view template

Julian Eisel noreply at git.blender.org
Wed Mar 31 17:55:49 CEST 2021


Commit: 9f8cc981647aec2f77c46c81076569d206c3782a
Author: Julian Eisel
Date:   Wed Mar 31 17:54:41 2021 +0200
Branches: asset-browser-poselib
https://developer.blender.org/rB9f8cc981647aec2f77c46c81076569d206c3782a

Add button to refresh the asset list from the asset view template

Adds an operator to refresh the asset list and exposes that next to the
asset library selector above the template, when showing an external
library.

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

M	source/blender/editors/asset/asset_list.cc
M	source/blender/editors/asset/asset_ops.cc
M	source/blender/editors/include/ED_asset.h
M	source/blender/editors/interface/interface_template_asset_view.cc
M	source/blender/windowmanager/WM_types.h

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

diff --git a/source/blender/editors/asset/asset_list.cc b/source/blender/editors/asset/asset_list.cc
index eda16be1e50..b7e1d34e948 100644
--- a/source/blender/editors/asset/asset_list.cc
+++ b/source/blender/editors/asset/asset_list.cc
@@ -167,6 +167,7 @@ class AssetList : NonCopyable {
   void setup(const AssetFilterSettings *filter_settings = nullptr);
   void fetch(const bContext &C);
   void ensurePreviewsJob(bContext *C);
+  void clear(bContext *C);
 
   bool needsRefetch() const;
   void iterate(AssetListIterFn fn) const;
@@ -250,7 +251,7 @@ void AssetList::fetch(const bContext &C)
 
 bool AssetList::needsRefetch() const
 {
-  return filelist_needs_force_reset(filelist_);
+  return filelist_needs_force_reset(filelist_) || filelist_needs_reading(filelist_);
 }
 
 void AssetList::iterate(AssetListIterFn fn) const
@@ -290,6 +291,18 @@ void AssetList::ensurePreviewsJob(bContext *C)
   }
 }
 
+void AssetList::clear(bContext *C)
+{
+  /* Based on #ED_fileselect_clear() */
+
+  FileList *files = filelist_;
+  filelist_readjob_stop(files, CTX_wm_manager(C));
+  filelist_freelib(files);
+  filelist_clear(files);
+
+  WM_main_add_notifier(NC_ASSET | ND_ASSET_LIST, NULL);
+}
+
 /**
  * \return True if the asset-list needs a UI redraw.
  */
@@ -297,7 +310,7 @@ bool AssetList::listen(const wmNotifier &notifier) const
 {
   switch (notifier.category) {
     case NC_ASSET:
-      if (ELEM(notifier.data, ND_ASSET_LIST_READING, ND_ASSET_LIST_PREVIEW)) {
+      if (ELEM(notifier.data, ND_ASSET_LIST, ND_ASSET_LIST_READING, ND_ASSET_LIST_PREVIEW)) {
         return true;
       }
       if (ELEM(notifier.action, NA_ADDED, NA_REMOVED)) {
@@ -467,6 +480,19 @@ void ED_assetlist_ensure_previews_job(const AssetLibraryReference *library_refer
   }
 }
 
+void ED_assetlist_clear(const AssetLibraryReference *library_reference, bContext *C)
+{
+  AssetList *list = AssetListStorage::lookup_list(*library_reference);
+  if (list) {
+    list->clear(C);
+  }
+}
+
+bool ED_assetlist_storage_has_list_for_library(const AssetLibraryReference *library_reference)
+{
+  return AssetListStorage::lookup_list(*library_reference) != nullptr;
+}
+
 /* TODO expose AssetList with an iterator? */
 void ED_assetlist_iterate(const AssetLibraryReference *library_reference, AssetListIterFn fn)
 {
diff --git a/source/blender/editors/asset/asset_ops.cc b/source/blender/editors/asset/asset_ops.cc
index 8ca1b488a1d..79edd1f8a6a 100644
--- a/source/blender/editors/asset/asset_ops.cc
+++ b/source/blender/editors/asset/asset_ops.cc
@@ -252,8 +252,41 @@ static void ASSET_OT_clear(wmOperatorType *ot)
 
 /* -------------------------------------------------------------------- */
 
+static bool asset_list_refresh_poll(bContext *C)
+{
+  const AssetLibraryReference *library = CTX_wm_asset_library(C);
+  if (!library) {
+    return false;
+  }
+
+  return ED_assetlist_storage_has_list_for_library(library);
+}
+
+static int asset_list_refresh_exec(bContext *C, wmOperator *UNUSED(unused))
+{
+  const AssetLibraryReference *library = CTX_wm_asset_library(C);
+  ED_assetlist_clear(library, C);
+  return OPERATOR_FINISHED;
+}
+
+static void ASSET_OT_list_refresh(struct wmOperatorType *ot)
+{
+  /* identifiers */
+  ot->name = "Refresh Asset List";
+  ot->description = "Trigger a reread of the assets";
+  ot->idname = "ASSET_OT_list_refresh";
+
+  /* api callbacks */
+  ot->exec = asset_list_refresh_exec;
+  ot->poll = asset_list_refresh_poll;
+}
+
+/* -------------------------------------------------------------------- */
+
 void ED_operatortypes_asset(void)
 {
   WM_operatortype_append(ASSET_OT_mark);
   WM_operatortype_append(ASSET_OT_clear);
+
+  WM_operatortype_append(ASSET_OT_list_refresh);
 }
diff --git a/source/blender/editors/include/ED_asset.h b/source/blender/editors/include/ED_asset.h
index d46846132dc..aae48d583cc 100644
--- a/source/blender/editors/include/ED_asset.h
+++ b/source/blender/editors/include/ED_asset.h
@@ -58,6 +58,8 @@ void ED_assetlist_storage_fetch(const struct AssetLibraryReference *library_refe
                                 const struct bContext *C);
 void ED_assetlist_ensure_previews_job(const struct AssetLibraryReference *library_reference,
                                       struct bContext *C);
+void ED_assetlist_clear(const struct AssetLibraryReference *library_reference, struct bContext *C);
+bool ED_assetlist_storage_has_list_for_library(const AssetLibraryReference *library_reference);
 void ED_assetlist_storage_tag_main_data_dirty(void);
 void ED_assetlist_storage_id_remap(struct ID *id_old, struct ID *id_new);
 void ED_assetlist_storage_exit(void);
diff --git a/source/blender/editors/interface/interface_template_asset_view.cc b/source/blender/editors/interface/interface_template_asset_view.cc
index 04d33b53c6a..66947928711 100644
--- a/source/blender/editors/interface/interface_template_asset_view.cc
+++ b/source/blender/editors/interface/interface_template_asset_view.cc
@@ -205,10 +205,15 @@ void uiTemplateAssetView(uiLayout *layout,
 
   PropertyRNA *asset_library_prop = RNA_struct_find_property(asset_library_dataptr,
                                                              asset_library_propname);
-  uiItemFullR(col, asset_library_dataptr, asset_library_prop, RNA_NO_INDEX, 0, 0, "", 0);
-
   AssetLibraryReference asset_library = ED_asset_library_reference_from_enum_value(
       RNA_property_enum_get(asset_library_dataptr, asset_library_prop));
+
+  uiLayout *row = uiLayoutRow(col, true);
+  uiItemFullR(row, asset_library_dataptr, asset_library_prop, RNA_NO_INDEX, 0, 0, "", 0);
+  if (asset_library.type != ASSET_LIBRARY_LOCAL) {
+    uiItemO(row, "", ICON_FILE_REFRESH, "ASSET_OT_list_refresh");
+  }
+
   ED_assetlist_storage_fetch(&asset_library, filter_settings, C);
   ED_assetlist_ensure_previews_job(&asset_library, C);
 
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index 536b74d525c..ce19443954d 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -437,8 +437,9 @@ typedef struct wmNotifier {
 /* NC_ASSET */
 /* Denotes that the AssetList is done reading some previews. NOT that the preview generation of
  * assets is done. */
-#define ND_ASSET_LIST_PREVIEW (1 << 16)
-#define ND_ASSET_LIST_READING (2 << 16)
+#define ND_ASSET_LIST (1 << 16)
+#define ND_ASSET_LIST_PREVIEW (2 << 16)
+#define ND_ASSET_LIST_READING (3 << 16)
 
 /* subtype, 256 entries too */
 #define NOTE_SUBTYPE 0x0000FF00



More information about the Bf-blender-cvs mailing list