[polari] application: Allow to undo connection removal



commit 520cf1050ec55f58a4cdcd25ffff22ff60669af9
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Jan 29 13:03:47 2016 +0100

    application: Allow to undo connection removal
    
    Since commit 6ef2e57371aa added a "Remove" menu action to the room
    header popover, it is now a lot easier to remove a connection by
    accident. We should be more forgiving in that case, so show an app
    notification that allows the user to undo the operation, and only
    actually remove the account when the notification has been dismissed
    or timed out.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=761281

 src/appNotifications.js |   41 +++++++++++++++++++++++++++++++++++++++++
 src/application.js      |   19 ++++++++++++++++---
 2 files changed, 57 insertions(+), 3 deletions(-)
---
diff --git a/src/appNotifications.js b/src/appNotifications.js
index 4f16920..4ed48fc 100644
--- a/src/appNotifications.js
+++ b/src/appNotifications.js
@@ -1,9 +1,12 @@
 const Gtk = imports.gi.Gtk;
+const Pango = imports.gi.Pango;
 const Tp = imports.gi.TelepathyGLib;
 
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
+const Signals = imports.signals;
 
+const UNDO_TIMEOUT = 7;
 const COMMAND_OUTPUT_REVEAL_TIME = 3;
 
 const AppNotification = new Lang.Class({
@@ -28,6 +31,44 @@ const AppNotification = new Lang.Class({
     }
 });
 
+const UndoNotification = new Lang.Class({
+    Name: 'UndoNotification',
+    Extends: AppNotification,
+
+    _init: function(label) {
+        this.parent();
+
+        this._undo = false;
+
+        Mainloop.timeout_add_seconds(UNDO_TIMEOUT, Lang.bind(this, this.close));
+
+        let box = new Gtk.Box({ spacing: 12 });
+        box.add(new Gtk.Label({ label: label, hexpand: true,
+                                ellipsize: Pango.EllipsizeMode.END }));
+
+        let undoButton = new Gtk.Button({ label: _("Undo") });
+        undoButton.connect('clicked', Lang.bind(this, function() {
+            this._undo = true;
+            this.close();
+        }));
+        box.add(undoButton);
+
+        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.widget.add(box);
+        this.widget.show_all();
+    },
+
+    close: function() {
+        this.emit(this._undo ? 'undo' : 'closed');
+        this.parent();
+    }
+});
+Signals.addSignalMethods(UndoNotification.prototype);
+
 const CommandOutputNotification = new Lang.Class({
     Name: 'CommandOutputNotification',
     Extends: AppNotification,
diff --git a/src/application.js b/src/application.js
index eedfeda..d3093cf 100644
--- a/src/application.js
+++ b/src/application.js
@@ -438,9 +438,22 @@ const Application = new Lang.Class({
         let accountPath = parameter.deep_unpack();
         let factory = Tp.AccountManager.dup().get_factory();
         let account = factory.ensure_account(accountPath, []);
-        account.remove_async(Lang.bind(this,
-            function(a, res) {
-                a.remove_finish(res); // TODO: Check for errors
+        account.set_enabled_async(false, Lang.bind(this,
+            function() {
+                let label = _("%s removed.").format(account.display_name);
+                let n = new AppNotifications.UndoNotification(label);
+                this.notificationQueue.addNotification(n);
+
+                n.connect('closed', function() {
+                    account.remove_async(function(a, res) {
+                        a.remove_finish(res); // TODO: Check for errors
+                    });
+                });
+                n.connect('undo', function() {
+                    account.set_enabled_async(true, function(a, res) {
+                        a.set_enabled_finish(res); // TODO: Check for errors
+                    });
+                });
             }));
     },
 


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