From: Matthias Clasen Date: Fri, 3 Jul 2015 16:22:39 +0000 (-0700) Subject: file chooser: Improve column sizing X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~24^2~9164 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=22294a4a0d9edd101dd9d1f9df92b54362454d71;p=gtk4.git file chooser: Improve column sizing Allow the name and location columns to be resized, but arrange for their sizing to be reset when the column layout changes (either by the location column appearing/disappearing, or by the time column changing between mtime and atime. This gives a decent compromise between good automatic sizing and user control. --- diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index 7ca2282585..9f3ca6b64e 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -1611,10 +1611,9 @@ update_time_renderer_visible (GtkFileChooserWidget *impl) g_object_set (priv->list_time_renderer, "visible", priv->show_time, NULL); - gtk_widget_queue_draw (priv->browse_files_tree_view); - gtk_tree_view_column_queue_resize (priv->list_time_column); clear_model_cache (impl, MODEL_COL_DATE_TEXT); clear_model_cache (impl, MODEL_COL_TIME_TEXT); + gtk_widget_queue_draw (priv->browse_files_tree_view); } static void @@ -3812,6 +3811,35 @@ set_busy_cursor (GtkFileChooserWidget *impl, g_object_unref (cursor); } +static void +update_columns (GtkFileChooserWidget *impl, + gboolean location_visible, + const gchar *time_title) +{ + GtkFileChooserWidgetPrivate *priv = impl->priv; + gboolean need_resize = FALSE; + + if (gtk_tree_view_column_get_visible (priv->list_location_column) != location_visible) + { + gtk_tree_view_column_set_visible (priv->list_location_column, location_visible); + need_resize = TRUE; + } + + if (g_strcmp0 (gtk_tree_view_column_get_title (priv->list_time_column), time_title) != 0) + { + gtk_tree_view_column_set_title (priv->list_time_column, time_title); + need_resize = TRUE; + } + + if (need_resize) + { + /* This undoes user resizing of columns when the columns change. */ + gtk_tree_view_column_set_expand (priv->list_name_column, TRUE); + gtk_tree_view_column_set_expand (priv->list_location_column, TRUE); + gtk_tree_view_columns_autosize (GTK_TREE_VIEW (priv->browse_files_tree_view)); + } +} + /* Creates a sort model to wrap the file system model and sets it on the tree view */ static void load_set_model (GtkFileChooserWidget *impl) @@ -3825,9 +3853,7 @@ load_set_model (GtkFileChooserWidget *impl) profile_msg (" gtk_tree_view_set_model start", NULL); gtk_tree_view_set_model (GTK_TREE_VIEW (priv->browse_files_tree_view), GTK_TREE_MODEL (priv->browse_files_model)); - gtk_tree_view_column_set_visible (priv->list_location_column, FALSE); - gtk_tree_view_column_set_title (priv->list_time_column, _("Modified")); - gtk_tree_view_columns_autosize (GTK_TREE_VIEW (priv->browse_files_tree_view)); + update_columns (impl, FALSE, _("Modified")); file_list_set_sort_column_ids (impl); set_sort_column (impl); profile_msg (" gtk_tree_view_set_model end", NULL); @@ -6691,9 +6717,7 @@ search_setup_model (GtkFileChooserWidget *impl) gtk_tree_view_column_set_sort_column_id (priv->list_size_column, -1); gtk_tree_view_column_set_sort_column_id (priv->list_location_column, -1); - gtk_tree_view_column_set_visible (priv->list_location_column, TRUE); - gtk_tree_view_column_set_title (priv->list_time_column, _("Modified")); - gtk_tree_view_columns_autosize (GTK_TREE_VIEW (priv->browse_files_tree_view)); + update_columns (impl, TRUE, _("Modified")); } static gboolean @@ -6912,9 +6936,7 @@ recent_idle_cleanup (gpointer data) gtk_tree_view_column_set_sort_column_id (priv->list_size_column, -1); gtk_tree_view_column_set_sort_column_id (priv->list_location_column, -1); - gtk_tree_view_column_set_visible (priv->list_location_column, TRUE); - gtk_tree_view_column_set_title (priv->list_time_column, _("Accessed")); - gtk_tree_view_columns_autosize (GTK_TREE_VIEW (priv->browse_files_tree_view)); + update_columns (impl, TRUE, _("Accessed")); set_busy_cursor (impl, FALSE); diff --git a/gtk/ui/gtkfilechooserwidget.ui b/gtk/ui/gtkfilechooserwidget.ui index 33ed215eea..21ad01fa8d 100644 --- a/gtk/ui/gtkfilechooserwidget.ui +++ b/gtk/ui/gtkfilechooserwidget.ui @@ -172,8 +172,8 @@ - True Name + True True @@ -182,34 +182,35 @@ + 10 end - + + Location True - Size + False + True - + 0 + 10 + start 6 - - True - False - Location + + Size + fixed - + 0 - start - 15 - 30 6 @@ -217,20 +218,15 @@ - True Modified + fixed - 1 6 - - True - - 1 6