diff options
author | David King <amigadave@amigadave.com> | 2013-07-11 23:27:07 +0100 |
---|---|---|
committer | David King <amigadave@amigadave.com> | 2013-07-11 23:27:07 +0100 |
commit | 5d0e924a39ee72b7cc10eb64b58f57a1e8804f2b (patch) | |
tree | bcca7d19444b68882509f0f7748063c96820db96 /src | |
parent | aadb907aadab1470f4a82dcac2a1ec36ebae1d74 (diff) | |
download | cheese-5d0e924a39ee72b7cc10eb64b58f57a1e8804f2b.tar.gz |
Refactor thumbnail context menu event handling
Use Gdk.Event.triggers_context_menu() rather than checking if the
secondary button was pressed. Return true if the event was handled, to
stop further event propagation.
Diffstat (limited to 'src')
-rw-r--r-- | src/cheese-window.vala | 75 |
1 files changed, 42 insertions, 33 deletions
diff --git a/src/cheese-window.vala b/src/cheese-window.vala index fa77a3cf..7c18df83 100644 --- a/src/cheese-window.vala +++ b/src/cheese-window.vala @@ -117,42 +117,51 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow GLib.Object (application: application); } - /** - * Popup a context menu when right-clicking on a thumbnail. - * - * @param iconview the thumbnail view that emitted the signal - * @param event the event - * @return false, to allow further processing of the event - */ - public bool on_thumbnail_mouse_button_press (Gtk.Widget iconview, - Gdk.EventButton event) - { - Gtk.TreePath path; - path = thumb_view.get_path_at_pos ((int) event.x, (int) event.y); + /** + * Popup a context menu when right-clicking on a thumbnail. + * + * @param iconview the thumbnail view that emitted the signal + * @param event the event + * @return false to allow further processing of the event, true to indicate + * that the event was handled completely + */ + public bool on_thumbnail_button_press_event (Gtk.Widget iconview, + Gdk.EventButton event) + { + Gtk.TreePath path; + path = thumb_view.get_path_at_pos ((int) event.x, (int) event.y); - if (path == null) - return false; + if (path == null) + { + return false; + } - if (!thumb_view.path_is_selected (path)) - { - thumb_view.unselect_all (); - thumb_view.select_path (path); - thumb_view.set_cursor (path, null, false); - } + if (!thumb_view.path_is_selected (path)) + { + thumb_view.unselect_all (); + thumb_view.select_path (path); + thumb_view.set_cursor (path, null, false); + } - if (event.type == Gdk.EventType.BUTTON_PRESS) - { - if (event.button == 3) - thumbnail_popup.popup (null, thumb_view, null, event.button, event.time); - } - else - if (event.type == Gdk.EventType.2BUTTON_PRESS) - { - on_file_open (); - } + if (event.type == Gdk.EventType.BUTTON_PRESS) + { + Gdk.Event* button_press = (Gdk.Event*)(&event); - return false; - } + if (button_press->triggers_context_menu ()) + { + thumbnail_popup.popup (null, thumb_view, null, event.button, + event.time); + } + else if (event.type == Gdk.EventType.2BUTTON_PRESS) + { + on_file_open (); + } + + return true; + } + + return false; + } /** * Open an image associated with a thumbnail in the default application. @@ -1244,7 +1253,7 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow Gtk.StyleContext.add_provider_for_screen (screen, css, STYLE_PROVIDER_PRIORITY_USER); - thumb_view.button_press_event.connect (on_thumbnail_mouse_button_press); + thumb_view.button_press_event.connect (on_thumbnail_button_press_event); this.add (main_vbox); main_vbox.show_all (); |