@@ -1620,27 +1620,14 @@ void dt_gui_favorite_presets_menu_show(GtkWidget *w)
16201620 dt_gui_menu_popup (menu , w , GDK_GRAVITY_SOUTH_WEST , GDK_GRAVITY_NORTH_WEST );
16211621}
16221622
1623- // Comparator function to sort menu items alphabetically by their labels in reverse order
1624- static gint _compare_menu_items (gpointer a , gpointer b )
1623+ static void _menu_shell_insert_sorted (GtkWidget * menu_shell , GtkWidget * item , gchar * name )
16251624{
1626- int d = g_object_get_data (a , "builtin" ) - g_object_get_data (b , "builtin" );
1627- return d ? d : - g_utf8_collate (gtk_menu_item_get_label (a ), gtk_menu_item_get_label (b ));
1628- }
1629-
1630- // Function to sort GtkMenuShell items
1631- static void _sort_menu_shell (GtkWidget * menu_shell )
1632- {
1633- if (!GTK_IS_MENU_SHELL (menu_shell )) return ;
16341625 GList * items = gtk_container_get_children (GTK_CONTAINER (menu_shell ));
1635- items = g_list_sort (items , (GCompareFunc )_compare_menu_items );
1636- for (GList * iter = items ; iter ; iter = g_list_delete_link (iter , iter ))
1637- {
1638- g_object_ref (iter -> data );
1639- gtk_container_remove (GTK_CONTAINER (menu_shell ), GTK_WIDGET (iter -> data ));
1640- _sort_menu_shell (gtk_menu_item_get_submenu (GTK_MENU_ITEM (iter -> data )));
1641- gtk_menu_shell_prepend (GTK_MENU_SHELL (menu_shell ), GTK_WIDGET (iter -> data ));
1642- g_object_unref (iter -> data );
1643- }
1626+ int num = g_list_length (items );
1627+ for (GList * i = g_list_last (items ); i ; i = i -> prev , num -- )
1628+ if (g_utf8_collate (gtk_menu_item_get_label (i -> data ), name ) < 0 ) break ;
1629+ gtk_menu_shell_insert (GTK_MENU_SHELL (menu_shell ), item , num );
1630+ g_list_free (items );
16441631}
16451632
16461633GtkMenu * dt_gui_presets_popup_menu_show_for_module (dt_iop_module_t * module )
@@ -1781,7 +1768,7 @@ GtkMenu *dt_gui_presets_popup_menu_show_for_module(dt_iop_module_t *module)
17811768 GtkWidget * sm = gtk_menu_item_new_with_label (* s );
17821769 menu_path = g_slist_prepend (menu_path , sm ); // push
17831770
1784- gtk_menu_shell_append ( GTK_MENU_SHELL ( submenu ) , sm );
1771+ _menu_shell_insert_sorted ( submenu , sm , * s );
17851772 submenu = gtk_menu_new ();
17861773 gtk_menu_item_set_submenu (GTK_MENU_ITEM (sm ), submenu );
17871774 }
@@ -1802,7 +1789,7 @@ GtkMenu *dt_gui_presets_popup_menu_show_for_module(dt_iop_module_t *module)
18021789 else
18031790 label = g_strdup (* s );
18041791 mi = gtk_check_menu_item_new_with_label (label );
1805- g_object_set_data ( G_OBJECT ( mi ), "builtin" , GINT_TO_POINTER ( chk_writeprotect ) );
1792+ _menu_shell_insert_sorted ( submenu , mi , label );
18061793 dt_gui_add_class (mi , "dt_transparent_background" );
18071794 g_free (label );
18081795
@@ -1837,15 +1824,12 @@ GtkMenu *dt_gui_presets_popup_menu_show_for_module(dt_iop_module_t *module)
18371824 gtk_widget_set_tooltip_text (mi , (const char * )sqlite3_column_text (stmt , 3 ));
18381825 _menuitem_connect_preset (mi , name , module );
18391826 }
1840- gtk_menu_shell_append (GTK_MENU_SHELL (submenu ), mi );
18411827 cnt ++ ;
18421828 }
18431829 sqlite3_finalize (stmt );
18441830 g_slist_free (menu_path );
18451831 g_strfreev (prev_split );
18461832
1847- _sort_menu_shell (mainmenu );
1848-
18491833 if (cnt > 0 ) gtk_menu_shell_append (GTK_MENU_SHELL (menu ), gtk_separator_menu_item_new ());
18501834
18511835 if (module )
0 commit comments