← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~ted/indicator-session/async-menu into lp:indicator-session

 

Ted Gould has proposed merging lp:~ted/indicator-session/async-menu into lp:indicator-session.

    Requested reviews:
    Indicator Applet Developers (indicator-applet-developers)


Better handling of menus.
-- 
https://code.launchpad.net/~ted/indicator-session/async-menu/+merge/12869
Your team ayatana-commits is subscribed to branch lp:indicator-session.
=== modified file 'src/indicator-session.c'
--- src/indicator-session.c	2009-09-28 22:43:06 +0000
+++ src/indicator-session.c	2009-10-05 13:35:18 +0000
@@ -84,10 +84,52 @@
 
 typedef struct _realized_data_t realized_data_t;
 struct _realized_data_t {
-	guint position;
 	section_t section;
 };
 
+static void 
+resort_menu (void)
+{
+	guint location = 0;
+	guint clientnum;
+
+	for (clientnum = 0; clientnum < 3; clientnum++) {
+		DbusmenuGtkClient * client = NULL;
+		if (clientnum == 0) client = status_client;
+		if (clientnum == 1) client = users_client;
+		if (clientnum == 2) client = session_client;
+
+		if (client == NULL) continue;
+
+		DbusmenuMenuitem * root = dbusmenu_client_get_root(DBUSMENU_CLIENT(client));
+
+		GList * children = dbusmenu_menuitem_get_children(root);
+		if (children == NULL) {
+			continue;
+		}
+
+		GList * child;
+		for (child = children; child != NULL; child = g_list_next(child)) {
+			GtkMenuItem * widget = dbusmenu_gtkclient_menuitem_get(client, DBUSMENU_MENUITEM(child->data));
+			if (widget != NULL) {
+				gtk_menu_reorder_child(main_menu, GTK_WIDGET(widget), location);
+				location++;
+			}
+		}
+
+		if (clientnum == 0) {
+			gtk_menu_reorder_child(main_menu, status_separator, location);
+			location++;
+		}
+		if (clientnum == 1) {
+			gtk_menu_reorder_child(main_menu, users_separator, location);
+			location++;
+		}
+	}
+
+	return;
+}
+
 static void
 child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint position, gpointer section)
 {
@@ -97,7 +139,6 @@
 		return;
 	}
 
-	data->position = position;
 	data->section = GPOINTER_TO_UINT(section);
 
 	g_signal_connect(G_OBJECT(child), DBUSMENU_MENUITEM_SIGNAL_REALIZED, G_CALLBACK(child_realized), data);
@@ -111,7 +152,6 @@
 	g_return_if_fail(DBUSMENU_IS_MENUITEM(child));
 
 	realized_data_t * data = (realized_data_t *)userdata;	
-	guint position = data->position;
 	section_t section = data->section;
 	g_free(data);
 
@@ -145,8 +185,6 @@
 		return;
 	}
 
-	position += posfunc();
-	g_debug("SUS: Adding child: %d", position);
 	GtkMenuItem * widget = dbusmenu_gtkclient_menuitem_get(client, child);
 
 	if (widget == NULL) {
@@ -154,9 +192,11 @@
 		return;
 	}
 
-	gtk_menu_insert(main_menu, GTK_WIDGET(widget), position);
+	gtk_menu_append(main_menu, GTK_WIDGET(widget));
 	gtk_widget_show(GTK_WIDGET(widget));
 
+	resort_menu();
+
 	gtk_widget_hide(loading_item);
 
 	return;


Follow ups