Remove the nodes of a tree

View: New views
4 Messages — Rating Filter:   Alert me  

Remove the nodes of a tree

by Fernando Correa da Conceição-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have a GtkTreeView which show a tree o files. How can I remove all
childs of a node? Or I have to get each one of then and remove?

Thanks!

Fernando Correa da Conceição

--
PHP-GTK General Mailing List (http://gtk.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: Remove the nodes of a tree

by kksou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Fernando Correa da Conceição-3 wrote:
I have a GtkTreeView which show a tree o files. How can I remove all
childs of a node? Or I have to get each one of then and remove?

Fernando Correa da Conceição
Hi Fernando,

You'll laugh when you see the solution. It's a one-liner unset($model[$iter]).

The complete sample code here:
http://www.kksou.com/php-gtk2/articles/remove-nodes-from-GtkTreeView---Part-1.php

It make use the GtkTreeModel functionality implemented by Andrei:
http://www.nabble.com/New-GtkTreeModel-functionality-p3009641.html

Regards,
/kksou


Re: Remove the nodes of a tree

by Fernando Correa da Conceição-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

kksou escreveu:

> Fernando Correa da Conceição-3 wrote:
>  
>> I have a GtkTreeView which show a tree o files. How can I remove all
>> childs of a node? Or I have to get each one of then and remove?
>>
>> Fernando Correa da Conceição
>>
>>    
>
> Hi Fernando,
>
> You'll laugh when you see the solution. It's a one-liner
> unset($model[$iter]).
>
> The complete sample code here:
> http://www.kksou.com/php-gtk2/articles/remove-nodes-from-GtkTreeView---Part-1.php
>
> It make use the GtkTreeModel functionality implemented by Andrei:
> http://www.nabble.com/New-GtkTreeModel-functionality-p3009641.html
>
> Regards,
> /kksou
>
>
>  
Thanks, but this is not exacty what I need, but I can use it as an
example. And about the post you refer from Andrei, it is very usefull
thing but is not on the manual, I will write some docs using it and add
to the manual as a tutorial. My case is that I do not want remove the
parent node, only the childs.

Fernando Correa da Conceição.

Re: Remove the nodes of a tree

by kksou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Fernando Correa da Conceição-3 wrote:
Thanks, but this is not exacty what I need...
My case is that I do not want remove the
parent node, only the childs.

Fernando Correa da Conceição.
Try this then...

$parent_node = $model[$iter];
$nodes_to_remove = array();

foreach ($parent_node->children() as $child_node) {
    $iter = $child_node->iter;
    $nodes_to_remove[] = $model->get_string_from_iter($iter);
}

for ($i=count($nodes_to_remove)-1; $i>=0; --$i) {
    unset($model[$nodes_to_remove[$i]]);
}

Complete sample code here:
http://www.kksou.com/php-gtk2/articles/remove-nodes-from-GtkTreeView---Part-3---remove-child-nodes-only.php

Regards,
/kksou