messageTray: Split out addButton to allow consumers to pass a pre-made button

Some consumers may want to construct their buttons specially, so allow them
to do that by adding a new API that takes a button instead of a label.

https://bugzilla.gnome.org/show_bug.cgi?id=710137
This commit is contained in:
Jasper St. Pierre 2013-10-13 23:08:16 -04:00
parent 88d0731d80
commit 5023542882
5 changed files with 40 additions and 36 deletions

View File

@ -1095,8 +1095,8 @@ const RoomInviteNotification = new Lang.Class({
* for example. */ * for example. */
this.addBody(_("%s is inviting you to join %s").format(inviter.get_alias(), channel.get_identifier())); this.addBody(_("%s is inviting you to join %s").format(inviter.get_alias(), channel.get_identifier()));
this.addButton('decline', _("Decline")); this.addAction('decline', _("Decline"));
this.addButton('accept', _("Accept")); this.addAction('accept', _("Accept"));
this.connect('action-invoked', Lang.bind(this, function(self, action) { this.connect('action-invoked', Lang.bind(this, function(self, action) {
switch (action) { switch (action) {
@ -1136,9 +1136,9 @@ const AudioVideoNotification = new Lang.Class({
this.setUrgency(MessageTray.Urgency.CRITICAL); this.setUrgency(MessageTray.Urgency.CRITICAL);
this.addButton('reject', _("Decline")); this.addAction('reject', _("Decline"));
/* translators: this is a button label (verb), not a noun */ /* translators: this is a button label (verb), not a noun */
this.addButton('answer', _("Answer")); this.addAction('answer', _("Answer"));
this.connect('action-invoked', Lang.bind(this, function(self, action) { this.connect('action-invoked', Lang.bind(this, function(self, action) {
switch (action) { switch (action) {
@ -1176,8 +1176,8 @@ const FileTransferNotification = new Lang.Class({
{ customContent: true }); { customContent: true });
this.setResident(true); this.setResident(true);
this.addButton('decline', _("Decline")); this.addAction('decline', _("Decline"));
this.addButton('accept', _("Accept")); this.addAction('accept', _("Accept"));
this.connect('action-invoked', Lang.bind(this, function(self, action) { this.connect('action-invoked', Lang.bind(this, function(self, action) {
switch (action) { switch (action) {
@ -1239,8 +1239,8 @@ const SubscriptionRequestNotification = new Lang.Class({
this.addActor(layout); this.addActor(layout);
this.addButton('decline', _("Decline")); this.addAction('decline', _("Decline"));
this.addButton('accept', _("Accept")); this.addAction('accept', _("Accept"));
this.connect('action-invoked', Lang.bind(this, function(self, action) { this.connect('action-invoked', Lang.bind(this, function(self, action) {
switch (action) { switch (action) {
@ -1358,7 +1358,7 @@ const AccountNotification = new Lang.Class({
this._account = account; this._account = account;
this.addButton('view', _("View account")); this.addAction('view', _("View account"));
this.connect('action-invoked', Lang.bind(this, function(self, action) { this.connect('action-invoked', Lang.bind(this, function(self, action) {
switch (action) { switch (action) {

View File

@ -836,17 +836,7 @@ const Notification = new Lang.Class({
} }
}, },
// addButton: addButton: function(id, button) {
// @id: the action ID
// @label: the label for the action's button
//
// Adds a button with the given @label to the notification. All
// action buttons will appear in a single row at the bottom of
// the notification.
//
// If the button is clicked, the notification will emit the
// %action-invoked signal with @id as a parameter
addButton: function(id, label) {
if (!this._buttonBox) { if (!this._buttonBox) {
let box = new St.BoxLayout({ style_class: 'notification-actions' }); let box = new St.BoxLayout({ style_class: 'notification-actions' });
this.setActionArea(box, { x_expand: false, this.setActionArea(box, { x_expand: false,
@ -858,6 +848,24 @@ const Notification = new Lang.Class({
global.focus_manager.add_group(this._buttonBox); global.focus_manager.add_group(this._buttonBox);
} }
this._buttonBox.add(button);
button.connect('clicked', Lang.bind(this, this._onActionInvoked, id));
this.updated();
return button;
},
// addAction:
// @id: the action ID
// @label: the label for the action's button
//
// Adds a button with the given @label to the notification. All
// action buttons will appear in a single row at the bottom of
// the notification.
//
// If the button is clicked, the notification will emit the
// %action-invoked signal with @id as a parameter
addAction: function(id, label) {
let button = new St.Button({ can_focus: true }); let button = new St.Button({ can_focus: true });
let iconName = strHasSuffix(id, '-symbolic') ? id : id + '-symbolic'; let iconName = strHasSuffix(id, '-symbolic') ? id : id + '-symbolic';
@ -869,11 +877,7 @@ const Notification = new Lang.Class({
button.label = label; button.label = label;
} }
this._buttonBox.add(button); return this.addButton(id, button);
button.connect('clicked', Lang.bind(this, this._onActionInvoked, id));
this.updated();
return button;
}, },
setUrgency: function(urgency) { setUrgency: function(urgency) {

View File

@ -422,7 +422,7 @@ const NotificationDaemon = new Lang.Class({
this._emitActionInvoked(ndata.id, "default"); this._emitActionInvoked(ndata.id, "default");
})); }));
else else
notification.addButton(actions[i], actions[i + 1]); notification.addAction(actions[i], actions[i + 1]);
} }
} }
switch (hints.urgency) { switch (hints.urgency) {

View File

@ -79,7 +79,7 @@ const ShellInfo = new Lang.Class({
this._undoCallback = undoCallback; this._undoCallback = undoCallback;
if (undoCallback) { if (undoCallback) {
notification.addButton('system-undo', _("Undo")); notification.addAction('system-undo', _("Undo"));
notification.connect('action-invoked', Lang.bind(this, this._onUndoClicked)); notification.connect('action-invoked', Lang.bind(this, this._onUndoClicked));
} }

View File

@ -105,8 +105,8 @@ const AuthNotification = new Lang.Class({
this._devicePath = device_path; this._devicePath = device_path;
this.addBody(_("Device %s wants to pair with this computer").format(long_name)); this.addBody(_("Device %s wants to pair with this computer").format(long_name));
this.addButton('allow', _("Allow")); this.addAction('allow', _("Allow"));
this.addButton('deny', _("Deny")); this.addAction('deny', _("Deny"));
this.connect('action-invoked', Lang.bind(this, function(self, action) { this.connect('action-invoked', Lang.bind(this, function(self, action) {
if (action == 'allow') if (action == 'allow')
@ -133,9 +133,9 @@ const AuthServiceNotification = new Lang.Class({
this._devicePath = device_path; this._devicePath = device_path;
this.addBody(_("Device %s wants access to the service '%s'").format(long_name, uuid)); this.addBody(_("Device %s wants access to the service '%s'").format(long_name, uuid));
this.addButton('always-grant', _("Always grant access")); this.addAction('always-grant', _("Always grant access"));
this.addButton('grant', _("Grant this time only")); this.addAction('grant', _("Grant this time only"));
this.addButton('reject', _("Reject")); this.addAction('reject', _("Reject"));
this.connect('action-invoked', Lang.bind(this, function(self, action) { this.connect('action-invoked', Lang.bind(this, function(self, action) {
switch (action) { switch (action) {
@ -172,8 +172,8 @@ const ConfirmNotification = new Lang.Class({
this.addBody(_("Please confirm whether the Passkey '%06d' matches the one on the device.").format(pin)); this.addBody(_("Please confirm whether the Passkey '%06d' matches the one on the device.").format(pin));
/* Translators: this is the verb, not the noun */ /* Translators: this is the verb, not the noun */
this.addButton('matches', _("Matches")); this.addAction('matches', _("Matches"));
this.addButton('does-not-match', _("Does not match")); this.addAction('does-not-match', _("Does not match"));
this.connect('action-invoked', Lang.bind(this, function(self, action) { this.connect('action-invoked', Lang.bind(this, function(self, action) {
if (action == 'matches') if (action == 'matches')
@ -217,8 +217,8 @@ const PinNotification = new Lang.Class({
})); }));
this.addActor(this._entry); this.addActor(this._entry);
let okButton = this.addButton('ok', _("OK")); let okButton = this.addAction('ok', _("OK"));
this.addButton('cancel', _("Cancel")); this.addAction('cancel', _("Cancel"));
okButton.reactive = this._canActivateOkButton(); okButton.reactive = this._canActivateOkButton();
this._entry.clutter_text.connect('text-changed', Lang.bind(this, function() { this._entry.clutter_text.connect('text-changed', Lang.bind(this, function() {