Skip to content

Commit 88dde35

Browse files
committed
Fix #1142
1 parent 7cb0823 commit 88dde35

File tree

2 files changed

+133
-8
lines changed

2 files changed

+133
-8
lines changed

src/Views/Project/Project.vala

+2-2
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,8 @@ public class Views.Project : Adw.Bin {
398398
var order_by_model = new Gee.ArrayList<string> ();
399399
order_by_model.add (_("Custom sort order"));
400400
order_by_model.add (_("Alphabetically"));
401-
order_by_model.add (_("Due date"));
402-
order_by_model.add (_("Date added"));
401+
order_by_model.add (_("Due Date"));
402+
order_by_model.add (_("Date Added"));
403403
order_by_model.add (_("Priority"));
404404

405405
var order_by_item = new Widgets.ContextMenu.MenuPicker (_("Order by"), "view-list-ordered-symbolic", order_by_model);

src/Views/Today.vala

+131-6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class Views.Today : Adw.Bin {
3030
private Gtk.Grid listbox_grid;
3131
private Gtk.ScrolledWindow scrolled_window;
3232
private Gtk.Stack listbox_placeholder_stack;
33+
private Gtk.Revealer indicator_revealer;
3334

3435
public Gee.HashMap <string, Layouts.ItemRow> overdue_items;
3536
public Gee.HashMap <string, Layouts.ItemRow> items;
@@ -54,7 +55,36 @@ public class Views.Today : Adw.Bin {
5455
overdue_items = new Gee.HashMap <string, Layouts.ItemRow> ();
5556
items = new Gee.HashMap <string, Layouts.ItemRow> ();
5657

58+
var indicator_grid = new Gtk.Grid () {
59+
width_request = 9,
60+
height_request = 9,
61+
margin_top = 6,
62+
margin_end = 6,
63+
css_classes = { "indicator" }
64+
};
65+
66+
indicator_revealer = new Gtk.Revealer () {
67+
transition_type = Gtk.RevealerTransitionType.CROSSFADE,
68+
child = indicator_grid,
69+
halign = END,
70+
valign = START,
71+
};
72+
73+
var view_setting_button = new Gtk.MenuButton () {
74+
valign = Gtk.Align.CENTER,
75+
halign = Gtk.Align.CENTER,
76+
popover = build_view_setting_popover (),
77+
icon_name = "view-sort-descending-rtl-symbolic",
78+
css_classes = { "flat" },
79+
tooltip_text = _("View option menu")
80+
};
81+
82+
var view_setting_overlay = new Gtk.Overlay ();
83+
view_setting_overlay.child = view_setting_button;
84+
view_setting_overlay.add_overlay (indicator_revealer);
85+
5786
headerbar = new Layouts.HeaderBar ();
87+
headerbar.pack_end (view_setting_overlay);
5888

5989
event_list = new Widgets.EventsList.for_day (date) {
6090
margin_top = 12,
@@ -95,10 +125,10 @@ public class Views.Today : Adw.Bin {
95125
valign = Gtk.Align.START,
96126
activate_on_single_click = true,
97127
selection_mode = Gtk.SelectionMode.SINGLE,
98-
hexpand = true
128+
hexpand = true,
129+
css_classes = { "listbox-background" }
99130
};
100-
101-
overdue_listbox.add_css_class ("listbox-background");
131+
overdue_listbox.set_sort_func (set_sort_func);
102132

103133
var overdue_listbox_grid = new Gtk.Grid () {
104134
margin_top = 6
@@ -156,10 +186,10 @@ public class Views.Today : Adw.Bin {
156186
valign = Gtk.Align.START,
157187
activate_on_single_click = true,
158188
selection_mode = Gtk.SelectionMode.SINGLE,
159-
hexpand = true
189+
hexpand = true,
190+
css_classes = { "listbox-background" }
160191
};
161-
162-
listbox.add_css_class ("listbox-background");
192+
listbox.set_sort_func (set_sort_func);
163193

164194
listbox_grid = new Gtk.Grid () {
165195
margin_top = 6,
@@ -233,6 +263,7 @@ public class Views.Today : Adw.Bin {
233263
child = toolbar_view;
234264
update_today_label ();
235265
add_today_items ();
266+
check_default_view ();
236267

237268
Timeout.add (listbox_placeholder_stack.transition_duration, () => {
238269
check_placeholder ();
@@ -262,6 +293,14 @@ public class Views.Today : Adw.Bin {
262293
magic_button.clicked.connect (() => {
263294
prepare_new_item ();
264295
});
296+
297+
Services.Settings.get_default ().settings.changed.connect ((key) => {
298+
if (key == "today-sort-order") {
299+
listbox.invalidate_sort ();
300+
overdue_listbox.invalidate_sort ();
301+
check_default_view ();
302+
}
303+
});
265304
}
266305

267306
private void check_placeholder () {
@@ -270,6 +309,10 @@ public class Views.Today : Adw.Bin {
270309
} else {
271310
listbox_placeholder_stack.visible_child_name = "placeholder";
272311
}
312+
313+
listbox.invalidate_sort ();
314+
overdue_listbox.invalidate_sort ();
315+
check_default_view ();
273316
}
274317

275318
private void add_today_items () {
@@ -419,4 +462,86 @@ public class Views.Today : Adw.Bin {
419462
));
420463
headerbar.title = "%s <small>%s</small>".printf (today_label, date_format);
421464
}
465+
466+
private Gtk.Popover build_view_setting_popover () {
467+
var order_by_model = new Gee.ArrayList<string> ();
468+
order_by_model.add (_("Due Date"));
469+
order_by_model.add (_("Alphabetically"));
470+
order_by_model.add (_("Date Added"));
471+
order_by_model.add (_("Priority"));
472+
473+
var order_by_item = new Widgets.ContextMenu.MenuPicker (_("Order by"), "view-list-ordered-symbolic", order_by_model);
474+
order_by_item.selected = Services.Settings.get_default ().settings.get_int ("today-sort-order");
475+
476+
var menu_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
477+
menu_box.margin_top = menu_box.margin_bottom = 3;
478+
menu_box.append (order_by_item);
479+
480+
var popover = new Gtk.Popover () {
481+
has_arrow = false,
482+
position = Gtk.PositionType.BOTTOM,
483+
child = menu_box,
484+
width_request = 250
485+
};
486+
487+
order_by_item.notify["selected"].connect (() => {
488+
Services.Settings.get_default ().settings.set_int ("today-sort-order", order_by_item.selected);
489+
});
490+
491+
return popover;
492+
}
493+
494+
private int set_sort_func (Gtk.ListBoxRow lbrow, Gtk.ListBoxRow lbbefore) {
495+
Objects.Item item1 = ((Layouts.ItemRow) lbrow).item;
496+
Objects.Item item2 = ((Layouts.ItemRow) lbbefore).item;
497+
int sort_order = Services.Settings.get_default ().settings.get_int ("today-sort-order");
498+
499+
if (sort_order == 0) {
500+
if (item1.has_due && item2.has_due) {
501+
var date1 = item1.due.datetime;
502+
var date2 = item2.due.datetime;
503+
504+
return date1.compare (date2);
505+
}
506+
507+
if (!item1.has_due && item2.has_due) {
508+
return 1;
509+
}
510+
511+
return 0;
512+
}
513+
514+
if (sort_order == 1) {
515+
return item1.content.strip ().collate (item2.content.strip ());
516+
}
517+
518+
if (sort_order == 2) {
519+
return item1.added_datetime.compare (item2.added_datetime);
520+
}
521+
522+
if (sort_order == 3) {
523+
if (item1.priority < item2.priority) {
524+
return 1;
525+
}
526+
527+
if (item1.priority < item2.priority) {
528+
return -1;
529+
}
530+
531+
return 0;
532+
}
533+
534+
return 0;
535+
}
536+
537+
private void check_default_view () {
538+
bool defaults = true;
539+
int sort_order = Services.Settings.get_default ().settings.get_int ("today-sort-order");
540+
541+
if (sort_order != 0) {
542+
defaults = false;
543+
}
544+
545+
indicator_revealer.reveal_child = !defaults;
546+
}
422547
}

0 commit comments

Comments
 (0)