diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2018-01-26 21:55:44 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2018-01-26 22:10:31 +0300 |
commit | 5798345c99b118c9b372f3f57ab8a6a4c9b19760 (patch) | |
tree | b0a8a69928104c4a3976502264ecc37be6f78c57 /source/blender/editors/space_outliner/outliner_ops.c | |
parent | 376fc19b240299857b088a1a21ced7e8b9cceacc (diff) |
Outliner: If a collection is empty and you drag something inside it, it opens up.
Idea by Pablo Vazquez.
Diffstat (limited to 'source/blender/editors/space_outliner/outliner_ops.c')
-rw-r--r-- | source/blender/editors/space_outliner/outliner_ops.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/source/blender/editors/space_outliner/outliner_ops.c b/source/blender/editors/space_outliner/outliner_ops.c index ff322b49a27..52f27b9708e 100644 --- a/source/blender/editors/space_outliner/outliner_ops.c +++ b/source/blender/editors/space_outliner/outliner_ops.c @@ -179,6 +179,28 @@ static void outliner_item_drag_handle( te_dragged->drag_data->insert_handle = te_insert_handle; } +/** + * Returns true if it is a collection and empty. + */ +static bool is_empty_collection(TreeElement *te) +{ + if (!ELEM(TREESTORE(te)->type, TSE_SCENE_COLLECTION, TSE_LAYER_COLLECTION)) { + return false; + } + + SceneCollection *scene_collection; + if (TREESTORE(te)->type == TSE_SCENE_COLLECTION) { + scene_collection = (SceneCollection *)te->directdata; + } + else { + BLI_assert(TREESTORE(te)->type == TSE_LAYER_COLLECTION); + scene_collection = ((LayerCollection *)te->directdata)->scene_collection; + } + + return BLI_listbase_is_empty(&scene_collection->objects) && + BLI_listbase_is_empty(&scene_collection->scene_collections); +} + static bool outliner_item_drag_drop_apply( Main *bmain, SpaceOops *soops, @@ -198,7 +220,16 @@ static bool outliner_item_drag_drop_apply( /* call of assert above should not have changed insert_handle and insert_type at this point */ BLI_assert(dragged_te->drag_data->insert_handle == insert_handle && dragged_te->drag_data->insert_type == insert_type); + + /* If the collection was just created and you moved objects/collections inside it, + * it is strange to have it closed and we not see the newly dragged elements. */ + const bool should_open_collection = (insert_type == TE_INSERT_INTO) && is_empty_collection(insert_handle); + dragged_te->reinsert(bmain, soops, dragged_te, insert_handle, insert_type, event); + + if (should_open_collection && !is_empty_collection(insert_handle)) { + TREESTORE(insert_handle)->flag &= ~TSE_CLOSED; + } return true; } |