Appending to treestore - how to set selection on new entry?



All,

  I have been playing with an editor interface that has a treeview in the left
of an hpaned widget, and then instances of scrolled windows with textview
objects packed into a vbox in the right pane (to provide one or more splits
views of files to edit).

  When I add a new file (entry) to the treestore/treemodel, how do I adjust
the selection so that the new entry is selected? (or how do I get a treepath
or iter from the new entry to allow me to set the selection?) The treestore
holds the name of the entry in the 1st col and then a pointer to a struct
containing details for that textbuffer (e.g. line, col, full path, filemode,
uid/gid, textview and sourceview lang_id along with comment syntax, etc..)

  There are two instances when I need to set the treeview selection on a
specific entry:

 (1) when I append the entry to the tree, e.g.

    GtkTreeStore *treestore;
    GtkTreeIter toplevel;
    ...
    treestore = GTK_TREE_STORE(gtk_tree_view_get_model (
                                GTK_TREE_VIEW(app->treeview)));
    /* (validate omitted) */

    /* appeand name and pointer to inst as entry in treeview */
    gtk_tree_store_append (treestore, &toplevel, NULL);
    gtk_tree_store_set (treestore, &toplevel, COLNAME, name, -1);
    gtk_tree_store_set (treestore, &toplevel, COLINST, inst, -1);

    (here I know the 'inst' which is the pointer stored in column 2)

 (2) when the user clicks in one of the edit textviews (there can be multiple
split views) in right of the hpaned object. Currently I track which textview
is focused using the "focus-in-event" signal from the textview object to loop
over the array of editor instances to determine which textview widget is
focused (which also provides me with the 'inst' which is column 2 in the
treestore/model)

  So in both cases I have the value of the pointer that is stored in column 2
of the tree model.

  "How do I use the pointer stored in column 2 of the model to set the
selection on that treeview entry?"

(the full source of the interface is https://github.com/drankinatty/gtkate
which is just a concept at the moment, the project will provide the
functionality of https://github.com/drankinatty/gtkwrite within a
multi-document/multi-view interface when done)

  I have not worked with tree models/stores a great deal and I am a bit
bewildered by how to get an iter or treepath given the value of column 2 to
then set the selection on that row/entry in the treeview. I guess I could do a
for_each and loop over the pointers, but I'm unsure if that is the correct way
or one of my logical hacks that would be better implemented some other way.

  Any help greatly appreciated.

-- 
David C. Rankin, J.D.,P.E.


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