* 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.

svn path=/trunk/gtk-sharp/; revision=41805
This commit is contained in:
Dan Winship 2005-03-14 21:38:27 +00:00
parent 6a6e89d67e
commit e957a84316
3 changed files with 46 additions and 13 deletions

View File

@ -1,3 +1,13 @@
2005-03-14 Dan Winship <danw@novell.com>
* 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 <mkestner@novell.com>
* glade/Glade.metadata : mark the XMLCustomWidgetHandler string params

View File

@ -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);

View File

@ -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);