36 {
37
38 log_debug(
"MiscBox: init_date_format_option()");
39 add_label_header(box,
_(
"Date Format"),
false);
40
41 var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 6);
42 box.append(hbox);
43
44 var combo = new Gtk.ComboBoxText();
45 combo.hexpand = true;
46 hbox.append(combo);
47
48 var entry = new Gtk.Entry();
49 entry.hexpand = true;
50 hbox.append(entry);
51
52 var
now =
new DateTime.local(2019, 8, 11, 20, 25, 43);
53 string[] formats = {
54 "",
55 "%Y-%m-%d %H:%M:%S",
56 "%Y-%m-%d %I:%M %p",
57 "%d %b %Y %I:%M %p",
58 "%Y %b %d, %I:%M %p",
59 "%c"
60 };
61
62 int active = 0;
63 for (int i = 0; i < formats.length; i++){
64 string fmt = formats[i];
65 string preview = (fmt.length == 0) ?
_(
"Custom") :
now.format(fmt);
66 combo.append_text(preview);
68 active = i;
69 }
70 }
71 combo.active = active;
72
73 combo.changed.connect(() => {
74 int idx = combo.get_active();
75 if ((idx < 0) || (idx >= formats.length)){
76 return;
77 }
78 string fmt = (formats[
idx].length > 0) ? formats[idx] : Main.date_format_default;
79 entry.text = fmt;
80 entry.sensitive = (formats[
idx].length == 0);
81 App.date_format = fmt;
82 });
83
85 entry.sensitive = (combo.get_active() == 0);
86
87 entry.notify["has-focus"].connect(() => {
88 if (!entry.has_focus){
89 App.date_format = entry.text;
91 }
92 });
93
94 show();
95 log_debug(
"MiscBox: init_date_format_option(): exit");
96 }