]> git.0d.be Git - empathy.git/commitdiff
add empathy_context_menu_new()
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Wed, 16 Feb 2011 14:09:09 +0000 (15:09 +0100)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Wed, 16 Feb 2011 14:09:09 +0000 (15:09 +0100)
That's basically the same trick as we did in
individual_view_popup_menu_idle_cb(). We can't unfortunatelly not use this
function there as the popup may be reused in some cases.

libempathy-gtk/empathy-ui-utils.c
libempathy-gtk/empathy-ui-utils.h

index b53be03ec175df0977136c4331b17e902c7a20f1..1016c729ccc5ca47ff9b2180ff31f3060374c02f 100644 (file)
@@ -1907,3 +1907,37 @@ empathy_make_color_whiter (GdkRGBA *color)
        color->green = (color->green + white.green) / 2;
        color->blue = (color->blue + white.blue) / 2;
 }
+
+static void
+menu_deactivate_cb (GtkMenu *menu,
+       gpointer user_data)
+{
+       gtk_menu_detach (menu);
+
+       /* FIXME: we shouldn't have to disconnect the signal (bgo #641327) */
+       g_signal_handlers_disconnect_by_func (menu,
+                    menu_deactivate_cb, user_data);
+}
+
+/* Convenient function to create a GtkMenu attached to @attach_to and detach
+ * it when the menu is not displayed any more. This is useful when creating a
+ * context menu that we want to get rid as soon as it as been displayed. */
+GtkWidget *
+empathy_context_menu_new (GtkWidget *attach_to)
+{
+       GtkWidget *menu;
+
+       menu = gtk_menu_new ();
+
+       gtk_menu_attach_to_widget (GTK_MENU (menu), attach_to, NULL);
+
+       /* menu is initially unowned but gtk_menu_attach_to_widget() taked its
+        * floating ref. We can either wait that @attach_to releases its ref when
+        * it will be destroyed (when leaving Empathy most of the time) or explicitely
+        * detach the menu when it's not displayed any more.
+        * We go for the latter as we don't want to keep useless menus in memory
+        * during the whole lifetime of Empathy. */
+       g_signal_connect (menu, "deactivate", G_CALLBACK (menu_deactivate_cb), NULL);
+
+       return menu;
+}
index 0ff637a33c4fed0e529299d0e459988d8366ca11..6dd64ac51f4c92d7e3dc10ae77b83806e340ee05 100644 (file)
@@ -148,6 +148,8 @@ void        empathy_receive_file_with_file_chooser      (EmpathyFTHandler *handl
 /* Misc */
 void        empathy_make_color_whiter                   (GdkRGBA *color);
 
+GtkWidget * empathy_context_menu_new                    (GtkWidget *attach_to);
+
 G_END_DECLS
 
 #endif /*  __EMPATHY_UI_UTILS_H__ */