messageTray: Add removeAction() method and allow references to actions

Internally in gnome-shell it may be useful to modify the actions
available on a notification while it’s still visible, but without
clearing them all and re-creating them.

Allow that by returning the action object when adding it, and adding a
`removeAction()` method which takes that object and removes it.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3251>
This commit is contained in:
Philip Withnall 2024-05-28 18:03:11 +01:00
parent e9ca27c663
commit 03e3d9f435

View File

@ -439,6 +439,16 @@ export class Notification extends GObject.Object {
});
this._actions.push(action);
this.emit('action-added', action);
return action;
}
removeAction(action) {
const index = this._actions.indexOf(action);
if (index < 0)
throw new Error('Action was already removed previously');
this._actions.splice(index, 1);
this.emit('action-removed', action);
}
clearActions() {