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



commit dac1a9baa14c6be67e609d5456d891701dafc47e
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 |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
---
diff --git a/src/notification.js b/src/notification.js
index cf61dd9..285d4f7 100644
--- a/src/notification.js
+++ b/src/notification.js
@@ -80,11 +80,14 @@ const Plain = new Lang.Class({
     }
 });
 
+const Type = { };
+
 const Manager = new Lang.Class({
     Name: 'Manager',
 
     _init: function(overlay) {
         this._overlay = overlay;
+        this._cache = {};
     },
 
     showMessage: function (msg) {
@@ -93,5 +96,29 @@ const Manager = new Lang.Class({
                              notification.destroy.bind(notification));
         this._overlay.add_overlay(notification);
         notification.reveal();
+    },
+
+    // Shows a static (reusable) notification
+    showNotification: function(notificationType) {
+        let notification = this._getNotification(notificationType);
+        if(!notification.get_parent())
+            this._overlay.add_overlay(notification);
+        notification.reveal();
+    },
+
+    _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();
+        notification.connect('dismissed', (function() {
+            this._overlay.remove(notification);
+        }).bind(this));
+
+        this._cache[notificationType.name] = notification;
     }
 });


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