[gnome-sudoku/gnome-3-14] Conditionally use header bar in print multiple dialog



commit 052af4c488e9d37c1000f18976e377c12ecc3ad4
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Fri Oct 3 20:43:03 2014 -0500

    Conditionally use header bar in print multiple dialog

 data/print-dialog.ui  |   65 ++++++++++++++----------------------------------
 src/print-dialog.vala |   15 ++++++++++-
 2 files changed, 32 insertions(+), 48 deletions(-)
---
diff --git a/data/print-dialog.ui b/data/print-dialog.ui
index a6fd14f..b0c1450 100644
--- a/data/print-dialog.ui
+++ b/data/print-dialog.ui
@@ -10,58 +10,31 @@
     <property name="page_increment">10</property>
   </object>
   <template class="PrintDialog" parent="GtkDialog">
+    <property name="title" translatable="yes">Print Multiple Puzzles</property>
     <property name="can_focus">False</property>
     <property name="type_hint">dialog</property>
-    <property name="height_request">300</property>
     <property name="width_request">450</property>
     <property name="expand">False</property>
     <property name="modal">True</property>
-    <child internal-child="headerbar">
-      <object class="GtkHeaderBar">
-        <property name="title" translatable="yes">Print Multiple Puzzles</property>
+    <child type="action">
+      <object class="GtkButton" id="cancelbutton1">
+        <property name="label" translatable="yes">_Cancel</property>
         <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="show-close-button">False</property>
-        <child>
-          <object class="GtkButton" id="print_button">
-            <property name="label" translatable="yes">_Print</property>
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="can_default">True</property>
-            <property name="receives_default">False</property>
-            <property name="use_underline">True</property>
-            <property name="valign">center</property>
-            <style>
-              <class name="suggested-action"/>
-              <class name="text-button"/>
-            </style>
-          </object>
-          <packing>
-            <property name="pack_type">end</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkButton" id="cancelbutton1">
-            <property name="label" translatable="yes">_Cancel</property>
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="can_default">True</property>
-            <property name="receives_default">False</property>
-            <property name="use_underline">True</property>
-          </object>
-          <packing>
-            <property name="pack_type">start</property>
-          </packing>
-        </child>
-        <child>
-            <object class="GtkSpinner" id="spinner">
-                <property name="valign">center</property>
-                <property name="visible">False</property>
-            </object>
-            <packing>
-                <property name="pack_type">end</property>
-            </packing>
-        </child>
+        <property name="can_focus">True</property>
+        <property name="can_default">True</property>
+        <property name="receives_default">False</property>
+        <property name="use_underline">True</property>
+      </object>
+    </child>
+    <child type="action">
+      <object class="GtkButton" id="print_button">
+        <property name="label" translatable="yes">_Print</property>
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="can_default">True</property>
+        <property name="receives_default">False</property>
+        <property name="use_underline">True</property>
+        <property name="valign">center</property>
       </object>
     </child>
     <child internal-child="vbox">
diff --git a/src/print-dialog.vala b/src/print-dialog.vala
index a6e8099..3363094 100644
--- a/src/print-dialog.vala
+++ b/src/print-dialog.vala
@@ -35,7 +35,7 @@ public class PrintDialog : Gtk.Dialog
     private Gtk.RadioButton hard_radio_button;
     [GtkChild]
     private Gtk.RadioButton very_hard_radio_button;
-    [GtkChild]
+
     private Gtk.Spinner spinner;
 
     private const string DIFFICULTY_KEY_NAME = "print-multiple-sudoku-difficulty";
@@ -46,13 +46,17 @@ public class PrintDialog : Gtk.Dialog
 
     public PrintDialog (SudokuSaver saver, Gtk.Window window)
     {
-        Object(use_header_bar: 1);
+        Object (use_header_bar: Gtk.Settings.get_default ().gtk_dialogs_use_header ? 1 : 0);
 
         this.saver = saver;
         settings = new GLib.Settings ("org.gnome.sudoku");
 
         set_transient_for (window);
 
+        spinner = new Gtk.Spinner ();
+        if (use_header_bar == 1)
+            ((Gtk.HeaderBar) get_header_bar ()).pack_end (spinner);
+
         var saved_difficulty = (DifficultyCategory) settings.get_enum (DIFFICULTY_KEY_NAME);
         if (saved_difficulty == DifficultyCategory.EASY)
             easy_radio_button.set_active (true);
@@ -68,6 +72,13 @@ public class PrintDialog : Gtk.Dialog
         wrap_adjustment ("print-multiple-sudokus-to-print", n_sudokus_button.get_adjustment ());
     }
 
+    ~PrintDialog ()
+    {
+        // The spinner still has a floating reference if it wasn't added to the header bar.
+        if (use_header_bar != 1)
+            spinner.destroy();
+    }
+
     private void wrap_adjustment (string key_name, Gtk.Adjustment action)
     {
         action.set_value (settings.get_int (key_name));


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