[gnome-documents] notifications: Add DeleteNotification
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] notifications: Add DeleteNotification
- Date: Tue, 12 Aug 2014 07:59:15 +0000 (UTC)
commit f2ddcfec427ed2b788ea843605738096adc8bac6
Author: Debarshi Ray <debarshir gnome org>
Date: Mon Aug 11 14:32:50 2014 +0200
notifications: Add DeleteNotification
https://bugzilla.gnome.org/show_bug.cgi?id=661599
src/notifications.js | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/selections.js | 12 +++++++-
2 files changed, 81 insertions(+), 2 deletions(-)
---
diff --git a/src/notifications.js b/src/notifications.js
index 0ced93a..74f57ab 100644
--- a/src/notifications.js
+++ b/src/notifications.js
@@ -20,6 +20,7 @@
*/
const Gd = imports.gi.Gd;
+const Gettext = imports.gettext;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
@@ -34,6 +35,76 @@ const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Signals = imports.signals;
+const DELETE_TIMEOUT = 10; // seconds
+
+const DeleteNotification = new Lang.Class({
+ Name: 'DeleteNotification',
+
+ _init: function(docs) {
+ this._docs = docs;
+ this.widget = new Gtk.Grid({ orientation: Gtk.Orientation.HORIZONTAL,
+ column_spacing: 12,
+ margin_start: 12,
+ margin_end: 12 });
+
+ let msg = Gettext.ngettext("Selected item has been deleted",
+ "Selected items have been deleted",
+ this._docs.length);
+ let label = new Gtk.Label({ label: msg,
+ halign: Gtk.Align.START });
+ this.widget.add(label);
+
+ let undo = new Gtk.Button({ label: _("Undo"),
+ valign: Gtk.Align.CENTER });
+ this.widget.add(undo);
+ undo.connect('clicked', Lang.bind(this,
+ function() {
+ this._docs.forEach(Lang.bind(this,
+ function(doc) {
+ Application.documentManager.addItem(doc);
+ }));
+
+ this._removeTimeout();
+ this.widget.destroy();
+ }));
+
+ let close = new Gtk.Button({ image: new Gtk.Image({ icon_name: 'window-close-symbolic',
+ pixel_size: 16,
+ margin_top: 2,
+ margin_bottom: 2 }),
+ valign: Gtk.Align.CENTER,
+ focus_on_click: false,
+ relief: Gtk.ReliefStyle.NONE });
+ this.widget.add(close);
+ close.connect('clicked', Lang.bind(this, this._deleteItems));
+
+ Application.notificationManager.addNotification(this);
+ this._timeoutId = Mainloop.timeout_add_seconds(DELETE_TIMEOUT, Lang.bind(this,
+ function() {
+ this._timeoutId = 0;
+ this._deleteItems();
+ return false;
+ }));
+ },
+
+ _deleteItems: function() {
+ this._docs.forEach(Lang.bind(this,
+ function(doc) {
+ doc.trash();
+ }))
+
+ this._removeTimeout();
+ this.widget.destroy();
+ },
+
+ _removeTimeout: function() {
+ if (this._timeoutId != 0) {
+ Mainloop.source_remove(this._timeoutId);
+ this._timeoutId = 0;
+ }
+ }
+});
+
const PrintNotification = new Lang.Class({
Name: 'PrintNotification',
diff --git a/src/selections.js b/src/selections.js
index 8a1f3bc..249f918 100644
--- a/src/selections.js
+++ b/src/selections.js
@@ -898,13 +898,21 @@ const SelectionToolbar = new Lang.Class({
_onToolbarTrash: function(widget) {
let selection = Application.selectionController.getSelection();
- Application.selectionController.setSelectionMode(false);
+ let docs = [];
selection.forEach(Lang.bind(this,
function(urn) {
let doc = Application.documentManager.getItemById(urn);
- doc.trash();
+ docs.push(doc);
+ }));
+
+ docs.forEach(Lang.bind(this,
+ function(doc) {
+ Application.documentManager.removeItem(doc);
}));
+
+ let deleteNotification = new Notifications.DeleteNotification(docs);
+ Application.selectionController.setSelectionMode(false);
},
_onToolbarProperties: function(widget) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]