Re: [gtk-list] Getting the "path" in a gtk tree



On Fri, Aug 06, 1999 at 09:16:12AM +0200, Jean-Paul ROUMIAN wrote:

> Now, I want to get the full path of an selected item  (the names of all the tree names from the 
> root).

This is unfortunately non-trivial. I walk up the tree from the
selected item:

void walk_up_tree( GtkWidget* item )
{
    gchar* current_path = context.current_path;
    gchar* text;
    GtkWidget* widget = item;
    GtkTree* next_tree = GTK_TREE( widget->parent );

    if( next_tree->level > 1 ) {
        walk_up_tree( next_tree->tree_owner );
    }

    GtkLabel* label = GTK_LABEL( GTK_BIN( widget )->child );
    gtk_label_get( label, &text );
    strncat( current_path, text, PAKFileEntry::MAX_FILENAMESIZE - 1 );

    // No "/" on front of path.
    if( next_tree->level >= 1 ) {
        strcat( current_path, "/" );
    }

}

Replace context.current_path with your initially null-terminated
string, my magic constant with your magic constant, and away you
go. You'll notice I'm also putting the "/" character in to separate
the tree, since my app was representing a directory structure.

m.

-- 
"How wonderful! How mysterious!				Programmer
 I carry wood! I draw water!"	       Loki Entertainment Software
 - Anonymous Tao poet



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]