Skip to content

Commit 4b0d3d6

Browse files
committed
More state saving
1 parent 5f042bf commit 4b0d3d6

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

External/3rdParty/Aga-1.7/Aga.Controls/Tree/TreeViewAdv.Properties.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ internal Point ItemDragStart
130130
/// <summary>
131131
/// Number of rows fits to the current page
132132
/// </summary>
133-
internal int CurrentPageSize
133+
public int CurrentPageSize
134134
{
135135
get
136136
{
@@ -170,6 +170,27 @@ internal int FirstVisibleRow
170170
}
171171
}
172172

173+
public TreeNodeAdv FirstVisibleNode
174+
{
175+
get
176+
{
177+
if (_firstVisibleRow >= 0 && _firstVisibleRow < RowMap.Count)
178+
return RowMap[_firstVisibleRow];
179+
return null;
180+
}
181+
}
182+
183+
public TreeNodeAdv LastVisibleNode
184+
{
185+
get
186+
{
187+
int lastVisibleRow = _firstVisibleRow + CurrentPageSize - 1;
188+
if (lastVisibleRow >= 0 && lastVisibleRow < RowMap.Count)
189+
return RowMap[lastVisibleRow];
190+
return null;
191+
}
192+
}
193+
173194
private int _offsetX;
174195
public int OffsetX
175196
{

External/Plugins/FlashDebugger/Controls/DataTreeControl.cs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,18 @@ public DataTreeControl(bool watchMode)
7575

7676
_model = new DataTreeModel();
7777
_tree.Model = _model;
78+
_tree.FullRowSelect = true;
7879
Controls.Add(_tree);
7980
_tree.Expanding += TreeExpanding;
8081
_tree.SelectionChanged += TreeSelectionChanged;
82+
_tree.NodeMouseDoubleClick += Tree_NodeMouseDoubleClick;
8183
_tree.LoadOnDemand = true;
8284
_tree.AutoRowHeight = true;
8385
ValueNodeTextBox.DrawText += ValueNodeTextBox_DrawText;
8486
ValueNodeTextBox.IsEditEnabledValueNeeded += ValueNodeTextBox_IsEditEnabledValueNeeded;
8587
ValueNodeTextBox.EditorShowing += ValueNodeTextBox_EditorShowing;
8688
ValueNodeTextBox.EditorHided += ValueNodeTextBox_EditorHided;
8789
ValueNodeTextBox.LabelChanged += ValueNodeTextBox_LabelChanged;
88-
_tree.NodeMouseDoubleClick += Tree_NodeMouseDoubleClick;
8990
_contextMenuStrip = new ContextMenuStrip();
9091
if (PluginBase.MainForm != null && PluginBase.Settings != null)
9192
{
@@ -478,6 +479,7 @@ public void SaveState()
478479
state.Selected = _tree.SelectedNode == null ? null : _model.GetFullPath(_tree.SelectedNode.Tag as Node);
479480
state.Expanded.Clear();
480481
SaveExpanded(Nodes);
482+
SaveScrollState();
481483
}
482484

483485
private void SaveExpanded(Collection<Node> nodes)
@@ -493,12 +495,26 @@ private void SaveExpanded(Collection<Node> nodes)
493495
}
494496
}
495497

498+
private void SaveScrollState()
499+
{
500+
if (Nodes.Count < 1)
501+
{
502+
state.TopPath = state.BottomPath = null;
503+
return;
504+
}
505+
var topNode = _tree.FirstVisibleNode;
506+
state.TopPath = topNode != null ? _model.GetFullPath(_tree.FirstVisibleNode.Tag as Node) : null;
507+
var bottomNode = _tree.LastVisibleNode;
508+
state.BottomPath = bottomNode != null ? _model.GetFullPath(bottomNode.Tag as Node) : null;
509+
}
510+
496511
public void RestoreState()
497512
{
498513
if (state == null) return;
499514
RestoreExpanded(Nodes);
500515
if (state.Selected != null)
501516
_tree.SelectedNode = _tree.FindNodeByTag(_model.FindNode(state.Selected));
517+
RestoreScrollState();
502518
}
503519

504520
private void RestoreExpanded(Collection<Node> nodes)
@@ -514,6 +530,22 @@ private void RestoreExpanded(Collection<Node> nodes)
514530
}
515531
}
516532

533+
private void RestoreScrollState()
534+
{
535+
if (Nodes.Count < 1) return;
536+
537+
if (state.BottomPath != null)
538+
{
539+
var bottomNode = Tree.FindNodeByTag(_model.FindNode(state.BottomPath));
540+
if (bottomNode != null) Tree.EnsureVisible(bottomNode);
541+
}
542+
543+
if (state.TopPath != null)
544+
{
545+
var topNode = Tree.FindNodeByTag(_model.FindNode(state.TopPath));
546+
if (topNode != null) Tree.EnsureVisible(topNode);
547+
}
548+
}
517549

518550
#region IToolTipProvider Members
519551

@@ -545,7 +577,8 @@ private class DataTreeState
545577

546578
public HashSet<string> Expanded = new HashSet<String>();
547579
public string Selected;
548-
580+
public string TopPath;
581+
public string BottomPath;
549582
}
550583

551584
#endregion

External/Plugins/FlashDebugger/Controls/DataTreeModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ private Node FindNode(Node root, string path)
3131
{
3232
foreach (Node node in root.Nodes)
3333
{
34+
// TODO: We could optimize some more here, we don't need to get the full path
3435
string nodePath = GetFullPath(node);
3536
if (path == nodePath) return node;
3637
if (path.StartsWith(nodePath))

0 commit comments

Comments
 (0)