[polari/wip/fmuellner/irc-url-handling: 2/4] appNotification: Add class CloseNotification



commit 3b24729d8a23efbd7069923ed9917cd6417abbdd
Author: Bastian Ilsø <hougaard junior gmail com>
Date:   Thu Feb 11 16:43:57 2016 +0100

    appNotification: Add class CloseNotification
    
    We are about to land IRC URL parsing which error
    handling requires using an app notification when
    IRC URLs cannot be properly parsed. This adds a
    new CloseNotification class which shows a notification
    for 7 seconds along with a close button.

 src/appNotifications.js |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/src/appNotifications.js b/src/appNotifications.js
index d8b4912..b80c2b1 100644
--- a/src/appNotifications.js
+++ b/src/appNotifications.js
@@ -68,6 +68,36 @@ const UndoNotification = new Lang.Class({
     }
 });
 
+const CloseNotification = new Lang.Class({
+    Name: 'CloseNotification',
+    Extends: AppNotification,
+    Signals: { closed: {} },
+
+    _init: function(label, icon_name) {
+        this.parent();
+
+        Mainloop.timeout_add_seconds(TIMEOUT, Lang.bind(this, this.close));
+
+        let box = new Gtk.Box({ spacing: 12 });
+        box.add(new Gtk.Image({ icon_name: icon_name }));
+        box.add(new Gtk.Label({ label: label, hexpand: true,
+                                ellipsize: Pango.EllipsizeMode.END }));
+
+        let closeButton = new Gtk.Button({ relief: Gtk.ReliefStyle.NONE });
+        closeButton.image = new Gtk.Image({ icon_name: 'window-close-symbolic' });
+        closeButton.connect('clicked', Lang.bind(this, this.close));
+        box.add(closeButton);
+
+        this.add(box);
+        this.show_all();
+    },
+
+    close: function() {
+        this.emit(this._undo ? 'undo' : 'closed');
+        this.parent();
+    }
+});
+
 const CommandOutputNotification = new Lang.Class({
     Name: 'CommandOutputNotification',
     Extends: AppNotification,


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