From 3f725f10ccffd546c3c7a1cad24d7694c64a4ba7 Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Mon, 19 Aug 2019 14:45:07 +0200 Subject: Fix T68647: objects cannot be moved to collection if there is no active object This showed e.g. when deleting active object, then selecting using box select. This commit also lifts the restriction that linked objects could not be moved to a collection. Reviewers: campbellbarton, dfelinto Maniphest Tasks: T68647 Differential Revision: https://developer.blender.org/D5485 --- source/blender/editors/object/object_edit.c | 37 +++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'source') diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index ed40a4eb948..16d21a11e2b 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -116,6 +116,7 @@ typedef struct MoveToCollectionData MoveToCollectionData; static void move_to_collection_menus_items(struct uiLayout *layout, struct MoveToCollectionData *menu); +static ListBase selected_objects_get(bContext *C); /* ************* XXX **************** */ static void error(const char *UNUSED(arg)) @@ -1460,6 +1461,23 @@ void OBJECT_OT_mode_set_or_submode(wmOperatorType *ot) RNA_def_property_flag(prop, PROP_SKIP_SAVE); } +static ListBase selected_objects_get(bContext *C) +{ + ListBase objects = {NULL}; + + if (CTX_wm_space_outliner(C) != NULL) { + ED_outliner_selected_objects_get(C, &objects); + } + else { + CTX_DATA_BEGIN (C, Object *, ob, selected_objects) { + BLI_addtail(&objects, BLI_genericNodeN(ob)); + } + CTX_DATA_END; + } + + return objects; +} + static bool move_to_collection_poll(bContext *C) { if (CTX_wm_space_outliner(C) != NULL) { @@ -1472,7 +1490,7 @@ static bool move_to_collection_poll(bContext *C) return false; } - return ED_operator_object_active_editable(C); + return ED_operator_objectmode(C); } } @@ -1498,15 +1516,7 @@ static int move_to_collection_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - if (CTX_wm_space_outliner(C) != NULL) { - ED_outliner_selected_objects_get(C, &objects); - } - else { - CTX_DATA_BEGIN (C, Object *, ob, selected_objects) { - BLI_addtail(&objects, BLI_genericNodeN(ob)); - } - CTX_DATA_END; - } + objects = selected_objects_get(C); if (is_new) { char new_collection_name[MAX_NAME]; @@ -1650,6 +1660,13 @@ static int move_to_collection_invoke(bContext *C, wmOperator *op, const wmEvent { Scene *scene = CTX_data_scene(C); + ListBase objects = selected_objects_get(C); + if (BLI_listbase_is_empty(&objects)) { + BKE_report(op->reports, RPT_ERROR, "No objects selected"); + return OPERATOR_CANCELLED; + } + BLI_freelistN(&objects); + /* Reset the menus data for the current master collection, and free previously allocated data. */ move_to_collection_menus_free(&master_collection_menu); -- cgit v1.2.3