mirror of
https://github.com/blender/blender
synced 2026-09-29 04:37:17 +03:00
Outliner: Move object hierarchy to target collection during drag-drop
Drag-drop for an object to target collection just moves parent object. For children objects, user need to select hierarchy before dragdrop. To avoid this extra effort, move children objects along with parent to the target collection. New function `find_child_objects_recursive` to iterate/store child objects inside Vector, it's called from `collection_drop_invoke`. Now by default entire hierarchy is moved to target collection. For old behavior of "drag drop just parent object", use `ctrl + shift + LMB drag`. See PR description for video and RCS thread Pull Request: https://projects.blender.org/blender/blender/pulls/156916
This commit is contained in:
parent
3427c0c1ae
commit
aae30c8a13
1 changed files with 29 additions and 6 deletions
|
|
@ -366,7 +366,7 @@ static bool parent_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
|
|||
}
|
||||
|
||||
if (!allow_parenting_without_modifier_key(space_outliner)) {
|
||||
if ((event->modifier & KM_SHIFT) == 0) {
|
||||
if (event->modifier != KM_SHIFT) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1247,7 +1247,7 @@ static bool collection_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event
|
|||
bool changed = outliner_flag_set(*space_outliner, TSE_HIGHLIGHTED_ANY | TSE_DRAG_ANY, false);
|
||||
|
||||
CollectionDrop data;
|
||||
if (((event->modifier & KM_SHIFT) == 0) && collection_drop_init(C, drag, event->xy, &data)) {
|
||||
if (((event->modifier != KM_SHIFT)) && collection_drop_init(C, drag, event->xy, &data)) {
|
||||
TreeElement *te = data.te;
|
||||
TreeStoreElem *tselem = TREESTORE(te);
|
||||
switch (data.insert_type) {
|
||||
|
|
@ -1285,8 +1285,8 @@ static std::string collection_drop_tooltip(bContext *C,
|
|||
const wmEvent *event = win ? win->runtime->eventstate : nullptr;
|
||||
|
||||
CollectionDrop data;
|
||||
if (event && ((event->modifier & KM_SHIFT) == 0) && collection_drop_init(C, drag, xy, &data)) {
|
||||
const bool is_link = !data.from || (event->modifier & KM_CTRL);
|
||||
if (event && collection_drop_init(C, drag, xy, &data)) {
|
||||
const bool is_link = !data.from || (event->modifier == KM_CTRL);
|
||||
|
||||
/* Test if we are moving within same parent collection. */
|
||||
bool same_level = false;
|
||||
|
|
@ -1329,7 +1329,12 @@ static std::string collection_drop_tooltip(bContext *C,
|
|||
wmDragID *drag_id = static_cast<wmDragID *>(drag->ids.first);
|
||||
const bool is_object = (GS(drag_id->id->name) == ID_OB);
|
||||
if (is_object) {
|
||||
return TIP_("Move inside collection (Ctrl to link, Shift to parent)");
|
||||
if (event->modifier & (KM_SHIFT | KM_CTRL)) {
|
||||
return TIP_("Move parent object inside collection");
|
||||
}
|
||||
return TIP_(
|
||||
"Move inside collection (Ctrl to link, Shift to parent,\n Ctrl + Shift to move "
|
||||
"only parent)");
|
||||
}
|
||||
return TIP_("Move inside collection (Ctrl to link)");
|
||||
}
|
||||
|
|
@ -1338,6 +1343,17 @@ static std::string collection_drop_tooltip(bContext *C,
|
|||
return {};
|
||||
}
|
||||
|
||||
static void find_child_objects_recursive(bContext *C, Object *ob, Vector<Object *> &child_objects)
|
||||
{
|
||||
CTX_DATA_BEGIN (C, Base *, base, selectable_bases) {
|
||||
if (base->object->parent == ob) {
|
||||
child_objects.append(base->object);
|
||||
find_child_objects_recursive(C, base->object, child_objects);
|
||||
}
|
||||
}
|
||||
CTX_DATA_END;
|
||||
}
|
||||
|
||||
static wmOperatorStatus collection_drop_invoke(bContext *C,
|
||||
wmOperator * /*op*/,
|
||||
const wmEvent *event)
|
||||
|
|
@ -1386,7 +1402,7 @@ static wmOperatorStatus collection_drop_invoke(bContext *C,
|
|||
|
||||
for (wmDragID &drag_id : drag->ids) {
|
||||
/* Ctrl enables linking, so we don't need a from collection then. */
|
||||
Collection *from = (event->modifier & KM_CTRL) ?
|
||||
Collection *from = (event->modifier == KM_CTRL) ?
|
||||
nullptr :
|
||||
collection_parent_from_ID(drag_id.from_parent);
|
||||
|
||||
|
|
@ -1396,6 +1412,13 @@ static wmOperatorStatus collection_drop_invoke(bContext *C,
|
|||
|
||||
if (from) {
|
||||
BKE_collection_object_move(bmain, scene, data.to, from, object);
|
||||
if ((event->modifier & (KM_CTRL | KM_SHIFT)) == 0) {
|
||||
Vector<Object *> child_objects;
|
||||
find_child_objects_recursive(C, object, child_objects);
|
||||
for (Object *child_ob : child_objects) {
|
||||
BKE_collection_object_move(bmain, scene, data.to, from, child_ob);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
BKE_collection_object_add(bmain, data.to, object);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue