[gtk/gbsneto/filechooser-column-view: 40/82] filechooserwidget: Move size to column view




commit f98ac22344926aabda4c2a6f4125fb8690e88ecd
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Oct 8 09:13:01 2022 -0300

    filechooserwidget: Move size to column view
    
    This was one of the easier ones. We merely delegate the hard work
    to g_format_size(), like we already do for treeview.

 gtk/gtkfilechooserwidget.c     | 42 +++++++++++++++++-------------------------
 gtk/ui/gtkfilechooserwidget.ui | 42 ++++++++++++++++++++++++++++++------------
 2 files changed, 47 insertions(+), 37 deletions(-)
---
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index ad72ed3166..3c3143de4b 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -276,12 +276,11 @@ struct _GtkFileChooserWidget
   GtkTreeViewColumn *list_time_column;
   GtkCellRenderer *list_date_renderer;
   GtkCellRenderer *list_time_renderer;
-  GtkTreeViewColumn *list_size_column;
-  GtkCellRenderer *list_size_renderer;
   GtkTreeViewColumn *list_type_column;
   GtkCellRenderer *list_type_renderer;
 
   GtkColumnViewColumn *column_view_location_column;
+  GtkColumnViewColumn *column_view_size_column;
 
   guint location_changed_id;
 
@@ -360,7 +359,6 @@ enum {
   MODEL_COL_NAME_COLLATED,
   MODEL_COL_IS_FOLDER,
   MODEL_COL_IS_SENSITIVE,
-  MODEL_COL_SIZE_TEXT,
   MODEL_COL_DATE_TEXT,
   MODEL_COL_TIME_TEXT,
   MODEL_COL_ELLIPSIZE,
@@ -378,7 +376,6 @@ enum {
         G_TYPE_STRING,            /* MODEL_COL_NAME_COLLATED */ \
         G_TYPE_BOOLEAN,           /* MODEL_COL_IS_FOLDER */     \
         G_TYPE_BOOLEAN,           /* MODEL_COL_IS_SENSITIVE */  \
-        G_TYPE_STRING,            /* MODEL_COL_SIZE_TEXT */     \
         G_TYPE_STRING,            /* MODEL_COL_DATE_TEXT */     \
         G_TYPE_STRING,            /* MODEL_COL_TIME_TEXT */     \
         PANGO_TYPE_ELLIPSIZE_MODE /* MODEL_COL_ELLIPSIZE */
@@ -1365,7 +1362,7 @@ rename_selected_cb (GtkTreeModel *model,
                       -1);
 
   gtk_tree_view_get_cell_area (GTK_TREE_VIEW (impl->browse_files_tree_view),
-                               path, impl->list_size_column, &rect);
+                               path, impl->list_type_column, &rect);
 
   gtk_tree_view_convert_bin_window_to_widget_coords (GTK_TREE_VIEW (impl->browse_files_tree_view),
                                                      rect.x, rect.y,
@@ -1493,8 +1490,8 @@ change_show_size_state (GSimpleAction *action,
   g_simple_action_set_state (action, state);
   impl->show_size_column = g_variant_get_boolean (state);
 
-  gtk_tree_view_column_set_visible (impl->list_size_column,
-                                    impl->show_size_column);
+  gtk_column_view_column_set_visible (impl->column_view_size_column,
+                                      impl->show_size_column);
 }
 
 /* Callback used when the "Show Type Column" menu item is toggled */
@@ -2134,6 +2131,16 @@ column_view_get_location (GtkListItem *list_item)
   return g_steal_pointer (&location);
 }
 
+static char *
+column_view_get_size (GtkListItem *item,
+                      GFileInfo   *info)
+{
+  if (!_gtk_file_info_consider_as_directory (info))
+    return g_format_size (g_file_info_get_size (info));
+  else
+    return NULL;
+}
+
 typedef struct {
   OperationMode operation_mode;
   int general_column;
@@ -2150,7 +2157,6 @@ file_list_set_sort_column_ids (GtkFileChooserWidget *impl)
   gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->browse_files_tree_view), -1);
 
   gtk_tree_view_column_set_sort_column_id (impl->list_time_column, MODEL_COL_TIME);
-  gtk_tree_view_column_set_sort_column_id (impl->list_size_column, MODEL_COL_SIZE);
   gtk_tree_view_column_set_sort_column_id (impl->list_type_column, MODEL_COL_TYPE);
 }
 
@@ -3353,7 +3359,7 @@ settings_load (GtkFileChooserWidget *impl)
   set_show_hidden (impl, show_hidden);
 
   impl->show_size_column = show_size_column;
-  gtk_tree_view_column_set_visible (impl->list_size_column, show_size_column);
+  gtk_column_view_column_set_visible (impl->column_view_size_column, show_size_column);
   impl->show_type_column = show_type_column;
   gtk_tree_view_column_set_visible (impl->list_type_column, show_type_column);
 
@@ -4456,12 +4462,6 @@ file_system_model_set (GtkFileSystemModel *model,
     case MODEL_COL_SIZE:
       g_value_set_int64 (value, info ? g_file_info_get_size (info) : 0);
       break;
-    case MODEL_COL_SIZE_TEXT:
-      if (info == NULL || _gtk_file_info_consider_as_directory (info))
-        g_value_set_string (value, NULL);
-      else
-        g_value_take_string (value, g_format_size (g_file_info_get_size (info)));
-      break;
     case MODEL_COL_TYPE:
       if (info == NULL || _gtk_file_info_consider_as_directory (info))
         g_value_set_string (value, NULL);
@@ -6520,7 +6520,6 @@ search_setup_model (GtkFileChooserWidget *impl)
                            GTK_TREE_MODEL (impl->search_model));
 
   gtk_tree_view_column_set_sort_column_id (impl->list_time_column, -1);
-  gtk_tree_view_column_set_sort_column_id (impl->list_size_column, -1);
   gtk_tree_view_column_set_sort_column_id (impl->list_type_column, -1);
 
   update_columns (impl, TRUE, _("Modified"));
@@ -6758,7 +6757,6 @@ recent_start_loading (GtkFileChooserWidget *impl)
   gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->browse_files_tree_view), -1);
 
   gtk_tree_view_column_set_sort_column_id (impl->list_time_column, -1);
-  gtk_tree_view_column_set_sort_column_id (impl->list_size_column, -1);
   gtk_tree_view_column_set_sort_column_id (impl->list_type_column, -1);
 
   update_columns (impl, TRUE, _("Accessed"));
@@ -6951,12 +6949,6 @@ path_bar_clicked (GtkPathBar           *path_bar,
 static void
 update_cell_renderer_attributes (GtkFileChooserWidget *impl)
 {
-  gtk_tree_view_column_set_attributes (impl->list_size_column,
-                                       impl->list_size_renderer,
-                                       "text", MODEL_COL_SIZE_TEXT,
-                                       "sensitive", MODEL_COL_IS_SENSITIVE,
-                                       NULL);
-
   gtk_tree_view_column_set_attributes (impl->list_type_column,
                                        impl->list_type_renderer,
                                        "text", MODEL_COL_TYPE,
@@ -7560,6 +7552,7 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
   gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, browse_path_bar_size_group);
   gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, browse_path_bar);
   gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, column_view_location_column);
+  gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, column_view_size_column);
   gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, filter_combo_hbox);
   gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, filter_combo);
   gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, extra_align);
@@ -7570,8 +7563,6 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
   gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_time_column);
   gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_date_renderer);
   gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_time_renderer);
-  gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_size_column);
-  gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_size_renderer);
   gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_type_column);
   gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_type_renderer);
   gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, new_folder_name_entry);
@@ -7606,6 +7597,7 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
   gtk_widget_class_bind_template_callback (widget_class, click_cb);
   gtk_widget_class_bind_template_callback (widget_class, long_press_cb);
   gtk_widget_class_bind_template_callback (widget_class, column_view_get_location);
+  gtk_widget_class_bind_template_callback (widget_class, column_view_get_size);
 
   gtk_widget_class_set_css_name (widget_class, I_("filechooser"));
 
diff --git a/gtk/ui/gtkfilechooserwidget.ui b/gtk/ui/gtkfilechooserwidget.ui
index 588779cc12..8a3ae325ab 100644
--- a/gtk/ui/gtkfilechooserwidget.ui
+++ b/gtk/ui/gtkfilechooserwidget.ui
@@ -218,6 +218,36 @@
                                               </object>
                                             </child>
 
+                                            <child>
+                                              <object class="GtkColumnViewColumn" 
id="column_view_size_column">
+                                                <property name="title" translatable="yes">Size</property>
+                                                <property name="factory">
+                                                  <object class="GtkBuilderListItemFactory">
+                                                    <property name="bytes"><![CDATA[
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GtkListItem">
+    <property name="child">
+      <object class="GtkLabel">
+        <property name="hexpand">1</property>
+        <property name="xalign">0</property>
+        <binding name="label">
+          <closure type="gchararray" function="column_view_get_size">
+            <lookup type="GtkFileSystemItem" name="file-info">
+              <lookup name="item">GtkListItem</lookup>
+            </lookup>
+          </closure>
+        </binding>
+      </object>
+    </property>
+  </template>
+</interface>
+                                                ]]></property>
+                                                  </object>
+                                                </property>
+                                              </object>
+                                            </child>
+
                                           </object>
                                         </child>
                                       </object>
@@ -270,18 +300,6 @@
                                                 <signal name="changed" handler="list_selection_changed" 
swapped="no"/>
                                               </object>
                                             </child>
-                                            <child>
-                                              <object class="GtkTreeViewColumn" id="list_size_column">
-                                                <property name="title" translatable="yes">Size</property>
-                                                <property name="sizing">2</property>
-                                                <child>
-                                                  <object class="GtkCellRendererText" 
id="list_size_renderer">
-                                                    <property name="xalign">0</property>
-                                                    <property name="xpad">6</property>
-                                                  </object>
-                                                </child>
-                                              </object>
-                                            </child>
                                             <child>
                                               <object class="GtkTreeViewColumn" id="list_type_column">
                                                 <property name="title" translatable="yes">Type</property>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]