Re: Remove Multiple Rows from Gtk2::ListStore

Torsten Schoenfeld <kaffeetisch gmx de> writes:

converting the paths to Gtk2::TreeRowReferences

I think GtkTreeSelection may have roughly that internally.  Another
possibility would be that ListStore is "iters persist", so convert paths
to iters and the iters stay good.

In my Gtk2::Ex::TreeViewBits I made the few lines below, deleting the
first of get_selected_rows() repeatedly.  It probably ends up O(N^2),
but should be safe against anyone mucking about with the selection or
the rows from within the various delete signals.

I can't remember why I return $removed_path.  Must have seemed like a
good idea for something -- but then I didn't document it. :-)  Maybe
it's to say if anything was in fact removed ...

sub remove_selected_rows {
  my ($treeview) = @_;
  my $model = $treeview->get_model;
  my $selection = $treeview->get_selection;
  my $removed_path;
  while (my ($path) = $selection->get_selected_rows) {
    my $iter = $model->get_iter ($path)
      || do {
        carp 'Oops, selected row path "',$path->to_string,'" has no iter';
    $model->remove ($iter);
    $removed_path = $path;
  return $removed_path;

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