From 6190d6c962ca4df2675789e29672e74e5c55fa32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 17 May 2012 21:05:36 +0200 Subject: [PATCH] messageTray: Allow to make notification buttons insensitive The availability of a notification action may depend on conditions, so add a method to control the sensitivity of buttons which have been added with addButton(). https://bugzilla.gnome.org/show_bug.cgi?id=651251 --- data/theme/gnome-shell.css | 5 +++++ js/ui/messageTray.js | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/data/theme/gnome-shell.css b/data/theme/gnome-shell.css index 259be2695..a229653bd 100644 --- a/data/theme/gnome-shell.css +++ b/data/theme/gnome-shell.css @@ -328,6 +328,11 @@ StScrollBar StButton#vhandle:hover background-gradient-end: rgba(255, 255, 255, 0.2); } +.notification-icon-button:insensitive, +.notification-button:insensitive { + color: #9f9f9f; +} + /* Panel */ #panel { diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index c7e341086..a5bd47251 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -746,6 +746,7 @@ const Notification = new Lang.Class({ } let button = new St.Button({ can_focus: true }); + button._actionId = id; if (this._useActionIcons && Gtk.IconTheme.get_default().has_icon(id)) { button.add_style_class_name('notification-icon-button'); @@ -765,6 +766,31 @@ const Notification = new Lang.Class({ this.updated(); }, + // setButtonSensitive: + // @id: the action ID + // @sensitive: whether the button should be sensitive + // + // If the notification contains a button with action ID @id, + // its sensitivity will be set to @sensitive. Insensitive + // buttons cannot be clicked. + setButtonSensitive: function(id, sensitive) { + if (!this._buttonBox) + return; + + let button = this._buttonBox.get_children().filter(function(b) { + return b._actionId == id; + })[0]; + + if (!button || button.reactive == sensitive) + return; + + button.reactive = sensitive; + if (sensitive) + button.remove_style_pseudo_class('insensitive'); + else + button.add_style_pseudo_class('insensitive'); + }, + setUrgency: function(urgency) { this.urgency = urgency; },