diff options
author | Nathan Craddock <nzcraddock@gmail.com> | 2020-08-26 19:58:23 +0300 |
---|---|---|
committer | Nathan Craddock <nzcraddock@gmail.com> | 2020-08-26 19:58:23 +0300 |
commit | 70151e41dc025aa92c80420f7d14df20f58f6354 (patch) | |
tree | f6e5b0bf00499d007d57da7516c85c69a667d00c /source | |
parent | b028a43245afeb73ca1b35a3698fbbd329d1f100 (diff) |
Outliner: Left and right walk navigation
Previously the left and right arrow keys would close and open the active
tree element, but a subsequent key press would not select up or
down the tree as is common in tree-based interfaces.
Walking left and right now does a selection action after opening or closing
the active tree item. For example, a right key press on a closed element
will open it's subtree, and an additional right key press will select
the first child element.
A left key press anywhere in a subtree will first close the active
element if it's subtree is expanded. Walking left again will select the
parent element.
Part of T77408
Differential Revision: https://developer.blender.org/D8650
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/space_outliner/outliner_edit.c | 5 | ||||
-rw-r--r-- | source/blender/editors/space_outliner/outliner_select.c | 38 |
2 files changed, 40 insertions, 3 deletions
diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c index 8567dd4da13..99eb9a04c0e 100644 --- a/source/blender/editors/space_outliner/outliner_edit.c +++ b/source/blender/editors/space_outliner/outliner_edit.c @@ -152,8 +152,11 @@ void OUTLINER_OT_highlight_update(wmOperatorType *ot) /* Open or close a tree element, optionally toggling all children recursively */ void outliner_item_openclose(TreeElement *te, bool open, bool toggle_all) { - TreeStoreElem *tselem = TREESTORE(te); + if (BLI_listbase_is_empty(&te->subtree)) { + return; + } + TreeStoreElem *tselem = TREESTORE(te); if (open) { tselem->flag &= ~TSE_CLOSED; } diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c index d720747e953..28f7fc70618 100644 --- a/source/blender/editors/space_outliner/outliner_select.c +++ b/source/blender/editors/space_outliner/outliner_select.c @@ -1634,6 +1634,40 @@ static TreeElement *outliner_find_next_element(SpaceOutliner *space_outliner, Tr return te; } +static TreeElement *outliner_walk_left(SpaceOutliner *space_outliner, + TreeElement *te, + bool toggle_all) +{ + TreeStoreElem *tselem = TREESTORE(te); + + if (TSELEM_OPEN(tselem, space_outliner)) { + outliner_item_openclose(te, false, toggle_all); + } + /* Only walk up a level if the element is closed and not toggling expand */ + else if (!toggle_all && te->parent) { + te = te->parent; + } + + return te; +} + +static TreeElement *outliner_walk_right(SpaceOutliner *space_outliner, + TreeElement *te, + bool toggle_all) +{ + TreeStoreElem *tselem = TREESTORE(te); + + /* Only walk down a level if the element is open and not toggling expand */ + if (!toggle_all && TSELEM_OPEN(tselem, space_outliner) && !BLI_listbase_is_empty(&te->subtree)) { + te = te->subtree.first; + } + else { + outliner_item_openclose(te, true, toggle_all); + } + + return te; +} + static TreeElement *do_outliner_select_walk(SpaceOutliner *space_outliner, TreeElement *te, const int direction, @@ -1650,10 +1684,10 @@ static TreeElement *do_outliner_select_walk(SpaceOutliner *space_outliner, te = outliner_find_next_element(space_outliner, te); break; case UI_SELECT_WALK_LEFT: - outliner_item_openclose(te, false, toggle_all); + te = outliner_walk_left(space_outliner, te, toggle_all); break; case UI_SELECT_WALK_RIGHT: - outliner_item_openclose(te, true, toggle_all); + te = outliner_walk_right(space_outliner, te, toggle_all); break; } |