From a05007c869c922c5ce528ae8dbe9898c57f799be Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 4 Jul 2025 16:50:51 +0100 Subject: [PATCH 1/6] Add datetimeformat combobox to app menu --- libcore/Enums.vala | 37 +++++++++++++++++++++++++++++++++++ src/View/Widgets/AppMenu.vala | 17 ++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/libcore/Enums.vala b/libcore/Enums.vala index 9fb2405063..ff48a52bdd 100644 --- a/libcore/Enums.vala +++ b/libcore/Enums.vala @@ -253,4 +253,41 @@ namespace Files { } } } + + // Matches settings enum for format of datetimes in view + public enum DateFormatMode { + ISO, + LOCALE, + INFORMAL; + + public string to_string () { + switch (this) { + case ISO: + ///TRANSLATORS "ISO" is the acronym for "International Standards Organisation" + return _("ISO"); + case LOCALE: + return _("Locale"); + case INFORMAL: + return _("Informal"); + default: + assert_not_reached (); + } + } + + public static DateFormatMode from_string (string format) { + var fmt = format.down (); + switch (fmt) { + case "iso": + ///TRANSLATORS "ISO" is the acronym for "International Standards Organisation" + return ISO; + case "locale": + return LOCALE; + case "informal": + return INFORMAL; + default: + assert_not_reached (); + } + } + } + } diff --git a/src/View/Widgets/AppMenu.vala b/src/View/Widgets/AppMenu.vala index 86d0244374..32b23932ba 100644 --- a/src/View/Widgets/AppMenu.vala +++ b/src/View/Widgets/AppMenu.vala @@ -112,6 +112,21 @@ public class Files.AppMenu : Gtk.Popover { }; show_remote_thumbnails.get_style_context ().add_class (Gtk.STYLE_CLASS_MENUITEM); + ///TRANSLATORS The format of the date (possibly with time) shown in the Modified column of the file view + var datetimeformat_label = new Gtk.Label (_("Date & Time Format")); + var datetimeformat_combo = new Gtk.ComboBoxText (); + datetimeformat_combo.append_text (DateFormatMode.ISO.to_string ()); + datetimeformat_combo.append_text (DateFormatMode.LOCALE.to_string ()); + datetimeformat_combo.append_text (DateFormatMode.INFORMAL.to_string ()); + //TODO Add a custom format wizard? Or a detailed informat format? Or "days ago" format? + datetimeformat_combo.active = (int) DateFormatMode.from_string (Files.Preferences.get_default ().date_format.down ()); + + var datetimeformat_box = new Gtk.Box (HORIZONTAL, 6); + datetimeformat_box.add (datetimeformat_label); + datetimeformat_box.add (datetimeformat_combo); + + datetimeformat_box.get_style_context ().add_class ("menuitem"); + var menu_box = new Gtk.Box (VERTICAL, 0) { margin_bottom = 6 }; @@ -126,6 +141,8 @@ public class Files.AppMenu : Gtk.Popover { menu_box.add (show_hidden_button); menu_box.add (show_local_thumbnails); menu_box.add (show_remote_thumbnails); + menu_box.add (new Gtk.Separator (HORIZONTAL) { margin_top = 3, margin_bottom = 3 }); + menu_box.add (datetimeformat_box); menu_box.show_all (); child = menu_box; From 3175dcdc2a85600af8245d39fcd35b9c2d0ab37d Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 4 Jul 2025 17:16:52 +0100 Subject: [PATCH 2/6] Sync with settings --- src/View/Widgets/AppMenu.vala | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/View/Widgets/AppMenu.vala b/src/View/Widgets/AppMenu.vala index 32b23932ba..5d4cb7e8f3 100644 --- a/src/View/Widgets/AppMenu.vala +++ b/src/View/Widgets/AppMenu.vala @@ -9,6 +9,7 @@ public class Files.AppMenu : Gtk.Popover { private Gtk.Button zoom_default_button; private Gtk.Button zoom_in_button; private Gtk.Button zoom_out_button; + private Gtk.ComboBoxText datetimeformat_combo; private string[] redo_accels; private string[] undo_accels; private unowned UndoManager undo_manager; @@ -114,7 +115,7 @@ public class Files.AppMenu : Gtk.Popover { ///TRANSLATORS The format of the date (possibly with time) shown in the Modified column of the file view var datetimeformat_label = new Gtk.Label (_("Date & Time Format")); - var datetimeformat_combo = new Gtk.ComboBoxText (); + datetimeformat_combo = new Gtk.ComboBoxText (); datetimeformat_combo.append_text (DateFormatMode.ISO.to_string ()); datetimeformat_combo.append_text (DateFormatMode.LOCALE.to_string ()); datetimeformat_combo.append_text (DateFormatMode.INFORMAL.to_string ()); @@ -156,6 +157,11 @@ public class Files.AppMenu : Gtk.Popover { Files.icon_view_settings.changed["zoom-level"].connect (on_zoom_setting_changed); Files.list_view_settings.changed["zoom-level"].connect (on_zoom_setting_changed); Files.column_view_settings.changed["zoom-level"].connect (on_zoom_setting_changed); + app_settings.changed["date-format"].connect (on_dateformat_setting_changed); + + datetimeformat_combo.changed.connect (() => { + app_settings.set_enum ("date-format", datetimeformat_combo.active); + }); } private void set_undo_redo_tooltips () { @@ -194,4 +200,8 @@ public class Files.AppMenu : Gtk.Popover { zoom_in_button.sensitive = zoom_level < max_zoom; zoom_out_button.sensitive = zoom_level > min_zoom; } + + private void on_dateformat_setting_changed (Settings settings, string key) { + datetimeformat_combo.active = settings.get_enum (key); + } } From 576925b64970143dbd90eaef94aa0d54d5f172f0 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 4 Jul 2025 17:24:37 +0100 Subject: [PATCH 3/6] React to external changes --- src/View/AbstractDirectoryView.vala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/View/AbstractDirectoryView.vala b/src/View/AbstractDirectoryView.vala index b6e6529bb8..e2f231ff3c 100644 --- a/src/View/AbstractDirectoryView.vala +++ b/src/View/AbstractDirectoryView.vala @@ -409,6 +409,7 @@ namespace Files { prefs.notify["show-remote-thumbnails"].connect (on_show_thumbnails_changed); prefs.notify["show-local-thumbnails"].connect (on_show_thumbnails_changed); prefs.notify["sort-directories-first"].connect (on_sort_directories_first_changed); + prefs.notify["date-format"].connect (on_dateformat_changed); prefs.bind_property ( "singleclick-select", this, "singleclick_select", BindingFlags.DEFAULT | BindingFlags.SYNC_CREATE ); @@ -1455,6 +1456,10 @@ namespace Files { dir.load_hiddens (); } + private void on_dateformat_changed () { + slot.reload (); + } + /** Handle popup menu events */ private bool on_popup_menu () { Gdk.Event event = Gtk.get_current_event (); From 5ac07b5262d978557a248fb995f24a554f6ad10d Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 4 Jul 2025 19:09:42 +0100 Subject: [PATCH 4/6] Date format in Preferences as enum --- libcore/FileUtils.vala | 6 +++--- libcore/Preferences.vala | 2 +- src/View/Widgets/AppMenu.vala | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libcore/FileUtils.vala b/libcore/FileUtils.vala index a42562bf60..1a8849ec1c 100644 --- a/libcore/FileUtils.vala +++ b/libcore/FileUtils.vala @@ -631,10 +631,10 @@ namespace Files.FileUtils { return ""; } - switch (Files.Preferences.get_default ().date_format.down ()) { - case "locale": + switch (Files.Preferences.get_default ().date_format) { + case DateFormatMode.LOCALE: return dt.format ("%c"); - case "iso" : + case DateFormatMode.ISO : return dt.format ("%Y-%m-%d %H:%M:%S"); default: return get_informal_date_time (dt); diff --git a/libcore/Preferences.vala b/libcore/Preferences.vala index 0bff19b3b9..0f8f8352b4 100644 --- a/libcore/Preferences.vala +++ b/libcore/Preferences.vala @@ -34,7 +34,7 @@ namespace Files { public bool sort_directories_first { get; set; default = true; } public bool remember_history { get; set; default = true; } - public string date_format {set; get; default = "iso";} + public DateFormatMode date_format {set; get; default = DateFormatMode.ISO;} public string clock_format {set; get; default = "24h";} public static Preferences get_default () { diff --git a/src/View/Widgets/AppMenu.vala b/src/View/Widgets/AppMenu.vala index 5d4cb7e8f3..7814714f2e 100644 --- a/src/View/Widgets/AppMenu.vala +++ b/src/View/Widgets/AppMenu.vala @@ -120,7 +120,7 @@ public class Files.AppMenu : Gtk.Popover { datetimeformat_combo.append_text (DateFormatMode.LOCALE.to_string ()); datetimeformat_combo.append_text (DateFormatMode.INFORMAL.to_string ()); //TODO Add a custom format wizard? Or a detailed informat format? Or "days ago" format? - datetimeformat_combo.active = (int) DateFormatMode.from_string (Files.Preferences.get_default ().date_format.down ()); + datetimeformat_combo.active = (int) Files.Preferences.get_default ().date_format; var datetimeformat_box = new Gtk.Box (HORIZONTAL, 6); datetimeformat_box.add (datetimeformat_label); From 18a07c4d456a9a11cf05fa374c7910bfcdc8c5dd Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 4 Jul 2025 20:20:05 +0100 Subject: [PATCH 5/6] Add a compact date format --- data/schemas/io.elementary.files.gschema.xml | 1 + libcore/Enums.vala | 6 +++++- libcore/FileUtils.vala | 3 +++ src/View/Widgets/AppMenu.vala | 7 ++++--- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/data/schemas/io.elementary.files.gschema.xml b/data/schemas/io.elementary.files.gschema.xml index 2ee79022a3..e400caabdc 100644 --- a/data/schemas/io.elementary.files.gschema.xml +++ b/data/schemas/io.elementary.files.gschema.xml @@ -20,6 +20,7 @@ + diff --git a/libcore/Enums.vala b/libcore/Enums.vala index ff48a52bdd..abe3dc845e 100644 --- a/libcore/Enums.vala +++ b/libcore/Enums.vala @@ -258,7 +258,9 @@ namespace Files { public enum DateFormatMode { ISO, LOCALE, - INFORMAL; + INFORMAL, + COMPACT, + INVALID; public string to_string () { switch (this) { @@ -269,6 +271,8 @@ namespace Files { return _("Locale"); case INFORMAL: return _("Informal"); + case COMPACT: + return _("Compact"); default: assert_not_reached (); } diff --git a/libcore/FileUtils.vala b/libcore/FileUtils.vala index 1a8849ec1c..8264989d6b 100644 --- a/libcore/FileUtils.vala +++ b/libcore/FileUtils.vala @@ -636,6 +636,9 @@ namespace Files.FileUtils { return dt.format ("%c"); case DateFormatMode.ISO : return dt.format ("%Y-%m-%d %H:%M:%S"); + case DateFormatMode.COMPACT : + var locale_format_string = Posix.nl_langinfo (D_FMT); + return dt.format (locale_format_string.down ()); default: return get_informal_date_time (dt); } diff --git a/src/View/Widgets/AppMenu.vala b/src/View/Widgets/AppMenu.vala index 7814714f2e..009773af6c 100644 --- a/src/View/Widgets/AppMenu.vala +++ b/src/View/Widgets/AppMenu.vala @@ -116,9 +116,10 @@ public class Files.AppMenu : Gtk.Popover { ///TRANSLATORS The format of the date (possibly with time) shown in the Modified column of the file view var datetimeformat_label = new Gtk.Label (_("Date & Time Format")); datetimeformat_combo = new Gtk.ComboBoxText (); - datetimeformat_combo.append_text (DateFormatMode.ISO.to_string ()); - datetimeformat_combo.append_text (DateFormatMode.LOCALE.to_string ()); - datetimeformat_combo.append_text (DateFormatMode.INFORMAL.to_string ()); + for (uint dfm = 0; dfm < DateFormatMode.INVALID; dfm++) { + datetimeformat_combo.append_text (((DateFormatMode) dfm).to_string ()); + } + //TODO Add a custom format wizard? Or a detailed informat format? Or "days ago" format? datetimeformat_combo.active = (int) Files.Preferences.get_default ().date_format; From 52eb858627d1f82164be13327511dc6f72fc23ee Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 4 Jul 2025 20:34:34 +0100 Subject: [PATCH 6/6] Add time --- libcore/FileUtils.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcore/FileUtils.vala b/libcore/FileUtils.vala index 8264989d6b..7e4d44d0d6 100644 --- a/libcore/FileUtils.vala +++ b/libcore/FileUtils.vala @@ -638,7 +638,7 @@ namespace Files.FileUtils { return dt.format ("%Y-%m-%d %H:%M:%S"); case DateFormatMode.COMPACT : var locale_format_string = Posix.nl_langinfo (D_FMT); - return dt.format (locale_format_string.down ()); + return dt.format (string.join (" ", locale_format_string.down (), "%H:%M")); default: return get_informal_date_time (dt); }