diff options
author | Julian Eisel <julian@blender.org> | 2022-04-26 23:30:33 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2022-04-26 23:30:33 +0300 |
commit | 994da7077d4a683a122f40ad0c3b0585d4968fcc (patch) | |
tree | 26e667a2547268a822b0de5422773a5766fc545c /source/blender/editors/util | |
parent | 83c8f996f1618a51496100dc680a877a89be7a4e (diff) |
Outliner: Add icon column to toggle if library overrides are editable
Adds a column to the right in the Library Overrides Hierarchies view
mode to toggle editability of library overrides.
Note that making a library override non-editable currently involves
clearing all overridden properties. This is an arguable design choice,
we should probably at least warn the user before doing this.
Part of T95802.
Reviewed by: Bastien Montagne
Differential Revision: https://developer.blender.org/D14653
Diffstat (limited to 'source/blender/editors/util')
-rw-r--r-- | source/blender/editors/util/CMakeLists.txt | 5 | ||||
-rw-r--r-- | source/blender/editors/util/ed_util_ops.cc | 47 |
2 files changed, 52 insertions, 0 deletions
diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt index 7b4551fdb0c..89d80d582f8 100644 --- a/source/blender/editors/util/CMakeLists.txt +++ b/source/blender/editors/util/CMakeLists.txt @@ -18,6 +18,8 @@ set(INC ../../../../intern/clog ../../../../intern/glew-mx ../../../../intern/guardedalloc + # RNA_prototypes.h + ${CMAKE_BINARY_DIR}/source/blender/makesrna ) @@ -110,3 +112,6 @@ if(WITH_PYTHON) endif() blender_add_lib(bf_editor_util "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") + +# RNA_prototypes.h +add_dependencies(bf_editor_util bf_rna) diff --git a/source/blender/editors/util/ed_util_ops.cc b/source/blender/editors/util/ed_util_ops.cc index ccc28353518..803e65590a0 100644 --- a/source/blender/editors/util/ed_util_ops.cc +++ b/source/blender/editors/util/ed_util_ops.cc @@ -17,6 +17,7 @@ #include "BKE_context.h" #include "BKE_icons.h" #include "BKE_lib_id.h" +#include "BKE_lib_override.h" #include "BKE_main.h" #include "BKE_report.h" @@ -28,6 +29,7 @@ #include "ED_util.h" #include "RNA_access.h" +#include "RNA_prototypes.h" #include "UI_interface.h" @@ -294,6 +296,50 @@ static void ED_OT_lib_id_unlink(wmOperatorType *ot) ot->flag = OPTYPE_UNDO | OPTYPE_INTERNAL; } +static bool lib_id_override_editable_toggle_poll(bContext *C) +{ + const PointerRNA id_ptr = CTX_data_pointer_get_type(C, "id", &RNA_ID); + const ID *id = static_cast<ID *>(id_ptr.data); + + return id && ID_IS_OVERRIDE_LIBRARY_REAL(id) && !ID_IS_LINKED(id); +} + +static int lib_id_override_editable_toggle_exec(bContext *C, wmOperator *UNUSED(op)) +{ + Main *bmain = CTX_data_main(C); + const PointerRNA id_ptr = CTX_data_pointer_get_type(C, "id", &RNA_ID); + ID *id = static_cast<ID *>(id_ptr.data); + + const bool is_system_override = BKE_lib_override_library_is_system_defined(bmain, id); + if (is_system_override) { + /* A system override is not editable. Make it an editable (non-system-defined) one. */ + id->override_library->flag &= ~IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED; + } + else { + /* Reset override, which makes it non-editable (i.e. a system define override). */ + BKE_lib_override_library_id_reset(bmain, id, true); + } + + WM_main_add_notifier(NC_WM | ND_LIB_OVERRIDE_CHANGED, nullptr); + + return OPERATOR_FINISHED; +} + +static void ED_OT_lib_id_override_editable_toggle(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Toggle Library Override Editable"; + ot->description = "Set if this library override data-block can be edited"; + ot->idname = "ED_OT_lib_id_override_editable_toggle"; + + /* api callbacks */ + ot->poll = lib_id_override_editable_toggle_poll; + ot->exec = lib_id_override_editable_toggle_exec; + + /* flags */ + ot->flag = OPTYPE_UNDO | OPTYPE_INTERNAL; +} + /** \} */ /* -------------------------------------------------------------------- */ @@ -331,6 +377,7 @@ void ED_operatortypes_edutils() WM_operatortype_append(ED_OT_lib_id_fake_user_toggle); WM_operatortype_append(ED_OT_lib_id_unlink); + WM_operatortype_append(ED_OT_lib_id_override_editable_toggle); WM_operatortype_append(ED_OT_flush_edits); |