From 972206d08c35108e2796ebf8d3cb082c4a1b70b7 Mon Sep 17 00:00:00 2001 From: Jehan Date: Mon, 5 May 2025 15:12:02 +0200 Subject: [PATCH] =?UTF-8?q?libgimp:=20different=20widget=20default=20for?= =?UTF-8?q?=20GimpChoice=20in=20GimpProcedureDialog=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … depending on the number of choices. Enforcing a UX decision into code from GIMP/Design/gimp-ux#323. Note that this is not a perfect automatization, since the right default widget may still be a combo box even for limited choices arguments, when the dialog is crowded. It still improves the defaults, and it is still possible to override the widget on case by case (just as of now). (cherry picked from commit bcb736db618394d0e97161634d9eae411bb76c31) --- libgimp/gimpproceduredialog.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/libgimp/gimpproceduredialog.c b/libgimp/gimpproceduredialog.c index f14095dc00..ea336506cf 100644 --- a/libgimp/gimpproceduredialog.c +++ b/libgimp/gimpproceduredialog.c @@ -647,8 +647,8 @@ gimp_procedure_dialog_set_ok_label (GimpProcedureDialog *dialog, * * %GIMP_TYPE_LABEL_ENTRY (default): an entry with a label. * * %GTK_TYPE_ENTRY: an entry with no label. * * %GTK_TYPE_TEXT_VIEW: a text view with no label. - * - %GIMP_TYPE_CHOICE: - * * %GTK_TYPE_COMBO_BOX (default): a combo box displaying every + * - %GIMP_TYPE_CHOICE (default will depend on the number of choices): + * * %GTK_TYPE_COMBO_BOX: a combo box displaying every * choice. * * %GIMP_TYPE_INT_RADIO_FRAME: a frame with radio buttons. * - %GEGL_TYPE_COLOR: @@ -857,14 +857,28 @@ gimp_procedure_dialog_get_widget (GimpProcedureDialog *dialog, } else if (G_PARAM_SPEC_TYPE (pspec) == GIMP_TYPE_PARAM_CHOICE) { - if (widget_type == G_TYPE_NONE || widget_type == GTK_TYPE_COMBO_BOX) + GType real_widget_type = widget_type; + + if (real_widget_type == G_TYPE_NONE) + { + GimpChoice *choice = gimp_param_spec_choice_get_choice (pspec); + gint n_choices; + + n_choices = g_list_length (gimp_choice_list_nicks (choice)); + if (n_choices > 3) + real_widget_type = GTK_TYPE_COMBO_BOX; + else + real_widget_type = GIMP_TYPE_INT_RADIO_FRAME; + } + + if (real_widget_type == GTK_TYPE_COMBO_BOX) { widget = gimp_prop_choice_combo_box_new (G_OBJECT (priv->config), property); gtk_widget_set_vexpand (widget, FALSE); gtk_widget_set_hexpand (widget, TRUE); widget = gimp_label_string_widget_new (g_param_spec_get_nick (pspec), widget); } - else if (widget_type == GIMP_TYPE_INT_RADIO_FRAME) + else if (real_widget_type == GIMP_TYPE_INT_RADIO_FRAME) { widget = gimp_prop_choice_radio_frame_new (G_OBJECT (priv->config), property); gtk_widget_set_vexpand (widget, FALSE);