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
This commit is contained in:
parent
ceb049133c
commit
3ff5d8f719
Notes:
blender-bot
2023-10-12 12:49:04 +02:00
Referenced by issue #90299, Add dedicated Context Menu for Assets
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue