From a46de41db595de4c2564af25a091a420723a222f Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 28 Mar 2022 17:34:36 +0200 Subject: LibOverride: Massive edits to 'editable' IDs checks in editors code. Add new `BKE_id_is_editable` helper in `BKE_lib_id.h`, that supercedes previous check (simple `ID_IS_LINKED()` macro) for many editing cases. This allows to also take into account 'system override' (aka non-editable override) case. Ref: {T95707}. --- .../editors/space_outliner/outliner_collections.cc | 15 +++++++++------ .../blender/editors/space_outliner/outliner_dragdrop.cc | 15 ++++++++------- source/blender/editors/space_outliner/outliner_draw.cc | 6 ++++-- source/blender/editors/space_outliner/outliner_select.cc | 5 +++-- 4 files changed, 24 insertions(+), 17 deletions(-) (limited to 'source/blender/editors/space_outliner') diff --git a/source/blender/editors/space_outliner/outliner_collections.cc b/source/blender/editors/space_outliner/outliner_collections.cc index a4ff44512ef..8ca2ffe6a9c 100644 --- a/source/blender/editors/space_outliner/outliner_collections.cc +++ b/source/blender/editors/space_outliner/outliner_collections.cc @@ -354,7 +354,7 @@ void outliner_collection_delete( else { LISTBASE_FOREACH (CollectionParent *, cparent, &collection->parents) { Collection *parent = cparent->collection; - if (ID_IS_LINKED(parent)) { + if (ID_IS_LINKED(parent) || ID_IS_OVERRIDE_LIBRARY(parent)) { skip = true; break; } @@ -366,7 +366,7 @@ void outliner_collection_delete( ID *scene_owner = id_type->owner_get(bmain, &parent->id); BLI_assert(GS(scene_owner->name) == ID_SCE); - if (ID_IS_LINKED(scene_owner)) { + if (ID_IS_LINKED(scene_owner) || ID_IS_OVERRIDE_LIBRARY(scene_owner)) { skip = true; break; } @@ -603,7 +603,9 @@ static int collection_duplicate_exec(bContext *C, wmOperator *op) if (ID_IS_LINKED(scene_owner) || ID_IS_OVERRIDE_LIBRARY(scene_owner)) { scene_owner = CTX_data_scene(C); - parent = ID_IS_LINKED(scene_owner) ? nullptr : scene_owner->master_collection; + parent = (ID_IS_LINKED(scene_owner) || ID_IS_OVERRIDE_LIBRARY(scene_owner)) ? + nullptr : + scene_owner->master_collection; } } @@ -1293,6 +1295,7 @@ static bool collection_disable_render_poll(bContext *C) static int collection_flag_exec(bContext *C, wmOperator *op) { + Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); SpaceOutliner *space_outliner = CTX_wm_space_outliner(C); @@ -1319,7 +1322,7 @@ static int collection_flag_exec(bContext *C, wmOperator *op) LayerCollection *layer_collection = reinterpret_cast( BLI_gsetIterator_getKey(&collections_to_edit_iter)); Collection *collection = layer_collection->collection; - if (ID_IS_LINKED(collection)) { + if (!BKE_id_is_editable(bmain, &collection->id)) { continue; } if (clear) { @@ -1347,7 +1350,7 @@ static int collection_flag_exec(bContext *C, wmOperator *op) GSET_ITER (collections_to_edit_iter, data.collections_to_edit) { Collection *collection = reinterpret_cast( BLI_gsetIterator_getKey(&collections_to_edit_iter)); - if (ID_IS_LINKED(collection)) { + if (!BKE_id_is_editable(bmain, &collection->id)) { continue; } @@ -1600,7 +1603,7 @@ static int outliner_color_tag_set_exec(bContext *C, wmOperator *op) if (collection == scene->master_collection) { continue; } - if (ID_IS_LINKED(collection)) { + if (!BKE_id_is_editable(CTX_data_main(C), &collection->id)) { BKE_report(op->reports, RPT_WARNING, "Can't add a color tag to a linked collection"); continue; } diff --git a/source/blender/editors/space_outliner/outliner_dragdrop.cc b/source/blender/editors/space_outliner/outliner_dragdrop.cc index 30b81b2ecb2..88640210ea3 100644 --- a/source/blender/editors/space_outliner/outliner_dragdrop.cc +++ b/source/blender/editors/space_outliner/outliner_dragdrop.cc @@ -22,6 +22,7 @@ #include "BKE_collection.h" #include "BKE_context.h" #include "BKE_layer.h" +#include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_material.h" #include "BKE_object.h" @@ -374,7 +375,7 @@ static void parent_drop_set_parents(bContext *C, Object *object = (Object *)drag_id->id; /* Do nothing to linked data */ - if (ID_IS_LINKED(object)) { + if (!BKE_id_is_editable(bmain, &object->id)) { linked_objects = true; continue; } @@ -387,7 +388,7 @@ static void parent_drop_set_parents(bContext *C, } if (linked_objects) { - BKE_report(reports, RPT_INFO, "Can't edit library linked object(s)"); + BKE_report(reports, RPT_INFO, "Can't edit library linked or non-editable override object(s)"); } if (parent_set) { @@ -556,7 +557,7 @@ static int scene_drop_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent Scene *scene = (Scene *)outliner_ID_drop_find(C, event, ID_SCE); Object *ob = (Object *)WM_drag_get_local_ID_from_event(event, ID_OB); - if (ELEM(nullptr, ob, scene) || ID_IS_LINKED(scene)) { + if (ELEM(nullptr, ob, scene) || !BKE_id_is_editable(bmain, &scene->id)) { return OPERATOR_CANCELLED; } @@ -748,7 +749,7 @@ static bool datastack_drop_init(bContext *C, const wmEvent *event, StackDropData ob = nullptr; } - if (ob && ID_IS_LINKED(&ob->id)) { + if (ob && !BKE_id_is_editable(CTX_data_main(C), &ob->id)) { return false; } @@ -1107,8 +1108,8 @@ struct CollectionDrop { static Collection *collection_parent_from_ID(ID *id) { - /* Can't change linked parent collections. */ - if (!id || ID_IS_LINKED(id)) { + /* Can't change linked or override parent collections. */ + if (!id || ID_IS_LINKED(id) || ID_IS_OVERRIDE_LIBRARY(id)) { return nullptr; } @@ -1134,7 +1135,7 @@ static bool collection_drop_init( } Collection *to_collection = outliner_collection_from_tree_element(te); - if (ID_IS_LINKED(to_collection)) { + if (ID_IS_LINKED(to_collection) || ID_IS_OVERRIDE_LIBRARY(to_collection)) { return false; } diff --git a/source/blender/editors/space_outliner/outliner_draw.cc b/source/blender/editors/space_outliner/outliner_draw.cc index 9857abb3da7..a6f09a86eb4 100644 --- a/source/blender/editors/space_outliner/outliner_draw.cc +++ b/source/blender/editors/space_outliner/outliner_draw.cc @@ -2165,8 +2165,10 @@ static void outliner_draw_mode_column_toggle(uiBlock *block, /* Mode toggling handles its own undo state because undo steps need to be grouped. */ UI_but_flag_disable(but, UI_BUT_UNDO); - if (ID_IS_LINKED(&ob->id)) { - UI_but_disable(but, TIP_("Can't edit external library data")); + if (ID_IS_LINKED(&ob->id) || + (ID_IS_OVERRIDE_LIBRARY_REAL(ob) && + (ob->id.override_library->flag & IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED) != 0)) { + UI_but_disable(but, TIP_("Can't edit library or non-editable override data")); } } diff --git a/source/blender/editors/space_outliner/outliner_select.cc b/source/blender/editors/space_outliner/outliner_select.cc index a202ded6deb..fd0ee422df0 100644 --- a/source/blender/editors/space_outliner/outliner_select.cc +++ b/source/blender/editors/space_outliner/outliner_select.cc @@ -31,6 +31,7 @@ #include "BKE_gpencil.h" #include "BKE_gpencil_modifier.h" #include "BKE_layer.h" +#include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_modifier.h" #include "BKE_object.h" @@ -116,8 +117,8 @@ static void do_outliner_item_posemode_toggle(bContext *C, Scene *scene, Base *ba Main *bmain = CTX_data_main(C); Object *ob = base->object; - if (ID_IS_LINKED(ob)) { - BKE_report(CTX_wm_reports(C), RPT_WARNING, "Cannot pose libdata"); + if (!BKE_id_is_editable(CTX_data_main(C), &ob->id)) { + BKE_report(CTX_wm_reports(C), RPT_WARNING, "Cannot pose non-editable data"); return; } -- cgit v1.2.3