Commit 520cf105 authored by Florian Müllner's avatar Florian Müllner

application: Allow to undo connection removal

Since commit 6ef2e573 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
parent 645639fb
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,
......
......@@ -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
});
});
}));
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment