[gnome-contacts] Add a Favorite button.



commit 6d0b5125f42631d709b20fd3df2224547606522d
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Fri Jan 19 11:43:11 2018 +0100

    Add a Favorite button.
    
    Now that we show favorites separately, that makes sense.

 data/ui/contacts-window.ui |   20 ++++++++++++++++++++
 src/contacts-window.vala   |   23 +++++++++++++++++++++--
 2 files changed, 41 insertions(+), 2 deletions(-)
---
diff --git a/data/ui/contacts-window.ui b/data/ui/contacts-window.ui
index 19fad4c..2294701 100644
--- a/data/ui/contacts-window.ui
+++ b/data/ui/contacts-window.ui
@@ -133,6 +133,26 @@
               </packing>
             </child>
             <child>
+              <object class="GtkToggleButton" id="favorite_button">
+                <property name="visible">False</property>
+                <property name="can_focus">True</property>
+                <property name="focus_on_click">False</property>
+                <property name="valign">center</property>
+                <signal name="toggled" handler="on_favorite_button_toggled"/>
+                <child>
+                  <object class="GtkImage">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="icon_name">starred-symbolic</property>
+                    <property name="icon_size">1</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="pack_type">end</property>
+              </packing>
+            </child>
+            <child>
               <object class="GtkButton" id="done_button">
                 <property name="visible">False</property>
                 <property name="can_focus">True</property>
diff --git a/src/contacts-window.vala b/src/contacts-window.vala
index c55b922..4e006fd 100644
--- a/src/contacts-window.vala
+++ b/src/contacts-window.vala
@@ -42,6 +42,9 @@ public class Contacts.Window : Gtk.ApplicationWindow {
   [GtkChild]
   private Button select_cancel_button;
   [GtkChild]
+  private ToggleButton favorite_button;
+  private bool ignore_favorite_button_toggled;
+  [GtkChild]
   private Button edit_button;
   [GtkChild]
   private Button cancel_button;
@@ -123,7 +126,9 @@ public class Contacts.Window : Gtk.ApplicationWindow {
         = (new_state == UiState.NORMAL || new_state == UiState.SHOWING);
 
     // UI when showing a contact
-    this.edit_button.visible = (new_state == UiState.SHOWING);
+    this.edit_button.visible
+        = this.favorite_button.visible
+        = (new_state == UiState.SHOWING);
 
     // Selecting UI
     this.select_cancel_button.visible = (new_state == UiState.SELECTING);
@@ -164,6 +169,16 @@ public class Contacts.Window : Gtk.ApplicationWindow {
     this.contact_pane.set_edit_mode (true);
   }
 
+  [GtkCallback]
+  private void on_favorite_button_toggled (ToggleButton button) {
+    // Don't change the contact being favorite while switching between the two of them
+    if (this.ignore_favorite_button_toggled)
+      return;
+
+    var is_fav = this.contact_pane.contact.individual.is_favourite;
+    this.contact_pane.contact.individual.is_favourite = !is_fav;
+  }
+
   private void stop_editing (bool drop_changes = false) {
     if (this.state == UiState.CREATING) {
 
@@ -202,8 +217,12 @@ public class Contacts.Window : Gtk.ApplicationWindow {
       list_pane.select_contact (c);
 
     // clearing right_header
-    if (c != null)
+    if (c != null) {
+      this.ignore_favorite_button_toggled = true;
+      this.favorite_button.active = c.individual.is_favourite;
+      this.ignore_favorite_button_toggled = false;
       this.right_header.title = c.display_name;
+    }
   }
 
   [GtkCallback]


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