[recipes] Make the chef dialog a dialog



commit 37b126ec9882b36d58cf8c618e4e7bc249be4979
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Feb 28 22:24:00 2017 -0500

    Make the chef dialog a dialog
    
    This will let us adapt to platform conventions wrt to header bars.

 src/gr-chef-dialog.c  |   32 +++++++++++++++++++-------------
 src/gr-chef-dialog.h  |    2 +-
 src/gr-chef-dialog.ui |   48 +++++++++++++++++++++---------------------------
 3 files changed, 41 insertions(+), 41 deletions(-)
---
diff --git a/src/gr-chef-dialog.c b/src/gr-chef-dialog.c
index b9ec120..060a351 100644
--- a/src/gr-chef-dialog.c
+++ b/src/gr-chef-dialog.c
@@ -38,7 +38,7 @@
 
 struct _GrChefDialog
 {
-        GtkWindow parent_instance;
+        GtkDialog parent_instance;
 
         GtkWidget *fullname;
         GtkWidget *name;
@@ -60,7 +60,7 @@ struct _GrChefDialog
         GrChef *chef;
 };
 
-G_DEFINE_TYPE (GrChefDialog, gr_chef_dialog, GTK_TYPE_WINDOW)
+G_DEFINE_TYPE (GrChefDialog, gr_chef_dialog, GTK_TYPE_DIALOG)
 
 static int done_signal;
 
@@ -112,7 +112,9 @@ revert_changes (GrChefDialog *self)
 static void
 field_changed (GrChefDialog *self)
 {
-        gtk_widget_set_sensitive (self->save_button, TRUE);
+        gtk_dialog_set_response_sensitive (GTK_DIALOG (self),
+                                           GTK_RESPONSE_APPLY,
+                                           TRUE);
 }
 
 static void
@@ -331,10 +333,9 @@ gr_chef_dialog_set_chef (GrChefDialog *self,
                 update_image (self);
         }
 
-        if (same_chef)
-                gtk_widget_set_sensitive (self->save_button, TRUE);
-        else
-                gtk_widget_set_sensitive (self->save_button, FALSE);
+        gtk_dialog_set_response_sensitive (GTK_DIALOG (self),
+                                           GTK_RESPONSE_APPLY,
+                                           same_chef);
 }
 
 static void
@@ -457,11 +458,9 @@ gr_chef_dialog_can_create (GrChefDialog *dialog,
         }
         else {
                 gtk_widget_hide (dialog->create_button);
-
-                if (gr_chef_is_readonly (dialog->chef))
-                        gtk_widget_set_sensitive (dialog->save_button, FALSE);
-                else
-                        gtk_widget_set_sensitive (dialog->save_button, TRUE);
+                gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
+                                                   GTK_RESPONSE_APPLY,
+                                                   !gr_chef_is_readonly (dialog->chef));
         }
 }
 
@@ -470,8 +469,15 @@ gr_chef_dialog_new (GrChef   *chef,
                     gboolean  create)
 {
         GrChefDialog *dialog;
+        gboolean use_header_bar;
+
+        g_object_get (gtk_settings_get_default (),
+                      "gtk-dialogs-use-header", &use_header_bar,
+                      NULL);
 
-        dialog = g_object_new (GR_TYPE_CHEF_DIALOG, NULL);
+        dialog = g_object_new (GR_TYPE_CHEF_DIALOG,
+                               "use-header-bar", use_header_bar,
+                               NULL);
 
         gr_chef_dialog_set_chef (dialog, chef);
         gr_chef_dialog_can_create (dialog, create);
diff --git a/src/gr-chef-dialog.h b/src/gr-chef-dialog.h
index 13bcf82..4f377e1 100644
--- a/src/gr-chef-dialog.h
+++ b/src/gr-chef-dialog.h
@@ -28,7 +28,7 @@ G_BEGIN_DECLS
 
 #define GR_TYPE_CHEF_DIALOG (gr_chef_dialog_get_type())
 
-G_DECLARE_FINAL_TYPE (GrChefDialog, gr_chef_dialog, GR, CHEF_DIALOG, GtkWindow)
+G_DECLARE_FINAL_TYPE (GrChefDialog, gr_chef_dialog, GR, CHEF_DIALOG, GtkDialog)
 
 GrChefDialog *gr_chef_dialog_new        (GrChef       *chef,
                                          gboolean      create);
diff --git a/src/gr-chef-dialog.ui b/src/gr-chef-dialog.ui
index 194a381..08609ab 100644
--- a/src/gr-chef-dialog.ui
+++ b/src/gr-chef-dialog.ui
@@ -1,39 +1,29 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface domain="gnome-recipes">
   <!-- interface-requires gtk+ 3.8 -->
-  <template class="GrChefDialog" parent="GtkWindow">
+  <template class="GrChefDialog" parent="GtkDialog">
     <property name="title" translatable="yes">Chef Information</property>
     <property name="resizable">False</property>
     <property name="modal">True</property>
-    <child type="titlebar">
-      <object class="GtkHeaderBar">
+    <child type="action">
+      <object class="GtkButton" id="cancel_button">
         <property name="visible">1</property>
-        <child>
-          <object class="GtkButton" id="cancel_button">
-            <property name="visible">1</property>
-            <property name="label" translatable="yes">_Cancel</property>
-            <property name="use-underline">1</property>
-            <signal name="clicked" handler="close_dialog" swapped="yes"/>
-          </object>
-        </child>
-        <child>
-          <object class="GtkButton" id="save_button">
-            <property name="visible">1</property>
-            <property name="sensitive">0</property>
-            <property name="label" translatable="yes">_Save</property>
-            <property name="use-underline">1</property>
-            <signal name="clicked" handler="save_chef" swapped="yes"/>
-            <style>
-              <class name="suggested-action"/>
-            </style>
-          </object>
-          <packing>
-            <property name="pack-type">end</property>
-          </packing>
-        </child>
+        <property name="label" translatable="yes">_Cancel</property>
+        <property name="use-underline">1</property>
+        <signal name="clicked" handler="close_dialog" swapped="yes"/>
       </object>
     </child>
-    <child>
+    <child type="action">
+      <object class="GtkButton" id="save_button">
+        <property name="visible">1</property>
+        <property name="sensitive">0</property>
+        <property name="can-default">1</property>
+        <property name="label" translatable="yes">_Save</property>
+        <property name="use-underline">1</property>
+        <signal name="clicked" handler="save_chef" swapped="yes"/>
+      </object>
+    </child>
+    <child internal-child="vbox">
       <object class="GtkBox">
         <property name="visible">1</property>
         <property name="orientation">vertical</property>
@@ -204,6 +194,10 @@
         </child>
       </object>
     </child>
+    <action-widgets>
+      <action-widget response="cancel">cancel_button</action-widget>
+      <action-widget response="apply" default="true">save_button</action-widget>
+    </action-widgets>
   </template>
   <object class="GtkPopover" id="chef_popover">
     <child>


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