filechooser: Save and restore view type
authorMatthias Clasen <mclasen@redhat.com>
Sun, 23 Oct 2022 00:12:20 +0000 (20:12 -0400)
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Tue, 13 Dec 2022 17:45:15 +0000 (14:45 -0300)
With this, the filechooser comes up with the
same view (grid or list) that it had the last
time you used it.

gtk/gtkfilechooserprivate.h
gtk/gtkfilechooserwidget.c
gtk/org.gtk.gtk4.Settings.FileChooser.gschema.xml

index ac6da257a47ab34bb44d3bcc12ab843e2e668109..7f3215ff3eeaf3c4fa7e7aa33cb04836ed9ed485 100644 (file)
@@ -46,6 +46,7 @@ G_BEGIN_DECLS
 #define SETTINGS_KEY_CLOCK_FORMAT           "clock-format"
 #define SETTINGS_KEY_DATE_FORMAT            "date-format"
 #define SETTINGS_KEY_TYPE_FORMAT            "type-format"
+#define SETTINGS_KEY_VIEW_TYPE              "view-type"
 
 #define GTK_FILE_CHOOSER_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_CHOOSER, GtkFileChooserIface))
 
index 0ed294309f04dce108cd8fea1f315ea3bc69e82f..40e9ceedbb479f6a41d83c147a30a350f7d14383 100644 (file)
@@ -3224,6 +3224,7 @@ settings_load (GtkFileChooserWidget *impl)
   gboolean sort_directories_first;
   DateFormat date_format;
   TypeFormat type_format;
+  ViewType view_type;
   int sort_column;
   GtkSortType sort_order;
   StartupMode startup_mode;
@@ -3242,6 +3243,7 @@ settings_load (GtkFileChooserWidget *impl)
   sort_directories_first = g_settings_get_boolean (settings, SETTINGS_KEY_SORT_DIRECTORIES_FIRST);
   date_format = g_settings_get_enum (settings, SETTINGS_KEY_DATE_FORMAT);
   type_format = g_settings_get_enum (settings, SETTINGS_KEY_TYPE_FORMAT);
+  view_type = g_settings_get_enum (settings, SETTINGS_KEY_VIEW_TYPE);
 
   set_show_hidden (impl, show_hidden);
 
@@ -3258,6 +3260,8 @@ settings_load (GtkFileChooserWidget *impl)
   impl->clock_format = g_settings_get_enum (settings, "clock-format");
   impl->type_format = type_format;
 
+  set_view_type (impl, view_type);
+
   /* We don't call set_sort_column() here as the models may not have been
    * created yet.  The individual functions that create and set the models will
    * call set_sort_column() themselves.
@@ -3294,6 +3298,7 @@ settings_save (GtkFileChooserWidget *impl)
                       gtk_paned_get_position (GTK_PANED (impl->browse_widgets_hpaned)));
   g_settings_set_enum (settings, SETTINGS_KEY_DATE_FORMAT, impl->show_time ? DATE_FORMAT_WITH_TIME : DATE_FORMAT_REGULAR);
   g_settings_set_enum (settings, SETTINGS_KEY_TYPE_FORMAT, impl->type_format);
+  g_settings_set_enum (settings, SETTINGS_KEY_VIEW_TYPE, impl->view_type);
 
   /* Now apply the settings */
   g_settings_apply (settings);
index d70fab035da6132eb083e11c95237e93eb2fd927..054a256d1a73601758f3480dd1d28efcb1ecdd51 100644 (file)
     <value nick='category' value='2'/>
   </enum>
 
+  <enum id='org.gtk.gtk4.Settings.FileChooser.ViewType'>
+    <value nick='list' value='0'/>
+    <value nick='grid' value='1'/>
+  </enum>
+
   <schema id='org.gtk.gtk4.Settings.FileChooser' path='/org/gtk/gtk4/settings/file-chooser/'>
     <key name='location-mode' enum='org.gtk.gtk4.Settings.FileChooser.LocationMode'>
       <default>'path-bar'</default>
         'category' -> 'Video'
       </description>
     </key>
+    <key name="view-type" enum="org.gtk.gtk4.Settings.FileChooser.ViewType">
+      <default>'list'</default>
+      <summary>View type</summary>
+      <description>
+        Whether the files are shown in a list or in a grid.
+      </description>
+    </key>
   </schema>
 
 </schemalist>