@@ -88,7 +88,7 @@ void dt_gui_presets_init()
8888 NULL , NULL );
8989}
9090
91- void dt_gui_presets_add_generic (const char * name ,
91+ void ( dt_gui_presets_add_generic ) (const char * name ,
9292 const dt_dev_operation_t op ,
9393 const int32_t version ,
9494 const void * params ,
@@ -98,9 +98,11 @@ void dt_gui_presets_add_generic(const char *name,
9898{
9999 dt_develop_blend_params_t default_blendop_params ;
100100 dt_develop_blend_init_blend_parameters (& default_blendop_params , blend_cst );
101+ gchar * prefixed_name = g_strdup_printf (BUILTIN_PREFIX "%s" , name );
101102 dt_gui_presets_add_with_blendop (
102- name , op , version , params , params_size ,
103+ prefixed_name , op , version , params , params_size ,
103104 & default_blendop_params , enabled );
105+ g_free (prefixed_name );
104106}
105107
106108void dt_gui_presets_add_with_blendop (const char * name ,
@@ -1588,11 +1590,13 @@ void dt_gui_favorite_presets_menu_show(GtkWidget *w)
15881590 gchar * txt = g_strdup_printf ("ꬹ%s|%sꬹ" , iop -> so -> op , name );
15891591 if (config && strstr (config , txt ))
15901592 {
1591- GtkWidget * mi = gtk_menu_item_new_with_label (name );
1593+ GtkWidget * mi = gtk_menu_item_new_with_label ("" );
1594+ gchar * local_name = dt_util_localize_segmented_name (name , TRUE);
15921595 gchar * tt = g_markup_printf_escaped ("<b>%s %s</b> %s" ,
1593- iop -> name (), iop -> multi_name , name );
1596+ iop -> name (), iop -> multi_name , local_name );
15941597 gtk_label_set_markup (GTK_LABEL (gtk_bin_get_child (GTK_BIN (mi ))), tt );
15951598 g_free (tt );
1599+ g_free (local_name );
15961600 _menuitem_connect_preset (mi , name , iop );
15971601 gtk_menu_shell_append (GTK_MENU_SHELL (menu ), GTK_WIDGET (mi ));
15981602 }
@@ -1616,6 +1620,27 @@ void dt_gui_favorite_presets_menu_show(GtkWidget *w)
16161620 dt_gui_menu_popup (menu , w , GDK_GRAVITY_SOUTH_WEST , GDK_GRAVITY_NORTH_WEST );
16171621}
16181622
1623+ // Comparator function to sort menu items alphabetically by their labels in reverse order
1624+ static gint _compare_menu_items (GtkMenuItem * a , GtkMenuItem * b )
1625+ {
1626+ return - g_utf8_collate (gtk_menu_item_get_label (a ), gtk_menu_item_get_label (b ));
1627+ }
1628+
1629+ // Function to sort GtkMenuShell items
1630+ static void _sort_menu_shell (GtkWidget * menu_shell )
1631+ {
1632+ if (!GTK_IS_MENU_SHELL (menu_shell )) return ;
1633+ GList * items = gtk_container_get_children (GTK_CONTAINER (menu_shell ));
1634+ items = g_list_sort (items , (GCompareFunc )_compare_menu_items );
1635+ for (GList * iter = items ; iter ; iter = g_list_delete_link (iter , iter ))
1636+ {
1637+ g_object_ref (iter -> data );
1638+ gtk_container_remove (GTK_CONTAINER (menu_shell ), GTK_WIDGET (iter -> data ));
1639+ _sort_menu_shell (gtk_menu_item_get_submenu (GTK_MENU_ITEM (iter -> data )));
1640+ gtk_menu_shell_prepend (GTK_MENU_SHELL (menu_shell ), GTK_WIDGET (iter -> data ));
1641+ g_object_unref (iter -> data );
1642+ }
1643+ }
16191644
16201645GtkMenu * dt_gui_presets_popup_menu_show_for_module (dt_iop_module_t * module )
16211646{
@@ -1707,7 +1732,7 @@ GtkMenu *dt_gui_presets_popup_menu_show_for_module(dt_iop_module_t *module)
17071732 int last_wp = -1 ;
17081733 gchar * * prev_split = NULL ;
17091734 GtkWidget * submenu = GTK_WIDGET (menu );
1710- GSList * menu_stack = NULL ; // stack of submenus
1735+ GtkWidget * mainmenu = submenu ;
17111736 GSList * menu_path = NULL ; // stack of menuitems which are the parents of submenus on menu_stack
17121737 while (sqlite3_step (stmt ) == SQLITE_ROW )
17131738 {
@@ -1740,23 +1765,19 @@ GtkMenu *dt_gui_presets_popup_menu_show_for_module(dt_iop_module_t *module)
17401765 if (darktable .gui -> last_preset && strcmp (darktable .gui -> last_preset , name ) == 0 )
17411766 found = TRUE;
17421767
1743- gchar * * split = g_strsplit (name , "|" , -1 ), * * s = split , * * p = prev_split ;
1768+ gchar * local_name = dt_util_localize_segmented_name (name , FALSE);
1769+ gchar * * split = g_strsplit (local_name , "|" , -1 ), * * s = split , * * p = prev_split ;
1770+ g_free (local_name );
17441771 for (; p && * (p + 1 ) && * (s + 1 ) && !g_strcmp0 (* s , * p ); p ++ , s ++ )
17451772 ;
17461773 for (; p && * (p + 1 ); p ++ )
17471774 {
1748- submenu = menu_stack -> data ;
1749- menu_stack = g_slist_delete_link (menu_stack , menu_stack ); // pop
17501775 menu_path = g_slist_delete_link (menu_path , menu_path ); // pop
1776+ submenu = menu_path ? gtk_menu_item_get_submenu (menu_path -> data ) : mainmenu ;
17511777 }
17521778 for (; * (s + 1 ); s ++ )
17531779 {
1754- GtkWidget * sm = gtk_menu_item_new_with_label ("" );
1755- GtkWidget * mi_label = gtk_bin_get_child (GTK_BIN (sm ));
1756- gchar * el = g_markup_escape_text (* s , -1 );
1757- gtk_label_set_markup (GTK_LABEL (mi_label ), el );
1758- g_free (el );
1759- menu_stack = g_slist_prepend (menu_stack , submenu ); // push
1780+ GtkWidget * sm = gtk_menu_item_new_with_label (* s );
17601781 menu_path = g_slist_prepend (menu_path , sm ); // push
17611782
17621783 gtk_menu_shell_append (GTK_MENU_SHELL (submenu ), sm );
@@ -1779,13 +1800,9 @@ GtkMenu *dt_gui_presets_popup_menu_show_for_module(dt_iop_module_t *module)
17791800 label = g_strdup_printf ("%s %s" , * s , _ ("(default)" ));
17801801 else
17811802 label = g_strdup (* s );
1782- mi = gtk_check_menu_item_new_with_label ("" );
1783- GtkWidget * mi_label = gtk_bin_get_child (GTK_BIN (mi ));
1784- gchar * el = g_markup_escape_text (label , -1 );
1785- gtk_label_set_markup (GTK_LABEL (mi_label ), el );
1803+ mi = gtk_check_menu_item_new_with_label (label );
17861804 dt_gui_add_class (mi , "dt_transparent_background" );
17871805 g_free (label );
1788- g_free (el );
17891806
17901807 if (module
17911808 && ((op_params_size == 0
@@ -1805,16 +1822,7 @@ GtkMenu *dt_gui_presets_popup_menu_show_for_module(dt_iop_module_t *module)
18051822 g_set_weak_pointer (& _active_menu_item , mi );
18061823 // walk back up the menu hierarchy and highlight the entire path down to the current leaf
18071824 for (const GSList * mp = menu_path ; mp ; mp = g_slist_next (mp ))
1808- {
1809- const char * curr_label = gtk_menu_item_get_label (GTK_MENU_ITEM (mp -> data ));
1810- if (curr_label )
1811- {
1812- gchar * boldface = g_strdup_printf ("<b>%s</b>" ,curr_label );
1813- GtkWidget * child = gtk_bin_get_child (GTK_BIN (mp -> data ));
1814- gtk_label_set_markup (GTK_LABEL (child ), boldface );
1815- g_free (boldface );
1816- }
1817- }
1825+ dt_gui_add_class (gtk_bin_get_child (GTK_BIN (mp -> data )), "active_menu_item" );
18181826 }
18191827
18201828 if (isdisabled )
@@ -1831,9 +1839,11 @@ GtkMenu *dt_gui_presets_popup_menu_show_for_module(dt_iop_module_t *module)
18311839 cnt ++ ;
18321840 }
18331841 sqlite3_finalize (stmt );
1834- g_slist_free (menu_stack );
1842+ g_slist_free (menu_path );
18351843 g_strfreev (prev_split );
18361844
1845+ _sort_menu_shell (mainmenu );
1846+
18371847 if (cnt > 0 ) gtk_menu_shell_append (GTK_MENU_SHELL (menu ), gtk_separator_menu_item_new ());
18381848
18391849 if (module )
@@ -1859,7 +1869,7 @@ GtkMenu *dt_gui_presets_popup_menu_show_for_module(dt_iop_module_t *module)
18591869
18601870 if (darktable .gui -> last_preset && found )
18611871 {
1862- char * markup = g_markup_printf_escaped ("%s <span weight='bold' >%s</span >" ,
1872+ char * markup = g_markup_printf_escaped ("%s <b >%s</b >" ,
18631873 _ ("update preset" ),
18641874 darktable .gui -> last_preset );
18651875 mi = gtk_menu_item_new_with_label ("" );
0 commit comments