[gnome-contacts] Support undo for delete



commit 3d0635ecc1bd23c3655c815029a48eb35dd37ce8
Author: Erick PÃrez Castellanos <erick red gmail com>
Date:   Mon Dec 19 15:31:04 2011 +0100

    Support undo for delete

 src/contacts-app.vala          |   27 +++++++++++++++++++++++++--
 src/contacts-contact-pane.vala |    8 ++++++--
 2 files changed, 31 insertions(+), 4 deletions(-)
---
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index f004997..f03fa12 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -117,7 +117,12 @@ public class Contacts.App : Gtk.Application {
     window.key_press_event.connect (window_key_press_event);
 
     var grid = new Grid();
-    window.add (grid);
+
+    var overlay = new Gtk.Overlay ();
+    overlay.add (grid);
+    Gdk.RGBA transparent = { 0, 0, 0, 0 };
+    overlay.override_background_color (0, transparent);
+    window.add (overlay);
 
     list_pane = new ListPane (contacts_store);
     list_pane.selection_changed.connect (selection_changed);
@@ -130,9 +135,27 @@ public class Contacts.App : Gtk.Application {
 
     contacts_pane = new ContactPane (contacts_store);
     contacts_pane.set_hexpand (true);
+    contacts_pane.will_delete.connect ( (c) => {
+      string msg = _("Contact deleted: \"%s\"").printf (c.display_name);
+      var notification = new Gtk.Notification (msg, Stock.UNDO);
+      notification.show ();
+      ulong id;
+      id = notification.destroy.connect ( () => {
+	contacts_store.aggregator.remove_individual (c.individual);
+      });
+      notification.actioned.connect ( () => {
+	notification.disconnect (id);
+	notification.destroy ();
+	c.show ();
+	list_pane.select_contact (c);
+	contacts_pane.show_contact (c);
+      });
+
+      overlay.add_overlay (notification);
+    });
     grid.attach (contacts_pane, 1, 0, 1, 2);
 
-    grid.show_all ();
+    overlay.show_all ();
   }
 
   public override void startup () {
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index fc2df8c..ba26ca5 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -2046,8 +2046,12 @@ public class Contacts.ContactPane : ScrolledWindow {
     dialog.show_all ();
   }
 
+  public signal void will_delete (Contact contact);
+
   void delete_contact () {
-    contacts_store.aggregator.remove_individual (contact.individual);
+    if (contact != null) {
+      contact.hide ();
+      this.will_delete (contact);
+    }
   }
-
 }



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