Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load only non-completed tasks by default #295

Merged
merged 6 commits into from
Sep 24, 2021
Merged
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/tasks.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<li>Fix an issue where an account name header could be displayed multiple times in the sidebar</li>
<li>Fix an issue with long descriptions being truncated at the beginning instead of the end</li>
<li>Fix an issue where removing descriptions wasn't saved</li>
<li>Improve performance in lists with lots of completed tasks</li>
<li>Updated translations</li>
</ul>
</description>
Expand Down
59 changes: 33 additions & 26 deletions src/Widgets/TaskListGrid.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
public E.Source source { get; construct; }
private ECal.ClientView view;
private ECal.ClientView? view = null;

private EditableLabel editable_title;
private Gtk.ListBox add_task_list;
Expand All @@ -32,17 +32,6 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
}

construct {
try {
view = Tasks.Application.model.create_task_list_view (
source,
"(contains? 'any' '')",
on_tasks_added,
on_tasks_modified,
on_tasks_removed );
} catch (Error e) {
critical ("Error creating view for source %s: %s", source.display_name, e.message);
}

E.SourceRegistry? registry = null;
try {
registry = Application.model.get_registry_sync ();
Expand Down Expand Up @@ -115,7 +104,6 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
selection_mode = Gtk.SelectionMode.MULTIPLE,
activate_on_single_click = true
};
task_list.set_filter_func (filter_function);
task_list.set_placeholder (placeholder);
task_list.set_sort_func (sort_function);
task_list.get_style_context ().add_class (Gtk.STYLE_CLASS_BACKGROUND);
Expand All @@ -133,8 +121,9 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
attach (scrolled_window, 0, 2, 2);

Application.settings.changed["show-completed"].connect (() => {
task_list.invalidate_filter ();
on_show_completed_changed (Application.settings.get_boolean ("show-completed"));
});
on_show_completed_changed (Application.settings.get_boolean ("show-completed"));

settings_button.toggled.connect (() => {
unowned GLib.ActionMap win_action_map = (GLib.ActionMap) get_action_group (MainWindow.ACTION_GROUP_PREFIX);
Expand Down Expand Up @@ -201,6 +190,36 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
show_all ();
}

private void on_show_completed_changed (bool show_completed) {
if (show_completed) {
set_view_for_query ("(contains? 'any' '')");
} else {
set_view_for_query ("NOT is-completed?");
}
}

private void set_view_for_query (string query) {
var children = task_list.get_children ();
foreach (unowned var child in children) {
task_list.remove (child);
}

if (view != null) {
Application.model.destroy_task_list_view (view);
}

try {
view = Tasks.Application.model.create_task_list_view (
source,
query,
on_tasks_added,
on_tasks_modified,
on_tasks_removed );
} catch (Error e) {
critical ("Error creating view with query for source %s[%s]: %s", source.display_name, query, e.message);
}
}

private void on_row_activated (Gtk.ListBoxRow row) {
var task_row = (Tasks.Widgets.TaskRow) row;
task_row.reveal_child_request (true);
Expand Down Expand Up @@ -237,18 +256,6 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
});
}

[CCode (instance_pos = -1)]
private bool filter_function (Gtk.ListBoxRow row) {
if (
Application.settings.get_boolean ("show-completed") == false &&
((TaskRow) row).completed
) {
return false;
}

return true;
}

[CCode (instance_pos = -1)]
private int sort_function (Gtk.ListBoxRow row1, Gtk.ListBoxRow row2) {
var row_a = (Tasks.Widgets.TaskRow) row1;
Expand Down