[easytag/wip/application-window: 61/73] Refactor popup menu handling



commit 60f45604bb99572ba7cc24d9154ac78282318e3a
Author: David King <amigadave amigadave com>
Date:   Mon Jul 14 17:16:41 2014 +0100

    Refactor popup menu handling
    
    Use gdk_event_triggers_context_menu() in button-press-event handlers.
    Use GDK_BUTTON_PRIMARY instead of 1 where appropriate.

 src/application_window.c |   70 ++++++++++++++++++++-------------------------
 src/browser.c            |   12 +++++--
 src/cddb_dialog.c        |    6 ++--
 src/load_files_dialog.c  |    8 +++--
 src/log.c                |    6 ++-
 src/picture.c            |    5 ++-
 6 files changed, 54 insertions(+), 53 deletions(-)
---
diff --git a/src/application_window.c b/src/application_window.c
index acc38ee..83105e9 100644
--- a/src/application_window.c
+++ b/src/application_window.c
@@ -218,38 +218,18 @@ Convert_Remove_All_Text (GtkWidget *entry)
     gtk_entry_set_text (GTK_ENTRY (entry), "");
 }
 
-/* Show the popup menu when the third mouse button is pressed. */
-static gboolean
-Entry_Popup_Menu_Handler (GtkMenu *menu,
-                          GdkEventButton *event,
-                          gpointer user_data)
-{
-    if (event && (event->type == GDK_BUTTON_PRESS) && (event->button == 3))
-    {
-        gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event->button,
-                        event->time);
-        return TRUE;
-    }
-
-    return FALSE;
-}
-
-/*
+/* TODO: Support populate-all and do not assume the widget is a GtkMenu.
  * Popup menu attached to all entries of tag + filename + rename combobox.
  * Displayed when pressing the right mouse button and contains functions to process ths strings.
  */
 static void
-Attach_Popup_Menu_To_Tag_Entries (GtkEntry *entry)
+on_entry_populate_popup (GtkEntry *entry,
+                         GtkWidget *menu,
+                         gpointer user_data)
 {
-    GtkWidget *menu;
     GtkWidget *image;
     GtkWidget *menu_item;
 
-    menu = gtk_menu_new ();
-    g_signal_connect_swapped (entry, "button-press-event",
-                              G_CALLBACK (Entry_Popup_Menu_Handler),
-                              G_OBJECT (menu));
-
     /* Menu items */
     menu_item = gtk_image_menu_item_new_with_label (_("Tag selected files with this field"));
     image = gtk_image_new_from_icon_name ("go-jump", GTK_ICON_SIZE_MENU);
@@ -997,7 +977,8 @@ create_file_area (void)
     gtk_editable_set_editable (GTK_EDITABLE (FileEntry), TRUE);
     gtk_box_pack_start (GTK_BOX (hbox), FileEntry, TRUE, TRUE, 2);
 
-    Attach_Popup_Menu_To_Tag_Entries (GTK_ENTRY (FileEntry));
+    g_signal_connect (FileEntry, "populate-popup",
+                      G_CALLBACK (on_entry_populate_popup), NULL);
 
     /*
      *  File Infos
@@ -1138,7 +1119,8 @@ create_tag_area (EtApplicationWindow *self)
                                      GTK_ENTRY_ICON_SECONDARY,
                                      _("Tag selected files with this title"));
 
-    Attach_Popup_Menu_To_Tag_Entries (GTK_ENTRY (TitleEntry));
+    g_signal_connect (TitleEntry, "populate-popup",
+                      G_CALLBACK (on_entry_populate_popup), NULL);
 
     /* Artist */
     priv->artist_label = gtk_label_new (_("Artist:"));
@@ -1157,7 +1139,8 @@ create_tag_area (EtApplicationWindow *self)
                                      GTK_ENTRY_ICON_SECONDARY,
                                      _("Tag selected files with this artist"));
 
-    Attach_Popup_Menu_To_Tag_Entries (GTK_ENTRY (ArtistEntry));
+    g_signal_connect (ArtistEntry, "populate-popup",
+                      G_CALLBACK (on_entry_populate_popup), NULL);
 
     /* Album Artist */
     priv->album_artist_label = gtk_label_new (_("Album artist:"));
@@ -1176,7 +1159,8 @@ create_tag_area (EtApplicationWindow *self)
                                      GTK_ENTRY_ICON_SECONDARY,
                                      _("Tag selected files with this album artist"));
 
-    Attach_Popup_Menu_To_Tag_Entries (GTK_ENTRY (AlbumArtistEntry));
+    g_signal_connect (AlbumArtistEntry, "populate-popup",
+                      G_CALLBACK (on_entry_populate_popup), NULL);
 
     /* Album */
     priv->album_label = gtk_label_new (_("Album:"));
@@ -1195,7 +1179,8 @@ create_tag_area (EtApplicationWindow *self)
                                      GTK_ENTRY_ICON_SECONDARY,
                                      _("Tag selected files with this album name"));
 
-    Attach_Popup_Menu_To_Tag_Entries (GTK_ENTRY (AlbumEntry));
+    g_signal_connect (AlbumEntry, "populate-popup",
+                      G_CALLBACK (on_entry_populate_popup), NULL);
 
     /* Disc Number */
     priv->disc_number_label = gtk_label_new (_("CD:"));
@@ -1217,7 +1202,8 @@ create_tag_area (EtApplicationWindow *self)
                                      GTK_ENTRY_ICON_SECONDARY,
                                      _("Tag selected files with this disc number"));
 
-    Attach_Popup_Menu_To_Tag_Entries (GTK_ENTRY (DiscNumberEntry));
+    g_signal_connect (DiscNumberEntry, "populate-popup",
+                      G_CALLBACK (on_entry_populate_popup), NULL);
 
     /* Year */
     priv->year_label = gtk_label_new (_("Year:"));
@@ -1367,7 +1353,9 @@ create_tag_area (EtApplicationWindow *self)
                                      GTK_ENTRY_ICON_SECONDARY,
                                      _("Tag selected files with this genre"));
 
-    Attach_Popup_Menu_To_Tag_Entries (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (GenreCombo))));
+    g_signal_connect (gtk_bin_get_child (GTK_BIN (GenreCombo)),
+                      "populate-popup", G_CALLBACK (on_entry_populate_popup),
+                      NULL);
 
     /* Comment */
     priv->comment_label = gtk_label_new (_("Comment:"));
@@ -1386,7 +1374,8 @@ create_tag_area (EtApplicationWindow *self)
                                      GTK_ENTRY_ICON_SECONDARY,
                                      _("Tag selected files with this comment"));
 
-    Attach_Popup_Menu_To_Tag_Entries (GTK_ENTRY (CommentEntry));
+    g_signal_connect (CommentEntry, "populate-popup",
+                      G_CALLBACK (on_entry_populate_popup), NULL);
 
     /* Composer (name of the composers) */
     priv->composer_label = gtk_label_new (_("Composer:"));
@@ -1405,7 +1394,8 @@ create_tag_area (EtApplicationWindow *self)
                                      GTK_ENTRY_ICON_SECONDARY,
                                      _("Tag selected files with this composer"));
 
-    Attach_Popup_Menu_To_Tag_Entries (GTK_ENTRY (ComposerEntry));
+    g_signal_connect (ComposerEntry, "populate-popup",
+                      G_CALLBACK (on_entry_populate_popup), NULL);
 
     /* Translators: Original Artist / Performer. Please try to keep this string
      * as short as possible, as it must fit into a narrow column. */
@@ -1425,7 +1415,8 @@ create_tag_area (EtApplicationWindow *self)
                                      GTK_ENTRY_ICON_SECONDARY,
                                      _("Tag selected files with this original artist"));
 
-    Attach_Popup_Menu_To_Tag_Entries (GTK_ENTRY (OrigArtistEntry));
+    g_signal_connect (OrigArtistEntry, "populate-popup",
+                      G_CALLBACK (on_entry_populate_popup), NULL);
 
 
     /* Copyright */
@@ -1445,7 +1436,8 @@ create_tag_area (EtApplicationWindow *self)
                                      GTK_ENTRY_ICON_SECONDARY,
                                      _("Tag selected files with this copyright"));
 
-    Attach_Popup_Menu_To_Tag_Entries (GTK_ENTRY (CopyrightEntry));
+    g_signal_connect (CopyrightEntry, "populate-popup",
+                      G_CALLBACK (on_entry_populate_popup), NULL);
 
 
     /* URL */
@@ -1465,7 +1457,8 @@ create_tag_area (EtApplicationWindow *self)
                                      GTK_ENTRY_ICON_SECONDARY,
                                      _("Tag selected files with this URL"));
 
-    Attach_Popup_Menu_To_Tag_Entries(GTK_ENTRY(URLEntry));
+    g_signal_connect (URLEntry, "populate-popup",
+                      G_CALLBACK (on_entry_populate_popup), NULL);
 
 
     /* Encoded by */
@@ -1485,7 +1478,8 @@ create_tag_area (EtApplicationWindow *self)
                                      GTK_ENTRY_ICON_SECONDARY,
                                      _("Tag selected files with this encoder name"));
 
-    Attach_Popup_Menu_To_Tag_Entries (GTK_ENTRY (EncodedByEntry));
+    g_signal_connect (EncodedByEntry, "populate-popup",
+                      G_CALLBACK (on_entry_populate_popup), NULL);
 
     /* Set focus chain. */
     focus_chain = g_list_prepend (focus_chain, TitleEntry);
@@ -1642,8 +1636,6 @@ create_tag_area (EtApplicationWindow *self)
     g_signal_connect (priv->apply_image_toolitem, "clicked",
                       G_CALLBACK (Mini_Button_Clicked), NULL);
 
-    /*Attach_Popup_Menu_To_Tag_Entries (GTK_ENTRY (PictureEntryView));*/
-
     gtk_widget_show_all (TagFrame);
     return TagFrame;
 }
diff --git a/src/browser.c b/src/browser.c
index c807d81..33a8e4d 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -730,7 +730,8 @@ Browser_List_Button_Press (EtBrowser *self,
 {
     g_return_val_if_fail (event != NULL, FALSE);
 
-    if (event->type==GDK_2BUTTON_PRESS && event->button==1)
+    if (event->type == GDK_2BUTTON_PRESS
+        && event->button == GDK_BUTTON_PRIMARY)
     {
         /* Double left mouse click */
         // Select files of the same directory (useful when browsing sub-directories)
@@ -766,7 +767,9 @@ Browser_List_Button_Press (EtBrowser *self,
         g_free(path_ref);
         if (currentPath)
             gtk_tree_path_free(currentPath);
-    }else if (event->type==GDK_3BUTTON_PRESS && event->button==1)
+    }
+    else if (event->type == GDK_3BUTTON_PRESS
+             && event->button == GDK_BUTTON_PRIMARY)
     {
         /* Triple left mouse click, select all files of the list. */
         g_action_group_activate_action (G_ACTION_GROUP (MainWindow),
@@ -2795,10 +2798,11 @@ et_browser_set_sensitive (EtBrowser *self, gboolean sensitive)
  * Browser_Popup_Menu_Handler : displays the corresponding menu
  */
 static gboolean
-Browser_Popup_Menu_Handler (GtkWidget *widget, GdkEventButton *event,
+Browser_Popup_Menu_Handler (GtkWidget *widget,
+                            GdkEventButton *event,
                             GtkMenu *menu)
 {
-    if (event && (event->type == GDK_BUTTON_PRESS) && (event->button == 3))
+    if (gdk_event_triggers_context_menu ((GdkEvent *)event))
     {
         if (GTK_IS_TREE_VIEW (widget))
         {
diff --git a/src/cddb_dialog.c b/src/cddb_dialog.c
index 103b91d..d77f6fb 100644
--- a/src/cddb_dialog.c
+++ b/src/cddb_dialog.c
@@ -2825,13 +2825,13 @@ track_list_select_all (EtCDDBDialog *self)
 static gboolean
 on_track_list_button_press_event (EtCDDBDialog *self, GdkEventButton *event)
 {
-    g_return_val_if_fail (event != NULL, FALSE);
-
-    if (event->type == GDK_2BUTTON_PRESS && event->button == 1)
+    if (event->type == GDK_2BUTTON_PRESS
+        && event->button == GDK_BUTTON_PRIMARY)
     {
         /* Double left mouse click */
         track_list_select_all (self);
     }
+
     return FALSE;
 }
 
diff --git a/src/load_files_dialog.c b/src/load_files_dialog.c
index 85d80b5..fd96ca5 100644
--- a/src/load_files_dialog.c
+++ b/src/load_files_dialog.c
@@ -619,12 +619,14 @@ Load_Filename_Select_Row_In_Other_List (GtkWidget* treeview_target, gpointer ori
  * Create and attach a popup menu on the two clist of the LoadFileWindow
  */
 static gboolean
-Load_Filename_Popup_Menu_Handler (GtkWidget *treeview, GdkEventButton *event,
+Load_Filename_Popup_Menu_Handler (GtkWidget *treeview,
+                                  GdkEventButton *event,
                                   GtkMenu *menu)
 {
-    if (event && (event->type==GDK_BUTTON_PRESS) && (event->button==3))
+    if (gdk_event_triggers_context_menu ((GdkEvent *)event))
     {
-        gtk_menu_popup(menu,NULL,NULL,NULL,NULL,event->button,event->time);
+        gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event->button,
+                        event->time);
         return TRUE;
     }
     return FALSE;
diff --git a/src/log.c b/src/log.c
index 1293704..0db4cc0 100644
--- a/src/log.c
+++ b/src/log.c
@@ -196,11 +196,13 @@ static gboolean
 Log_Popup_Menu_Handler (GtkWidget *treeview, GdkEventButton *event,
                         GtkMenu *menu)
 {
-    if (event && (event->type==GDK_BUTTON_PRESS) && (event->button == 3))
+    if (gdk_event_triggers_context_menu ((GdkEvent *)event))
     {
-        gtk_menu_popup(menu,NULL,NULL,NULL,NULL,event->button,event->time);
+        gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event->button,
+                        event->time);
         return TRUE;
     }
+
     return FALSE;
 }
 
diff --git a/src/picture.c b/src/picture.c
index 1abfbf7..e8e6121 100644
--- a/src/picture.c
+++ b/src/picture.c
@@ -1285,7 +1285,7 @@ et_picture_save_file_data (const Picture *pic, GFile *file, GError **error)
  */
 gboolean Picture_Entry_View_Button_Pressed (GtkTreeView *treeview, GdkEventButton *event, gpointer data)
 {
-    if (event->type == GDK_BUTTON_PRESS && event->button == 1)
+    if (event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_PRIMARY)
     {
         if (event->window == gtk_tree_view_get_bin_window (treeview))
         {
@@ -1297,7 +1297,8 @@ gboolean Picture_Entry_View_Button_Pressed (GtkTreeView *treeview, GdkEventButto
         }
     }
 
-    if (event->type==GDK_2BUTTON_PRESS && event->button==1)
+    if (event->type == GDK_2BUTTON_PRESS
+        && event->button == GDK_BUTTON_PRIMARY)
     {
         GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(PictureEntryView));
 


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