[gnome-contacts/wip/exalm/primarymenu] contacts-window: Clean up primary menu



commit 9c7464aa61989ebb3938d48afb458d67f5c51995
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Sun Dec 23 21:34:57 2018 +0500

    contacts-window: Clean up primary menu
    
    Use model buttons instead of grid with labels and radio buttons, also
    shrink paddings to match other apps.

 data/ui/contacts-window.ui | 62 +++++++++-------------------------------------
 src/contacts-window.vala   | 22 ++++++++++++----
 2 files changed, 29 insertions(+), 55 deletions(-)
---
diff --git a/data/ui/contacts-window.ui b/data/ui/contacts-window.ui
index e8d8815..f9941f9 100644
--- a/data/ui/contacts-window.ui
+++ b/data/ui/contacts-window.ui
@@ -5,13 +5,13 @@
     <child>
       <object class="GtkBox" id="hamburger_menu_box">
         <property name="visible">True</property>
-        <property name="spacing">6</property>
-        <property name="margin">18</property>
+        <property name="margin">12</property>
         <property name="orientation">vertical</property>
         <property name="width_request">200</property>
         <child>
           <object class="GtkLabel">
             <property name="visible">True</property>
+            <property name="margin">5</property>
             <property name="halign">start</property>
             <property name="label" translatable="yes">List contacts by:</property>
             <attributes>
@@ -24,55 +24,17 @@
           </object>
         </child>
         <child>
-          <object class="GtkGrid">
+          <object class="GtkModelButton" id="sort_on_firstname_button">
             <property name="visible">True</property>
-            <property name="row_spacing" bind-source="hamburger_menu_box" bind-property="spacing" 
bind-flags="bidirectional|sync-create"/>
-            <child>
-              <object class="GtkRadioButton" id="sort_on_firstname_button">
-                <property name="visible">True</property>
-                <property name="group">sort_on_firstname_button</property>
-              </object>
-              <packing>
-                <property name="top_attach">0</property>
-                <property name="left_attach">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel">
-                <property name="visible">True</property>
-                <property name="halign">start</property>
-                <property name="hexpand">True</property>
-                <property name="label" translatable="yes">First name</property>
-                <property name="mnemonic_widget">sort_on_firstname_button</property>
-              </object>
-              <packing>
-                <property name="top_attach">0</property>
-                <property name="left_attach">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkRadioButton" id="sort_on_surname_button">
-                <property name="visible">True</property>
-                <property name="group">sort_on_firstname_button</property>
-              </object>
-              <packing>
-                <property name="top_attach">1</property>
-                <property name="left_attach">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel">
-                <property name="visible">True</property>
-                <property name="halign">start</property>
-                <property name="hexpand">True</property>
-                <property name="label" translatable="yes">Surname</property>
-                <property name="mnemonic_widget">sort_on_surname_button</property>
-              </object>
-              <packing>
-                <property name="top_attach">1</property>
-                <property name="left_attach">0</property>
-              </packing>
-            </child>
+            <property name="text" translatable="yes">First name</property>
+            <property name="role">radio</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkModelButton" id="sort_on_surname_button">
+            <property name="visible">True</property>
+            <property name="text" translatable="yes">Surname</property>
+            <property name="role">radio</property>
           </object>
         </child>
         <child>
diff --git a/src/contacts-window.vala b/src/contacts-window.vala
index a8e4003..8c8c9c7 100644
--- a/src/contacts-window.vala
+++ b/src/contacts-window.vala
@@ -45,7 +45,9 @@ public class Contacts.Window : Gtk.ApplicationWindow {
   [GtkChild]
   private MenuButton hamburger_menu_button;
   [GtkChild]
-  private RadioButton sort_on_surname_button;
+  private ModelButton sort_on_firstname_button;
+  [GtkChild]
+  private ModelButton sort_on_surname_button;
   [GtkChild]
   private ToggleButton favorite_button;
   private bool ignore_favorite_button_toggled;
@@ -91,10 +93,15 @@ public class Contacts.Window : Gtk.ApplicationWindow {
     );
 
     this.settings = settings;
-    this.sort_on_surname_button.active = this.settings.sort_on_surname;
-    this.sort_on_surname_button.toggled.connect (() => {
-        this.settings.sort_on_surname = this.sort_on_surname_button.active;
-      });
+    this.sort_on_firstname_button.clicked.connect (() => {
+      this.settings.sort_on_surname = false;
+      on_sort_changed ();
+    });
+    this.sort_on_surname_button.clicked.connect (() => {
+      this.settings.sort_on_surname = true;
+      on_sort_changed ();
+    });
+    on_sort_changed ();
 
     this.notify["state"].connect (on_ui_state_changed);
 
@@ -104,6 +111,11 @@ public class Contacts.Window : Gtk.ApplicationWindow {
     restore_window_size_and_position_from_settings ();
   }
 
+  private void on_sort_changed () {
+    this.sort_on_firstname_button.active = !this.settings.sort_on_surname;
+    this.sort_on_surname_button.active = this.settings.sort_on_surname;
+  }
+
   private void restore_window_size_and_position_from_settings () {
     var screen = get_screen();
     if (screen != null && this.window_width <= screen.get_width () && this.window_height <= 
screen.get_height ()) {


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