Content-Type: text/plain; charset="us-ascii" From: Stalkern 2 Reply-To: stalkern2 at tin.it To: lablgtk at kaba.or.jp Subject: Rebuilding trees with selected items gives a reselection error Date: Mon, 3 Feb 2003 11:27:44 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200302031127.44932.stalkern2 at tin.it> I've also found a nice posting on a "Gtk-CRITICAL **: file gtkwidget.c: line 3246 (gtk_widget_set_state): assertion `widget != NULL' failed." when regenerating a tree that has something selected. The posting is at http://mail.gnome.org/archives/gtk-list/1999-August/msg00333.html and the clue is to build a function deselecting tree children recursively, and use it before deleting the main tree (this does not require a recursive function, just a call to theMainTree #clear_items ) I add a snippet of code for beginners like me: ============================== let rec unselect_treeChildren (aTree:GTree.tree) = let childrenOfTree = aTree #children in let numberOfTreeChildren = (List.length childrenOfTree) in let rec unselect_firstGenerationOfTree_using_childrenList (aTree:GTree.tree) overallListLenght listPositionNow = ( if ( not(listPositionNow > overallListLenght)) then ( let () = aTree #unselect_item listPositionNow in unselect_firstGenerationOfTree_using_childrenList aTree overallListLenght (listPositionNow + 1) ) else () ) in (* let's start deselecting the first generation*) let () = unselect_firstGenerationOfTree_using_childrenList aTree numberOfTreeChildren 0 in (*let's apply the same to every tree at lower level*) let apply_unselection_to_childrenList aTreeItem = match (aTreeItem #subtree) with None -> () (*this is a leaf: so it's just a child and it has already been unselected by its parent tree*) | Some t -> (*this is a tree!*) unselect_treeChildren t in List.iter (apply_unselection_to_childrenList) childrenOfTree;; let callback_remove_rootTree (aTreeToRefresh:GTree.tree) () = (*In this case the rootTree has exactly ONE child, so we know when to stop*) (* first deselect everything that is selected so to avoid errors if we rebuild this tree and then we select an item of it and then GTK attempts to unselect what was selected before... but what was selected before was destroyed together with the *old* tree, so we'd get a Gtk-CRITICAL error*) let () = unselect_treeChildren aTreeToRefresh in let () = aTreeToRefresh #clear_items ~start:0 ~stop:1 in ();; ============================== Ciao Ernesto