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:
authorCampbell Barton <ideasman42@gmail.com>2019-10-21 11:57:43 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-10-21 11:57:43 +0300
commit6a1118092aa74f0b1e07900178e3df6e9a215b3b (patch)
tree3b6165417b8ba89f9c7b55f41059cac61acb810a /source/blender/editors/interface/interface_context_menu.c
parent34c835cbd10d544088b365a78e5da7cda1f0d6c2 (diff)
Fix invalid property shortcuts being created
When there was no way to find the data-path from context the shortcut was still being created. It would evaluate to "context.(null)". Now adding shortcuts will be disabled if the path can't be computed.
Diffstat (limited to 'source/blender/editors/interface/interface_context_menu.c')
-rw-r--r--source/blender/editors/interface/interface_context_menu.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/source/blender/editors/interface/interface_context_menu.c b/source/blender/editors/interface/interface_context_menu.c
index b84b07adba5..ae6a71f17e6 100644
--- a/source/blender/editors/interface/interface_context_menu.c
+++ b/source/blender/editors/interface/interface_context_menu.c
@@ -63,7 +63,14 @@
static IDProperty *shortcut_property_from_rna(bContext *C, uiBut *but)
{
/* Compute data path from context to property. */
+
+ /* If this returns null, we won't be able to bind shortcuts to these RNA properties.
+ * Support can be added at #wm_context_member_from_ptr. */
const char *member_id = WM_context_member_from_ptr(C, &but->rnapoin);
+ if (member_id == NULL) {
+ return NULL;
+ }
+
const char *data_path = RNA_path_from_ID_to_struct(&but->rnapoin);
const char *member_id_data_path = member_id;
@@ -90,27 +97,35 @@ static IDProperty *shortcut_property_from_rna(bContext *C, uiBut *but)
return prop;
}
-static const char *shortcut_get_operator_property(bContext *C, uiBut *but, IDProperty **prop)
+static const char *shortcut_get_operator_property(bContext *C, uiBut *but, IDProperty **r_prop)
{
if (but->optype) {
/* Operator */
- *prop = (but->opptr && but->opptr->data) ? IDP_CopyProperty(but->opptr->data) : NULL;
+ *r_prop = (but->opptr && but->opptr->data) ? IDP_CopyProperty(but->opptr->data) : NULL;
return but->optype->idname;
}
else if (but->rnaprop) {
- if (RNA_property_type(but->rnaprop) == PROP_BOOLEAN) {
+ const PropertyType rnaprop_type = RNA_property_type(but->rnaprop);
+
+ if (rnaprop_type == PROP_BOOLEAN) {
/* Boolean */
- *prop = shortcut_property_from_rna(C, but);
+ *r_prop = shortcut_property_from_rna(C, but);
+ if (*r_prop == NULL) {
+ return NULL;
+ }
return "WM_OT_context_toggle";
}
- else if (RNA_property_type(but->rnaprop) == PROP_ENUM) {
+ else if (rnaprop_type == PROP_ENUM) {
/* Enum */
- *prop = shortcut_property_from_rna(C, but);
+ *r_prop = shortcut_property_from_rna(C, but);
+ if (*r_prop == NULL) {
+ return NULL;
+ }
return "WM_OT_context_menu_enum";
}
}
- *prop = NULL;
+ *r_prop = NULL;
return NULL;
}