From bfeff732523f2ee8053b00d56f8df9fdb6662000 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 23 Jul 2020 11:32:53 +0200 Subject: LibOverride: Add reset operations to the outliner menu. --- .../editors/space_outliner/outliner_tools.c | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c index 9e7bf1e268c..7515178e1d1 100644 --- a/source/blender/editors/space_outliner/outliner_tools.c +++ b/source/blender/editors/space_outliner/outliner_tools.c @@ -797,6 +797,34 @@ static void id_override_library_create_cb(bContext *C, } } +static void id_override_library_reset_cb(bContext *C, + ReportList *UNUSED(reports), + Scene *UNUSED(scene), + TreeElement *UNUSED(te), + TreeStoreElem *UNUSED(tsep), + TreeStoreElem *tselem, + void *user_data) +{ + BLI_assert(TSE_IS_REAL_ID(tselem)); + ID *id_root = tselem->id; + OutlinerLibOverrideData *data = user_data; + const bool do_hierarchy = data->do_hierarchy; + + if (ID_IS_OVERRIDE_LIBRARY_REAL(id_root)) { + Main *bmain = CTX_data_main(C); + + if (do_hierarchy) { + BKE_lib_override_library_id_hierarchy_reset(bmain, id_root); + } + else { + BKE_lib_override_library_id_reset(bmain, id_root); + } + + WM_event_add_notifier(C, NC_WM | ND_DATACHANGED, NULL); + WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL); + } +} + static void id_fake_user_set_cb(bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *UNUSED(scene), @@ -1547,6 +1575,8 @@ typedef enum eOutlinerIdOpTypes { OUTLINER_IDOP_LOCAL, OUTLINER_IDOP_OVERRIDE_LIBRARY_CREATE, OUTLINER_IDOP_OVERRIDE_LIBRARY_CREATE_HIERARCHY, + OUTLINER_IDOP_OVERRIDE_LIBRARY_RESET, + OUTLINER_IDOP_OVERRIDE_LIBRARY_RESET_HIERARCHY, OUTLINER_IDOP_SINGLE, OUTLINER_IDOP_DELETE, OUTLINER_IDOP_REMAP, @@ -1583,6 +1613,16 @@ static const EnumPropertyItem prop_id_op_types[] = { 0, "Add Library Override Hierarchy", "Add a local override of this linked data-block, and its hierarchy of dependencies"}, + {OUTLINER_IDOP_OVERRIDE_LIBRARY_RESET, + "OVERRIDE_LIBRARY_RESET", + 0, + "Reset Library Override", + "Reset this local override to its linked values"}, + {OUTLINER_IDOP_OVERRIDE_LIBRARY_RESET_HIERARCHY, + "OVERRIDE_LIBRARY_RESET_HIERARCHY", + 0, + "Reset Library Override Hierarchy", + "Reset this local override to its linked values, as well as its hierarchy of dependencies"}, {0, "", 0, NULL, NULL}, {OUTLINER_IDOP_COPY, "COPY", ICON_COPYDOWN, "Copy", ""}, {OUTLINER_IDOP_PASTE, "PASTE", ICON_PASTEDOWN, "Paste", ""}, @@ -1610,6 +1650,9 @@ static bool outliner_id_operation_item_poll(bContext *C, case OUTLINER_IDOP_OVERRIDE_LIBRARY_CREATE: case OUTLINER_IDOP_OVERRIDE_LIBRARY_CREATE_HIERARCHY: return true; + case OUTLINER_IDOP_OVERRIDE_LIBRARY_RESET: + case OUTLINER_IDOP_OVERRIDE_LIBRARY_RESET_HIERARCHY: + return true; case OUTLINER_IDOP_SINGLE: if (!soops || ELEM(soops->outlinevis, SO_SCENES, SO_VIEW_LAYER)) { return true; @@ -1746,6 +1789,30 @@ static int outliner_id_operation_exec(bContext *C, wmOperator *op) ED_undo_push(C, "Overridden Data Hierarchy"); break; } + case OUTLINER_IDOP_OVERRIDE_LIBRARY_RESET: { + /* make local */ + outliner_do_libdata_operation(C, + op->reports, + scene, + soops, + &soops->tree, + id_override_library_reset_cb, + &(OutlinerLibOverrideData){.do_hierarchy = false}); + ED_undo_push(C, "Reset Overridden Data"); + break; + } + case OUTLINER_IDOP_OVERRIDE_LIBRARY_RESET_HIERARCHY: { + /* make local */ + outliner_do_libdata_operation(C, + op->reports, + scene, + soops, + &soops->tree, + id_override_library_reset_cb, + &(OutlinerLibOverrideData){.do_hierarchy = true}); + ED_undo_push(C, "Reset Overridden Data Hierarchy"); + break; + } case OUTLINER_IDOP_SINGLE: { /* make single user */ switch (idlevel) { -- cgit v1.2.3