Fix T65064: Keymaps items controlling dynamic enums fail to export
Keymap UI and import/export could depend on the current context for dynamic enum's. Use STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID for OperatorProperties.
This commit is contained in:
parent
43b08d0578
commit
919558854d
Notes:
blender-bot
2023-04-19 22:54:54 +02:00
Referenced by commitebde6e1852
, Fix T88251: "Operator Cheat Sheet" Crash Referenced by commit36863cf129
, Fix T87864: Context is None for draw method Referenced by commit8245805ce3
, Fix creating operator properties without an owner_id Referenced by commit0bf630493f
, Fix missing owner_id values from919558854d
Referenced by issue #89560, Insert key dropdown on keymap doesn't show keying sets anymore Referenced by issue #88251, "Operator Cheat Sheet" Crash 2.93.0 Referenced by issue #65064, Added hotkeys to switch mode disfunctional / lost hotkeys in keymap
|
@ -374,7 +374,12 @@ typedef struct wmKeyMapItem {
|
|||
/** Unique identifier. Positive for kmi that override builtins, negative otherwise. */
|
||||
short id;
|
||||
char _pad[2];
|
||||
/** Rna pointer to access properties. */
|
||||
/**
|
||||
* RNA pointer to access properties.
|
||||
*
|
||||
* \note The `ptr.owner_id` value must be NULL, as a signal not to use the context
|
||||
* when running property callbacks such as ENUM item functions.
|
||||
*/
|
||||
struct PointerRNA *ptr;
|
||||
} wmKeyMapItem;
|
||||
|
||||
|
|
|
@ -880,6 +880,7 @@ static PointerRNA rna_KeyMapItem_properties_get(PointerRNA *ptr)
|
|||
wmKeyMapItem *kmi = ptr->data;
|
||||
|
||||
if (kmi->ptr) {
|
||||
BLI_assert(kmi->ptr->owner_id == NULL);
|
||||
return *(kmi->ptr);
|
||||
}
|
||||
|
||||
|
@ -1974,7 +1975,7 @@ static void rna_def_operator(BlenderRNA *brna)
|
|||
RNA_def_struct_refine_func(srna, "rna_OperatorProperties_refine");
|
||||
RNA_def_struct_idprops_func(srna, "rna_OperatorProperties_idprops");
|
||||
RNA_def_struct_property_tags(srna, rna_enum_operator_property_tags);
|
||||
RNA_def_struct_flag(srna, STRUCT_NO_DATABLOCK_IDPROPERTIES);
|
||||
RNA_def_struct_flag(srna, STRUCT_NO_DATABLOCK_IDPROPERTIES | STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID);
|
||||
RNA_def_struct_clear_flag(srna, STRUCT_UNDO);
|
||||
}
|
||||
|
||||
|
|
|
@ -80,6 +80,9 @@ static wmKeyMapItem *wm_keymap_item_copy(wmKeyMapItem *kmi)
|
|||
kmin->ptr = MEM_callocN(sizeof(PointerRNA), "UserKeyMapItemPtr");
|
||||
WM_operator_properties_create(kmin->ptr, kmin->idname);
|
||||
|
||||
/* Signal for no context, see #STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID. */
|
||||
kmin->ptr->owner_id = NULL;
|
||||
|
||||
kmin->properties = IDP_CopyProperty(kmin->properties);
|
||||
kmin->ptr->data = kmin->properties;
|
||||
}
|
||||
|
@ -106,6 +109,9 @@ static void wm_keymap_item_properties_set(wmKeyMapItem *kmi)
|
|||
{
|
||||
WM_operator_properties_alloc(&(kmi->ptr), &(kmi->properties), kmi->idname);
|
||||
WM_operator_properties_sanitize(kmi->ptr, 1);
|
||||
|
||||
/* Signal for no context, see #STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID. */
|
||||
kmi->ptr->owner_id = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -136,6 +142,9 @@ static void wm_keymap_item_properties_update_ot(wmKeyMapItem *kmi)
|
|||
kmi->ptr->data = kmi->properties;
|
||||
}
|
||||
WM_operator_properties_sanitize(kmi->ptr, 1);
|
||||
|
||||
/* Signal for no context, see #STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID. */
|
||||
kmi->ptr->owner_id = NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -583,7 +583,8 @@ char *WM_prop_pystring_assign(bContext *C, PointerRNA *ptr, PropertyRNA *prop, i
|
|||
|
||||
void WM_operator_properties_create_ptr(PointerRNA *ptr, wmOperatorType *ot)
|
||||
{
|
||||
RNA_pointer_create(NULL, ot->srna, NULL, ptr);
|
||||
/* Set the ID so the context can be accessed: see #STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID. */
|
||||
RNA_pointer_create(G_MAIN->wm.first, ot->srna, NULL, ptr);
|
||||
}
|
||||
|
||||
void WM_operator_properties_create(PointerRNA *ptr, const char *opstring)
|
||||
|
@ -594,7 +595,8 @@ void WM_operator_properties_create(PointerRNA *ptr, const char *opstring)
|
|||
WM_operator_properties_create_ptr(ptr, ot);
|
||||
}
|
||||
else {
|
||||
RNA_pointer_create(NULL, &RNA_OperatorProperties, NULL, ptr);
|
||||
/* Set the ID so the context can be accessed: see #STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID. */
|
||||
RNA_pointer_create(G_MAIN->wm.first, &RNA_OperatorProperties, NULL, ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue