Skip to content
Open
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
19 changes: 18 additions & 1 deletion src/Views/ListView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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?");
}
}
Expand Down Expand Up @@ -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<ECal.Component> tasks) {
unowned Tasks.Widgets.TaskRow task_row = null;
var row_index = 0;
Expand Down
17 changes: 14 additions & 3 deletions src/Widgets/TaskRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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 ();
Expand Down Expand Up @@ -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;
Expand Down
Loading