[cheese/wip/trad-title-bar: 2/2] Use a traditional title bar when requested



commit 691b4e4681c9571c0a4349f1c7bd64d02b65dce7
Author: Iain Lane <iain lane canonical com>
Date:   Thu Apr 24 11:49:26 2014 +0100

    Use a traditional title bar when requested
    
    Not all environments desire header bars. We use the
    'gtk-shell-shows-menubar' setting to decide whether to use the header
    bar.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=728866

 Makefile.am                         |    1 +
 data/cheese-main-window.ui          |   11 -----------
 data/headerbar.ui                   |   10 ++++++++++
 data/org.gnome.Cheese.gresource.xml |    1 +
 src/cheese-window.vala              |   27 ++++++++++++++++++++++-----
 5 files changed, 34 insertions(+), 16 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index fa69074..be23ccb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -201,6 +201,7 @@ noinst_resource_files = \
        data/cheese-appmenu.ui \
        data/cheese-main-window.ui \
        data/cheese-prefs.ui \
+       data/headerbar.ui \
        data/pixmaps/cheese-1.svg \
        data/pixmaps/cheese-2.svg \
        data/pixmaps/cheese-3.svg \
diff --git a/data/cheese-main-window.ui b/data/cheese-main-window.ui
index 153edb8..05b1216 100644
--- a/data/cheese-main-window.ui
+++ b/data/cheese-main-window.ui
@@ -2,17 +2,6 @@
 <interface domain="cheese">
   <requires lib="gtk+" version="3.10"/>
     <template class="CheeseMainWindow" parent="GtkApplicationWindow">
-        <child type="titlebar">
-  <object class="GtkHeaderBar" id="header_bar">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="title" translatable="yes">Take a Photo</property>
-    <property name="show-close-button">True</property>
-    <style>
-      <class name="titlebar"/>
-    </style>
-  </object>
-        </child>
         <child>
   <object class="GtkBox" id="main_vbox">
     <property name="orientation">vertical</property>
diff --git a/data/headerbar.ui b/data/headerbar.ui
new file mode 100644
index 0000000..05be621
--- /dev/null
+++ b/data/headerbar.ui
@@ -0,0 +1,10 @@
+<interface domain="cheese">
+  <object class="GtkHeaderBar" id="header_bar">
+    <property name="can_focus">False</property>
+    <property name="title" translatable="yes">Take a Photo</property>
+    <property name="show-close-button">True</property>
+    <style>
+      <class name="titlebar"/>
+    </style>
+  </object>
+</interface>
diff --git a/data/org.gnome.Cheese.gresource.xml b/data/org.gnome.Cheese.gresource.xml
index bf1bdaa..4d02eea 100644
--- a/data/org.gnome.Cheese.gresource.xml
+++ b/data/org.gnome.Cheese.gresource.xml
@@ -6,6 +6,7 @@
         <file preprocess="xml-stripblanks">cheese-appmenu.ui</file>
         <file preprocess="xml-stripblanks">cheese-main-window.ui</file>
         <file preprocess="xml-stripblanks">cheese-prefs.ui</file>
+        <file preprocess="xml-stripblanks">headerbar.ui</file>
         <file>pixmaps/cheese-1.svg</file>
         <file>pixmaps/cheese-2.svg</file>
         <file>pixmaps/cheese-3.svg</file>
diff --git a/src/cheese-window.vala b/src/cheese-window.vala
index aea42eb..afa3f03 100644
--- a/src/cheese-window.vala
+++ b/src/cheese-window.vala
@@ -47,7 +47,8 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
 
     private Clutter.Script clutter_builder;
 
-    [GtkChild]
+    private Gtk.Builder header_bar_ui = new Gtk.Builder.from_resource ("/org/gnome/Cheese/headerbar.ui");
+
     private Gtk.HeaderBar header_bar;
 
     private GLib.Settings settings;
@@ -123,6 +124,16 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
     {
         GLib.Object (application: application);
 
+        header_bar = header_bar_ui.get_object ("header_bar") as Gtk.HeaderBar;
+
+        Gtk.Settings settings = Gtk.Settings.get_default ();
+
+        if (!settings.gtk_shell_shows_menubar)
+        {
+            header_bar.visible = true;
+            this.set_titlebar (header_bar);
+        }
+
         if (get_direction () == Gtk.TextDirection.RTL)
         {
             effects_prev_page_button_image.icon_name = "go-previous-rtl-symbolic";
@@ -135,6 +146,12 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
         }
     }
 
+    private void set_window_title (string title)
+    {
+        header_bar.set_title (title);
+        this.set_title (title);
+    }
+
     private bool on_window_state_change_event (Gtk.Widget widget,
                                                Gdk.EventWindowState event)
     {
@@ -1336,22 +1353,22 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
     {
         if (is_effects_selector_active)
         {
-            header_bar.set_title (_("Choose an Effect"));
+            set_window_title (_("Choose an Effect"));
         }
         else
         {
             switch (current_mode)
             {
                 case MediaMode.PHOTO:
-                    header_bar.set_title (_("Take a Photo"));
+                    set_window_title (_("Take a Photo"));
                     break;
 
                 case MediaMode.VIDEO:
-                    header_bar.set_title (_("Record a Video"));
+                    set_window_title (_("Record a Video"));
                     break;
 
                 case MediaMode.BURST:
-                    header_bar.set_title (_("Take Multiple Photos"));
+                    set_window_title (_("Take Multiple Photos"));
                     break;
             }
         }


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