[Gtk-sharp-list] removing childrens of a node in treeview

Rampage atomikramp at email.it
Thu Aug 19 13:34:39 EDT 2010


Christopher David Howie ha scritto:
> On 08/18/2010 07:57 PM, Rampage wrote:
>   
>> is there a way from the iter of the collapsing node to get the iter of each
>> children and then to a
>> TreeStore.Remove(iter) ?
>>     
>
> This is untested, but should work:
>
> ----------8<----------
> private static void RemoveAllChildren(TreeModel model, TreeIter node)
> {
>     TreeIter child;
>
>     if (model.IterChildren(out child, node)) {
>         // There are children.
>
>         // Get the depth of the parent node so we know when to stop.
>         int depth = model.IterDepth(node);
>
>         while (model.Remove(ref child) &&
>                model.IterDepth(child) > depth);
>     }
> }
> ----------8<----------
>
>   
Hi, again :)
i've adapted your snipplet to work in the testcollapse, and it works 
great, it removes all child nodes.
the problem is that once all children are deleted i can't add anything 
anymore, couse it looks like the iter goes lost, and without the dummy 
value i can't test expansion anymore to trigger the population event.

here is the method as it's now:

------------------------------------------------------------------------
    protected virtual void OnDirectoryTreeTestCollapseRow (object o, 
Gtk.TestCollapseRowArgs args)
    {
        TreeIter child;

        if (dirtreestore.IterChildren(out child, args.Iter))
        {
            // There are children.

            // Get the depth of the parent node so we know when to stop.
            int depth = dirtreestore.IterDepth(args.Iter);

            while (dirtreestore.Remove(ref child) &&
                   dirtreestore.IterDepth(child) > depth);
        }

        //dirtreestore.AppendValues(args.Iter, "<loading>", "test");
    }
--------------------------------------------------------------------------------------

if i uncomment the last line the program crashes

here is the error.. a bit long :)

----------------------------------------------
Stacktrace:

  at (wrapper managed-to-native) Gtk.Application.gtk_main () <0x00052>
  at (wrapper managed-to-native) Gtk.Application.gtk_main () <0xffffffff>
  at Gtk.Application.Run () <0x0000b>
  at VoodooToolkit.MainClass.Main (string[]) [0x00020] in 
/home/rampage/Projects/voodoo/trunk/VoodooToolkit/VoodooToolkit/Main.cs:78
  at (wrapper runtime-invoke) 
VoodooToolkit.MainClass.runtime_invoke_void_object 
(object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

    /usr/bin/mono() [0x47b77f]
    /usr/bin/mono() [0x4aef3f]
    /lib/libpthread.so.0(+0xf8f0) [0x7fb3c3a518f0]
    /usr/lib/libgtk-x11-2.0.so.0(+0x182b00) [0x7fb3c1150b00]
    /usr/lib/libgtk-x11-2.0.so.0(+0x23edf1) [0x7fb3c120cdf1]
    /usr/lib/libgtk-x11-2.0.so.0(+0x2409ca) [0x7fb3c120e9ca]
    /usr/lib/libgtk-x11-2.0.so.0(+0x142178) [0x7fb3c1110178]
    /usr/lib/libgobject-2.0.so.0(g_closure_invoke+0x15e) [0x7fb3bde9c5de]
    /usr/lib/libgobject-2.0.so.0(+0x211dd) [0x7fb3bdeb01dd]
    /usr/lib/libgobject-2.0.so.0(g_signal_emit_valist+0x639) 
[0x7fb3bdeb18b9]
    /usr/lib/libgobject-2.0.so.0(g_signal_emit+0x83) [0x7fb3bdeb2033]
    /usr/lib/libgtk-x11-2.0.so.0(+0x2590bf) [0x7fb3c12270bf]
    /usr/lib/libgtk-x11-2.0.so.0(gtk_propagate_event+0xc3) [0x7fb3c1108643]
    /usr/lib/libgtk-x11-2.0.so.0(gtk_main_do_event+0x2eb) [0x7fb3c110971b]
    /usr/lib/libgdk-x11-2.0.so.0(+0x5c86c) [0x7fb3c0d7d86c]
    /lib/libglib-2.0.so.0(g_main_context_dispatch+0x1f2) [0x7fb3c40a98c2]
    /lib/libglib-2.0.so.0(+0x42748) [0x7fb3c40ad748]
    /lib/libglib-2.0.so.0(g_main_loop_run+0x195) [0x7fb3c40adc55]
    /usr/lib/libgtk-x11-2.0.so.0(gtk_main+0xa7) [0x7fb3c1109bb7]
    [0x409799d2]

Debug info from gdb:

[Thread debugging using libthread_db enabled]
[New Thread 0x7fb3c199c710 (LWP 3485)]
[New Thread 0x7fb3c22f8710 (LWP 3482)]
[New Thread 0x7fb3c4755710 (LWP 3481)]
0x00007fb3c3a5093d in read () from /lib/libpthread.so.0
  4 Thread 0x7fb3c4755710 (LWP 3481)  0x00007fb3c3a5111d in nanosleep ()
   from /lib/libpthread.so.0
  3 Thread 0x7fb3c22f8710 (LWP 3482)  0x00007fb3c3a4fb50 in sem_wait ()
   from /lib/libpthread.so.0
  2 Thread 0x7fb3c199c710 (LWP 3485)  0x00007fb3c35144ad in read ()
   from /lib/libc.so.6
* 1 Thread 0x7fb3c474a740 (LWP 3478)  0x00007fb3c3a5093d in read ()
   from /lib/libpthread.so.0

Thread 4 (Thread 0x7fb3c4755710 (LWP 3481)):
#0  0x00007fb3c3a5111d in nanosleep () from /lib/libpthread.so.0
#1  0x0000000000556342 in ?? ()
#2  0x00007fb3c3a489ca in start_thread () from /lib/libpthread.so.0
#3  0x00007fb3c35226fd in clone () from /lib/libc.so.6
#4  0x0000000000000000 in ?? ()

Thread 3 (Thread 0x7fb3c22f8710 (LWP 3482)):
#0  0x00007fb3c3a4fb50 in sem_wait () from /lib/libpthread.so.0
#1  0x00000000004e4aaa in ?? ()
#2  0x0000000000505035 in ?? ()
#3  0x0000000000570073 in ?? ()
#4  0x000000000058de21 in ?? ()
#5  0x00007fb3c3a489ca in start_thread () from /lib/libpthread.so.0
#6  0x00007fb3c35226fd in clone () from /lib/libc.so.6
#7  0x0000000000000000 in ?? ()

Thread 2 (Thread 0x7fb3c199c710 (LWP 3485)):
#0  0x00007fb3c35144ad in read () from /lib/libc.so.6
#1  0x000000004185e555 in ?? ()
#2  0x0000000001e48e00 in ?? ()
#3  0x00007fb3c199c710 in ?? ()
#4  0x00007fb3c1d28000 in ?? ()
#5  0x00007fb3c1d2b3a8 in ?? ()
#6  0x00007fb3c45cc990 in ?? ()
#7  0x00007fb3c199bcc0 in ?? ()
#8  0x00007fb3c199bc00 in ?? ()
#9  0x00007fb3c199c710 in ?? ()
#10 0x00007fb3c1d28000 in ?? ()
#11 0xffffffffffffffff in ?? ()
#12 0x00007fb3c20ada60 in ?? ()
#13 0x000000004185e400 in ?? ()
#14 0x0000000000000d9d in ?? ()
#15 0x0000000000000000 in ?? ()

Thread 1 (Thread 0x7fb3c474a740 (LWP 3478)):
#0  0x00007fb3c3a5093d in read () from /lib/libpthread.so.0
#1  0x000000000047b8f4 in ?? ()
#2  0x00000000004aef3f in ?? ()
#3  <signal handler called>
#4  0x00007fb3c1150b00 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#5  0x00007fb3c120cdf1 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#6  0x00007fb3c120e9ca in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#7  0x00007fb3c1110178 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#8  0x00007fb3bde9c5de in g_closure_invoke ()
   from /usr/lib/libgobject-2.0.so.0
#9  0x00007fb3bdeb01dd in ?? () from /usr/lib/libgobject-2.0.so.0
#10 0x00007fb3bdeb18b9 in g_signal_emit_valist ()
   from /usr/lib/libgobject-2.0.so.0
#11 0x00007fb3bdeb2033 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
#12 0x00007fb3c12270bf in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#13 0x00007fb3c1108643 in gtk_propagate_event ()
   from /usr/lib/libgtk-x11-2.0.so.0
#14 0x00007fb3c110971b in gtk_main_do_event ()
   from /usr/lib/libgtk-x11-2.0.so.0
#15 0x00007fb3c0d7d86c in ?? () from /usr/lib/libgdk-x11-2.0.so.0
#16 0x00007fb3c40a98c2 in g_main_context_dispatch ()
   from /lib/libglib-2.0.so.0
#17 0x00007fb3c40ad748 in ?? () from /lib/libglib-2.0.so.0
#18 0x00007fb3c40adc55 in g_main_loop_run () from /lib/libglib-2.0.so.0
#19 0x00007fb3c1109bb7 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0
#20 0x00000000409799d2 in ?? ()
#21 0x00000000018cc150 in ?? ()
#22 0x0000000000000000 in ?? ()

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
-------------------------

maybe you can help me out.
oh.. and also is there a way to delete only the first children?

thanks again for all the help you are providing me :)



More information about the Gtk-sharp-list mailing list