Fix tree node navigation with key arrows to be more usable for deep hierarchies
This commit is contained in:
@@ -339,12 +339,10 @@ namespace FlaxEditor.GUI.Tree
|
||||
var node = SelectedNode;
|
||||
|
||||
// Check if has focus and if any node is focused and it isn't a root
|
||||
if (ContainsFocus && node != null && !node.IsRoot)
|
||||
if (ContainsFocus && node != null && node.AutoFocus)
|
||||
{
|
||||
var window = Root;
|
||||
|
||||
// Check if can perform update
|
||||
if (_keyUpdateTime >= KeyUpdateTimeout)
|
||||
if (_keyUpdateTime >= KeyUpdateTimeout && window is WindowRootControl windowRoot && windowRoot.Window.IsFocused)
|
||||
{
|
||||
bool keyUpArrow = window.GetKeyDown(KeyboardKeys.ArrowUp);
|
||||
bool keyDownArrow = window.GetKeyDown(KeyboardKeys.ArrowDown);
|
||||
@@ -358,13 +356,12 @@ namespace FlaxEditor.GUI.Tree
|
||||
Assert.AreNotEqual(-1, myIndex);
|
||||
|
||||
// Up
|
||||
TreeNode toSelect = null;
|
||||
if (keyUpArrow)
|
||||
{
|
||||
TreeNode toSelect = null;
|
||||
if (myIndex == 0)
|
||||
{
|
||||
// Select parent (if it exists and it isn't a root)
|
||||
if (parentNode != null && !parentNode.IsRoot)
|
||||
// Select parent
|
||||
toSelect = parentNode;
|
||||
}
|
||||
else
|
||||
@@ -372,24 +369,16 @@ namespace FlaxEditor.GUI.Tree
|
||||
// Select previous parent child
|
||||
toSelect = nodeParent.GetChild(myIndex - 1) as TreeNode;
|
||||
|
||||
// Check if is valid and expanded and has any children
|
||||
// Select last child if is valid and expanded and has any children
|
||||
if (toSelect != null && toSelect.IsExpanded && toSelect.HasAnyVisibleChild)
|
||||
{
|
||||
// Select last child
|
||||
toSelect = toSelect.GetChild(toSelect.ChildrenCount - 1) as TreeNode;
|
||||
}
|
||||
}
|
||||
if (toSelect != null)
|
||||
{
|
||||
// Select
|
||||
Select(toSelect);
|
||||
toSelect.Focus();
|
||||
}
|
||||
}
|
||||
// Down
|
||||
else
|
||||
{
|
||||
TreeNode toSelect = null;
|
||||
if (node.IsExpanded && node.HasAnyVisibleChild)
|
||||
{
|
||||
// Select the first child
|
||||
@@ -398,13 +387,14 @@ namespace FlaxEditor.GUI.Tree
|
||||
else if (myIndex == nodeParent.ChildrenCount - 1)
|
||||
{
|
||||
// Select next node after parent
|
||||
if (parentNode != null)
|
||||
while (parentNode != null && toSelect == null)
|
||||
{
|
||||
int parentIndex = parentNode.IndexInParent;
|
||||
if (parentIndex != -1 && parentIndex < parentNode.Parent.ChildrenCount - 1)
|
||||
{
|
||||
toSelect = parentNode.Parent.GetChild(parentIndex + 1) as TreeNode;
|
||||
}
|
||||
parentNode = parentNode.Parent as TreeNode;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -412,13 +402,13 @@ namespace FlaxEditor.GUI.Tree
|
||||
// Select next parent child
|
||||
toSelect = nodeParent.GetChild(myIndex + 1) as TreeNode;
|
||||
}
|
||||
if (toSelect != null)
|
||||
}
|
||||
if (toSelect != null && toSelect.AutoFocus)
|
||||
{
|
||||
// Select
|
||||
Select(toSelect);
|
||||
toSelect.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
// Reset time
|
||||
_keyUpdateTime = 0.0f;
|
||||
@@ -452,7 +442,7 @@ namespace FlaxEditor.GUI.Tree
|
||||
if (node.IsCollapsed)
|
||||
{
|
||||
// Select parent if has and is not a root
|
||||
if (node.HasParent && node.Parent is TreeNode nodeParentNode && !nodeParentNode.IsRoot)
|
||||
if (node.HasParent && node.Parent is TreeNode nodeParentNode && nodeParentNode.AutoFocus)
|
||||
{
|
||||
Select(nodeParentNode);
|
||||
nodeParentNode.Focus();
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace FlaxEditor.SceneGraph
|
||||
protected RootNode()
|
||||
: base(null, Guid.NewGuid())
|
||||
{
|
||||
_treeNode.AutoFocus = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -29,6 +30,7 @@ namespace FlaxEditor.SceneGraph
|
||||
protected RootNode(Guid id)
|
||||
: base(null, id)
|
||||
{
|
||||
_treeNode.AutoFocus = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user