Re: List view, editable renderers and popupmenus



I had this same problem except for I didn't have editable entries, but this
should still work for you.  In your button-press-event you use
gtk_tree_view_get_path_at_pos() with the coordinates in the event
structure...then popup the contextual menu with the path and after doing your
work you set the selection with gtk_tree_selection_select_path().  And finally
return TRUE.  This basically emulates what gtk would do in the callback.  The
only thing is that I don't know how well this would work with selection modes
other than single.  For those of you who did understand my rambling logic
here's some psuedo-code:

button-press-event:
gtk_tree_view_get_path_at_pos(tree_view, event-x, event->y, &path, ...);
popup_menu_from_path(path, event);
selection = gtk_tree_view_get_selection(tree_view);
gtk_tree_selection_select_path(selection, path);
return TRUE;

-Jeff

On Sun, Feb 23, 2003 at 09:35:31AM -0800, Evan Martin wrote:
On Sun, Feb 23, 2003 at 07:10:47PM +0100, Remco Poelstra wrote:
How can I make sure that the right mouse button only selects the row 
and not turns it in edit mode? And how can I make sure that the row is 
selected before the menu is displayed.

I tried connecting the "button-press" event with 
g_signal_connect_after(), but then the menu isn't displayed at all.
To determine the current row, I connected a handler to the "changed" 
signal of the list selection.

Yes, I encountered that too.  I can't remember if I put it into
bugzilla.

I worked around it by connecting to button-press-event but returning
FALSE from it, so the event passes through to the list and eventually
selects the item in the list, which then updates the menu that has been
popped up.  That means the menu originally pops up with the wrong item
selected, but in practice it happens so fast you can't see it.

That won't really work in your case, though, because what you really
want to do is return TRUE from the event handler so that the button
click doesn't go through.  This would fix the editing problem...

You might be able to do something like this to hack around it:

my_button_press_handler:
  if right mouse button:
    block the edit somehow (block the signal or turn off the setting)
  return FALSE   // let it fall through to the gtk one

my_button_release_handler
  if right mouse button:
    fix up the above change back to normal
  return FALSE

-- 
      Evan Martin
martine cs washington edu
  http://neugierig.org
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



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