[gnome-maps/wip/notifications-jonas: 5/5] notificationmanager in overlay
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/notifications-jonas: 5/5] notificationmanager in overlay
- Date: Mon, 24 Feb 2014 13:19:33 +0000 (UTC)
commit 847092dc7be94babee6a019721e03b842d3148c3
Author: Jonas Danielsson <jonas threetimestwo org>
Date: Mon Feb 24 14:03:15 2014 +0100
notificationmanager in overlay
src/application.js | 2 +-
src/mainWindow.js | 1 +
src/notification.js | 78 +++++++++++++++++++++++++-------------------------
3 files changed, 41 insertions(+), 40 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index d15c783..ae313cc 100644
--- a/src/application.js
+++ b/src/application.js
@@ -95,7 +95,7 @@ const Application = new Lang.Class({
return;
let overlay = new Gtk.Overlay({ visible: true });
- notificationManager = new Notification.Manager(overlay);
+ notificationManager = new Notification.Manager();
notificationManager.showNotification(Notification.Type.NO_NETWORK);
this._mainWindow = new MainWindow.MainWindow(this, overlay);
this._mainWindow.window.connect('destroy', this._onWindowDestroy.bind(this));
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 027d928..4c61895 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -84,6 +84,7 @@ const MainWindow = new Lang.Class({
this._restoreWindowGeometry();
overlay.add_overlay(new ZoomControl.ZoomControl(this.mapView));
+ overlay.add_overlay(Application.notificationManager);
overlay.show_all();
},
diff --git a/src/notification.js b/src/notification.js
index db52d94..ec49d54 100644
--- a/src/notification.js
+++ b/src/notification.js
@@ -28,40 +28,20 @@ const Utils = imports.utils;
const Notification = new Lang.Class({
Name: 'Notification',
- Extends: Gtk.Revealer,
+ Extends: Gtk.Bin,
Abstract: true,
_init: function() {
- this.parent({ visible: true,
- halign: Gtk.Align.CENTER,
- valign: Gtk.Align.START });
-
+ this.parent({ visible: true });
this._ui = Utils.getUIObject('notification', [ 'frame',
'body',
'dismiss-button']);
- this._ui.dismissButton.connect('clicked', this.dismiss.bind(this));
- this.add(this._ui.frame);
- },
-
- reveal: function() {
- this._setRevealAndEmit(true, 'revealed');
- },
-
- dismiss: function() {
- this._setRevealAndEmit(false, 'dismissed');
- },
+ this._ui.dismissButton.connect('clicked', (function() {
+ this.emit('dismiss');
+ }).bind(this));
- _setRevealAndEmit: function(state, signal) {
- // We only want to send a dismissed / shown -signal
- // if there is an actual change in revealed state.
- if(state !== this.child_revealed) {
- this.set_reveal_child(state);
- Mainloop.timeout_add(this.transition_duration, (function() {
- this.emit(signal);
- return false;
- }).bind(this));
- }
+ this.add(this._ui.frame);
}
});
Utils.addSignalMethods(Notification.prototype);
@@ -133,26 +113,48 @@ const Type = {
const Manager = new Lang.Class({
Name: 'Manager',
-
- _init: function(overlay) {
- this._overlay = overlay;
+ Extends: Gtk.Revealer,
+
+ _init: function() {
+ this._stack = new Gtk.Stack({ visible: true });
this._cache = {};
+
+ this.parent({ visible: true,
+ halign: Gtk.Align.CENTER,
+ valign: Gtk.Align.START });
+ this.add(this._stack);
},
showMessage: function (msg) {
let notification = new Plain(msg);
- notification.connect('dismissed',
- notification.destroy.bind(notification));
- this._overlay.add_overlay(notification);
- notification.reveal();
+ this._revealNotification(notification);
},
// Shows a static (reusable) notification
showNotification: function(notificationType) {
let notification = this._getNotification(notificationType);
- if(!notification.get_parent())
- this._overlay.add_overlay(notification);
- notification.reveal();
+ if (!notification.get_parent())
+ this._revealNotification(notification);
+ },
+
+ _revealNotification: function(notification) {
+ // only conceal the notification when it's the last one
+ notification.connect('dismiss', (function() {
+ if (this._stack.get_children().length > 1) {
+ this._stack.remove(notification);
+ } else {
+ this.set_reveal_child(false);
+ Mainloop.timeout_add(this.transition_duration, (function() {
+ this._stack.remove(notification);
+ }).bind(this));
+ }
+ }).bind(this));
+
+ this._stack.add(notification);
+ // make sure that we get the right order when dismissing
+ this._stack.child_set_property(notification, 'position', 0);
+ this._stack.set_visible_child(notification);
+ this.set_reveal_child(true);
},
_getNotification: function(notificationType) {
@@ -164,10 +166,8 @@ const Manager = new Lang.Class({
_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]