[empathy] Instead of destroying the submenu when it's not needed only create it if there



commit d0fcb58a5ffb5e4025dcac522e3dbc94930c4124
Author: Lars-Peter Clausen <lars metafoo de>
Date:   Mon Apr 20 21:04:59 2009 +0200

    Instead of destroying the submenu when it's not needed only create it if there
    is a submenu item.
---
 libempathy-gtk/empathy-contact-menu.c |   18 +++++-------------
 1 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/libempathy-gtk/empathy-contact-menu.c b/libempathy-gtk/empathy-contact-menu.c
index 7e5a86c..2b12128 100644
--- a/libempathy-gtk/empathy-contact-menu.c
+++ b/libempathy-gtk/empathy-contact-menu.c
@@ -360,9 +360,7 @@ empathy_contact_invite_menu_item_new (EmpathyContact *contact)
 	GtkWidget *room_item;
 	EmpathyChatroomManager *mgr;
 	GList *rooms, *l;
-	GtkWidget *submenu;
-	GtkMenuShell *submenu_shell;
-	gboolean have_rooms = FALSE;
+	GtkWidget *submenu = NULL;
 
 	g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
 
@@ -375,29 +373,23 @@ empathy_contact_invite_menu_item_new (EmpathyContact *contact)
 	rooms = empathy_chatroom_manager_get_chatrooms (mgr,
 		empathy_contact_get_account (contact));
 
-	/* create rooms sub menu */
-	submenu = gtk_menu_new ();
-	submenu_shell = GTK_MENU_SHELL (submenu);
-
 	for (l = rooms; l != NULL; l = g_list_next (l)) {
 		EmpathyChatroom *chatroom = l->data;
 
 		if (empathy_chatroom_get_tp_chat (chatroom) != NULL) {
-			have_rooms = TRUE;
+			if (G_UNLIKELY (submenu == NULL))
+				submenu = gtk_menu_new ();
 
 			room_item = create_room_sub_menu (contact, chatroom);
-			gtk_menu_shell_append (submenu_shell, room_item);
+			gtk_menu_shell_append ((GtkMenuShell*)submenu, room_item);
 			gtk_widget_show (room_item);
 		}
 	}
 
-	if (have_rooms) {
+	if (submenu) {
 		gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
 	} else {
 		gtk_widget_set_sensitive (item, FALSE);
-		g_object_ref_sink (submenu);
-		gtk_widget_destroy (submenu);
-		g_object_unref (submenu);
 	}
 
 	gtk_widget_show (image);



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