diff options
author | Bastien Montagne <bastien@blender.org> | 2022-02-22 18:36:31 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2022-02-22 18:38:04 +0300 |
commit | 8073c95fe9d47bc42ba390f61da35062ffd6398a (patch) | |
tree | 3b043493d9c77890a5f308eb9555274f94981179 /source/blender | |
parent | 51c7193405873a0d90596f3683686bbf1603fc1f (diff) |
Cleanup: Deduplicate logic in `RNA_property_editable` & co.
Fairly straight-forward, now all the logic for all those 'is editable'
complex checks is gathered into a single util function.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 108 |
2 files changed, 34 insertions, 76 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index eb25733a88a..bc4e7314512 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -997,7 +997,7 @@ bool RNA_property_editable_info(PointerRNA *ptr, PropertyRNA *prop, const char * /** * Same as RNA_property_editable(), except this checks individual items in an array. */ -bool RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop, int index); +bool RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop, const int index); /** * Without lib check, only checks the flag. diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 59acbc81afd..c8f710d9931 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1898,17 +1898,28 @@ int RNA_property_ui_icon(const PropertyRNA *prop) return rna_ensure_property((PropertyRNA *)prop)->icon; } -bool RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop_orig) +static bool rna_property_editable_do(PointerRNA *ptr, + PropertyRNA *prop_orig, + const int index, + const char **r_info) { ID *id = ptr->owner_id; - int flag; - const char *dummy_info; PropertyRNA *prop = rna_ensure_property(prop_orig); - flag = prop->editable ? prop->editable(ptr, &dummy_info) : prop->flag; + + const char *info = ""; + const int flag = (prop->itemeditable != NULL && index >= 0) ? + prop->itemeditable(ptr, index) : + (prop->editable != NULL ? prop->editable(ptr, &info) : prop->flag); + if (r_info != NULL) { + *r_info = info; + } /* Early return if the property itself is not editable. */ if ((flag & PROP_EDITABLE) == 0 || (flag & PROP_REGISTER) != 0) { + if (r_info != NULL && (*r_info)[0] == '\0') { + *r_info = N_("This property is for internal use only and can't be edited"); + } return false; } @@ -1919,55 +1930,31 @@ bool RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop_orig) /* 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_LINKED(id) && !is_linked_prop_exception) { + if (r_info != NULL && (*r_info)[0] == '\0') { + *r_info = N_("Can't edit this property from a linked data-block"); + } + return false; } - if (ID_IS_OVERRIDE_LIBRARY(id)) { - return RNA_property_overridable_get(ptr, prop_orig); + if (ID_IS_OVERRIDE_LIBRARY(id) && !RNA_property_overridable_get(ptr, prop_orig)) { + if (r_info != NULL && (*r_info)[0] == '\0') { + *r_info = N_("Can't edit this property from an override data-block"); + } + return false; } /* At this point, property is owned by a local ID and therefore fully editable. */ return true; } -bool RNA_property_editable_info(PointerRNA *ptr, PropertyRNA *prop, const char **r_info) +bool RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop) { - ID *id = ptr->owner_id; - int flag; - - PropertyRNA *prop_type = rna_ensure_property(prop); - *r_info = ""; - - /* get flag */ - if (prop_type->editable) { - flag = prop_type->editable(ptr, r_info); - } - else { - flag = prop_type->flag; - if ((flag & PROP_EDITABLE) == 0 || (flag & PROP_REGISTER)) { - *r_info = N_("This property is for internal use only and can't be edited"); - } - } - - /* property from linked data-block */ - if (id) { - if (ID_IS_LINKED(id) && (prop_type->flag & PROP_LIB_EXCEPTION) == 0) { - if (!(*r_info)[0]) { - *r_info = N_("Can't edit this property from a linked data-block"); - } - return false; - } - if (ID_IS_OVERRIDE_LIBRARY(id)) { - if (!RNA_property_overridable_get(ptr, prop)) { - if (!(*r_info)[0]) { - *r_info = N_("Can't edit this property from an override data-block"); - } - return false; - } - } - } + return rna_property_editable_do(ptr, prop, -1, NULL); +} - return ((flag & PROP_EDITABLE) && (flag & PROP_REGISTER) == 0); +bool RNA_property_editable_info(PointerRNA *ptr, PropertyRNA *prop, const char **r_info) +{ + return rna_property_editable_do(ptr, prop, -1, r_info); } bool RNA_property_editable_flag(PointerRNA *ptr, PropertyRNA *prop) @@ -1980,40 +1967,11 @@ bool RNA_property_editable_flag(PointerRNA *ptr, PropertyRNA *prop) return (flag & PROP_EDITABLE) != 0; } -bool RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop_orig, int index) +bool RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop, const int index) { BLI_assert(index >= 0); - ID *id = ptr->owner_id; - const char *dummy_info; - - PropertyRNA *prop = rna_ensure_property(prop_orig); - - const int flag = prop->itemeditable != NULL ? - prop->itemeditable(ptr, index) : - (prop->editable != NULL ? prop->editable(ptr, &dummy_info) : prop->flag); - - /* Early return if the property itself is not editable. */ - if ((flag & PROP_EDITABLE) == 0 || (flag & PROP_REGISTER) != 0) { - return false; - } - - /* If there is no owning ID, the property is editable at this point. */ - if (id == NULL) { - return true; - } - - /* 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); - } - - /* At this point, property is owned by a local ID and therefore fully editable. */ - return true; + return rna_property_editable_do(ptr, prop, index, NULL); } bool RNA_property_animateable(PointerRNA *ptr, PropertyRNA *prop) |