Skip to content

Commit

Permalink
feat: all delete all for completed view
Browse files Browse the repository at this point in the history
  • Loading branch information
alainm23 committed May 18, 2024
1 parent 0eeb5c2 commit e79a77f
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 5 deletions.
13 changes: 13 additions & 0 deletions core/Services/Database.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,19 @@ public class Services.Database : GLib.Object {
}
}

public Gee.ArrayList<Objects.Item> get_items_checked () {
Gee.ArrayList<Objects.Item> return_value = new Gee.ArrayList<Objects.Item> ();
lock (_items) {
foreach (Objects.Item item in items) {
if (item.checked) {
return_value.add (item);
}
}

return return_value;
}
}

public Objects.Item _fill_item (Sqlite.Statement stmt) {
Objects.Item return_value = new Objects.Item ();
return_value.id = stmt.column_text (0);
Expand Down
3 changes: 2 additions & 1 deletion src/Layouts/ItemRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ public class Layouts.ItemRow : Layouts.ItemBase {
project_label = new Gtk.Label (null) {
css_classes = { "caption", "dim-label" },
margin_start = 6,
ellipsize = Pango.EllipsizeMode.END
ellipsize = Pango.EllipsizeMode.END,
max_width_chars = 16
};

project_label_revealer = new Gtk.Revealer () {
Expand Down
64 changes: 63 additions & 1 deletion src/Views/Filter.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Views.Filter : Adw.Bin {
private Adw.Bin listbox_content;
private Gtk.Stack listbox_stack;
private Widgets.MagicButton magic_button;
private Gtk.Revealer view_setting_revealer;

private Gee.HashMap <string, Layouts.ItemRow> items = new Gee.HashMap <string, Layouts.ItemRow> ();

Expand All @@ -47,8 +48,24 @@ public class Views.Filter : Adw.Bin {
}
}

construct {
construct {
var view_setting_button = new Gtk.MenuButton () {
valign = Gtk.Align.CENTER,
halign = Gtk.Align.CENTER,
margin_end = 12,
popover = build_view_setting_popover (),
icon_name = "view-sort-descending-rtl-symbolic",
css_classes = { "flat" },
tooltip_text = _("View Option Menu")
};

view_setting_revealer = new Gtk.Revealer () {
transition_type = Gtk.RevealerTransitionType.CROSSFADE,
child = view_setting_button
};

headerbar = new Layouts.HeaderBar ();
headerbar.pack_end (view_setting_revealer);

listbox = new Gtk.ListBox () {
valign = Gtk.Align.START,
Expand Down Expand Up @@ -208,6 +225,8 @@ public class Views.Filter : Adw.Bin {
listbox_content.margin_top = 12;
magic_button.visible = true;
}

view_setting_revealer.reveal_child = filter is Objects.Filters.Completed;
}

private void add_items () {
Expand Down Expand Up @@ -473,4 +492,47 @@ public class Views.Filter : Adw.Bin {

return header_box;
}

private Gtk.Popover build_view_setting_popover () {
var delete_all_completed = new Widgets.ContextMenu.MenuItem (_("Delete All Completed Tasks") ,"user-trash-symbolic");
delete_all_completed.add_css_class ("menu-item-danger");

var menu_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
menu_box.margin_top = menu_box.margin_bottom = 3;
menu_box.append (delete_all_completed);

var popover = new Gtk.Popover () {
has_arrow = false,
position = Gtk.PositionType.BOTTOM,
child = menu_box,
width_request = 250
};

delete_all_completed.activate_item.connect (() => {
popover.popdown ();

var items = Services.Database.get_default ().get_items_checked ();

var dialog = new Adw.AlertDialog (
_("Delete All Completed Tasks"),
_("This will delete %d completed tasks and their subtasks".printf (items.size))
);

dialog.body_use_markup = true;
dialog.add_response ("cancel", _("Cancel"));
dialog.add_response ("delete", _("Delete"));
dialog.set_response_appearance ("delete", Adw.ResponseAppearance.DESTRUCTIVE);
dialog.present (Planify._instance.main_window);

dialog.response.connect ((response) => {
if (response == "delete") {
foreach (Objects.Item item in items) {
item.delete_item ();
}
}
});
});

return popover;
}
}
2 changes: 1 addition & 1 deletion src/Views/Project/Project.vala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class Views.Project : Adw.Bin {
popover = build_view_setting_popover (),
icon_name = "view-sort-descending-rtl-symbolic",
css_classes = { "flat" },
tooltip_text = _("View option menu")
tooltip_text = _("View Option Menu")
};

var view_setting_overlay = new Gtk.Overlay ();
Expand Down
2 changes: 1 addition & 1 deletion src/Views/Scheduled/Scheduled.vala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class Views.Scheduled.Scheduled : Adw.Bin {
popover = build_view_setting_popover (),
icon_name = "view-sort-descending-rtl-symbolic",
css_classes = { "flat" },
tooltip_text = _("View option menu")
tooltip_text = _("View Option Menu")
};

var view_setting_overlay = new Gtk.Overlay ();
Expand Down
2 changes: 1 addition & 1 deletion src/Views/Today.vala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class Views.Today : Adw.Bin {
popover = build_view_setting_popover (),
icon_name = "view-sort-descending-rtl-symbolic",
css_classes = { "flat" },
tooltip_text = _("View option menu")
tooltip_text = _("View Option Menu")
};

var view_setting_overlay = new Gtk.Overlay ();
Expand Down

0 comments on commit e79a77f

Please sign in to comment.