Improved TreeListView copy/paste support.

- Fix sorting to respect visual ordering by ID, including parent.
- Provide Ctrl-A to 'Select All'. Note that there is an extant
bug with the redraw where renderdocui will not repaint when
it gets focus back.
This commit is contained in:
Michael Vance
2017-03-30 14:22:45 -04:00
committed by Baldur Karlsson
parent 3193595358
commit a74ddadd59
3 changed files with 59 additions and 17 deletions
@@ -328,21 +328,6 @@ namespace TreelistView
{
return GetRoot().Owner;
}
public string GetId()
{
StringBuilder sb = new StringBuilder(32);
Node node = this;
while (node != null)
{
node.Owner.UpdateChildIds(false);
if (node.Parent != null)
sb.Insert(0, "." + node.Id.ToString());
else
sb.Insert(0, node.Id.ToString());
node = node.Parent;
}
return sb.ToString();
}
internal void InsertBefore(Node insertBefore, NodeCollection owner)
{
this.m_owner = owner;
@@ -1100,11 +1085,53 @@ namespace TreelistView
return m_nodesMap.ContainsKey(node);
}
private class NodeSorter : IComparer<Node>
{
private Stack<int> BuildIds(Node node)
{
Stack<int> ids = new Stack<int>();
while (node != null)
{
node.Owner.UpdateChildIds(false);
ids.Push(node.Id);
node = node.Parent;
}
return ids;
}
private int NextId(Stack<int> ids)
{
if (ids.Count > 0)
return ids.Pop();
else
return -1;
}
public int Compare(Node left, Node right)
{
Stack<int> leftIds = BuildIds(left);
Stack<int> rightIds = BuildIds(right);
int deepest = Math.Max(leftIds.Count, rightIds.Count);
while(deepest > 0)
{
int lid = NextId(leftIds);
int rid = NextId(rightIds);
if (lid < rid)
return -1;
else if (lid > rid)
return 1;
deepest -= 1;
}
return 0;
}
}
public void Sort()
{
SortedList<string, Node> list = new SortedList<string,Node>();
NodeSorter Sorter = new NodeSorter();
SortedList<Node, Node> list = new SortedList<Node, Node>(m_nodes.Count, Sorter);
foreach (Node node in m_nodes)
list.Add(node.GetId(), node);
list.Add(node, node);
m_nodes = new List<Node>(list.Values);
}
@@ -410,6 +410,17 @@ namespace TreelistView
m_nodesSelection.Sort();
}
public void SelectAll()
{
FocusedNode = null;
NodesSelection.Clear();
foreach (Node node in NodeCollection.ForwardNodeIterator(m_firstVisibleNode, true))
{
NodesSelection.Add(node);
}
Invalidate();
}
[Browsable(false)]
public Node SelectedNode
{
@@ -364,6 +364,10 @@ namespace renderdocui.Controls
}
}
}
else if(e.KeyCode == Keys.A && e.Control)
{
variables.SelectAll();
}
}
private BufferFormatSpecifier m_FormatSpecifier = null;