[empathy] add empathy_context_menu_new()
- From: Guillaume Desmottes <gdesmott src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [empathy] add empathy_context_menu_new()
- Date: Wed, 16 Feb 2011 14:49:37 +0000 (UTC)
commit 33fec6ea1836eaa5ba39bd233a5b81e4f6998a18
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date: Wed Feb 16 15:09:09 2011 +0100
add empathy_context_menu_new()
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 | 34 ++++++++++++++++++++++++++++++++++
libempathy-gtk/empathy-ui-utils.h | 2 ++
2 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c
index b53be03..1016c72 100644
--- a/libempathy-gtk/empathy-ui-utils.c
+++ b/libempathy-gtk/empathy-ui-utils.c
@@ -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;
+}
diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h
index 0ff637a..6dd64ac 100644
--- a/libempathy-gtk/empathy-ui-utils.h
+++ b/libempathy-gtk/empathy-ui-utils.h
@@ -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__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]