Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2021-07-13 16:01:00 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-07-15 17:12:36 +0300
commit87c1c8112fa44ccb94a3e996b7499d6577d85d7f (patch)
tree931599775e351a8a5eb78668d3f41625d59507a0 /source/blender/windowmanager
parent8edcb3af963113e37490288876419e8f50d4f1e8 (diff)
UI: Support UI list tooltips, defined via Python scripts
Makes it possible to create tooltips for UI list rows, which can be filled in .py scripts, similar to how they can extend other menus. This is used by the (to be committed) Pose Library add-on to display pose operations (selecting bones of a pose, blending a pose, etc). It's important that the Python scripts check if the UI list is the correct one by checking the list ID. For this to work, a new `bpy.context.ui_list` can be checked. For example, the Pose Library add-on does the following check: ``` def is_pose_asset_view() -> bool: # Important: Must check context first, or the menu is added for every kind of list. list = getattr(context, "ui_list", None) if not list or list.bl_idname != "UI_UL_asset_view" or list.list_id != "pose_assets": return False if not context.asset_handle: return False return True ```
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/WM_api.h1
-rw-r--r--source/blender/windowmanager/intern/wm_uilist_type.c14
2 files changed, 15 insertions, 0 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 601db427381..c529fef73ef 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -624,6 +624,7 @@ void WM_uilisttype_free(void);
void WM_uilisttype_to_full_list_id(const struct uiListType *ult,
const char *list_id,
char *r_ui_list_id);
+const char *WM_uilisttype_list_id_get(const struct uiListType *ult, struct uiList *list);
/* wm_menu_type.c */
void WM_menutype_init(void);
diff --git a/source/blender/windowmanager/intern/wm_uilist_type.c b/source/blender/windowmanager/intern/wm_uilist_type.c
index 434131903fc..6d298ee63f1 100644
--- a/source/blender/windowmanager/intern/wm_uilist_type.c
+++ b/source/blender/windowmanager/intern/wm_uilist_type.c
@@ -21,6 +21,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "BLI_sys_types.h"
@@ -109,3 +110,16 @@ void WM_uilisttype_to_full_list_id(const uiListType *ult,
/* We tag the list id with the list type... */
BLI_snprintf(r_full_list_id, UI_MAX_NAME_STR, "%s_%s", ult->idname, list_id ? list_id : "");
}
+
+/**
+ * Get the "non-full" list-ID, see #WM_uilisttype_to_full_list_id() for details.
+ *
+ * \note Assumes `uiList.list_id` was set using #WM_uilisttype_to_full_list_id()!
+ */
+const char *WM_uilisttype_list_id_get(const uiListType *ult, uiList *list)
+{
+ /* Some sanity check for the assumed behavior of #WM_uilisttype_to_full_list_id(). */
+ BLI_assert((list->list_id + strlen(ult->idname))[0] == '_');
+ /* +1 to skip the '_' */
+ return list->list_id + strlen(ult->idname) + 1;
+}