[gnome-contacts] Window: provide entry point for inline contact creation



commit f973c7ed85225c8279f8789958d25be3ac251087
Author: Erick Pérez Castellanos <erick red gmail com>
Date:   Sun Aug 10 13:53:54 2014 -0400

    Window: provide entry point for inline contact creation
    
    Hook into ContactPane new API.
    Adjust leave edit-mode behavior so it can cancel contact creation

 data/ui/contacts-window.ui |    1 +
 src/contacts-app.vala      |    2 --
 src/contacts-window.vala   |   41 ++++++++++++++++++++++++++++++++++++-----
 3 files changed, 37 insertions(+), 7 deletions(-)
---
diff --git a/data/ui/contacts-window.ui b/data/ui/contacts-window.ui
index 46b0f4d..f27b806 100644
--- a/data/ui/contacts-window.ui
+++ b/data/ui/contacts-window.ui
@@ -176,6 +176,7 @@
             <property name="can_focus">True</property>
             <property name="halign">center</property>
             <property name="valign">center</property>
+            <signal name="clicked" handler="add_button_clicked_cb" object="ContactsWindow" after="no" 
swapped="no"/>
             <child internal-child="accessible">
               <object class="AtkObject" id="add_button_atkobject">
                 <property name="AtkObject::accessible-name" translatable="yes">Add contact</property>
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index 71a82d8..3b7440f 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -180,8 +180,6 @@ public class Contacts.App : Gtk.Application {
 
   private void create_window () {
     window = new Contacts.Window (this, contacts_store);
-
-    window.add_button.clicked.connect (app.new_contact);
   }
 
   private void schedule_window_creation () {
diff --git a/src/contacts-window.vala b/src/contacts-window.vala
index 7dfc972..3f52e2a 100644
--- a/src/contacts-window.vala
+++ b/src/contacts-window.vala
@@ -37,6 +37,8 @@ public class Contacts.Window : Gtk.ApplicationWindow {
   [GtkChild]
   private ContactPane contact_pane;
   [GtkChild]
+  private Button add_button;
+  [GtkChild]
   private ToggleButton select_button;
   [GtkChild]
   private Button edit_button;
@@ -80,8 +82,7 @@ public class Contacts.Window : Gtk.ApplicationWindow {
     }
   }
 
-  [GtkChild]
-  public Button add_button;
+  private bool new_contact_mode = false;
 
   public Store store {
     get; construct set;
@@ -257,15 +258,28 @@ public class Contacts.Window : Gtk.ApplicationWindow {
   public void leave_edit_mode (bool drop_changes = false) {
     edit_mode = false;
 
-    contact_pane.set_edit_mode (false, drop_changes);
 
     left_toolbar.get_style_context ().remove_class ("selection-mode");
     right_toolbar.get_style_context ().remove_class ("selection-mode");
 
-    if (contact_pane.contact != null)
+
+    if (new_contact_mode) {
+      done_button.label = _("Done");
+    }
+
+    if (drop_changes) {
+      contact_pane.set_edit_mode (false, drop_changes);
+    } else if (new_contact_mode) {
+      contact_pane.create_contact ();
+    }
+    new_contact_mode = false;
+
+    if (contact_pane.contact != null) {
       right_title = contact_pane.contact.display_name;
-    else
+    } else {
       right_title = "";
+      edit_button.hide ();
+    }
   }
 
   public void add_notification (Widget notification) {
@@ -321,6 +335,23 @@ public class Contacts.Window : Gtk.ApplicationWindow {
   }
 
   [GtkCallback]
+  void add_button_clicked_cb (Button button) {
+    /* FIXME: eventually ContactPane will become just a skeleton and
+     * this call will go through to ContactEditor */
+    edit_mode = true;
+    new_contact_mode = true;
+
+    right_title = _("New Contact");
+
+    left_toolbar.get_style_context ().add_class ("selection-mode");
+    right_toolbar.get_style_context ().add_class ("selection-mode");
+
+    done_button.label = _("Add");
+
+    contact_pane.new_contact ();
+  }
+
+  [GtkCallback]
   bool key_press_event_cb (Gdk.EventKey event) {
     if ((event.keyval == Gdk.keyval_from_name ("q")) &&
         ((event.state & Gdk.ModifierType.CONTROL_MASK) != 0)) {


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