diff --git a/src/Views/ListView.vala b/src/Views/ListView.vala index b677bc067..df357c7c0 100644 --- a/src/Views/ListView.vala +++ b/src/Views/ListView.vala @@ -11,6 +11,7 @@ public class Tasks.ListView : Granite.Bin { private Gtk.ListBox add_task_list; private Gtk.ListBox task_list; private bool is_gtasks; + private bool show_completed { get; private set; default = false; } public ListView (E.Source source) { Object (source: source); @@ -174,8 +175,10 @@ public class Tasks.ListView : Granite.Bin { private void on_show_completed_changed (bool show_completed) { if (show_completed) { + this.show_completed = true; set_view_for_query ("(contains? 'any' '')"); } else { + this.show_completed = false; set_view_for_query ("NOT is-completed?"); } } @@ -348,12 +351,26 @@ public class Tasks.ListView : Granite.Bin { }); Idle.add (() => { + remove_checked_items (); task_list.invalidate_sort (); - return Source.REMOVE; }); } + private void remove_checked_items () { + unowned Tasks.Widgets.TaskRow? task_row = null; + var row_index = 0; + do { + task_row = (Tasks.Widgets.TaskRow) task_list.get_row_at_index (row_index); + + if (task_row != null && task_row.completed && !show_completed) { + task_list.remove (task_row); + } else { + row_index++; + } + } while (task_row != null); + } + private void on_tasks_modified (Gee.Collection tasks) { unowned Tasks.Widgets.TaskRow task_row = null; var row_index = 0; diff --git a/src/Widgets/TaskRow.vala b/src/Widgets/TaskRow.vala index 2b41e87db..d8a7aac3b 100644 --- a/src/Widgets/TaskRow.vala +++ b/src/Widgets/TaskRow.vala @@ -16,6 +16,8 @@ public class Tasks.Widgets.TaskRow : Gtk.ListBoxRow { public bool is_scheduled_view { get; construct; } private bool created; + // Set while the check state is synced from the backend, so we don't request a completion change in return + private bool syncing_check { get; private set; default = false; } private Tasks.Widgets.EntryPopover.DateTime due_datetime_popover; private Gtk.Revealer due_datetime_popover_revealer; @@ -53,6 +55,8 @@ public class Tasks.Widgets.TaskRow : Gtk.ListBoxRow { } construct { + + created = calcomponent_created (task); // GTasks tasks only have date on due time, so only show the date @@ -288,7 +292,7 @@ public class Tasks.Widgets.TaskRow : Gtk.ListBoxRow { add_controller (key_controller); check.toggled.connect (() => { - if (task == null) { + if (task == null || syncing_check) { return; } task_completed (task); @@ -412,7 +416,7 @@ public class Tasks.Widgets.TaskRow : Gtk.ListBoxRow { state_stack.set_visible_child (icon); completed = false; - check.active = completed; + set_check_active (completed); summary_entry.text = ""; summary_entry.remove_css_class (Granite.STYLE_CLASS_DIM_LABEL); summary_entry.has_frame = true; @@ -430,7 +434,7 @@ public class Tasks.Widgets.TaskRow : Gtk.ListBoxRow { unowned ICal.Component ical_task = task.get_icalcomponent (); completed = ical_task.get_status () == ICal.PropertyStatus.COMPLETED; - check.active = completed; + set_check_active (completed); if (ical_task.get_description () != null) { description_textbuffer.text = ical_task.get_description (); @@ -484,6 +488,13 @@ public class Tasks.Widgets.TaskRow : Gtk.ListBoxRow { } } + private void set_check_active (bool active) { + + syncing_check = true; + check.active = active; + syncing_check = false; + } + private void task_details_reveal_request (bool value) { description_label_revealer.reveal_child = value && description_label.label != null && description_label.label.strip ().length > 0; due_datetime_popover_revealer.reveal_child = !value || due_datetime_popover.value != null;