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
This commit is contained in:
Philipp Oeser 2019-08-19 14:45:07 +02:00
parent 5615c675af
commit 3f725f10cc
Notes: blender-bot 2023-10-12 12:49:04 +02:00
Referenced by issue #68647, objects selected using box select cannot be moved to collection if there is no active object
1 changed files with 27 additions and 10 deletions

View File

@ -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);