[gnome-maps/wip/notifications-jonas: 2/4] Notifications: Add static notifications



commit 820dad241e88c1b0ab999f8e92a5cb85cd88e72f
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Sat Feb 15 06:33:25 2014 +0100

    Notifications: Add static notifications
    
    Add support for static notifications. These are pre-defined
    notifications that are cached and reused.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=723996

 src/notification.js |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/src/notification.js b/src/notification.js
index 9a87c05..b0261ab 100644
--- a/src/notification.js
+++ b/src/notification.js
@@ -60,6 +60,8 @@ const Plain = new Lang.Class({
     }
 });
 
+const Type = { };
+
 const Manager = new Lang.Class({
     Name: 'Manager',
     Extends: Gtk.Revealer,
@@ -79,6 +81,13 @@ const Manager = new Lang.Class({
         this._revealNotification(notification);
     },
 
+    // Shows a static (reusable) notification
+    showNotification: function(notificationType) {
+        let notification = this._getNotification(notificationType);
+        if(!notification.get_parent())
+            this._revealNotification(notification);
+    },
+
     _revealNotification: function(notification) {
         // only conceal the notification when it's the last one
         notification.connect('dismiss', (function() {
@@ -96,5 +105,17 @@ const Manager = new Lang.Class({
         this._stack.child_set_property(notification, 'position', 0);
         this._stack.set_visible_child(notification);
         this.set_reveal_child(true);
+    },
+
+    _getNotification: function(notificationType) {
+        if(!this._cache.hasOwnProperty(notificationType.name)) {
+            this._createNotification(notificationType);
+        }
+        return this._cache[notificationType.name];
+    },
+
+    _createNotification: function(notificationType) {
+        let notification = new notificationType.Class();
+        this._cache[notificationType.name] = notification;
     }
 });


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]