@@ -75,17 +75,18 @@ public DataTreeControl(bool watchMode)
75
75
76
76
_model = new DataTreeModel ( ) ;
77
77
_tree . Model = _model ;
78
+ _tree . FullRowSelect = true ;
78
79
Controls . Add ( _tree ) ;
79
80
_tree . Expanding += TreeExpanding ;
80
81
_tree . SelectionChanged += TreeSelectionChanged ;
82
+ _tree . NodeMouseDoubleClick += Tree_NodeMouseDoubleClick ;
81
83
_tree . LoadOnDemand = true ;
82
84
_tree . AutoRowHeight = true ;
83
85
ValueNodeTextBox . DrawText += ValueNodeTextBox_DrawText ;
84
86
ValueNodeTextBox . IsEditEnabledValueNeeded += ValueNodeTextBox_IsEditEnabledValueNeeded ;
85
87
ValueNodeTextBox . EditorShowing += ValueNodeTextBox_EditorShowing ;
86
88
ValueNodeTextBox . EditorHided += ValueNodeTextBox_EditorHided ;
87
89
ValueNodeTextBox . LabelChanged += ValueNodeTextBox_LabelChanged ;
88
- _tree . NodeMouseDoubleClick += Tree_NodeMouseDoubleClick ;
89
90
_contextMenuStrip = new ContextMenuStrip ( ) ;
90
91
if ( PluginBase . MainForm != null && PluginBase . Settings != null )
91
92
{
@@ -478,6 +479,7 @@ public void SaveState()
478
479
state . Selected = _tree . SelectedNode == null ? null : _model . GetFullPath ( _tree . SelectedNode . Tag as Node ) ;
479
480
state . Expanded . Clear ( ) ;
480
481
SaveExpanded ( Nodes ) ;
482
+ SaveScrollState ( ) ;
481
483
}
482
484
483
485
private void SaveExpanded ( Collection < Node > nodes )
@@ -493,12 +495,26 @@ private void SaveExpanded(Collection<Node> nodes)
493
495
}
494
496
}
495
497
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
+
496
511
public void RestoreState ( )
497
512
{
498
513
if ( state == null ) return ;
499
514
RestoreExpanded ( Nodes ) ;
500
515
if ( state . Selected != null )
501
516
_tree . SelectedNode = _tree . FindNodeByTag ( _model . FindNode ( state . Selected ) ) ;
517
+ RestoreScrollState ( ) ;
502
518
}
503
519
504
520
private void RestoreExpanded ( Collection < Node > nodes )
@@ -514,6 +530,22 @@ private void RestoreExpanded(Collection<Node> nodes)
514
530
}
515
531
}
516
532
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
+ }
517
549
518
550
#region IToolTipProvider Members
519
551
@@ -545,7 +577,8 @@ private class DataTreeState
545
577
546
578
public HashSet < string > Expanded = new HashSet < String > ( ) ;
547
579
public string Selected ;
548
-
580
+ public string TopPath ;
581
+ public string BottomPath ;
549
582
}
550
583
551
584
#endregion
0 commit comments