[gnome-maps] notificationManager: Simplify showNotification



commit 210cb8c4f487136c51b27745d3a810461867f16f
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Wed Apr 23 19:18:56 2014 +0200

    notificationManager: Simplify showNotification
    
    Right now showNotification takes a tuple of name and class to create
    and cache a kind of simpleton Notification class. This makes the API
    a bit awkward.
    
    Instead we can just have the method take a Notification instance
    directly. If the caller want the functionality of re-usable
    notifications they can do the simpleton creation on their end.
    The method still checks if the notification instance is already
    in the overlay.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=727706

 src/notificationManager.js |   26 +++++++-------------------
 1 files changed, 7 insertions(+), 19 deletions(-)
---
diff --git a/src/notificationManager.js b/src/notificationManager.js
index 5b098a5..583e16e 100644
--- a/src/notificationManager.js
+++ b/src/notificationManager.js
@@ -41,27 +41,15 @@ const NotificationManager = new Lang.Class({
         notification.reveal();
     },
 
-    // Shows a static (reusable) notification
-    showNotification: function(notificationType) {
-        let notification = this._getNotification(notificationType);
-        if(!notification.get_parent())
+    showNotification: function(notification) {
+        if(notification.get_parent() !== this._overlay) {
             this._overlay.add_overlay(notification);
-        notification.reveal();
-    },
 
-    _getNotification: function(notificationType) {
-        if(!this._cache.hasOwnProperty(notificationType.name)) {
-            this._createNotification(notificationType);
+            notification.connect('dismissed', (function() {
+                this._overlay.remove(notification);
+                notification.disconnectAll();
+            }).bind(this));
         }
-        return this._cache[notificationType.name];
+        notification.reveal();
     },
-
-    _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]