[gedit] Connect to ::selection-done to destroy the GeditNotebookPopupMenu's



commit 623f95466671f7b0a8e8aec746809b3ae52842b3
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Jan 13 16:45:44 2016 +0100

    Connect to ::selection-done to destroy the GeditNotebookPopupMenu's
    
    It's better than calling g_object_unref() directly after
    gtk_menu_popup(), ::selection-done has more guarantees to work.

 gedit/gedit-documents-panel.c |    7 ++++---
 gedit/gedit-window.c          |    7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)
---
diff --git a/gedit/gedit-documents-panel.c b/gedit/gedit-documents-panel.c
index 4f15d4f..5f394ba 100644
--- a/gedit/gedit-documents-panel.c
+++ b/gedit/gedit-documents-panel.c
@@ -1536,7 +1536,10 @@ row_on_button_pressed (GtkWidget      *row_event_box,
                        GeditTab *tab = GEDIT_TAB (document_row->ref);
                        GtkWidget *menu = gedit_notebook_popup_menu_new (window, tab);
 
-                       g_object_ref_sink (menu);
+                       g_signal_connect (menu,
+                                         "selection-done",
+                                         G_CALLBACK (gtk_widget_destroy),
+                                         NULL);
 
                        gtk_menu_popup_for_device (GTK_MENU (menu),
                                                   gdk_event_get_device ((GdkEvent *)event),
@@ -1545,8 +1548,6 @@ row_on_button_pressed (GtkWidget      *row_event_box,
                                                   event->button,
                                                   event->time);
 
-                       g_object_unref (menu);
-
                        return TRUE;
                }
        }
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index 7ef541e..8ca0ea4 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -2219,14 +2219,15 @@ on_show_popup_menu (GeditMultiNotebook *multi,
 
        menu = gedit_notebook_popup_menu_new (window, tab);
 
-       g_object_ref_sink (menu);
+       g_signal_connect (menu,
+                         "selection-done",
+                         G_CALLBACK (gtk_widget_destroy),
+                         NULL);
 
        gtk_widget_show (menu);
        gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
                        NULL, NULL,
                        event->button, event->time);
-
-       g_object_unref (menu);
 }
 
 static void


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