[cheese] Refactor thumbnail context menu event handling



commit 5d0e924a39ee72b7cc10eb64b58f57a1e8804f2b
Author: David King <amigadave amigadave com>
Date:   Thu Jul 11 23:27:07 2013 +0100

    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.

 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 fa77a3c..7c18df8 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 ();


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