[gnome-contacts] Added undo for some link opeartions



commit d4d7f7d4a86c9e6199695bb2f2057ff5481f96a4
Author: Erick PÃrez Castellanos <erick red gmail com>
Date:   Thu Jan 26 10:18:14 2012 -0500

    Added undo for some link opeartions
    
    Added undo for link when happening through inline suggestions.
    Added undo when happening through link-to-my-contacts mode of the LinkDialog.
    
    Tthere's other possible approach, maybe prettier, it's passing the names of the linked contacts, needed for the notification, inside the LinkOperation object. That will need some judgement of the ancients, then will do.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=668751

 src/contacts-app.vala          |   22 +++++++++++++++++++++-
 src/contacts-contact-pane.vala |   17 ++++++++++++-----
 src/contacts-link-dialog.vala  |   26 ++++++++++++++++----------
 3 files changed, 49 insertions(+), 16 deletions(-)
---
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index 7b0f8a5..4d4a973 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -294,9 +294,9 @@ public class Contacts.App : Gtk.Application {
     contacts_pane = new ContactPane (contacts_store);
     contacts_pane.set_hexpand (true);
     contacts_pane.will_delete.connect (delete_contact);
+    contacts_pane.contacts_linked.connect (contacts_linked);
     grid.attach (contacts_pane, 1, 1, 1, 1);
 
-
     grid.show_all ();
   }
 
@@ -364,6 +364,26 @@ public class Contacts.App : Gtk.Application {
     { null }
   };
 
+  private void contacts_linked (string main_contact, string linked_contact, LinkOperation operation) {
+    var notification = new Gtk.Notification ();
+
+    var g = new Grid ();
+    g.set_column_spacing (8);
+    notification.add (g);
+
+    string msg = _("%s linked to %s").printf (main_contact, linked_contact);
+    var b = new Button.from_stock (Stock.UNDO);
+    g.add (new Label (msg));
+    g.add (b);
+
+    notification.show_all ();
+    b.clicked.connect ( () => {
+      notification.dismiss ();
+      operation.undo ();
+    });
+    overlay.add_overlay (notification);
+  }
+  
   public override int command_line (ApplicationCommandLine command_line) {
     var args = command_line.get_arguments ();
     unowned string[] _args = args;
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index 4fadc76..6c3198d 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -1694,6 +1694,8 @@ public class Contacts.ContactPane : ScrolledWindow {
       call_button.hide ();
   }
 
+  public signal void contacts_linked (string main_contact, string linked_contact, LinkOperation operation);
+  
   public void add_suggestion (Contact c) {
     var row = new FieldRow (row_group);
     personas_grid.add (row);
@@ -1738,12 +1740,14 @@ public class Contacts.ContactPane : ScrolledWindow {
     var no = new Button.with_label (_("No"));
 
     yes.clicked.connect ( () => {
-	link_contacts.begin (contact, c, (obj, result) => {
-	    link_contacts.end (result);
-	  });
-	/* TODO: Add undo */
-	row.destroy ();
+      var main_contact = contact.display_name;
+      var linked_contact = c.display_name;
+      link_contacts.begin (contact, c, (obj, result) => {
+        var operation = link_contacts.end (result);
+        this.contacts_linked (main_contact, linked_contact, operation);
       });
+      row.destroy ();
+    });
 
     no.clicked.connect ( () => {
 	contacts_store.add_no_suggest_link (contact, c);
@@ -2130,6 +2134,9 @@ public class Contacts.ContactPane : ScrolledWindow {
 
   void link_contact () {
     var dialog = new LinkDialog (contact);
+    dialog.contacts_linked.connect ( (main_contact, linked_contact, operation) => {
+      this.contacts_linked (main_contact, linked_contact, operation);
+    });
     dialog.show_all ();
   }
 
diff --git a/src/contacts-link-dialog.vala b/src/contacts-link-dialog.vala
index b750f84..f360baf 100644
--- a/src/contacts-link-dialog.vala
+++ b/src/contacts-link-dialog.vala
@@ -34,6 +34,8 @@ public class Contacts.LinkDialog : Dialog {
   private Grid persona_grid;
   private uint filter_entry_changed_id;
 
+  public signal void contacts_linked (string main_contact, string linked_contact, LinkOperation operation);
+  
   private void update_contact () {
     // Remove previous personas
     foreach (var w in persona_grid.get_children ()) {
@@ -241,16 +243,20 @@ public class Contacts.LinkDialog : Dialog {
     scrolled.add_with_viewport (persona_grid);
 
     response.connect ( (response_id) => {
-	if (response_id == ResponseType.APPLY &&
-	    selected_contact != null) {
-	  // TODO: Link selected_contact.individual into contact.individual
-	  // ensure we get the same individual so that the Contact is the same
-	  link_contacts.begin (selected_contact, contact, (obj, result) => {
-	    link_contacts.end (result);
-	  });
-	}
-	this.destroy ();
-      });
+      if (response_id == ResponseType.APPLY &&
+          selected_contact != null) {
+        link_contacts.begin (selected_contact, contact, (obj, result) => {
+          var main_contact_name = selected_contact.display_name;
+          var linked_contact_name = contact.display_name;
+          var operation = link_contacts.end (result);
+          this.contacts_linked (main_contact_name, linked_contact_name, operation);
+          this.destroy ();
+        });
+      } else
+        this.destroy ();
+
+      this.hide ();
+    });
 
     set_default_size (710, 510);
   }



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