From 9256a153630bf427ddd7f6180a3054d404246748 Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Sun, 16 Jun 2024 16:12:16 +0000 Subject: [PATCH] widgets: Prevent image name from affecting the dialogue width Resolves #7588 After the port to GTK3, the Filter dialogue's width started to be affected the length of the image name. If the name was very long, the filter dialogue would expand to fit it. This patch encloses the image title label in a GtkScrolledWindow with polices of EXTERNAL width and NEVER height. This ensures there will not be a scrollbar, and the label will not influence the width of the dialogue. A tooltip was added in case the user wants to hover to see the full name. --- app/widgets/gimpviewabledialog.c | 34 +++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/app/widgets/gimpviewabledialog.c b/app/widgets/gimpviewabledialog.c index dc7be7935f..81a31b9cfd 100644 --- a/app/widgets/gimpviewabledialog.c +++ b/app/widgets/gimpviewabledialog.c @@ -106,6 +106,7 @@ gimp_viewable_dialog_init (GimpViewableDialog *dialog) GtkWidget *frame; GtkWidget *hbox; GtkWidget *vbox; + GtkWidget *scrolled_window; frame = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT); @@ -135,6 +136,16 @@ gimp_viewable_dialog_init (GimpViewableDialog *dialog) gtk_box_pack_start (GTK_BOX (vbox), dialog->desc_label, FALSE, FALSE, 0); gtk_widget_show (dialog->desc_label); + /* Put the image name in a scrolled window so it does not automatically + * increase the width of the dialog, but still allows it to be expanded + * if the user wants to see full name */ + scrolled_window = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), + GTK_POLICY_EXTERNAL, + GTK_POLICY_NEVER); + gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, FALSE, FALSE, 0); + gtk_widget_set_visible (scrolled_window, TRUE); + dialog->viewable_label = g_object_new (GTK_TYPE_LABEL, "xalign", 0.0, "ellipsize", PANGO_ELLIPSIZE_END, @@ -142,8 +153,8 @@ gimp_viewable_dialog_init (GimpViewableDialog *dialog) gimp_label_set_attributes (GTK_LABEL (dialog->viewable_label), PANGO_ATTR_SCALE, PANGO_SCALE_SMALL, -1); - gtk_box_pack_start (GTK_BOX (vbox), dialog->viewable_label, FALSE, FALSE, 0); - gtk_widget_show (dialog->viewable_label); + gtk_container_add (GTK_CONTAINER (scrolled_window), dialog->viewable_label); + gtk_widget_set_visible (dialog->viewable_label, TRUE); } static void @@ -252,15 +263,15 @@ gimp_viewable_dialog_new (GList *viewables, dialog = g_object_new (GIMP_TYPE_VIEWABLE_DIALOG, "viewables", viewables, - "context", context, - "title", title, - "role", role, - "help-func", help_func, - "help-id", help_id, - "icon-name", icon_name, - "description", desc, - "parent", parent, - "use-header-bar", use_header_bar, + "context", context, + "title", title, + "role", role, + "help-func", help_func, + "help-id", help_id, + "icon-name", icon_name, + "description", desc, + "parent", parent, + "use-header-bar", use_header_bar, NULL); va_start (args, help_id); @@ -382,6 +393,7 @@ gimp_viewable_dialog_name_changed (GimpObject *object, } gtk_label_set_text (GTK_LABEL (dialog->viewable_label), name); + gtk_widget_set_tooltip_text (dialog->viewable_label, name); g_free (name); }