internal static void RestoreState(TreeViewPad pad, ITreeNavigator nav, NodeState es)
        {
            if (es == null) return;

            Gtk.TreeIter it = nav.CurrentPosition._iter;
            if (es.Options != null) {
                pad.SetIterOptions (it, es.Options);
            }
            pad.ResetState (it);
            nav.Expanded = es.Expanded;

            if (es.ChildrenState != null) {
                foreach (NodeState ces in es.ChildrenState) {
                    if (nav.MoveToChild (ces.NodeName, null)) {
                        RestoreState (pad, nav, ces);
                        nav.MoveToParent ();
                    }
                }
            }

            if (es.Selected)
                nav.Selected = true;
        }
        static NodeState FromXml(XmlElement elem, TreeViewPad.TreeOptions parentOptions)
        {
            NodeState ns = new NodeState ();
            ns.NodeName = elem.GetAttribute ("name");
            string expanded = elem.GetAttribute ("expanded");
            ns.Expanded = (expanded == "" || bool.Parse (expanded));
            ns.Selected = elem.GetAttribute ("selected") == "True";

            XmlNodeList nodelist = elem.ChildNodes;
            foreach (XmlNode nod in nodelist) {
                XmlElement el = nod as XmlElement;
                if (el == null) continue;
                if (el.LocalName == "Option") {
                    if (ns.Options == null) {
                        if (parentOptions != null) ns.Options = parentOptions.CloneOptions (Gtk.TreeIter.Zero);
                        else ns.Options = new TreeViewPad.TreeOptions ();
                    }
                    ns.Options [el.GetAttribute ("id")] = bool.Parse (el.GetAttribute ("value"));
                }
                else if (el.LocalName == "Node") {
                    if (ns.ChildrenState == null) ns.ChildrenState = new ArrayList ();
                    ns.ChildrenState.Add (FromXml (el, ns.Options != null ? ns.Options : parentOptions));
                }
            }
            return ns;
        }
        static NodeState SaveStateRec(TreeViewPad pad, ITreeNavigator nav)
        {
            Gtk.TreeIter it = nav.CurrentPosition._iter;

            ArrayList childrenState = null;

            if (nav.Filled && nav.MoveToFirstChild ()) {
                do {
                    NodeState cs = SaveStateRec (pad, nav);
                    if (cs != null) {
                        cs.NodeName = nav.NodeName;
                        if (childrenState == null) childrenState = new ArrayList ();
                        childrenState.Add (cs);
                    }
                } while (nav.MoveNext ());
                nav.MoveToParent ();
            }

            TreeViewPad.TreeOptions ops = pad.GetIterOptions (it);

            if (ops != null || nav.Expanded || childrenState != null || nav.Selected) {
                NodeState es = new NodeState ();
                es.Expanded = nav.Expanded;
                es.Selected = nav.Selected;
                es.Options = ops;
                es.ChildrenState = childrenState;
                return es;
            } else
                return null;
        }
 public void RestoreState(NodeState state)
 {
     NodeState.RestoreState (pad, this, state);
 }