Asset Browser: Correct name & tooltip for asset list refresh operator

The name and tooltip were talking about file-lists, which exposes the
fact that the Asset Browser uses the File Browser code in the UI, which
we shouldn't do. This can confuse users.
Instead have a dedicated operator for the Asset Browser with a proper
name and tooltip.
This commit is contained in:
Julian Eisel 2021-10-29 16:45:08 +02:00
parent 81bd49d4fe
commit 2a4dfaa0e9
7 changed files with 40 additions and 4 deletions

@ -2140,7 +2140,9 @@ def km_file_browser(params):
("file.parent", {"type": 'UP_ARROW', "value": 'PRESS', "alt": True}, None),
("file.previous", {"type": 'LEFT_ARROW', "value": 'PRESS', "alt": True}, None),
("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),
("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),

@ -1227,7 +1227,9 @@ def km_file_browser(params):
("file.previous", {"type": 'LEFT_ARROW', "value": 'PRESS', "ctrl": True}, None),
("file.next", {"type": 'RIGHT_ARROW', "value": 'PRESS', "alt": True}, None),
("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),
("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'},
@ -1272,7 +1274,9 @@ def km_file_browser_main(params):
items.extend([
("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),
("file.select", {"type": 'LEFTMOUSE', "value": 'DOUBLE_CLICK'}, None),
("file.select", {"type": 'LEFTMOUSE', "value": 'CLICK'},
{"properties": [("open", False), ("deselect_all", True)]}),

@ -792,7 +792,7 @@ class ASSETBROWSER_MT_context_menu(AssetBrowserMenu, Menu):
st = context.space_data
params = st.params
layout.operator("file.refresh", text="Refresh")
layout.operator("file.asset_library_refresh")
layout.separator()

@ -79,6 +79,7 @@ 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);

@ -1950,8 +1950,36 @@ void FILE_OT_refresh(struct wmOperatorType *ot)
/* api callbacks */
ot->exec = file_refresh_exec;
/* Operator works for file or asset browsing */
ot->poll = ED_operator_file_active; /* <- important, handler is on window level */
ot->poll = ED_operator_file_browsing_active; /* <- important, handler is on window level */
}
/** \} */
/* -------------------------------------------------------------------- */
/** \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_asset_library_refresh_exec;
ot->poll = ED_operator_asset_browsing_active;
}
/** \} */

@ -247,7 +247,7 @@ static void file_panel_asset_catalog_buttons_draw(const bContext *C, Panel *pane
uiItemR(row, &params_ptr, "asset_library_ref", 0, "", ICON_NONE);
if (params->asset_library_ref.type != ASSET_LIBRARY_LOCAL) {
uiItemO(row, "", ICON_FILE_REFRESH, "FILE_OT_refresh");
uiItemO(row, "", ICON_FILE_REFRESH, "FILE_OT_asset_library_refresh");
}
uiItemS(col);

@ -688,6 +688,7 @@ static void file_operatortypes(void)
WM_operatortype_append(FILE_OT_previous);
WM_operatortype_append(FILE_OT_next);
WM_operatortype_append(FILE_OT_refresh);
WM_operatortype_append(FILE_OT_asset_library_refresh);
WM_operatortype_append(FILE_OT_bookmark_add);
WM_operatortype_append(FILE_OT_bookmark_delete);
WM_operatortype_append(FILE_OT_bookmark_cleanup);