From b00b9dadd819d3b94405f755131e609afa827438 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 1 Mar 2017 13:10:29 +0100 Subject: Outliner: Support dragging object into collection Doing this will add the object to the collection. --- .../editors/space_outliner/outliner_collections.c | 26 ++++++++++++++-------- .../blender/editors/space_outliner/outliner_edit.c | 16 ++++++++++++- .../editors/space_outliner/outliner_intern.h | 2 ++ .../editors/space_outliner/space_outliner.c | 12 ++++++++-- 4 files changed, 44 insertions(+), 12 deletions(-) (limited to 'source/blender/editors/space_outliner') diff --git a/source/blender/editors/space_outliner/outliner_collections.c b/source/blender/editors/space_outliner/outliner_collections.c index 87a9e019ee7..c5cfd47486f 100644 --- a/source/blender/editors/space_outliner/outliner_collections.c +++ b/source/blender/editors/space_outliner/outliner_collections.c @@ -54,6 +54,21 @@ static LayerCollection *outliner_collection_active(bContext *C) return CTX_data_layer_collection(C); } +SceneCollection *outliner_scene_collection_from_tree_element(TreeElement *te) +{ + TreeStoreElem *tselem = TREESTORE(te); + + if (tselem->type == TSE_SCENE_COLLECTION) { + return te->directdata; + } + else if (tselem->type == TSE_LAYER_COLLECTION) { + LayerCollection *lc = te->directdata; + return lc->scene_collection; + } + + return NULL; +} + #if 0 static CollectionOverride *outliner_override_active(bContext *UNUSED(C)) { @@ -294,16 +309,9 @@ static TreeTraversalAction collection_delete_cb(TreeElement *te, void *customdat { struct CollectionDeleteData *data = customdata; TreeStoreElem *tselem = TREESTORE(te); - SceneCollection *scene_collection; + SceneCollection *scene_collection = outliner_scene_collection_from_tree_element(te); - if (tselem->type == TSE_LAYER_COLLECTION) { - LayerCollection *lc = te->directdata; - scene_collection = lc->scene_collection; - } - else if (tselem->type == TSE_SCENE_COLLECTION) { - scene_collection = te->directdata; - } - else { + if (!scene_collection) { return TRAVERSE_SKIP_CHILDS; } diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c index fe31a796e4d..d4a8626e1ab 100644 --- a/source/blender/editors/space_outliner/outliner_edit.c +++ b/source/blender/editors/space_outliner/outliner_edit.c @@ -1916,6 +1916,7 @@ static int parent_drop_invoke(bContext *C, wmOperator *op, const wmEvent *event) Main *bmain = CTX_data_main(C); Scene *scene = NULL; TreeElement *te = NULL; + TreeStoreElem *tselem; char childname[MAX_ID_NAME]; char parname[MAX_ID_NAME]; int partype = 0; @@ -1925,8 +1926,21 @@ static int parent_drop_invoke(bContext *C, wmOperator *op, const wmEvent *event) /* Find object hovered over */ te = outliner_dropzone_find(soops, fmval, true); + tselem = te ? TREESTORE(te) : NULL; - if (te) { + if (tselem && ELEM(tselem->type, TSE_LAYER_COLLECTION, TSE_SCENE_COLLECTION)) { + SceneCollection *sc = outliner_scene_collection_from_tree_element(te); + + scene = BKE_scene_find_from_collection(bmain, sc); + BLI_assert(scene); + RNA_string_get(op->ptr, "child", childname); + ob = (Object *)BKE_libblock_find_name(ID_OB, childname); + BKE_collection_object_add(scene, sc, ob); + + DAG_relations_tag_update(bmain); + WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene); + } + else if (te) { RNA_string_set(op->ptr, "parent", te->name); /* Identify parent and child */ RNA_string_get(op->ptr, "child", childname); diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h index 096af698506..731b5041bd9 100644 --- a/source/blender/editors/space_outliner/outliner_intern.h +++ b/source/blender/editors/space_outliner/outliner_intern.h @@ -297,6 +297,8 @@ void outliner_keymap(struct wmKeyConfig *keyconf); /* outliner_collections.c */ +struct SceneCollection *outliner_scene_collection_from_tree_element(TreeElement *te); + void OUTLINER_OT_collections_delete(struct wmOperatorType *ot); void OUTLINER_OT_collection_select(struct wmOperatorType *ot); void OUTLINER_OT_collection_link(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_outliner/space_outliner.c b/source/blender/editors/space_outliner/space_outliner.c index 759ef4e78e4..348a4488f57 100644 --- a/source/blender/editors/space_outliner/space_outliner.c +++ b/source/blender/editors/space_outliner/space_outliner.c @@ -102,10 +102,14 @@ static int outliner_parent_drop_poll(bContext *C, wmDrag *drag, const wmEvent *e if (GS(id->name) == ID_OB) { /* Ensure item under cursor is valid drop target */ TreeElement *te = outliner_dropzone_find(soops, fmval, true); + TreeStoreElem *tselem = te ? TREESTORE(te) : NULL; - if (te && te->idcode == ID_OB && TREESTORE(te)->type == 0) { + if (!te) { + /* pass */ + } + else if (te->idcode == ID_OB && tselem->type == 0) { Scene *scene; - ID *te_id = TREESTORE(te)->id; + ID *te_id = tselem->id; /* check if dropping self or parent */ if (te_id == id || (Object *)te_id == ((Object *)id)->parent) @@ -122,6 +126,10 @@ static int outliner_parent_drop_poll(bContext *C, wmDrag *drag, const wmEvent *e return 1; } } + else if (ELEM(tselem->type, TSE_LAYER_COLLECTION, TSE_SCENE_COLLECTION)) { + /* support adding object from different scene to collection */ + return 1; + } } } return 0; -- cgit v1.2.3