diff --git a/src/Indicator.vala b/src/Indicator.vala index b10541b4..ae134de5 100644 --- a/src/Indicator.vala +++ b/src/Indicator.vala @@ -62,8 +62,12 @@ public class Notifications.Indicator : Wingpanel.Indicator { var clear_all_action = new SimpleAction ("clear-all", null); clear_all_action.activate.connect (clear_all); + var clear_app_action = new SimpleAction ("clear-app", VariantType.STRING); + clear_app_action.activate.connect (clear_app); + action_group = new SimpleActionGroup (); action_group.add_action (clear_all_action); + action_group.add_action (clear_app_action); } public override Gtk.Widget get_display_widget () { @@ -154,14 +158,14 @@ public class Notifications.Indicator : Wingpanel.Indicator { } private void remove_notification (Notification notification) { - var app_id = notification.desktop_id; + Session.get_instance ().remove_notification (notification); uint pos = -1; if (list_store.find (notification, out pos)) { list_store.remove (pos); - Session.get_instance ().remove_notification (notification); } + var app_id = notification.desktop_id; var items_for_appid = new Gtk.FilterListModel ( list_store, new Gtk.CustomFilter ((item) => { return ((Notification) item).desktop_id == app_id; @@ -197,6 +201,19 @@ public class Notifications.Indicator : Wingpanel.Indicator { close (); } + private void clear_app (SimpleAction action, Variant? parameter) { + var app_id = parameter.get_string (); + for (int i = 0; i < list_store.n_items; i++) { + var notification = (Notification) list_store.get_item (i); + if (notification.desktop_id == app_id) { + // Wait so that the header won't be removed before its animation finishes + Timeout.add_once (600, () => { + remove_notification (notification); + }); + } + } + } + private void set_display_icon_name () { if (notify_settings.get_boolean ("do-not-disturb")) { dynamic_icon.state = NotificationsIndicator.SymbolState.DISABLED; diff --git a/src/Widgets/ListHeader.vala b/src/Widgets/ListHeader.vala index cb5e1ca3..3b24421d 100644 --- a/src/Widgets/ListHeader.vala +++ b/src/Widgets/ListHeader.vala @@ -4,8 +4,6 @@ */ public class Notifications.ListHeader : Granite.Bin { - public signal void clear (); - private string _app_id = ""; public string app_id { get { @@ -14,6 +12,11 @@ public class Notifications.ListHeader : Granite.Bin { set { _app_id = value; + if (value != null) { + clear_btn_entry.action_target = new Variant.string (value); + } + + if (value in headers) { expander.active = headers[value]; } @@ -26,6 +29,7 @@ public class Notifications.ListHeader : Granite.Bin { private static Settings settings; private static HashTable headers; + private Gtk.Button clear_btn_entry; private Gtk.ToggleButton expander; static construct { @@ -64,7 +68,8 @@ public class Notifications.ListHeader : Granite.Bin { var clear_btn_image = new Gtk.Image.from_icon_name ("edit-clear-all-symbolic"); clear_btn_image.add_css_class ("sweep-animation"); - var clear_btn_entry = new Gtk.Button () { + clear_btn_entry = new Gtk.Button () { + action_name = Wingpanel.Indicator.MESSAGES + ".clear-app", tooltip_text = _("Clear all %s notifications").printf (app_name), child = clear_btn_image, has_frame = false @@ -80,11 +85,12 @@ public class Notifications.ListHeader : Granite.Bin { bind_property ("app-name", label, "label"); bind_property ("app-name", clear_btn_entry, "tooltip-text", DEFAULT, - (binding, _app_name, ref _tooltip_text) => { - _tooltip_text = _("Clear all %s notifications").printf ((string) _app_name); - return true; - }, - () => { return false; }); + (binding, _app_name, ref _tooltip_text) => { + _tooltip_text = _("Clear all %s notifications").printf ((string) _app_name); + return true; + }, + () => { return false; } + ); expander.toggled.connect (() => { headers[app_id] = expander.active; @@ -93,10 +99,6 @@ public class Notifications.ListHeader : Granite.Bin { clear_btn_entry.clicked.connect (() => { clear_btn_image.add_css_class ("active"); - GLib.Timeout.add (600, () => { - clear (); // Causes notification list to destroy this app entry after clearing its notification entries - return GLib.Source.REMOVE; - }); }); expander.bind_property ("active", image, "tooltip-text", SYNC_CREATE, (binding, srcval, ref targetval) => { diff --git a/src/Widgets/NotificationsList.vala b/src/Widgets/NotificationsList.vala index 31c7de96..c7fe34bb 100644 --- a/src/Widgets/NotificationsList.vala +++ b/src/Widgets/NotificationsList.vala @@ -124,10 +124,7 @@ public class Notifications.NotificationsList : Granite.Bin { } private void setup_header_factory (Object item) { - var app_entry = new ListHeader (); - app_entry.clear.connect (clear_app_entry); - - ((Gtk.ListHeader) item).child = app_entry; + ((Gtk.ListHeader) item).child = new ListHeader (); } private void bind_header_factory (Object item) { @@ -152,21 +149,6 @@ public class Notifications.NotificationsList : Granite.Bin { }); } - private void clear_app_entry (ListHeader app_entry) { - app_entry.clear.disconnect (clear_app_entry); - - Notification[] to_remove = {}; - for (int i = 0; i < list_model.get_n_items (); i++) { - var notification = (Notification) list_model.get_item (i); - if (notification.desktop_id == app_entry.app_id) { - notification.server_id = 0; - to_remove += notification; - } - } - - Session.get_instance ().remove_notifications (to_remove); - } - private void on_items_changed () { if (list_model.get_n_items () == 0) { stack.visible_child_name = "placeholder";