diff options
author | Bastien Montagne <bastien@blender.org> | 2022-02-22 17:18:08 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2022-02-22 17:18:08 +0300 |
commit | f449b8968819da3669a5a8a87ac0f5822b785a15 (patch) | |
tree | 101ad41cf952f25b6482b319abf3fe4b46d2e5f2 /source/blender/makesrna | |
parent | 472ddc6e2787e73e4c7c7def62ac3b31822bbbf5 (diff) |
Cleanup: Make `RNA_property_editable` logic clearer.
Split code in smaller bits with early returns, instead of a giant single
set of checks.
No behavioral change expected here.
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 6c3b46c4408..5a43fc2b053 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1907,10 +1907,27 @@ bool RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop_orig) PropertyRNA *prop = rna_ensure_property(prop_orig); flag = prop->editable ? prop->editable(ptr, &dummy_info) : prop->flag; - return ( - (flag & PROP_EDITABLE) && (flag & PROP_REGISTER) == 0 && - (!id || ((!ID_IS_LINKED(id) || (prop->flag & PROP_LIB_EXCEPTION)) && - (!ID_IS_OVERRIDE_LIBRARY(id) || RNA_property_overridable_get(ptr, prop_orig))))); + /* 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; } bool RNA_property_editable_info(PointerRNA *ptr, PropertyRNA *prop, const char **r_info) |