[gnome-contacts] ListPane: also use the UiState.



commit 00a3590fd0fc11dc57f3941a43e59c1a9f033d01
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Wed Jan 17 12:57:20 2018 +0100

    ListPane: also use the UiState.
    
    Set to insensitive when editing a contact.

 src/contacts-list-pane.vala |   27 ++++++++++++++++++---------
 src/contacts-window.vala    |   28 +++++++++++-----------------
 2 files changed, 29 insertions(+), 26 deletions(-)
---
diff --git a/src/contacts-list-pane.vala b/src/contacts-list-pane.vala
index 0de3115..333c1dd 100644
--- a/src/contacts-list-pane.vala
+++ b/src/contacts-list-pane.vala
@@ -40,6 +40,8 @@ public class Contacts.ListPane : Frame {
   [GtkChild]
   private ActionBar actions_bar;
 
+  public UiState state { get; set; }
+
   public signal void selection_changed (Contact? contact);
   public signal void link_contacts (LinkedList<Contact> contacts);
   public signal void delete_contacts (LinkedList<Contact> contacts);
@@ -48,6 +50,8 @@ public class Contacts.ListPane : Frame {
   public ListPane (Store contacts_store) {
     this.store = contacts_store;
 
+    this.notify["state"].connect ( () => { on_ui_state_changed(); });
+
     // Load the ContactsView and connect the necessary signals
     this.contacts_list = new ContactList (contacts_store);
     this.contacts_list_container.add (this.contacts_list);
@@ -63,6 +67,20 @@ public class Contacts.ListPane : Frame {
       });
   }
 
+  private void on_ui_state_changed () {
+    // Disable when editing a contact. (Not using `this.sensitive` to allow scrolling)
+    this.filter_entry.sensitive
+        = this.contacts_list.sensitive
+        = !this.state.editing ();
+
+    if (this.state == UiState.SELECTING)
+      this.contacts_list.show_selectors ();
+    else
+      this.contacts_list.hide_selectors ();
+
+    this.actions_bar.visible = (this.state == UiState.SELECTING);
+  }
+
   [GtkCallback]
   private void filter_entry_changed (Editable editable) {
     if (Utils.string_is_empty (this.filter_entry.text)) {
@@ -78,15 +96,6 @@ public class Contacts.ListPane : Frame {
     this.contacts_list.select_contact (contact);
   }
 
-  public void activate_selection_mode (bool active) {
-    if (active)
-      this.contacts_list.show_selectors ();
-    else
-      this.contacts_list.hide_selectors ();
-
-    this.actions_bar.visible = active;
-  }
-
   [GtkCallback]
   private void on_link_button_clicked (Gtk.Button link_button) {
     link_contacts (this.contacts_list.get_marked_contacts ());
diff --git a/src/contacts-window.vala b/src/contacts-window.vala
index c4ad76d..b0372b3 100644
--- a/src/contacts-window.vala
+++ b/src/contacts-window.vala
@@ -55,12 +55,7 @@ public class Contacts.Window : Gtk.ApplicationWindow {
   private ListPane list_pane;
   private ContactPane contact_pane;
 
-  // We start in the normal UI state
-  private UiState _state = UiState.NORMAL;
-  public UiState state {
-    get { return this._state; }
-    set { change_ui_state (value); }
-  }
+  public UiState state { get; set; default = UiState.NORMAL; }
 
   public Store store {
     get; construct set;
@@ -73,6 +68,8 @@ public class Contacts.Window : Gtk.ApplicationWindow {
       store: contacts_store
     );
 
+    this.notify["state"].connect ( () => { on_ui_state_changed(); });
+
     create_contact_pane ();
     set_headerbar_layout ();
     connect_button_signals ();
@@ -94,6 +91,7 @@ public class Contacts.Window : Gtk.ApplicationWindow {
       return;
 
     list_pane = new ListPane (store);
+    bind_property ("state", this.list_pane, "state", BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE);
     list_pane.selection_changed.connect (list_pane_selection_changed_cb);
     list_pane.link_contacts.connect (list_pane_link_contacts_cb);
     list_pane.delete_contacts.connect (list_pane_delete_contacts_cb);
@@ -118,12 +116,12 @@ public class Contacts.Window : Gtk.ApplicationWindow {
     list_pane.show ();
   }
 
-  private void change_ui_state (UiState new_state) {
+  private void on_ui_state_changed () {
     // UI when we're not editing of selecting stuff
     this.add_button.visible
         = this.right_header.show_close_button
         = this.select_button.visible
-        = (new_state == UiState.NORMAL || new_state == UiState.SHOWING);
+        = (this.state == UiState.NORMAL || this.state == UiState.SHOWING);
 
     // UI when showing a contact
     this.edit_button.visible
@@ -131,29 +129,25 @@ public class Contacts.Window : Gtk.ApplicationWindow {
         = (new_state == UiState.SHOWING);
 
     // Selecting UI
-    this.select_cancel_button.visible = (new_state == UiState.SELECTING);
-    this.list_pane.activate_selection_mode (new_state == UiState.SELECTING);
+    this.select_cancel_button.visible = (this.state == UiState.SELECTING);
 
     this.left_header.title = (new_state == UiState.SELECTING)?  _("Select") : _("Contacts");
 
     // Editing UI
     this.cancel_button.visible
         = this.done_button.visible
-        = new_state.editing ();
-    if (new_state.editing ())
-      this.done_button.label = (new_state == UiState.CREATING)? _("Add") : _("Done");
+        = this.state.editing ();
+    if (this.state.editing ())
+      this.done_button.label = (this.state == UiState.CREATING)? _("Add") : _("Done");
 
     // When selecting or editing, we get special headerbars
-    if (new_state == UiState.SELECTING || new_state.editing ()) {
+    if (this.state == UiState.SELECTING || this.state.editing ()) {
       this.left_header.get_style_context ().add_class ("selection-mode");
       this.right_header.get_style_context ().add_class ("selection-mode");
     } else {
       this.left_header.get_style_context ().remove_class ("selection-mode");
       this.right_header.get_style_context ().remove_class ("selection-mode");
     }
-
-    // Save the result
-    this._state = new_state;
   }
 
   [GtkCallback]


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