[gnome-clocks] world-location-dialog: Port to GtkWindow



commit 8e621407296909547e5b5ef0422f85ff85103761
Author: Maximiliano Sandoval R <msandova gnome org>
Date:   Mon Dec 13 12:19:42 2021 +0100

    world-location-dialog: Port to GtkWindow

 data/ui/world-location-dialog.ui | 117 +++++++++++++--------------------------
 src/world-face.vala              |  10 ++--
 src/world-location-dialog.vala   |  19 +++++--
 3 files changed, 57 insertions(+), 89 deletions(-)
---
diff --git a/data/ui/world-location-dialog.ui b/data/ui/world-location-dialog.ui
index 7005983c..ea3695d5 100644
--- a/data/ui/world-location-dialog.ui
+++ b/data/ui/world-location-dialog.ui
@@ -1,110 +1,75 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <template class="ClocksWorldLocationDialog" parent="GtkDialog">
-    <property name="title" translatable="yes">Add World Clock</property>
+  <template class="ClocksWorldLocationDialog" parent="GtkWindow">
+    <property name="title" translatable="yes">Add a New World Clock</property>
     <property name="modal">True</property>
-    <property name="window_position">center-on-parent</property>
     <property name="default_width">400</property>
     <property name="default_height">540</property>
     <property name="destroy_with_parent">True</property>
-    <property name="type_hint">dialog</property>
-    <property name="gravity">center</property>
-    <property name="use_header_bar">1</property>
-    <child internal-child="headerbar">
+    <property name="titlebar">
       <object class="GtkHeaderBar" id="dialog-header-bar">
-        <property name="title" translatable="yes">Add a New World Clock</property>
         <property name="show_title_buttons">False</property>
         <child>
-          <object class="GtkButton" id="button1">
+          <object class="GtkButton">
             <property name="label" translatable="yes">_Cancel</property>
-            <property name="receives_default">True</property>
             <property name="use_underline">True</property>
             <property name="valign">center</property>
+            <property name="action-name">window.close</property>
           </object>
         </child>
         <child type="end">
           <object class="GtkButton" id="button_add">
             <property name="label" translatable="yes">_Add</property>
             <property name="sensitive">False</property>
-            <property name="can_default">True</property>
-            <property name="has_default">True</property>
-            <property name="receives_default">True</property>
             <property name="use_underline">True</property>
             <property name="valign">center</property>
+            <signal name="clicked" handler="add_button_clicked"/>
             <style>
               <class name="suggested-action"/>
             </style>
           </object>
         </child>
       </object>
-    </child>
-    <child internal-child="vbox">
-      <object class="GtkBox" id="dialog-vbox1">
-        <property name="orientation">vertical</property>
-        <property name="spacing">2</property>
-        <child internal-child="action_area">
-          <object class="GtkButtonBox">
-          </object>
-        </child>
+    </property>
+    <child>
+      <object class="GtkScrolledWindow">
+        <property name="hscrollbar_policy">never</property>
+        <property name="height_request">250</property>
         <child>
-          <object class="GtkScrolledWindow">
-            <property name="hscrollbar_policy">never</property>
-            <property name="height_request">250</property>
+          <object class="AdwClamp">
+            <property name="width_request">300</property>
             <child>
-              <object class="AdwClamp">
-                <property name="width_request">300</property>
+              <object class="GtkBox">
+                <property name="orientation">vertical</property>
+                <child>
+                  <object class="GtkSearchEntry" id="location_entry">
+                    <property name="margin_top">18</property>
+                    <property name="margin_start">50</property>
+                    <property name="margin_end">50</property>
+                    <signal name="search-changed" handler="on_search_changed" swapped="no"/>
+                  </object>
+                </child>
                 <child>
-                  <object class="GtkBox">
-                    <property name="orientation">vertical</property>
+                  <object class="GtkStack" id="stack">
+                    <property name="hexpand">True</property>
+                    <property name="vexpand">True</property>
+                    <property name="transition_duration">100</property>
+                    <property name="transition_type">crossfade</property>
                     <child>
-                      <object class="GtkSearchEntry" id="location_entry">
-                        <property name="margin_top">18</property>
-                        <property name="margin_start">50</property>
-                        <property name="margin_end">50</property>
-                        <signal name="search-changed" handler="on_search_changed" swapped="no"/>
+                      <object class="AdwStatusPage" id="empty_search">
+                        <property name="icon_name">edit-find-symbolic</property>
+                        <property name="title" translatable="yes">Search for a City</property>
                       </object>
                     </child>
                     <child>
-                      <object class="GtkStack" id="stack">
-                        <property name="hexpand">True</property>
-                        <property name="vexpand">True</property>
-                        <property name="transition_duration">100</property>
-                        <property name="transition_type">crossfade</property>
-                        <child>
-                          <object class="GtkBox" id="empty_search_box">
-                            <property name="valign">center</property>
-                            <property name="orientation">vertical</property>
-                            <child>
-                              <object class="GtkImage">
-                                <property name="pixel_size">128</property>
-                                <property name="icon_name">edit-find-symbolic</property>
-                                <property name="margin_bottom">36</property>
-                                <style>
-                                  <class name="dim-label"/>
-                                </style>
-                              </object>
-                            </child>
-                            <child>
-                              <object class="GtkLabel">
-                                <property name="label" translatable="yes">Search for a City</property>
-                                <style>
-                                  <class name="large-title"/>
-                                </style>
-                              </object>
-                            </child>
-                          </object>
-                        </child>
-                        <child>
-                          <object class="GtkListBox" id="listbox">
-                            <property name="valign">start</property>
-                            <property name="selection_mode">none</property>
-                            <style>
-                              <class name="clocks-list"/>
-                              <class name="content"/>
-                            </style>
-                            <signal name="row-activated" handler="item_activated" swapped="no"/>
-                          </object>
-                        </child>
+                      <object class="GtkListBox" id="listbox">
+                        <property name="valign">start</property>
+                        <property name="selection_mode">none</property>
+                        <style>
+                          <class name="clocks-list"/>
+                          <class name="content"/>
+                        </style>
+                        <signal name="row-activated" handler="item_activated" swapped="no"/>
                       </object>
                     </child>
                   </object>
@@ -115,9 +80,5 @@
         </child>
       </object>
     </child>
-    <action-widgets>
-      <action-widget response="0">button1</action-widget>
-      <action-widget response="1">button_add</action-widget>
-    </action-widgets>
   </template>
 </interface>
diff --git a/src/world-face.vala b/src/world-face.vala
index 13f3baa1..2701bd93 100644
--- a/src/world-face.vala
+++ b/src/world-face.vala
@@ -151,16 +151,14 @@ public class Face : Adw.Bin, Clocks.Clock {
     public void activate_new () {
         var dialog = new LocationDialog ((Gtk.Window) get_root (), this);
 
-        dialog.response.connect ((_, response) => {
-            if (response == 1) {
+        dialog.location_added.connect (() => {
                 var location = dialog.get_selected_location ();
                 if (location != null)
                     add_location ((GWeather.Location) location);
-            }
 
-            dialog.destroy ();
-        });
-        dialog.show ();
+                dialog.destroy ();
+            });
+        dialog.present ();
     }
 
     private void reset_view () {
diff --git a/src/world-location-dialog.vala b/src/world-location-dialog.vala
index 7e288052..f90dd128 100644
--- a/src/world-location-dialog.vala
+++ b/src/world-location-dialog.vala
@@ -29,11 +29,11 @@ private class ClockLocation : Object {
 }
 
 [GtkTemplate (ui = "/org/gnome/clocks/ui/world-location-dialog.ui")]
-private class LocationDialog : Gtk.Dialog {
+private class LocationDialog : Gtk.Window {
     [GtkChild]
     private unowned Gtk.Stack stack;
     [GtkChild]
-    private unowned Gtk.Box empty_search_box;
+    private unowned Gtk.Widget empty_search;
     [GtkChild]
     private unowned Gtk.SearchEntry location_entry;
     [GtkChild]
@@ -56,7 +56,7 @@ private class LocationDialog : Gtk.Dialog {
     private const int RESULT_COUNT_LIMIT = 12;
 
     public LocationDialog (Gtk.Window parent, Face world_face) {
-        Object (transient_for: parent, use_header_bar: 1);
+        Object (transient_for: parent);
 
         // TODO GTK 4
         // key_press_event.connect ((event) => {
@@ -103,7 +103,7 @@ private class LocationDialog : Gtk.Dialog {
         locations.remove_all ();
 
         if (location_entry.text == "") {
-            stack.visible_child = empty_search_box;
+            stack.visible_child = empty_search;
             return;
         }
 
@@ -116,7 +116,7 @@ private class LocationDialog : Gtk.Dialog {
         query_locations ((GWeather.Location) world_location, search);
 
         if (locations.get_n_items () == 0) {
-            stack.visible_child = empty_search_box;
+            stack.visible_child = empty_search;
             return;
         }
         locations.sort ((a, b) => {
@@ -128,6 +128,15 @@ private class LocationDialog : Gtk.Dialog {
         stack.visible_child = listbox;
     }
 
+    public signal void location_added ();
+
+    [GtkCallback]
+    private void add_button_clicked () {
+        // emit ("location-added");
+        location_added ();
+        close ();
+    }
+
     private void query_locations (GWeather.Location location, string search) {
         if (locations.get_n_items () >= RESULT_COUNT_LIMIT) return;
 


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