gtkfilechooser: improve file chooser tooltips

This commit is contained in:
Daemonratte 2026-05-20 10:28:23 +02:00
commit a87dbdb9a9

View file

@ -887,6 +887,7 @@ static void
gtk_file_chooser_default_finalize (GObject *object)
{
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
GSList *l;
if (impl->list_tooltip_path)
{
@ -899,8 +900,6 @@ gtk_file_chooser_default_finalize (GObject *object)
g_free (impl->list_tooltip_text);
impl->list_tooltip_text = NULL;
GSList *l;
icon_view_scale_remove_timeout (impl);
if (impl->icon_tooltip_path)
@ -5618,7 +5617,13 @@ file_list_get_tooltip_width (GtkFileChooserDefault *impl)
{
gtk_cell_renderer_get_padding (text_renderer, &text_xpad, NULL);
width -= text_xpad * 2;
width -= 12;
/* Match GtkCellRendererText's practical ellipsize threshold more
* closely. gtk_tree_view_column_cell_get_position() plus renderer
* padding is still slightly wider than the text area where the
* renderer starts drawing an ellipsis.
*/
width -= 2;
}
else
{
@ -5800,16 +5805,20 @@ file_name_needs_tooltip (GtkFileChooserDefault *impl,
gint available_width)
{
PangoLayout *layout;
gint width;
gboolean ellipsized;
if (name == NULL || available_width <= 0)
return FALSE;
layout = gtk_widget_create_pango_layout (impl->browse_files_current_view, name);
pango_layout_get_pixel_size (layout, &width, NULL);
pango_layout_set_width (layout, available_width * PANGO_SCALE);
pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
ellipsized = pango_layout_is_ellipsized (layout);
g_object_unref (layout);
return width > available_width;
return ellipsized;
}
static gint
@ -5856,13 +5865,7 @@ file_icon_view_get_tooltip_width (GtkFileChooserDefault *impl)
else
return 0;
/*
* GtkCellRendererText still has its own padding and ellipsize threshold.
* Be conservative so that names shortened by only a few characters still
* get a tooltip.
*/
width -= text_xpad * 2;
width -= 12;
return MAX (1, width);
}
@ -6877,6 +6880,9 @@ view_mode_set (GtkFileChooserDefault *impl, ViewMode view_mode)
old_view = impl->browse_files_current_view;
selected_files = view_mode_get_selected_files (impl, old_view_mode);
file_list_tooltip_cache_clear (impl);
file_icon_view_tooltip_cache_clear (impl);
impl->view_mode = view_mode;
gtk_combo_box_set_active (GTK_COMBO_BOX (impl->view_mode_combo_box),
view_mode);
@ -8104,6 +8110,9 @@ operation_mode_set (GtkFileChooserDefault *impl, OperationMode mode)
{
ShortcutsIndex shortcut_to_select;
file_list_tooltip_cache_clear (impl);
file_icon_view_tooltip_cache_clear (impl);
operation_mode_stop (impl, impl->operation_mode);
impl->operation_mode = mode;
@ -13505,6 +13514,9 @@ current_view_set_file_model (GtkFileChooserDefault *impl, GtkTreeModel *model)
{
GtkWidget *view;
file_list_tooltip_cache_clear (impl);
file_icon_view_tooltip_cache_clear (impl);
impl->current_model = model;
if (impl->view_mode == VIEW_MODE_LIST)