Outliner: Support dragging objects into different collections

Doing so will remove the object from the old collection and insert it
into the new one.
This commit is contained in:
Julian Eisel 2017-03-10 20:47:48 +01:00
parent 0210df079c
commit 0d7dfd9f46
5 changed files with 60 additions and 16 deletions

View File

@ -47,11 +47,11 @@ bool BKE_collection_remove(struct Scene *scene, struct SceneCollection *sc);
struct SceneCollection *BKE_collection_master(const struct Scene *scene);
void BKE_collection_rename(const struct Scene *scene, struct SceneCollection *sc, const char *name);
void BKE_collection_master_free(struct Scene *scene);
void BKE_collection_object_add(struct Scene *scene, struct SceneCollection *sc, struct Object *object);
void BKE_collection_object_add(const struct Scene *scene, struct SceneCollection *sc, struct Object *object);
void BKE_collection_object_add_from(struct Scene *scene, struct Object *ob_src, struct Object *ob_dst);
void BKE_collection_object_remove(struct Main *bmain, struct Scene *scene, struct SceneCollection *sc, struct Object *object, const bool free_us);
void BKE_collection_object_remove(struct Main *bmain, const struct Scene *scene, struct SceneCollection *sc, struct Object *object, const bool free_us);
void BKE_collections_object_remove(struct Main *bmain, struct Scene *scene, struct Object *object, const bool free_us);
void BKE_collection_object_move(struct Main *bmain, struct Scene *scene, struct SceneCollection *sc_dst, struct SceneCollection *sc_src, struct Object *ob);
void BKE_collection_object_move(const struct Scene *scene, struct SceneCollection *sc_dst, struct SceneCollection *sc_src, struct Object *ob);
void BKE_collection_reinsert_after(const struct Scene *scene, struct SceneCollection *sc_reinsert, struct SceneCollection *sc_after);
void BKE_collection_reinsert_into(struct SceneCollection *sc_reinsert, struct SceneCollection *sc_into);

View File

@ -101,8 +101,8 @@ bool BKE_scene_has_object(struct Scene *scene, struct Object *ob);
/* syncing */
void BKE_layer_sync_new_scene_collection(struct Scene *scene, const struct SceneCollection *sc_parent, struct SceneCollection *sc);
void BKE_layer_sync_object_link(struct Scene *scene, struct SceneCollection *sc, struct Object *ob);
void BKE_layer_sync_object_unlink(struct Scene *scene, struct SceneCollection *sc, struct Object *ob);
void BKE_layer_sync_object_link(const struct Scene *scene, struct SceneCollection *sc, struct Object *ob);
void BKE_layer_sync_object_unlink(const struct Scene *scene, struct SceneCollection *sc, struct Object *ob);
/* override */

View File

@ -224,7 +224,7 @@ void BKE_collection_master_free(Scene *scene)
collection_free(BKE_collection_master(scene));
}
static void collection_object_add(Scene *scene, SceneCollection *sc, Object *ob)
static void collection_object_add(const Scene *scene, SceneCollection *sc, Object *ob)
{
BLI_addtail(&sc->objects, BLI_genericNodeN(ob));
id_us_plus((ID *)ob);
@ -234,7 +234,7 @@ static void collection_object_add(Scene *scene, SceneCollection *sc, Object *ob)
/**
* Add object to collection
*/
void BKE_collection_object_add(Scene *scene, SceneCollection *sc, Object *ob)
void BKE_collection_object_add(const Scene *scene, SceneCollection *sc, Object *ob)
{
if (BLI_findptr(&sc->objects, ob, offsetof(LinkData, data))) {
/* don't add the same object twice */
@ -259,9 +259,10 @@ void BKE_collection_object_add_from(Scene *scene, Object *ob_src, Object *ob_dst
}
/**
* Remove object from collection
* Remove object from collection.
* \param bmain: Can be NULL if free_us is false.
*/
void BKE_collection_object_remove(Main *bmain, Scene *scene, SceneCollection *sc, Object *ob, const bool free_us)
void BKE_collection_object_remove(Main *bmain, const Scene *scene, SceneCollection *sc, Object *ob, const bool free_us)
{
LinkData *link = BLI_findptr(&sc->objects, ob, offsetof(LinkData, data));
@ -287,10 +288,10 @@ void BKE_collection_object_remove(Main *bmain, Scene *scene, SceneCollection *sc
/**
* Move object from a collection into another
*/
void BKE_collection_object_move(Main *bmain, Scene *scene, SceneCollection *sc_dst, SceneCollection *sc_src, Object *ob)
void BKE_collection_object_move(const Scene *scene, SceneCollection *sc_dst, SceneCollection *sc_src, Object *ob)
{
BKE_collection_object_add(scene, sc_dst, ob);
BKE_collection_object_remove(bmain, scene, sc_src, ob, false);
BKE_collection_object_remove(NULL, scene, sc_src, ob, false);
}
/**

View File

@ -984,7 +984,7 @@ void BKE_layer_sync_new_scene_collection(Scene *scene, const SceneCollection *sc
/**
* Add a corresponding ObjectBase to all the equivalent LayerCollection
*/
void BKE_layer_sync_object_link(Scene *scene, SceneCollection *sc, Object *ob)
void BKE_layer_sync_object_link(const Scene *scene, SceneCollection *sc, Object *ob)
{
for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) {
for (LayerCollection *lc = sl->layer_collections.first; lc; lc = lc->next) {
@ -1000,7 +1000,7 @@ void BKE_layer_sync_object_link(Scene *scene, SceneCollection *sc, Object *ob)
* Remove the equivalent object base to all layers that have this collection
* also remove all reference to ob in the filter_objects
*/
void BKE_layer_sync_object_unlink(Scene *scene, SceneCollection *sc, Object *ob)
void BKE_layer_sync_object_unlink(const Scene *scene, SceneCollection *sc, Object *ob)
{
for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) {
for (LayerCollection *lc = sl->layer_collections.first; lc; lc = lc->next) {

View File

@ -388,12 +388,55 @@ static void outliner_add_scene_contents(SpaceOops *soops, ListBase *lb, Scene *s
#endif
}
static void outliner_object_reorder(
const Scene *scene, TreeElement *insert_element, TreeElement *insert_handle, TreeElementInsertType action)
{
TreeStoreElem *tselem_insert = TREESTORE(insert_element);
Object *ob = (Object *)tselem_insert->id;
SceneCollection *sc = outliner_scene_collection_from_tree_element(insert_handle);
SceneCollection *sc_ob_parent = NULL;
BLI_assert(action == TE_INSERT_INTO);
UNUSED_VARS_NDEBUG(action);
/* find parent scene-collection of object */
if (insert_element->parent) {
for (TreeElement *te_ob_parent = insert_element->parent; te_ob_parent; te_ob_parent = te_ob_parent->parent) {
if (ELEM(TREESTORE(te_ob_parent)->type, TSE_SCENE_COLLECTION, TSE_LAYER_COLLECTION)) {
sc_ob_parent = outliner_scene_collection_from_tree_element(te_ob_parent);
break;
}
}
}
else {
sc_ob_parent = BKE_collection_master(scene);
}
BKE_collection_object_move(scene, sc, sc_ob_parent, ob);
}
static bool outliner_object_reorder_poll(
const Scene *UNUSED(scene), const TreeElement *insert_element,
TreeElement **io_insert_handle, TreeElementInsertType *io_action)
{
TreeStoreElem *tselem_handle = TREESTORE(*io_insert_handle);
if (ELEM(tselem_handle->type, TSE_SCENE_COLLECTION, TSE_LAYER_COLLECTION) &&
(insert_element->parent != *io_insert_handle))
{
*io_action = TE_INSERT_INTO;
return true;
}
return false;
}
// can be inlined if necessary
static void outliner_add_object_contents(SpaceOops *soops, TreeElement *te, TreeStoreElem *tselem, Object *ob)
{
te->reinsert = outliner_object_reorder;
te->reinsert_poll = outliner_object_reorder_poll;
if (outliner_animdata_test(ob->adt))
outliner_add_element(soops, &te->subtree, ob, te, TSE_ANIM_DATA, 0);
outliner_add_element(soops, &te->subtree, ob->poselib, te, 0, 0); // XXX FIXME.. add a special type for this
if (ob->proxy && !ID_IS_LINKED_DATABLOCK(ob))
@ -1374,7 +1417,7 @@ static void outliner_add_layer_collections_recursive(
ten->reinsert_poll = outliner_layer_collections_reorder_poll;
for (LinkData *link = collection->object_bases.first; link; link = link->next) {
outliner_add_element(soops, &ten->subtree, ((Base *)link->data)->object, NULL, 0, 0);
outliner_add_element(soops, &ten->subtree, ((Base *)link->data)->object, ten, 0, 0);
}
outliner_make_hierarchy(&ten->subtree);
@ -1406,7 +1449,7 @@ static void outliner_add_scene_collections_recursive(SpaceOops *soops, ListBase
outliner_add_scene_collection_init(ten, collection);
for (LinkData *link = collection->objects.first; link; link = link->next) {
outliner_add_element(soops, &ten->subtree, link->data, NULL, 0, 0);
outliner_add_element(soops, &ten->subtree, link->data, ten, 0, 0);
}
outliner_make_hierarchy(&ten->subtree);