Date: Sun, 21 Sep 2003 18:03:18 +0200 From: Francois Pottier To: lablgtk at kaba.or.jp Subject: Re: Misc questions Message-ID: <20030921180318.A7068 at pauillac.inria.fr> Reply-To: Francois.Pottier at inria.fr References: <20030921111027.A12292 at pauillac.inria.fr> <87llsifhlq.dlv at wanadoo.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit In-Reply-To: <87llsifhlq.dlv at wanadoo.fr>; from vanicat at labri.u-bordeaux.fr on Sun, Sep 21, 2003 at 02:31:29PM +0200 Hi Rémi, On Sun, Sep 21, 2003 at 02:31:29PM +0200, Remi Vanicat wrote: > > Mmm ? I've wrote a program that can only work if tree_iter do not > become obsolete when rows are added or deleted. It work. What is your > problem more precisely ? Well, here is my problem. I have some code involving a [model] of class [GTree.list_store] and a [view] of class [GTree.view]. At some point, I want to iterate over all currently selected elements in the view. I originally wrote the following code: let fold_selected_elements accu f = List.fold_left (fun accu path -> let row = model#get_iter path in let element = ftu8 (model#get ~row ~column:element_column) in f accu row element ) accu (view#selection#get_selected_rows) (The call to model#get merely retrieves a string, so the type of [f] is 'a -> tree_iter -> string -> 'a.) The problem arises when the the function [f] calls [model#remove row]. In that case, the paths obtained in my initial code to [get_selected_rows] become invalid and subsequent iterations become meaningless. Of course, as I write this answer to your question, I realize that this means that [tree_path] objects are brittle, but [tree_iter] objects perhaps aren't. So the right thing to do may be to write instead: let fold_selected_elements accu f = List.fold_left (fun accu row -> let element = ftu8 (model#get ~row ~column:element_column) in f accu row element ) accu (List.map model#get_iter (view#selection#get_selected_rows)) in I have tried this, and indeed it appears to work. Sorry for the trouble! Still, I wonder whether there is sometimes a need for the functions in module [GtkTree.RowReference] and if so, how to use them? More generally, how do I distinguish low-level functions that I'm not supposed to use from high-level functions? The general rule seems to be that Gtk* modules are not for general use, while G* modules are, but is that rule always valid? Thanks, -- François Pottier Francois.Pottier@inria.fr http://pauillac.inria.fr/~fpottier/