[Bf-blender-cvs] [9e5aae4215d] blender-v3.0-release: Asset: Merge asset library/list refresh operators

Julian Eisel noreply at git.blender.org
Tue Nov 23 18:43:35 CET 2021


Commit: 9e5aae4215d0070c2af7da970a9fb1950ed7f4db
Author: Julian Eisel
Date:   Tue Nov 23 18:40:31 2021 +0100
Branches: blender-v3.0-release
https://developer.blender.org/rB9e5aae4215d0070c2af7da970a9fb1950ed7f4db

Asset: Merge asset library/list refresh operators

In rBdcdbaf89bd11, I introduced a new operator
(`file.asset_library_refresh()`) to handle Asset Browser refreshing more
separate from File Browser refreshing. However, there already was
`asset.asset_list_refresh()`, which at this point only works for asset
view templates, but was intended to cover the Asset Browser case in
future too. This would happen once the Asset Browser uses the asset list
design of the asset view template.

So rather than having two operators for refreshing asset library data,
have one that just handles both cases, until they converge into one.
This avoids changes to the Python API in future (deprecating/changing
operators).

Differential Revision: https://developer.blender.org/D13239

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

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
M	release/scripts/startup/bl_operators/assets.py
M	release/scripts/startup/bl_ui/space_filebrowser.py
M	source/blender/editors/asset/intern/asset_ops.cc
M	source/blender/editors/interface/interface_template_asset_view.cc
M	source/blender/editors/space_file/file_intern.h
M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_file/file_panels.c
M	source/blender/editors/space_file/space_file.c

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index d6032a3ecce..9e0d23a04e2 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -2143,7 +2143,7 @@ def km_file_browser(params):
         ("file.next", {"type": 'RIGHT_ARROW', "value": 'PRESS', "alt": True}, None),
         # The two refresh operators have polls excluding each other (so only one is available depending on context).
         ("file.refresh", {"type": 'R', "value": 'PRESS'}, None),
-        ("file.asset_library_refresh", {"type": 'R', "value": 'PRESS'}, None),
+        ("asset.library_refresh", {"type": 'R', "value": 'PRESS'}, None),
         ("file.parent", {"type": 'P', "value": 'PRESS'}, None),
         ("file.previous", {"type": 'BACK_SPACE', "value": 'PRESS'}, None),
         ("file.next", {"type": 'BACK_SPACE', "value": 'PRESS', "shift": True}, None),
diff --git a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
index 37cd554e872..3019322d340 100644
--- a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
+++ b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
@@ -1229,7 +1229,7 @@ def km_file_browser(params):
         ("file.next", {"type": 'RIGHT_ARROW', "value": 'PRESS', "ctrl": True}, None),
         # The two refresh operators have polls excluding each other (so only one is available depending on context).
         ("file.refresh", {"type": 'R', "value": 'PRESS', "ctrl": True}, None),
-        ("file.asset_library_refresh", {"type": 'R', "value": 'PRESS', "ctrl": True}, None),
+        ("asset.library_refresh", {"type": 'R', "value": 'PRESS', "ctrl": True}, None),
         ("file.previous", {"type": 'BACK_SPACE', "value": 'PRESS'}, None),
         ("file.next", {"type": 'BACK_SPACE', "value": 'PRESS', "shift": True}, None),
         ("wm.context_toggle", {"type": 'H', "value": 'PRESS'},
@@ -1276,7 +1276,7 @@ def km_file_browser_main(params):
         ("file.mouse_execute", {"type": 'LEFTMOUSE', "value": 'DOUBLE_CLICK'}, None),
         # The two refresh operators have polls excluding each other (so only one is available depending on context).
         ("file.refresh", {"type": 'R', "value": 'PRESS', "ctrl": True}, None),
-        ("file.asset_library_refresh", {"type": 'R', "value": 'PRESS', "ctrl": True}, None),
+        ("asset.library_refresh", {"type": 'R', "value": 'PRESS', "ctrl": True}, None),
         ("file.select", {"type": 'LEFTMOUSE', "value": 'DOUBLE_CLICK'}, None),
         ("file.select", {"type": 'LEFTMOUSE', "value": 'CLICK'},
          {"properties": [("open", False), ("deselect_all", True)]}),
diff --git a/release/scripts/startup/bl_operators/assets.py b/release/scripts/startup/bl_operators/assets.py
index 58f02201905..32e63f77b23 100644
--- a/release/scripts/startup/bl_operators/assets.py
+++ b/release/scripts/startup/bl_operators/assets.py
@@ -142,14 +142,8 @@ class ASSET_OT_open_containing_blend_file(Operator):
         if returncode:
             self.report({'WARNING'}, "Blender sub-process exited with error code %d" % returncode)
 
-        # TODO(Sybren): Replace this with a generic "reload assets" operator
-        # that can run outside of the Asset Browser context.
-        if bpy.ops.file.refresh.poll():
-            bpy.ops.file.refresh()
-        if bpy.ops.asset.list_refresh.poll():
-            bpy.ops.asset.list_refresh()
-        if bpy.ops.file.asset_library_refresh.poll():
-            bpy.ops.file.asset_library_refresh()
+        if bpy.ops.asset.library_refresh.poll():
+            bpy.ops.asset.library_refresh()
 
         self.cancel(context)
         return {'FINISHED'}
diff --git a/release/scripts/startup/bl_ui/space_filebrowser.py b/release/scripts/startup/bl_ui/space_filebrowser.py
index f601c795660..4ae9a33785f 100644
--- a/release/scripts/startup/bl_ui/space_filebrowser.py
+++ b/release/scripts/startup/bl_ui/space_filebrowser.py
@@ -793,7 +793,7 @@ class ASSETBROWSER_MT_context_menu(AssetBrowserMenu, Menu):
         st = context.space_data
         params = st.params
 
-        layout.operator("file.asset_library_refresh")
+        layout.operator("asset.library_refresh")
 
         layout.separator()
 
diff --git a/source/blender/editors/asset/intern/asset_ops.cc b/source/blender/editors/asset/intern/asset_ops.cc
index 41cca71b323..1f5d3f5c101 100644
--- a/source/blender/editors/asset/intern/asset_ops.cc
+++ b/source/blender/editors/asset/intern/asset_ops.cc
@@ -37,6 +37,7 @@
 
 #include "ED_asset.h"
 #include "ED_asset_catalog.hh"
+#include "ED_screen.h"
 #include "ED_util.h"
 /* XXX needs access to the file list, should all be done via the asset system in future. */
 #include "ED_fileselect.h"
@@ -395,8 +396,14 @@ static void ASSET_OT_clear(wmOperatorType *ot)
 
 /* -------------------------------------------------------------------- */
 
-static bool asset_list_refresh_poll(bContext *C)
+static bool asset_library_refresh_poll(bContext *C)
 {
+  if (ED_operator_asset_browsing_active(C)) {
+    return true;
+  }
+
+  /* While not inside an Asset Browser, check if there's a asset list stored for the active asset
+   * library (stored in the workspace, obtained via context). */
   const AssetLibraryReference *library = CTX_wm_asset_library_ref(C);
   if (!library) {
     return false;
@@ -405,23 +412,38 @@ static bool asset_list_refresh_poll(bContext *C)
   return ED_assetlist_storage_has_list_for_library(library);
 }
 
-static int asset_list_refresh_exec(bContext *C, wmOperator *UNUSED(unused))
+static int asset_library_refresh_exec(bContext *C, wmOperator *UNUSED(unused))
 {
-  const AssetLibraryReference *library = CTX_wm_asset_library_ref(C);
-  ED_assetlist_clear(library, C);
+  /* Execution mode #1: Inside the Asset Browser. */
+  if (ED_operator_asset_browsing_active(C)) {
+    SpaceFile *sfile = CTX_wm_space_file(C);
+    ED_fileselect_clear(CTX_wm_manager(C), sfile);
+    WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
+  }
+  else {
+    /* Execution mode #2: Outside the Asset Browser, use the asset list. */
+    const AssetLibraryReference *library = CTX_wm_asset_library_ref(C);
+    ED_assetlist_clear(library, C);
+  }
+
   return OPERATOR_FINISHED;
 }
 
-static void ASSET_OT_list_refresh(struct wmOperatorType *ot)
+/**
+ * This operator currently covers both cases, the File/Asset Browser file list and the asset list
+ * used for the asset-view template. Once the asset list design is used by the Asset Browser, this
+ * can be simplified to just that case.
+ */
+static void ASSET_OT_library_refresh(struct wmOperatorType *ot)
 {
   /* identifiers */
-  ot->name = "Refresh Asset List";
-  ot->description = "Trigger a reread of the assets";
-  ot->idname = "ASSET_OT_list_refresh";
+  ot->name = "Refresh Asset Library";
+  ot->description = "Reread assets and asset catalogs from the asset library on disk";
+  ot->idname = "ASSET_OT_library_refresh";
 
   /* api callbacks */
-  ot->exec = asset_list_refresh_exec;
-  ot->poll = asset_list_refresh_poll;
+  ot->exec = asset_library_refresh_exec;
+  ot->poll = asset_library_refresh_poll;
 }
 
 /* -------------------------------------------------------------------- */
@@ -908,5 +930,5 @@ void ED_operatortypes_asset(void)
   WM_operatortype_append(ASSET_OT_catalog_undo_push);
   WM_operatortype_append(ASSET_OT_bundle_install);
 
-  WM_operatortype_append(ASSET_OT_list_refresh);
+  WM_operatortype_append(ASSET_OT_library_refresh);
 }
diff --git a/source/blender/editors/interface/interface_template_asset_view.cc b/source/blender/editors/interface/interface_template_asset_view.cc
index d3ce7ebc3db..0ce30fdeb1a 100644
--- a/source/blender/editors/interface/interface_template_asset_view.cc
+++ b/source/blender/editors/interface/interface_template_asset_view.cc
@@ -227,7 +227,7 @@ void uiTemplateAssetView(uiLayout *layout,
   if ((display_flags & UI_TEMPLATE_ASSET_DRAW_NO_LIBRARY) == 0) {
     uiItemFullR(row, asset_library_dataptr, asset_library_prop, RNA_NO_INDEX, 0, 0, "", 0);
     if (asset_library_ref.type != ASSET_LIBRARY_LOCAL) {
-      uiItemO(row, "", ICON_FILE_REFRESH, "ASSET_OT_list_refresh");
+      uiItemO(row, "", ICON_FILE_REFRESH, "ASSET_OT_library_refresh");
     }
   }
 
diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h
index 4be5d6d8008..f6b5f0f47cd 100644
--- a/source/blender/editors/space_file/file_intern.h
+++ b/source/blender/editors/space_file/file_intern.h
@@ -79,7 +79,6 @@ void FILE_OT_directory_new(struct wmOperatorType *ot);
 void FILE_OT_previous(struct wmOperatorType *ot);
 void FILE_OT_next(struct wmOperatorType *ot);
 void FILE_OT_refresh(struct wmOperatorType *ot);
-void FILE_OT_asset_library_refresh(struct wmOperatorType *ot);
 void FILE_OT_filenum(struct wmOperatorType *ot);
 void FILE_OT_delete(struct wmOperatorType *ot);
 void FILE_OT_rename(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 844514759f3..15bb7917924 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -1955,35 +1955,6 @@ void FILE_OT_refresh(struct wmOperatorType *ot)
 
 /** \} */
 
-/* -------------------------------------------------------------------- */
-/** \name Refresh Asset Library Operator
- * \{ */
-
-static int file_asset_library_refresh_exec(bContext *C, wmOperator *UNUSED(unused))
-{
-  wmWindowManager *wm = CTX_wm_manager(C);
-  SpaceFile *sfile = CTX_wm_space_file(C);
-
-  ED_fileselect_clear(wm, sfile);
-  WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
-
-  return OPERATOR_FINISHED;
-}
-
-void FILE_OT_asset_library_refresh(struct wmOperatorType *ot)
-{
-  /* identifiers */
-  ot->name = "Refresh Asset Library";
-  ot->description = "Reread assets and asset catalogs from the asset library on disk";
-  ot->idname = "FILE_OT_asset_library_refresh";
-
-  /* api callbacks */
-  ot->exec = file

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list