diff --git a/ChangeLog b/ChangeLog index 05d6750d1..32eebf613 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-11-18 Peter Williams + + * gtk/NodeStore.cs (GetNode): New public function. Patch refactored + a bit to eliminate code duplication with get_node_cb. + 2003-11-18 John Luke * configure.in: test for gtkhtml3 diff --git a/doc/ChangeLog b/doc/ChangeLog index 0a7a615c3..8b97b12d2 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2003-11-18 Peter Williams + + * en/Gtk/NodeStore.xml: Document new GetNode functions. + 2003-11-17 John Luke * en/Gtk/Socket.xml: documented diff --git a/doc/en/Gtk/NodeStore.xml b/doc/en/Gtk/NodeStore.xml index 6f15fb21d..dde458dc5 100644 --- a/doc/en/Gtk/NodeStore.xml +++ b/doc/en/Gtk/NodeStore.xml @@ -42,6 +42,24 @@ + + + Method + + Gtk.ITreeNode + + + + + + Returns a node given a . + The path to look up. + + Looks up the node corresponding to and returns it, + or null if the node cannot be found. + + + Method diff --git a/gtk/NodeStore.cs b/gtk/NodeStore.cs index 1fb072798..c1777c97d 100644 --- a/gtk/NodeStore.cs +++ b/gtk/NodeStore.cs @@ -89,23 +89,15 @@ namespace Gtk { bool get_node_cb (out int node_idx, IntPtr path) { if (path == IntPtr.Zero) - Console.WriteLine ("Got a null path in get_node"); + throw new ArgumentNullException ("path"); + TreePath treepath = new TreePath (path); node_idx = -1; - int[] indices = treepath.Indices; - if (indices[0] >= Nodes.Count) + ITreeNode node = GetNodeAtPath (treepath); + if (node == null) return false; - ITreeNode node = Nodes [indices [0]] as ITreeNode; - int i; - for (i = 1; i < treepath.Depth; i++) { - if (indices [i] >= node.ChildCount) - return false; - - node = node [indices [i]]; - } - node_idx = node.ID; node_hash [node.ID] = node; return true; @@ -410,5 +402,31 @@ namespace Gtk { gtksharp_node_store_emit_row_deleted (Handle, path.Handle); } + + private ITreeNode GetNodeAtPath (TreePath path) + { + int[] indices = path.Indices; + + if (indices[0] >= Nodes.Count) + return null; + + ITreeNode node = Nodes [indices [0]] as ITreeNode; + int i; + for (i = 1; i < path.Depth; i++) { + if (indices [i] >= node.ChildCount) + return null; + + node = node [indices [i]]; + } + + return node; + } + + public ITreeNode GetNode (TreePath path) { + if (path == null) + throw new ArgumentNullException (); + + return GetNodeAtPath (path); + } } }