diff options
author | Bastien Montagne <bastien@blender.org> | 2022-02-22 17:33:52 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2022-02-22 17:33:52 +0300 |
commit | 37fb69e02033b59895173aa2f47858ff3923afad (patch) | |
tree | a0d95f13e3df88d91f7e2a5fd53786d902ac0449 /source/blender/makesrna | |
parent | f449b8968819da3669a5a8a87ac0f5822b785a15 (diff) |
Fix (unreported) `RNA_property_editable_index`.
NOTE: This function is currently unused. However, it does use a callback
defined by a few RNA properties through
`RNA_def_property_editable_array_func`, so don't think it should be
removed without further thinking.
This function had two main issues:
* It was doing bitwise AND on potentially three sources of property
flag, when actually used `RNA_property_editable` just use one source
ever.
* It was completely ignoring liboverride cases.
TODO: Deduplicate code between `RNA_property_editable`,
`RNA_property_editable_info` and `RNA_property_editable_index`.
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 5a43fc2b053..59acbc81afd 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1980,29 +1980,40 @@ bool RNA_property_editable_flag(PointerRNA *ptr, PropertyRNA *prop) return (flag & PROP_EDITABLE) != 0; } -bool RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop, int index) +bool RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop_orig, int index) { - ID *id; - int flag; - BLI_assert(index >= 0); - prop = rna_ensure_property(prop); + ID *id = ptr->owner_id; + const char *dummy_info; + + PropertyRNA *prop = rna_ensure_property(prop_orig); - flag = prop->flag; + const int flag = prop->itemeditable != NULL ? + prop->itemeditable(ptr, index) : + (prop->editable != NULL ? prop->editable(ptr, &dummy_info) : prop->flag); - if (prop->editable) { - const char *dummy_info; - flag &= prop->editable(ptr, &dummy_info); + /* Early return if the property itself is not editable. */ + if ((flag & PROP_EDITABLE) == 0 || (flag & PROP_REGISTER) != 0) { + return false; } - if (prop->itemeditable) { - flag &= prop->itemeditable(ptr, index); + /* If there is no owning ID, the property is editable at this point. */ + if (id == NULL) { + return true; } - id = ptr->owner_id; + /* Handle linked or liboverride ID cases. */ + const bool is_linked_prop_exception = (prop->flag & PROP_LIB_EXCEPTION) != 0; + if (ID_IS_LINKED(id)) { + return is_linked_prop_exception; + } + if (ID_IS_OVERRIDE_LIBRARY(id)) { + return RNA_property_overridable_get(ptr, prop_orig); + } - return (flag & PROP_EDITABLE) && (!id || !ID_IS_LINKED(id) || (prop->flag & PROP_LIB_EXCEPTION)); + /* At this point, property is owned by a local ID and therefore fully editable. */ + return true; } bool RNA_property_animateable(PointerRNA *ptr, PropertyRNA *prop) |