[Bf-blender-cvs] [3ff5d8f719f] master: Asset Browser: Proper context menu for assets
Julian Eisel
noreply at git.blender.org
Mon Aug 2 17:00:32 CEST 2021
Commit: 3ff5d8f719f592c2ea17533532708e883a8baa96
Author: Julian Eisel
Date: Mon Aug 2 16:59:10 2021 +0200
Branches: master
https://developer.blender.org/rB3ff5d8f719f592c2ea17533532708e883a8baa96
Asset Browser: Proper context menu for assets
Add a context menu dedicated to asset operations to the Asset Browser.
There are two separate context menus to keep things separated well and
avoid confusing if-else logic (similar to D12057 & D12059). Their polls
make sure they are displayed for the right contexts only.
Also (to be committed as followup cleanup): Remove now unused special
handling for assets in file delete operator.
Differential Revision: https://developer.blender.org/D12062
===================================================================
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_ui/space_filebrowser.py
M source/blender/editors/space_file/file_ops.c
===================================================================
diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 3527e993173..a37577e898b 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -2000,6 +2000,7 @@ def km_file_browser(params):
("file.filenum", {"type": 'NUMPAD_MINUS', "value": 'PRESS', "ctrl": True, "repeat": True},
{"properties": [("increment", -100)]}),
*_template_items_context_menu("FILEBROWSER_MT_context_menu", params.context_menu_event),
+ *_template_items_context_menu("ASSETBROWSER_MT_context_menu", params.context_menu_event),
])
return keymap
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 714126903d8..9d34b110afe 100644
--- a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
+++ b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
@@ -1249,6 +1249,7 @@ def km_file_browser(params):
("file.filenum", {"type": 'NUMPAD_MINUS', "value": 'PRESS', "ctrl": True, "repeat": True},
{"properties": [("increment", -100)]}),
*_template_items_context_menu("FILEBROWSER_MT_context_menu", {"type": 'RIGHTMOUSE', "value": 'PRESS'}),
+ *_template_items_context_menu("ASSETBROWSER_MT_context_menu", {"type": 'RIGHTMOUSE', "value": 'PRESS'}),
])
return keymap
diff --git a/release/scripts/startup/bl_ui/space_filebrowser.py b/release/scripts/startup/bl_ui/space_filebrowser.py
index 81a71ea0de2..44631e368a3 100644
--- a/release/scripts/startup/bl_ui/space_filebrowser.py
+++ b/release/scripts/startup/bl_ui/space_filebrowser.py
@@ -296,7 +296,7 @@ class FILEBROWSER_MT_bookmarks_context_menu(Menu):
text="Move to Bottom").direction = 'BOTTOM'
-class FILEBROWSER_PT_bookmarks_favorites(Panel):
+class FILEBROWSER_PT_bookmarks_favorites(FileBrowserPanel, Panel):
bl_space_type = 'FILE_BROWSER'
bl_region_type = 'TOOLS'
bl_category = "Bookmarks"
@@ -526,7 +526,7 @@ class FILEBROWSER_MT_select(FileBrowserMenu, Menu):
layout.operator("file.select_box")
-class FILEBROWSER_MT_context_menu(Menu):
+class FILEBROWSER_MT_context_menu(FileBrowserMenu, Menu):
bl_label = "Files Context Menu"
def draw(self, context):
@@ -553,10 +553,6 @@ class FILEBROWSER_MT_context_menu(Menu):
sub.operator_context = 'EXEC_DEFAULT'
sub.operator("file.delete", text="Delete")
- active_asset = asset_utils.SpaceAssetInfo.get_active_asset(context)
- if active_asset:
- layout.operator("asset.open_containing_blend_file")
-
layout.separator()
sub = layout.row()
@@ -755,6 +751,32 @@ class ASSETBROWSER_UL_metadata_tags(UIList):
row.prop(tag, "name", text="", emboss=False, icon_value=icon)
+class ASSETBROWSER_MT_context_menu(AssetBrowserMenu, Menu):
+ bl_label = "Assets Context Menu"
+
+ def draw(self, context):
+ layout = self.layout
+ st = context.space_data
+ params = st.params
+
+ layout.operator("file.refresh", text="Refresh")
+
+ layout.separator()
+
+ sub = layout.row()
+ sub.operator_context = 'EXEC_DEFAULT'
+ sub.operator("asset.clear", text="Clear Asset")
+
+ layout.separator()
+
+ layout.operator("asset.open_containing_blend_file")
+
+ layout.separator()
+
+ if params.display_type == 'THUMBNAIL':
+ layout.prop_menu_enum(params, "display_size")
+
+
classes = (
FILEBROWSER_HT_header,
FILEBROWSER_PT_display,
@@ -781,6 +803,7 @@ classes = (
ASSETBROWSER_PT_metadata_details,
ASSETBROWSER_PT_metadata_tags,
ASSETBROWSER_UL_metadata_tags,
+ ASSETBROWSER_MT_context_menu,
)
if __name__ == "__main__": # only for live edit.
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 616e7fe51db..944eb9988fa 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -2830,20 +2830,10 @@ static bool file_delete_single(const FileSelectParams *params,
FileDirEntry *file,
const char **r_error_message)
{
- if (file->typeflag & FILE_TYPE_ASSET) {
- ID *id = filelist_file_get_id(file);
- if (!id) {
- *r_error_message = "File is not a local data-block asset.";
- return false;
- }
- ED_asset_clear_id(id);
- }
- else {
- char str[FILE_MAX];
- BLI_join_dirfile(str, sizeof(str), params->dir, file->relpath);
- if (BLI_delete_soft(str, r_error_message) != 0 || BLI_exists(str)) {
- return false;
- }
+ char str[FILE_MAX];
+ BLI_join_dirfile(str, sizeof(str), params->dir, file->relpath);
+ if (BLI_delete_soft(str, r_error_message) != 0 || BLI_exists(str)) {
+ return false;
}
return true;
More information about the Bf-blender-cvs
mailing list