messageTray: Add action-added/action-removed signals to Notification
Add signals so that the message actor can update the it's action when they change. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3173>
This commit is contained in:
parent
6d6ac1372a
commit
7ff5f4ea51
@ -333,6 +333,24 @@ class Sound extends GObject.Object {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const Action = GObject.registerClass(
|
||||||
|
class Action extends GObject.Object {
|
||||||
|
constructor(label, callback) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this._label = label;
|
||||||
|
this._callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
get label() {
|
||||||
|
return this._label;
|
||||||
|
}
|
||||||
|
|
||||||
|
activate() {
|
||||||
|
this._callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Notification:
|
// Notification:
|
||||||
// @source: the notification's Source
|
// @source: the notification's Source
|
||||||
// @title: the title
|
// @title: the title
|
||||||
@ -393,6 +411,8 @@ export const Notification = GObject.registerClass({
|
|||||||
false),
|
false),
|
||||||
},
|
},
|
||||||
Signals: {
|
Signals: {
|
||||||
|
'action-added': {param_types: [Action]},
|
||||||
|
'action-removed': {param_types: [Action]},
|
||||||
'activated': {},
|
'activated': {},
|
||||||
'destroy': {param_types: [GObject.TYPE_UINT]},
|
'destroy': {param_types: [GObject.TYPE_UINT]},
|
||||||
'updated': {param_types: [GObject.TYPE_BOOLEAN]},
|
'updated': {param_types: [GObject.TYPE_BOOLEAN]},
|
||||||
@ -453,7 +473,7 @@ export const Notification = GObject.registerClass({
|
|||||||
this.gicon = params.gicon;
|
this.gicon = params.gicon;
|
||||||
|
|
||||||
if (params.clear)
|
if (params.clear)
|
||||||
this.actions = [];
|
this.clearActions();
|
||||||
|
|
||||||
if (this.sound !== params.sound) {
|
if (this.sound !== params.sound) {
|
||||||
this.sound = params.sound;
|
this.sound = params.sound;
|
||||||
@ -478,7 +498,19 @@ export const Notification = GObject.registerClass({
|
|||||||
// @label: the label for the action's button
|
// @label: the label for the action's button
|
||||||
// @callback: the callback for the action
|
// @callback: the callback for the action
|
||||||
addAction(label, callback) {
|
addAction(label, callback) {
|
||||||
this.actions.push({label, callback});
|
const action = new Action(label, callback);
|
||||||
|
this.actions.push(action);
|
||||||
|
this.emit('action-added', action);
|
||||||
|
}
|
||||||
|
|
||||||
|
clearActions() {
|
||||||
|
if (this.actions.length === 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.actions.forEach(action => {
|
||||||
|
this.emit('action-removed', action);
|
||||||
|
});
|
||||||
|
this.actions = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
setUrgency(urgency) {
|
setUrgency(urgency) {
|
||||||
@ -573,7 +605,7 @@ export const NotificationBanner = GObject.registerClass({
|
|||||||
|
|
||||||
_addActions() {
|
_addActions() {
|
||||||
this.notification.actions.forEach(action => {
|
this.notification.actions.forEach(action => {
|
||||||
this.addAction(action.label, action.callback);
|
this.addAction(action.label, () => action.activate());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user