diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2017-02-22 18:02:43 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2017-02-22 19:25:00 +0300 |
commit | 910b7dec8dca25473d98c23f7c4fd8e44fafd47d (patch) | |
tree | c4dba049c8670704a7d789cf6f16f0e711dd0ec3 /source/blender/blenkernel/intern/collection.c | |
parent | e003499f6ffed72f3a166cca4d59e855774767d2 (diff) |
UI: Support drag & drop reordering of collections
This adds initial support for reordering collections from the Outliner
using drag & drop.
Although drag & drop support is limited to collections for now, this
lays most foundations for general drag & drop reordering support in the
Outliner. There are some design questions to be answered though:
* Would reordering of other data types (like objects) be a purely visual change or would it affect the order in which they are stored? (Would that make a difference for the user?)
* Should/can we allow mixing of different data types? (e.g. mixing render layers with objects)
* How could we realize this technically?
Notes:
* "Sort Alphabetically" has to be disabled to use this ("View" menu).
* Reordering only works with collections on the same hierarchy level.
* Added some visual feedback that should work quite well, it's by far not a final design though: {F493806}
* Modified collection orders are stored in .blends.
* Reordering can be undone.
* Did minor cleanups here and there.
Diffstat (limited to 'source/blender/blenkernel/intern/collection.c')
-rw-r--r-- | source/blender/blenkernel/intern/collection.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index 100cbf2dd45..24f97c00afb 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -44,6 +44,9 @@ #include "MEM_guardedalloc.h" +bool collection_remlink(SceneCollection *, SceneCollection *); +bool collection_insert_after(SceneCollection *, SceneCollection *, SceneCollection *); + /** * Add a collection to a collection ListBase and syncronize all render layers * The ListBase is NULL when the collection is to be added to the master collection @@ -95,7 +98,7 @@ static void collection_free(SceneCollection *sc) * Unlink the collection recursively * return true if unlinked */ -static bool collection_remlink(SceneCollection *sc_parent, SceneCollection *sc_gone) +bool collection_remlink(SceneCollection *sc_parent, SceneCollection *sc_gone) { for (SceneCollection *sc = sc_parent->scene_collections.first; sc; sc = sc->next) { @@ -174,9 +177,35 @@ bool BKE_collection_remove(Scene *scene, SceneCollection *sc) } /** + * Lookup the parent listbase of \a sc_insert_after and insert \a sc_insert after it. + * \param sc_after: If this is NULL, \a sc_insert will be inserted as first collection in \a parent. + */ +bool collection_insert_after( + SceneCollection *parent, SceneCollection *sc_insert, SceneCollection *sc_after) +{ + if (sc_after == NULL) { + BLI_addhead(&parent->scene_collections, sc_insert); + return true; + } + + for (SceneCollection *sc = parent->scene_collections.first; sc; sc = sc->next) { + if (sc == sc_after) { + BLI_insertlinkafter(&parent->scene_collections, sc_after, sc_insert); + return true; + } + + if (collection_insert_after(sc, sc_insert, sc_after)) { + return true; + } + } + + return false; +} + +/** * Returns the master collection */ -SceneCollection *BKE_collection_master(Scene *scene) +SceneCollection *BKE_collection_master(const Scene *scene) { return scene->collection; } |