diff --git a/ChangeLog b/ChangeLog index b1825c10e..28e2fb912 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-03-14 Dan Winship + + * gtk/TreeNode.cs (AddNode): add an overload that takes a position + + * gtk/NodeStore.cs (AddNode): likewise + (AddNode, child_added_cb): when adding a node, recursively connect + to the node signals on its children + (RemoveNode, child_deleted_cb): when removing a node, recursively + remove its children from node_hash. + 2005-03-12 Mike Kestner * glade/Glade.metadata : mark the XMLCustomWidgetHandler string params diff --git a/gtk/NodeStore.cs b/gtk/NodeStore.cs index 965c69811..fcd3385e2 100644 --- a/gtk/NodeStore.cs +++ b/gtk/NodeStore.cs @@ -317,8 +317,6 @@ namespace Gtk { private void changed_cb (object o, EventArgs args) { ITreeNode node = o as ITreeNode; - node_hash [node.ID] = node; - gtksharp_node_store_emit_row_changed (Handle, get_path_cb (node.ID), node.ID); } @@ -327,8 +325,7 @@ namespace Gtk { private void child_added_cb (object o, ITreeNode child) { - node_hash [child.ID] = child; - + AddNodeInternal (child); gtksharp_node_store_emit_row_inserted (Handle, get_path_cb (child.ID), child.ID); } @@ -338,6 +335,13 @@ namespace Gtk { [DllImport("gtksharpglue-2")] static extern void gtksharp_node_store_emit_row_has_child_toggled (IntPtr handle, IntPtr path, int node_idx); + private void RemoveNodeInternal (ITreeNode node) + { + node_hash.Remove (node.ID); + for (int i = 0; i < node.ChildCount; i++) + RemoveNodeInternal (node [i]); + } + private void child_deleted_cb (object o, int idx) { ITreeNode node = o as ITreeNode; @@ -346,28 +350,39 @@ namespace Gtk { TreePath child_path = path.Copy (); child_path.AppendIndex (idx); + ITreeNode child = GetNodeAtPath (child_path); + RemoveNodeInternal (child); + gtksharp_node_store_emit_row_deleted (Handle, child_path.Handle); - if (node.ChildCount <= 0) { - node_hash [node.ID] = node; - gtksharp_node_store_emit_row_has_child_toggled (Handle, path.Handle, node.ID); - } + if (node.ChildCount <= 0) + gtksharp_node_store_emit_row_has_child_toggled (Handle, get_path_cb (node.ID), node.ID); } - private void ConnectNode (ITreeNode node) + private void AddNodeInternal (ITreeNode node) { + node_hash [node.ID] = node; + node.Changed += new EventHandler (changed_cb); node.ChildAdded += new TreeNodeAddedHandler (child_added_cb); node.ChildRemoved += new TreeNodeRemovedHandler (child_deleted_cb); + + for (int i = 0; i < node.ChildCount; i++) + AddNodeInternal (node [i]); } public void AddNode (ITreeNode node) { nodes.Add (node); - node_hash [node.ID] = node; - ConnectNode (node); - for (int i = 0; i < node.ChildCount; i++) - ConnectNode (node [i]); + AddNodeInternal (node); + + gtksharp_node_store_emit_row_inserted (Handle, get_path_cb (node.ID), node.ID); + } + + public void AddNode (ITreeNode node, int position) + { + nodes.Insert (position, node); + AddNodeInternal (node); gtksharp_node_store_emit_row_inserted (Handle, get_path_cb (node.ID), node.ID); } @@ -378,6 +393,7 @@ namespace Gtk { if (idx < 0) return; nodes.Remove (node); + RemoveNodeInternal (node); TreePath path = new TreePath (); path.AppendIndex (idx); diff --git a/gtk/TreeNode.cs b/gtk/TreeNode.cs index 96281b727..c48dd2af5 100644 --- a/gtk/TreeNode.cs +++ b/gtk/TreeNode.cs @@ -111,6 +111,13 @@ namespace Gtk { OnChildAdded (child); } + public void AddChild (TreeNode child, int position) + { + children.Insert (position, child); + child.SetParent (this); + OnChildAdded (child); + } + public void RemoveChild (TreeNode child) { int idx = children.IndexOf (child);