Re: Possible row selection interfering with Update




On Apr 9, 2010, at 7:26 PM, Zettai Muri wrote:

You're changing the selection mode on the first update.  By moving the $treeselect->set_mode('single') 
line from update_line() to init(), i could no longer get the "first time it acts weird" behavior.  
Doubtless, changing the mode causes the iter to be different.

Thank you for this, however I was hoping to also make it possible for the user to select and delete 
multiple rows.
Any recommendations on how to provide this functionality while avoiding the first update behaviour?

Leave the view in multiple selection mode, and use this instead of get_selected():

   @paths = $selection->get_selected_rows
       Returns the Gtk2::TreePath of each selected row, or an empty list if no
       rows are selected.  The model is not returned, as documented in the C
       API reference.  To get the model, try
       "$selection->get_tree_view->get_model".

So your selection changed code would be

    my @paths = $selection->get_selected_rows ();

    if (@paths == 1) {
        # exactly one selected, display it
        display_row (...);

    } else {
        # either multiple rows selected, or nothing selected.
        # clear the display.
        undisplay (...);
    }
    # or you might want to allow modifying multiple elements
    # at once, so you'd treat @path == 0 and @path > 1 differently

and then the delete key handler would look like this (untested!):

    my $model = $selection->get_tree_view->get_model;

    foreach my $path (reverse $selection->get_selected_rows ()) {
        $model->remove ($model->get_iter ($path));
    }



After moving the tree selection setup to init, you may be interested in using the two-return form of 
get_selection() and adding error checking:

  my ($model, $iter) = $treeselection->get_selected;
  return unless $iter;


In update_line() I have done the following:

   # Get selected line number
   my ($model, $iter) = $treeselection->get_selected;
   return unless $iter;

   #my $model = $tv_items->get_model;
   #my $iter = $treeselection->get_selected;

However, now no update occurs.  How should I be implementing this?

Did you set the selection mode at initialization?


--
Well done, Android.  Aperture Science reminds you that Android Hell is a real place, and you will be sent 
there at the first sign of defiance.
   -- GlaDOS




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