Permalink
Browse files

Restore subnode states on collapse/expand.

Case 461226.
  • Loading branch information...
1 parent d88f9ee commit 96548d5c456ea246a520854cf481424b1d96d03e @Tak Tak committed May 2, 2012
@@ -91,6 +91,8 @@ public partial class ExtensibleTreeView : CompactScrolledWindow
int updateLockCount;
string contextMenuPath;
IDictionary<string,string> contextMenuTypeNameAliases;
+ Dictionary<Gtk.TreeIter,NodeState> states;
+ bool isRestoring;
private static Gtk.TargetEntry [] target_table = new Gtk.TargetEntry [] {
new Gtk.TargetEntry ("text/uri-list", 0, 11 ),
@@ -125,6 +127,7 @@ public partial class ExtensibleTreeView : CompactScrolledWindow
public ExtensibleTreeView ()
{
+ states = new Dictionary<Gtk.TreeIter,NodeState> ();
}
public ExtensibleTreeView (NodeBuilder[] builders, TreePadOption[] options)
@@ -219,7 +222,9 @@ public virtual void Initialize (NodeBuilder[] builders, TreePadOption[] options,
tree.AppendColumn (complete_column);
tree.TestExpandRow += OnTestExpandRow;
+ tree.TestCollapseRow += HandleTestCollapseRow;
tree.RowActivated += OnNodeActivated;
+ tree.RowExpanded += HandleTreeRowExpanded;
tree.ButtonReleaseEvent += OnButtonRelease;
tree.ButtonPressEvent += OnButtonPress;
@@ -253,6 +258,28 @@ public virtual void Initialize (NodeBuilder[] builders, TreePadOption[] options,
GLib.Timeout.Add (3000, Checker);
#endif
}
+
+ void HandleTestCollapseRow (object o, Gtk.TestCollapseRowArgs args)
+ {
+ ITreeNavigator node = GetNodeAtIter (args.Iter);
+ states[args.Iter] = node.SaveState ();
+ }
+
+ void HandleTreeRowExpanded (object o, Gtk.RowExpandedArgs args)
+ {
+ if (isRestoring)
+ return; // stack overflows are bad
+
+ try {
+ isRestoring = true;
+ ITreeNavigator node = GetNodeAtIter (args.Iter);
+
+ if (states.ContainsKey (args.Iter))
+ node.RestoreState (states[args.Iter]);
+ } finally {
+ isRestoring = false;
+ }
+ }
#if TREE_VERIFY_INTEGRITY
// Verifies the consistency of the tree view. Disabled by default
@@ -668,9 +695,14 @@ public ITreeNavigator[] GetSelectedNodes ()
return navs;
}
+ public ITreeNavigator GetNodeAtIter (Gtk.TreeIter iter)
+ {
+ return new TreeNodeNavigator (this, iter);
+ }
+
public ITreeNavigator GetNodeAtPosition (NodePosition position)
{
- return new TreeNodeNavigator (this, position._iter);
+ return GetNodeAtIter (position._iter);
}
public ITreeNavigator GetNodeAtObject (object dataObject)

0 comments on commit 96548d5

Please sign in to comment.