# HG changeset patch
# Node ID fd309db59682
# Parent  4666203609e6
diff --git a/pidgin/gtkblist.c b/pidgin/gtkblist.c
--- a/pidgin/gtkblist.c
+++ b/pidgin/gtkblist.c
@@ -4525,7 +4525,7 @@
 void
 pidgin_blist_update_sort_methods(void)
 {
-	GtkWidget *sort_item = NULL;
+	GApplication *application = NULL;
 	GMenu *menu = NULL;
 	GList *l;
 
@@ -4533,10 +4533,13 @@
 		return;
 	}
 
-	/* create the gmenu */
-	menu = g_menu_new();
-
-	/* walk through the sort methods and update all the things */
+	/* get the menu and clear any existing entries. */
+	application = g_application_get_default();
+	menu = gtk_application_get_menu_by_id(GTK_APPLICATION(application),
+	                                      "sort-buddies");
+	g_menu_remove_all(menu);
+
+	/* Walk through the sort methods and add them to the menu. */
 	for (l = pidgin_blist_sort_methods; l; l = l->next) {
 		PidginBlistSortMethod *method = NULL;
 		GMenuItem *item = NULL;
@@ -4555,10 +4558,4 @@
 		g_menu_append_item(menu, item);
 		g_object_unref(item);
 	}
-
-	/* replace the old submenu with a new one */
-	sort_item = pidgin_contact_list_window_get_menu_sort_item(PIDGIN_CONTACT_LIST_WINDOW(gtkblist->window));
-	gtk_menu_item_set_submenu(GTK_MENU_ITEM(sort_item),
-	                          gtk_menu_new_from_model(G_MENU_MODEL(menu)));
-	g_object_unref(menu);
 }
diff --git a/pidgin/pidgincontactlistwindow.h b/pidgin/pidgincontactlistwindow.h
--- a/pidgin/pidgincontactlistwindow.h
+++ b/pidgin/pidgincontactlistwindow.h
@@ -71,18 +71,6 @@
 GtkWidget *pidgin_contact_list_window_get_vbox(PidginContactListWindow *window);
 
 /**
- * pidgin_contact_list_window_get_menu_sort_item:
- * @window: The #PidginContactListWindow instance.
- *
- * Returns the sort menu item from the menu of @window.
- *
- * Returns: (transfer none): The sort menu item from the menu of @window.
- *
- * Since: 3.0.0
- */
-GtkWidget *pidgin_contact_list_window_get_menu_sort_item(PidginContactListWindow *window);
-
-/**
  * pidgin_contact_list_window_get_menu_tray:
  * @window: The #PidginContactListWindow instance.
  *
diff --git a/pidgin/pidgincontactlistwindow.c b/pidgin/pidgincontactlistwindow.c
--- a/pidgin/pidgincontactlistwindow.c
+++ b/pidgin/pidgincontactlistwindow.c
@@ -28,9 +28,6 @@
 	GtkApplicationWindow parent;
 
 	GtkWidget *vbox;
-
-	GtkWidget *menu_bar;
-	GtkWidget *sort_buddies;
 };
 
 G_DEFINE_TYPE(PidginContactListWindow, pidgin_contact_list_window,
@@ -64,10 +61,6 @@
 
 	gtk_widget_class_bind_template_child(widget_class, PidginContactListWindow,
 	                                     vbox);
-	gtk_widget_class_bind_template_child(widget_class, PidginContactListWindow,
-	                                     menu_bar);
-	gtk_widget_class_bind_template_child(widget_class, PidginContactListWindow,
-	                                     sort_buddies);
 }
 
 /******************************************************************************
@@ -84,10 +77,3 @@
 
 	return window->vbox;
 }
-
-GtkWidget *
-pidgin_contact_list_window_get_menu_sort_item(PidginContactListWindow *window) {
-	g_return_val_if_fail(PIDGIN_IS_CONTACT_LIST_WINDOW(window), NULL);
-
-	return window->sort_buddies;
-}
diff --git a/pidgin/resources/BuddyList/window.ui b/pidgin/resources/BuddyList/window.ui
--- a/pidgin/resources/BuddyList/window.ui
+++ b/pidgin/resources/BuddyList/window.ui
@@ -35,39 +35,6 @@
         <property name="visible">True</property>
         <property name="can-focus">False</property>
         <property name="orientation">vertical</property>
-        <child>
-          <object class="GtkMenuBar" id="menu_bar">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <child>
-              <object class="GtkMenuItem">
-                <property name="visible">True</property>
-                <property name="can-focus">False</property>
-                <property name="label" translatable="yes">_Buddies</property>
-                <property name="use-underline">True</property>
-                <child type="submenu">
-                  <object class="GtkMenu">
-                    <property name="visible">True</property>
-                    <property name="can-focus">False</property>
-                    <child>
-                      <object class="GtkMenuItem" id="sort_buddies">
-                        <property name="visible">True</property>
-                        <property name="can-focus">False</property>
-                        <property name="label" translatable="yes">_Sort Buddies</property>
-                        <property name="use-underline">True</property>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
       </object>
     </child>
   </template>
diff --git a/pidgin/resources/gtk/menus.ui b/pidgin/resources/gtk/menus.ui
--- a/pidgin/resources/gtk/menus.ui
+++ b/pidgin/resources/gtk/menus.ui
@@ -45,6 +45,14 @@
       </section>
 
       <section>
+        <submenu>
+          <attribute name="label" translatable="yes">_Sort Buddies</attribute>
+
+          <section id="sort-buddies"/>
+        </submenu>
+      </section>
+
+      <section>
         <item>
           <attribute name="label" translatable="yes">_Add Buddy...</attribute>
           <attribute name="action">app.add-buddy</attribute>
