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;
        }
 internal static NodeState SaveState(TreeViewPad pad, ITreeNavigator nav)
 {
     NodeState state = SaveStateRec (pad, nav);
     if (state == null) return new NodeState ();
     else return state;
 }
        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;
        }
        XmlElement ToXml(XmlDocument doc, TreeViewPad.TreeOptions parentOptions)
        {
            XmlElement el = doc.CreateElement ("Node");
            if (NodeName != null)
                el.SetAttribute ("name", NodeName);
            el.SetAttribute ("expanded", Expanded.ToString ());
            if (Selected)
                el.SetAttribute ("selected", "True");

            TreeViewPad.TreeOptions ops = Options;
            if (ops != null) {
                foreach (DictionaryEntry de in ops) {
                    object parentVal = parentOptions != null ? parentOptions [de.Key] : null;
                    if (parentVal != null && !parentVal.Equals (de.Value) || (parentVal == null && de.Value != null) || parentOptions == null) {
                        XmlElement eop = doc.CreateElement ("Option");
                        eop.SetAttribute ("id", de.Key.ToString());
                        eop.SetAttribute ("value", de.Value.ToString ());
                        el.AppendChild (eop);
                    }
                }
            }

            if (ChildrenState == null) return el;
            foreach (NodeState ces in ChildrenState) {
                XmlElement child = ces.ToXml (doc, ops != null ? ops : parentOptions);
                el.AppendChild (child);
            }

            return el;
        }
 public void Restore(TreeViewPad view)
 {
     view.RestoreTreeState (parent);
 }
 internal void Initialize(TreeViewPad tree)
 {
     this.tree = tree;
 }
 public TreeNodeNavigator(TreeViewPad pad, Gtk.TreeIter iter)
 {
     this.pad = pad;
     tree = pad.tree;
     store = pad.store;
     currentIter = iter;
 }
 public TreeViewPadMemento(TreeViewPad treeView)
 {
     this.treeView = treeView;
 }
 public TreeNodeNavigator(TreeViewPad pad)
     : this(pad, Gtk.TreeIter.Zero)
 {
 }
 internal TreeBuilderContext(TreeViewPad pad)
 {
     this.pad = pad;
 }
 public TreeBuilder(TreeViewPad pad, Gtk.TreeIter iter)
     : base(pad, iter)
 {
 }
 public TreeBuilder(TreeViewPad pad)
     : base(pad)
 {
 }
 public TreeOptions(TreeViewPad pad, Gtk.TreeIter iter)
 {
     this.pad = pad;
     this.iter = iter;
 }