<?php// Treeview & ListStore Test// rewox@woxnet.org//// Platform: Windows 2000// PHP version 5.2// Gtk+ version: 2.6.9// php-gtk verion: php-gtk-2.0.0 alpha Windows binary for PHP 5.2.* //// Problem: The paths are not removed from GtkTreeview (just half of the paths, that are selected)// (Line 45)//// This code below is adapted from the gtk documentation:// http://gtk.php.net/manual/en/gtk.gtktreeselection.method.get_selected_rows.php////////create a model$model = new GtkListStore(Gtk::TYPE_STRING);//create the view to display the model data$view = new GtkTreeView($model);//now, get the selection object of that view$selection = $view->get_selection();//we want to be able to select multiple rows$selection->set_mode(Gtk::SELECTION_MULTIPLE);// Buttons$bt_remove = new GtkButton("Remove Selection");$bt_remove->connect_simple("clicked", "remove_selection", $selection);$bt_display = new GtkButton("Display Selection");$bt_display->connect_simple("clicked", "display_selection", $selection);// Box$hbox = new GtkHBox();function remove_selection($selection){ list($model, $arPaths) = $selection->get_selected_rows(); echo "Going to remove ".count($arPaths)." paths:\n"; # build an array of iter to remove $list = array(); foreach ($arPaths as $path) { $list[] = $model->get_iter($path); } # remove them in second step foreach($list as $iter){ echo ' ' . $model->get_value($iter, 0) . "\n"; // // This seems to operate only on half of the selected paths $model->remove($iter); }}function display_selection($selection){ list($model, $arPaths) = $selection->get_selected_rows(); echo "Selection is now:\n"; foreach ($arPaths as $path) { $iter = $model->get_iter($path); echo ' ' . $model->get_value($iter, 0) . "\n"; }}//add a column to display the data$col = new GtkTreeViewColumn('Number', new GtkCellRendererText(), 'text', 0);$view->append_column($col);//add some data to the model/store$model->append(array('Zero'));$model->append(array('One'));$model->append(array('Two'));$model->append(array('Three'));$model->append(array('Four'));$model->append(array('Five'));//add the view to the window$wnd = new GtkWindow();$wnd->set_title('GtkTreeView selection test');$wnd->connect_simple('destroy', array('Gtk', 'main_quit'));$hbox->pack_start($bt_remove);$hbox->pack_start($bt_display);$hbox->pack_start($view);$wnd->add($hbox);$wnd->show_all();Gtk::main();?>