Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/schemas/io.elementary.files.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<value value="0" nick="iso"/>
<value value="1" nick="locale"/>
<value value="2" nick="informal"/>
<value value="3" nick="compact"/>
</enum>
<enum id="windowstate">
<value value="0" nick="normal"/>
Expand Down
41 changes: 41 additions & 0 deletions libcore/Enums.vala
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,45 @@ namespace Files {
}
}
}

// Matches settings enum for format of datetimes in view
public enum DateFormatMode {
ISO,
LOCALE,
INFORMAL,
COMPACT,
INVALID;

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");
case COMPACT:
return _("Compact");
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 ();
}
}
}

}
9 changes: 6 additions & 3 deletions libcore/FileUtils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -631,11 +631,14 @@ 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");
case DateFormatMode.COMPACT :
var locale_format_string = Posix.nl_langinfo (D_FMT);
return dt.format (string.join (" ", locale_format_string.down (), "%H:%M"));
default:
return get_informal_date_time (dt);
}
Expand Down
2 changes: 1 addition & 1 deletion libcore/Preferences.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
5 changes: 5 additions & 0 deletions src/View/AbstractDirectoryView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down Expand Up @@ -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 ();
Expand Down
28 changes: 28 additions & 0 deletions src/View/Widgets/AppMenu.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -112,6 +113,22 @@ 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"));
datetimeformat_combo = new Gtk.ComboBoxText ();
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;

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
};
Expand All @@ -126,6 +143,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;
Expand All @@ -139,6 +158,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 () {
Expand Down Expand Up @@ -177,4 +201,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);
}
}