[easytag/wip/application-window: 32/39] Use GtkWidget popup-menu signal in EtLogArea



commit c7f2003f7f5f89ec0878616f8e5b32f52ce7f0e4
Author: David King <amigadave amigadave com>
Date:   Thu Jul 31 22:14:57 2014 +0200

    Use GtkWidget popup-menu signal in EtLogArea

 src/log.c |  121 ++++++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 80 insertions(+), 41 deletions(-)
---
diff --git a/src/log.c b/src/log.c
index 34eb24c..0e4fc4f 100644
--- a/src/log.c
+++ b/src/log.c
@@ -75,8 +75,6 @@ typedef struct
 /**************
  * Prototypes *
  **************/
-static gboolean Log_Popup_Menu_Handler (GtkWidget *treeview,
-                                        GdkEventButton *event, GtkMenu *menu);
 static void Log_List_Set_Row_Visible (EtLogArea *self, GtkTreeIter *rowIter);
 static void Log_Print_Tmp_List (EtLogArea *self);
 static gchar *Log_Format_Date (void);
@@ -88,6 +86,83 @@ static gchar *Log_Format_Date (void);
  *************/
 
 static void
+do_popup_menu (EtLogArea *self,
+               GdkEventButton *event)
+{
+    EtLogAreaPrivate *priv;
+    GtkBuilder *builder;
+    GError *error = NULL;
+    GMenuModel *menu_model;
+    GtkWidget *menu;
+    gint button;
+    gint event_time;
+
+    priv = et_log_area_get_instance_private (self);
+
+    /* Create Popup Menu on browser album list. */
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_resource (builder, "/org/gnome/EasyTAG/menus.ui",
+                                   &error);
+
+    if (error != NULL)
+    {
+        g_error ("Unable to get popup menu from resource: %s",
+                 error->message);
+    }
+
+    menu_model = G_MENU_MODEL (gtk_builder_get_object (builder, "log-menu"));
+    menu = gtk_menu_new_from_model (menu_model);
+    gtk_menu_attach_to_widget (GTK_MENU (menu), priv->log_view, NULL);
+    g_signal_connect (menu, "deactivate", G_CALLBACK (gtk_widget_destroy),
+                      NULL);
+
+    g_object_unref (builder);
+
+    if (event)
+    {
+        button = event->button;
+        event_time = event->time;
+    }
+    else
+    {
+        button = 0;
+        event_time = gtk_get_current_event_time ();
+    }
+
+    /* TODO: Add popup positioning function. */
+    gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, button,
+                    event_time);
+}
+
+static gboolean
+on_popup_menu (GtkWidget *treeview,
+               EtLogArea *self)
+{
+    do_popup_menu (self, NULL);
+
+    return GDK_EVENT_STOP;
+}
+
+/*
+ * Log_Popup_Menu_Handler : displays the corresponding menu
+ */
+static gboolean
+on_button_press_event (GtkWidget *treeview,
+                       GdkEventButton *event,
+                       EtLogArea *self)
+{
+    if (gdk_event_triggers_context_menu ((GdkEvent *)event))
+    {
+        do_popup_menu (self, event);
+
+        return GDK_EVENT_STOP;
+    }
+
+    return GDK_EVENT_PROPAGATE;
+}
+
+
+static void
 et_log_area_class_init (EtLogAreaClass *klass)
 {
     g_type_class_add_private (klass, sizeof (EtLogAreaPrivate));
@@ -100,10 +175,6 @@ et_log_area_init (EtLogArea *self)
     GtkWidget *ScrollWindowLogList;
     GtkCellRenderer *renderer;
     GtkTreeViewColumn *column;
-    GtkBuilder *builder;
-    GError *error = NULL;
-    GMenuModel *menu_model;
-    GtkWidget *menu;
 
     priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ET_TYPE_LOG_AREA,
                                                      EtLogAreaPrivate);
@@ -153,24 +224,10 @@ et_log_area_init (EtLogArea *self)
                                         "text",           LOG_TEXT,
                                         NULL);
 
-    /* Create Popup Menu on browser album list. */
-    builder = gtk_builder_new ();
-    gtk_builder_add_from_resource (builder, "/org/gnome/EasyTAG/menus.ui",
-                                   &error);
-
-    if (error != NULL)
-    {
-        g_error ("Unable to get popup menu from resource: %s",
-                 error->message);
-    }
-
-    menu_model = G_MENU_MODEL (gtk_builder_get_object (builder, "log-menu"));
-    menu = gtk_menu_new_from_model (menu_model);
-    gtk_menu_attach_to_widget (GTK_MENU (menu), priv->log_view, NULL);
+    g_signal_connect (priv->log_view, "popup-menu", G_CALLBACK (on_popup_menu),
+                      self);
     g_signal_connect (priv->log_view, "button-press-event",
-                      G_CALLBACK (Log_Popup_Menu_Handler), menu);
-
-    g_object_unref (builder);
+                      G_CALLBACK (on_button_press_event), self);
 
     /* Load pending messages in the Log list. */
     Log_Print_Tmp_List (self);
@@ -189,24 +246,6 @@ et_log_area_new ()
 }
 
 /*
- * Log_Popup_Menu_Handler : displays the corresponding menu
- */
-static gboolean
-Log_Popup_Menu_Handler (GtkWidget *treeview, GdkEventButton *event,
-                        GtkMenu *menu)
-{
-    if (gdk_event_triggers_context_menu ((GdkEvent *)event))
-    {
-        gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event->button,
-                        event->time);
-        return GDK_EVENT_STOP;
-    }
-
-    return GDK_EVENT_PROPAGATE;
-}
-
-
-/*
  * Set a row visible in the log list (by scrolling the list)
  */
 static void


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