Re: Directory Tree (GtkTreeModel)



Matthias Reis wrote:
Hi!

I'm trying to implement a directory tree with GtkTreeModel.I already
have a GtkTreeModel containing the / directory and its first-level
subdirectories. If a child row is collapsed, I want to add its children
(its subdirectories).

I did this recently.
Some stuff is hardcoded, but you should be able to see the idea. I build the path forward, so I can use g_stpcpy for speed while appending to the string... not that it really matters.


    indices = gtk_tree_path_get_indices(path);
    depth = gtk_tree_path_get_depth(path);

    curdirpath = g_stpcpy(dirpath, "/mp3");
    *curdirpath++ = '/';

    for (i = 0; i < depth; i++) {
        parent = iter;
gtk_tree_model_iter_nth_child(model, &iter, i > 0 ? &parent : NULL, indices[i]);

        gtk_tree_model_get(model, &iter,
                STORE_NAME, &dir,
                -1);
        curdirpath = g_stpcpy(curdirpath, dir);
        *curdirpath++ = '/';
        g_free(dir);
    }
    *curdirpath = 0;




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