[gnome-sudoku] Don't set the header bar as the titlebar in Unity



commit e4754cdc69de7752b615b374cc1682adcf91b864
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sun Sep 28 09:14:48 2014 -0500

    Don't set the header bar as the titlebar in Unity

 data/gnome-sudoku.ui  |  435 +++++++++++++++++++++++++------------------------
 src/gnome-sudoku.vala |   25 ++-
 2 files changed, 239 insertions(+), 221 deletions(-)
---
diff --git a/data/gnome-sudoku.ui b/data/gnome-sudoku.ui
index 84c3b08..91ca95e 100644
--- a/data/gnome-sudoku.ui
+++ b/data/gnome-sudoku.ui
@@ -1,286 +1,295 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
     <!-- interface-requires gtk+ 3.10 -->
-    <object class="GtkApplicationWindow" id="sudoku_app">
+    <object class="GtkHeaderBar" id="headerbar">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
         <property name="title" translatable="yes">Sudoku</property>
-        <property name="border-width">25</property>
-        <child type="titlebar">
-            <object class="GtkHeaderBar" id="headerbar">
+        <child>
+            <object class="GtkBox" id="undo_redo_box">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="show_close_button">True</property>
-                <property name="title" translatable="yes">Sudoku</property>
+                <property name="homogeneous">True</property>
+                <style>
+                  <class name="raised"/>
+                  <class name="linked"/>
+                </style>
                 <child>
-                    <object class="GtkBox" id="undo_redo_box">
+                    <object class="GtkButton" id="undo_button">
                         <property name="visible">True</property>
-                        <property name="homogeneous">True</property>
+                        <property name="sensitive">False</property>
+                        <property name="valign">center</property>
+                        <property name="tooltip-text" translatable="yes">Undo your last action</property>
+                        <property name="can_focus">True</property>
+                        <property name="focus_on_click">False</property>
+                        <property name="action-name">app.undo</property>
                         <style>
-                          <class name="raised"/>
-                          <class name="linked"/>
+                            <class name="image-button"/>
                         </style>
                         <child>
-                            <object class="GtkButton" id="undo_button">
-                                <property name="visible">True</property>
-                                <property name="sensitive">False</property>
-                                <property name="valign">center</property>
-                                <property name="tooltip-text" translatable="yes">Undo your last 
action</property>
-                                <property name="can_focus">True</property>
-                                <property name="focus_on_click">False</property>
-                                <property name="action-name">app.undo</property>
-                                <style>
-                                    <class name="image-button"/>
-                                </style>
-                                <child>
-                                    <object class="GtkImage" id="undo_image">
-                                        <property name="icon_name">edit-undo-symbolic</property>
-                                        <property name="visible">True</property>
-                                        <property name="icon_size">1</property>
-                                    </object>
-                                </child>
-                            </object>
-                        </child>
-                        <child>
-                            <object class="GtkButton" id="redo_button">
+                            <object class="GtkImage" id="undo_image">
+                                <property name="icon_name">edit-undo-symbolic</property>
                                 <property name="visible">True</property>
-                                <property name="sensitive">False</property>
-                                <property name="valign">center</property>
-                                <property name="tooltip-text" translatable="yes">Redo your last 
action</property>
-                                <property name="can_focus">True</property>
-                                <property name="focus_on_click">False</property>
-                                <property name="action-name">app.redo</property>
-                                <style>
-                                    <class name="image-button"/>
-                                </style>
-                                <child>
-                                    <object class="GtkImage" id="redo_image">
-                                        <property name="icon_name">edit-redo-symbolic</property>
-                                        <property name="visible">True</property>
-                                        <property name="icon_size">1</property>
-                                    </object>
-                                </child>
+                                <property name="icon_size">1</property>
                             </object>
                         </child>
                     </object>
                 </child>
                 <child>
-                    <object class="GtkButton" id="back_button">
-                        <property name="visible">False</property>
-                        <property name="halign">center</property>
+                    <object class="GtkButton" id="redo_button">
+                        <property name="visible">True</property>
+                        <property name="sensitive">False</property>
                         <property name="valign">center</property>
-                        <property name="tooltip-text" translatable="yes">Go back to the current 
game</property>
-                        <property name="use_underline">True</property>
-                        <property name="action-name">app.back</property>
+                        <property name="tooltip-text" translatable="yes">Redo your last action</property>
+                        <property name="can_focus">True</property>
+                        <property name="focus_on_click">False</property>
+                        <property name="action-name">app.redo</property>
                         <style>
                             <class name="image-button"/>
                         </style>
                         <child>
-                            <object class="GtkImage" id="back_image">
-                                <property name="icon_name">go-previous-symbolic</property>
+                            <object class="GtkImage" id="redo_image">
+                                <property name="icon_name">edit-redo-symbolic</property>
                                 <property name="visible">True</property>
                                 <property name="icon_size">1</property>
                             </object>
                         </child>
                     </object>
                 </child>
+            </object>
+        </child>
+        <child>
+            <object class="GtkBox" id="timer_box">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="spacing">6</property>
+                <child>
+                    <object class="GtkImage" id="clock_image">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="icon_name">preferences-system-time-symbolic</property>
+                        <property name="icon_size">1</property>
+                    </object>
+                </child>
                 <child>
                     <object class="GtkLabel" id="clock_label">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <property name="halign">center</property>
                     </object>
-                    <packing>
-                        <property name="pack-type">end</property>
-                    </packing>
                 </child>
+            </object>
+            <packing>
+                <property name="pack-type">end</property>
+            </packing>
+        </child>
+        <child>
+            <object class="GtkButton" id="back_button">
+                <property name="visible">False</property>
+                <property name="halign">center</property>
+                <property name="valign">center</property>
+                <property name="tooltip-text" translatable="yes">Go back to the current game</property>
+                <property name="use_underline">True</property>
+                <property name="action-name">app.back</property>
+                <style>
+                    <class name="image-button"/>
+                </style>
                 <child>
-                    <object class="GtkImage" id="clock_image">
+                    <object class="GtkImage" id="back_image">
+                        <property name="icon_name">go-previous-symbolic</property>
                         <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="icon_name">preferences-system-time-symbolic</property>
                         <property name="icon_size">1</property>
                     </object>
-                    <packing>
-                        <property name="pack-type">end</property>
-                    </packing>
                 </child>
             </object>
         </child>
+    </object>
+    <object class="GtkApplicationWindow" id="sudoku_app">
+        <property name="title" translatable="yes">Sudoku</property>
         <child>
-            <object class="GtkStack" id="main_stack">
+            <object class="GtkBox" id="vbox">
+                <property name="orientation">vertical</property>
                 <property name="visible">True</property>
-                <property name="homogeneous">True</property>
                 <child>
-                    <object class="GtkBox" id="start_box">
-                        <property name="orientation">vertical</property>
+                    <object class="GtkStack" id="main_stack">
                         <property name="visible">True</property>
-                        <property name="halign">center</property>
-                        <property name="valign">center</property>
                         <property name="homogeneous">True</property>
-                        <property name="margin">0</property>
-                        <property name="width-request">350</property>
-                        <property name="height-request">350</property>
-                        <child>
-                            <object class="GtkButton" id="easy_button">
-                                <property name="visible">True</property>
-                                <property name="use_underline">True</property>
-                                <property name="label" translatable="yes">_Easy</property>
-                                <property name="action-name">app.start-game</property>
-                                <property name="action-target">1</property>  <!-- 1 corresponds to enum 
DifficultyCategory.EASY -->
-                            </object>
-                            <packing>
-                                <property name="expand">True</property>
-                                <property name="fill">True</property>
-                                <property name="position">0</property>
-                            </packing>
-                        </child>
-                        <child>
-                            <object class="GtkButton" id="medium_button">
-                                <property name="visible">True</property>
-                                <property name="use_underline">True</property>
-                                <property name="label" translatable="yes">_Medium</property>
-                                <property name="action-name">app.start-game</property>
-                                <property name="action-target">2</property>  <!-- 2 corresponds to enum 
DifficultyCategory.MEDIUM -->
-                            </object>
-                            <packing>
-                                <property name="expand">True</property>
-                                <property name="fill">True</property>
-                                <property name="position">1</property>
-                            </packing>
-                        </child>
-                        <child>
-                            <object class="GtkButton" id="hard_button">
-                                <property name="visible">True</property>
-                                <property name="use_underline">True</property>
-                                <property name="label" translatable="yes">_Hard</property>
-                                <property name="action-name">app.start-game</property>
-                                <property name="action-target">3</property>  <!-- 3 corresponds to enum 
DifficultyCategory.HARD -->
-                            </object>
-                            <packing>
-                                <property name="expand">True</property>
-                                <property name="fill">True</property>
-                                <property name="position">2</property>
-                            </packing>
-                        </child>
+                        <property name="margin">25</property>
+                        <property name="expand">True</property>
                         <child>
-                            <object class="GtkButton" id="very_hard_button">
+                            <object class="GtkBox" id="start_box">
+                                <property name="orientation">vertical</property>
                                 <property name="visible">True</property>
-                                <property name="use_underline">True</property>
-                                <property name="label" translatable="yes">_Very Hard</property>
-                                <property name="action-name">app.start-game</property>
-                                <property name="action-target">4</property>  <!-- 4 corresponds to enum 
DifficultyCategory.VERY_HARD -->
-                            </object>
+                                <property name="halign">center</property>
+                                <property name="valign">center</property>
+                                <property name="homogeneous">True</property>
+                                <property name="margin">0</property>
+                                <property name="width-request">350</property>
+                                <property name="height-request">350</property>
+                                <child>
+                                    <object class="GtkButton" id="easy_button">
+                                        <property name="visible">True</property>
+                                        <property name="use_underline">True</property>
+                                        <property name="label" translatable="yes">_Easy</property>
+                                        <property name="action-name">app.start-game</property>
+                                        <property name="action-target">1</property>  <!-- 1 corresponds to 
enum DifficultyCategory.EASY -->
+                                    </object>
+                                    <packing>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">0</property>
+                                    </packing>
+                                </child>
+                                <child>
+                                    <object class="GtkButton" id="medium_button">
+                                        <property name="visible">True</property>
+                                        <property name="use_underline">True</property>
+                                        <property name="label" translatable="yes">_Medium</property>
+                                        <property name="action-name">app.start-game</property>
+                                        <property name="action-target">2</property>  <!-- 2 corresponds to 
enum DifficultyCategory.MEDIUM -->
+                                    </object>
+                                    <packing>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">1</property>
+                                    </packing>
+                                </child>
+                                <child>
+                                    <object class="GtkButton" id="hard_button">
+                                        <property name="visible">True</property>
+                                        <property name="use_underline">True</property>
+                                        <property name="label" translatable="yes">_Hard</property>
+                                        <property name="action-name">app.start-game</property>
+                                        <property name="action-target">3</property>  <!-- 3 corresponds to 
enum DifficultyCategory.HARD -->
+                                    </object>
+                                    <packing>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">2</property>
+                                    </packing>
+                                </child>
+                                <child>
+                                    <object class="GtkButton" id="very_hard_button">
+                                        <property name="visible">True</property>
+                                        <property name="use_underline">True</property>
+                                        <property name="label" translatable="yes">_Very Hard</property>
+                                        <property name="action-name">app.start-game</property>
+                                        <property name="action-target">4</property>  <!-- 4 corresponds to 
enum DifficultyCategory.VERY_HARD -->
+                                    </object>
+                                    <packing>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">3</property>
+                                    </packing>
+                                </child>
+                            </object> <!-- End of start_box -->
                             <packing>
-                                <property name="expand">True</property>
-                                <property name="fill">True</property>
-                                <property name="position">3</property>
+                                <property name="name">start_box</property>
                             </packing>
                         </child>
-                    </object> <!-- End of start_box -->
-                    <packing>
-                        <property name="name">start_box</property>
-                    </packing>
-                </child>
-                <child>
-                    <object class="GtkAspectFrame" id="frame">
-                        <property name="visible">True</property>
-                        <property name="shadow-type">GTK_SHADOW_NONE</property>
-                        <property name="obey-child">false</property>
-                        <property name="ratio">1.4</property>
-                        <property name="xalign">0.5</property>
-                        <property name="yalign">0.5</property>
                         <child>
-                            <object class="GtkBox" id="game_box">
+                            <object class="GtkAspectFrame" id="frame">
                                 <property name="visible">True</property>
-                                <property name="spacing">25</property>
+                                <property name="shadow-type">GTK_SHADOW_NONE</property>
+                                <property name="obey-child">false</property>
+                                <property name="ratio">1.4</property>
+                                <property name="xalign">0.5</property>
+                                <property name="yalign">0.5</property>
                                 <child>
-                                    <placeholder/>
-                                </child>
-                                <child>
-                                    <object class="GtkButtonBox" id="controls_box">
+                                    <object class="GtkBox" id="game_box">
                                         <property name="visible">True</property>
-                                        <property name="halign">end</property>
-                                        <property name="valign">end</property>
-                                        <property name="can_focus">False</property>
-                                        <property name="orientation">vertical</property>
-                                        <property name="spacing">6</property>
+                                        <property name="spacing">25</property>
                                         <child>
-                                            <object class="GtkButton" id="play_pause_button">
-                                               <property name="visible">True</property>
-                                                <property name="can_focus">True</property>
-                                                <property name="receives_default">True</property>
-                                                <property name="action_name">app.pause</property>
-                                                <property name="use_underline">True</property>
-                                                <property name="width-request">120</property>
-                                                <property name="height-request">60</property>
+                                            <object class="GtkButtonBox" id="controls_box">
+                                                <property name="visible">True</property>
+                                                <property name="halign">end</property>
+                                                <property name="valign">end</property>
+                                                <property name="can_focus">False</property>
+                                                <property name="orientation">vertical</property>
+                                                <property name="spacing">6</property>
                                                 <child>
-                                                    <object class="GtkLabel" id="play_pause_label">
+                                                    <object class="GtkButton" id="play_pause_button">
                                                         <property name="visible">True</property>
-                                                        <property name="can_focus">False</property>
-                                                        <property name="margin">12</property>
-                                                        <property name="label" 
translatable="yes">_Pause</property>
+                                                        <property name="can_focus">True</property>
+                                                        <property name="receives_default">True</property>
+                                                        <property name="action_name">app.pause</property>
                                                         <property name="use_underline">True</property>
+                                                        <property name="width-request">120</property>
+                                                        <property name="height-request">60</property>
+                                                        <child>
+                                                            <object class="GtkLabel" id="play_pause_label">
+                                                                <property name="visible">True</property>
+                                                                <property name="can_focus">False</property>
+                                                                <property name="margin">12</property>
+                                                                <property name="label" 
translatable="yes">_Pause</property>
+                                                                <property 
name="use_underline">True</property>
+                                                            </object>
+                                                        </child>
                                                     </object>
+                                                        <packing>
+                                                        <property name="expand">False</property>
+                                                        <property name="fill">True</property>
+                                                        <property name="pack_type">end</property>
+                                                        <property name="position">0</property>
+                                                    </packing>
                                                 </child>
-                                            </object>
-                                                <packing>
-                                                <property name="expand">False</property>
-                                                <property name="fill">True</property>
-                                                <property name="pack_type">end</property>
-                                                <property name="position">0</property>
-                                            </packing>
-                                        </child>
-                                        <child>
-                                            <object class="GtkButton" id="clear_button">
-                                                <property name="visible">True</property>
-                                                <property name="use_underline">True</property>
-                                                <property name="label" translatable="yes">_Clear 
Board</property>
-                                                <property name="halign">fill</property>
-                                                <property name="valign">center</property>
-                                                <property name="action-name">app.reset</property>
-                                                <property name="tooltip-text" translatable="yes">Reset the 
board to its original state</property>
-                                                <property name="width-request">120</property>
-                                                <property name="height-request">60</property>
-                                            </object>
-                                            <packing>
-                                                <property name="expand">True</property>
-                                                <property name="fill">True</property>
-                                                <property name="position">1</property>
-                                            </packing>
-                                        </child>
-                                        <child>
-                                            <object class="GtkButton" id="new_button">
-                                                <property name="visible">True</property>
-                                                <property name="use_underline">True</property>
-                                                <property name="label" translatable="yes">_New 
Puzzle</property>
-                                                <property name="halign">fill</property>
-                                                <property name="valign">center</property>
-                                                <property name="action-name">app.new-game</property>
-                                                <property name="tooltip-text" translatable="yes">Start a new 
puzzle</property>
-                                                <property name="width-request">120</property>
-                                                <property name="height-request">60</property>
-                                            </object>
+                                                <child>
+                                                    <object class="GtkButton" id="clear_button">
+                                                        <property name="visible">True</property>
+                                                        <property name="use_underline">True</property>
+                                                        <property name="label" translatable="yes">_Clear 
Board</property>
+                                                        <property name="halign">fill</property>
+                                                        <property name="valign">center</property>
+                                                        <property name="action-name">app.reset</property>
+                                                        <property name="tooltip-text" 
translatable="yes">Reset the board to its original state</property>
+                                                        <property name="width-request">120</property>
+                                                        <property name="height-request">60</property>
+                                                    </object>
+                                                    <packing>
+                                                        <property name="expand">True</property>
+                                                        <property name="fill">True</property>
+                                                        <property name="position">1</property>
+                                                    </packing>
+                                                </child>
+                                                <child>
+                                                    <object class="GtkButton" id="new_button">
+                                                        <property name="visible">True</property>
+                                                        <property name="use_underline">True</property>
+                                                        <property name="label" translatable="yes">_New 
Puzzle</property>
+                                                        <property name="halign">fill</property>
+                                                        <property name="valign">center</property>
+                                                        <property name="action-name">app.new-game</property>
+                                                        <property name="tooltip-text" 
translatable="yes">Start a new puzzle</property>
+                                                        <property name="width-request">120</property>
+                                                        <property name="height-request">60</property>
+                                                    </object>
+                                                    <packing>
+                                                        <property name="expand">False</property>
+                                                        <property name="fill">False</property>
+                                                        <property name="position">2</property>
+                                                    </packing>
+                                                </child>
+                                            </object>  <!-- End of controls_box -->
                                             <packing>
                                                 <property name="expand">False</property>
-                                                <property name="fill">False</property>
-                                                <property name="position">2</property>
+                                                <property name="fill">True</property>
+                                                <property name="pack-type">end</property>
+                                                <property name="padding">0</property>
                                             </packing>
                                         </child>
-                                    </object>  <!-- End of controls_box -->
-                                    <packing>
-                                        <property name="expand">False</property>
-                                        <property name="fill">True</property>
-                                        <property name="pack-type">end</property>
-                                        <property name="padding">0</property>
-                                    </packing>
+                                    </object> <!-- End of game_box -->
                                 </child>
-                            </object> <!-- End of game_box -->
+                            </object> <!-- End of frame -->
+                            <packing>
+                                <property name="name">frame</property>
+                            </packing>
                         </child>
-                    </object>
+                    </object> <!-- End of main_stack -->
                     <packing>
-                        <property name="name">frame</property>
+                        <property name="pack-type">end</property>
                     </packing>
                 </child>
-            </object>
+            </object> <!-- End of vbox -->
         </child>
-    </object>
+    </object> <!-- End of sudoku_app -->
 </interface>
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index d0bcda1..61d83c0 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -19,7 +19,7 @@ public class Sudoku : Gtk.Application
     private SudokuGame game;
     private SudokuView view;
 
-    private HeaderBar header_bar;
+    private HeaderBar headerbar;
     private Stack main_stack;
     private Box game_box; // Holds the view
 
@@ -36,8 +36,6 @@ public class Sudoku : Gtk.Application
     private SimpleAction pause_action;
     private SimpleAction new_game_action;
 
-    private string header_bar_subtitle;
-
     private bool show_possibilities = false;
 
     private const GLib.ActionEntry action_entries[] =
@@ -142,7 +140,7 @@ public class Sudoku : Gtk.Application
 
         add_window (window);
 
-        header_bar = (HeaderBar) builder.get_object ("headerbar");
+        headerbar = (HeaderBar) builder.get_object ("headerbar");
         main_stack = (Stack) builder.get_object ("main_stack");
         game_box = (Box) builder.get_object ("game_box");
         undo_redo_box = (Box) builder.get_object ("undo_redo_box");
@@ -160,6 +158,18 @@ public class Sudoku : Gtk.Application
         print_multiple_action = (SimpleAction) lookup_action ("print-multiple");
         pause_action = (SimpleAction) lookup_action ("pause");
 
+        var desktop = Environment.get_variable ("XDG_CURRENT_DESKTOP");
+        if (desktop == null || desktop != "Unity")
+        {
+            headerbar.show_close_button = true;
+            window.set_titlebar (headerbar);
+        }
+        else
+        {
+            var vbox = (Box) builder.get_object ("vbox");
+            vbox.pack_start (headerbar, false, false, 0);
+        }
+
         saver = new SudokuSaver ();
         var savegame = saver.get_savedgame ();
         if (savegame != null)
@@ -281,7 +291,7 @@ public class Sudoku : Gtk.Application
         if (view != null)
             game_box.remove (view);
 
-        header_bar_subtitle = board.difficulty_category.to_string ();
+        headerbar.title = board.difficulty_category.to_string ();
 
         back_cb ();
         game = new SudokuGame (board);
@@ -341,8 +351,7 @@ public class Sudoku : Gtk.Application
         clear_action.set_enabled (false);
         back_button.visible = game != null;
         undo_redo_box.visible = false;
-        header_bar_subtitle = header_bar.get_subtitle ();
-        header_bar.set_subtitle (null);
+        headerbar.title = _("Select Difficulty");
         print_action.set_enabled (false);
         clock_label.hide ();
         clock_image.hide ();
@@ -399,7 +408,6 @@ public class Sudoku : Gtk.Application
         main_stack.set_visible_child_name ("frame");
         back_button.visible = false;
         undo_redo_box.visible = true;
-        header_bar.set_subtitle (header_bar_subtitle);
         print_action.set_enabled (true);
         clock_label.show ();
         clock_image.show ();
@@ -408,6 +416,7 @@ public class Sudoku : Gtk.Application
         {
             game.continue_clock ();
             clear_action.set_enabled (!game.board.is_empty ());
+            headerbar.title = game.board.difficulty_category.to_string ();
         }
     }
 



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