[gnome-clocks] Port header bar widget from libgd to gtk+



commit a8646ab4b6f256c1565bfe093d773b19bd1d18a1
Author: Evgeny Bobkin <evgen ibqn gmail com>
Date:   Sun Jun 9 13:27:42 2013 +0200

    Port header bar widget from libgd to gtk+
    
    https://bugzilla.gnome.org/show_bug.cgi?id=701889

 configure.ac      |    1 -
 data/ui/window.ui |   11 ++++++++---
 src/alarm.vala    |    8 ++++----
 src/widgets.vala  |   42 +++++++++++++++++-------------------------
 src/window.vala   |    9 ++++++++-
 src/world.vala    |   17 ++++++++++-------
 6 files changed, 47 insertions(+), 41 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 550b063..16c0504 100644
--- a/configure.ac
+++ b/configure.ac
@@ -59,7 +59,6 @@ PKG_CHECK_MODULES(CLOCKS, [
 
 LIBGD_INIT([
     static
-    header-bar
     vapi
 ])
 
diff --git a/data/ui/window.ui b/data/ui/window.ui
index 3febaa5..bba49e5 100644
--- a/data/ui/window.ui
+++ b/data/ui/window.ui
@@ -6,8 +6,13 @@
     <child type="titlebar">
       <object class="ClocksHeaderBar" id="header_bar">
         <property name="visible">True</property>
-        <property name="vexpand">False</property>
         <property name="hexpand">True</property>
+        <property name="vexpand">False</property>
+        <child type="title">
+          <object class="GtkStackSwitcher" id="stack_switcher">
+            <property name="visible">True</property>
+          </object>
+        </child>
       </object>
     </child>
     <child>
@@ -23,8 +28,8 @@
         </style>
         <child>
           <object class="GtkStack" id="stack">
-           <property name="visible">True</property>
-           <property name="can_focus">False</property>
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
           </object>
         </child>
       </object>
diff --git a/src/alarm.vala b/src/alarm.vala
index 832427f..47c42e1 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -469,7 +469,7 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
 
     private List<Item> alarms;
     private GLib.Settings settings;
-    private Gd.HeaderSimpleButton new_button;
+    private Gtk.Button new_button;
     private ContentView content_view;
     private RingingPanel ringing_panel;
 
@@ -479,10 +479,10 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
         alarms = new List<Item> ();
         settings = new GLib.Settings ("org.gnome.clocks");
 
-        new_button = new Gd.HeaderSimpleButton ();
-
         // Translators: "New" refers to an alarm
-        new_button.label = _("New");
+        new_button = new Gtk.Button.with_label (_("New"));
+        new_button.get_style_context ().add_class ("text-button");
+        new_button.valign = Gtk.Align.CENTER;
         new_button.no_show_all = true;
         new_button.action_name = "win.new";
         header_bar.pack_start (new_button);
diff --git a/src/widgets.vala b/src/widgets.vala
index bc13b00..254e229 100644
--- a/src/widgets.vala
+++ b/src/widgets.vala
@@ -18,15 +18,13 @@
 
 namespace Clocks {
 
-public class HeaderBar : Gd.HeaderBar {
+public class HeaderBar : Gtk.HeaderBar {
     public enum Mode {
         NORMAL,
         SELECTION,
         STANDALONE
     }
 
-    private Gtk.StackSwitcher stack_switcher;
-
     [CCode (notify = false)]
     public Mode mode {
         get {
@@ -34,11 +32,9 @@ public class HeaderBar : Gd.HeaderBar {
         }
 
         set {
-            if (_mode != value && get_realized ()) {
+            if (_mode != value) {
                 _mode = value;
 
-                custom_title = (_mode == Mode.NORMAL) ? stack_switcher : null;
-
                 if (_mode == Mode.SELECTION) {
                     get_style_context ().add_class ("selection-mode");
                 } else {
@@ -52,18 +48,8 @@ public class HeaderBar : Gd.HeaderBar {
 
     private Mode _mode;
 
-    construct {
-        stack_switcher = new Gtk.StackSwitcher ();
-        realize.connect (() => {
-            custom_title = stack_switcher;
-        });
-    }
-
-    public void set_stack (Gtk.Stack stack) {
-        stack_switcher.set_stack (stack);
-    }
-
     public void clear () {
+        custom_title = null;
         foreach (Gtk.Widget w in get_children ()) {
             w.hide ();
         }
@@ -358,10 +344,10 @@ public class ContentView : Gtk.Bin {
     private Gtk.Widget empty_page;
     private IconView icon_view;
     private HeaderBar header_bar;
-    private Gd.HeaderSimpleButton select_button;
-    private Gd.HeaderSimpleButton cancel_button;
+    private Gtk.Button select_button;
+    private Gtk.Button cancel_button;
     private GLib.MenuModel selection_menu;
-    private Gd.HeaderMenuButton selection_menubutton;
+    private Gtk.MenuButton selection_menubutton;
     private Gtk.Frame selection_toolbar;
     private Gtk.Grid grid;
     private Gtk.Revealer revealer;
@@ -373,8 +359,11 @@ public class ContentView : Gtk.Bin {
 
         icon_view = new IconView ();
 
-        select_button = new Gd.HeaderSimpleButton ();
-        select_button.symbolic_icon_name = "object-select-symbolic";
+        select_button = new Gtk.Button ();
+        Gtk.Image select_button_image = new Gtk.Image.from_icon_name ("object-select-symbolic", 
Gtk.IconSize.MENU);
+        select_button.set_image (select_button_image);
+        select_button.valign = Gtk.Align.CENTER;
+        select_button.get_style_context ().add_class ("image-button");
         select_button.no_show_all = true;
         bind_property ("empty", select_button, "sensitive", BindingFlags.SYNC_CREATE | 
BindingFlags.INVERT_BOOLEAN);
         select_button.clicked.connect (() => {
@@ -382,10 +371,11 @@ public class ContentView : Gtk.Bin {
         });
         header_bar.pack_end (select_button);
 
-        cancel_button = new Gd.HeaderSimpleButton ();
-        cancel_button.label = _("Cancel");
+        cancel_button = new Gtk.Button.with_label (_("Cancel"));
         cancel_button.no_show_all = true;
         cancel_button.get_style_context ().add_class ("suggested-action");
+        cancel_button.get_style_context ().add_class ("text-button");
+        cancel_button.valign = Gtk.Align.CENTER;
         cancel_button.clicked.connect (() => {
             icon_view.mode = IconView.Mode.NORMAL;
         });
@@ -394,8 +384,10 @@ public class ContentView : Gtk.Bin {
         var builder = Utils.load_ui ("menu.ui");
         selection_menu = builder.get_object ("selection-menu") as GLib.MenuModel;
 
-        selection_menubutton = new Gd.HeaderMenuButton ();
+        selection_menubutton = new Gtk.MenuButton ();
         selection_menubutton.label = _("Click on items to select them");
+        selection_menubutton.valign = Gtk.Align.CENTER;
+        selection_menubutton.get_style_context ().add_class ("image-button");
         selection_menubutton.menu_model = selection_menu;
         selection_menubutton.get_style_context ().add_class ("selection-menu");
 
diff --git a/src/window.vala b/src/window.vala
index 717ab7b..699bb91 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -34,6 +34,8 @@ public class Window : Gtk.ApplicationWindow {
     private HeaderBar header_bar;
     [GtkChild]
     private Gtk.Stack stack;
+    [GtkChild]
+    private Gtk.StackSwitcher stack_switcher;
     private GLib.Settings settings;
     private Gtk.Widget[] panels;
     private Gtk.Separator separator;
@@ -67,7 +69,7 @@ public class Window : Gtk.ApplicationWindow {
             stack.add_titled (clock, ((Clock)clock).label, ((Clock)clock).label);
         }
 
-        header_bar.set_stack (stack);
+        stack_switcher.set_stack (stack);
 
         separator = new Gtk.Separator (Gtk.Orientation.VERTICAL);
         separator.no_show_all = true;
@@ -194,6 +196,7 @@ public class Window : Gtk.ApplicationWindow {
 
     private void update_header_bar () {
         header_bar.clear ();
+
         var clock = (Clock) stack.visible_child;
         if (clock != null) {
             settings.set_enum ("panel-id", clock.panel_id);
@@ -201,6 +204,10 @@ public class Window : Gtk.ApplicationWindow {
             ((Gtk.Widget) clock).grab_focus ();
         }
 
+        if (header_bar.mode == HeaderBar.Mode.NORMAL) {
+            header_bar.custom_title = stack_switcher;
+        }
+
         if (header_bar.mode != HeaderBar.Mode.SELECTION) {
             separator.show ();
             close_button.show ();
diff --git a/src/world.vala b/src/world.vala
index b1a844a..10b2239 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -256,8 +256,8 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
 
     private List<Item> locations;
     private GLib.Settings settings;
-    private Gd.HeaderSimpleButton new_button;
-    private Gd.HeaderSimpleButton back_button;
+    private Gtk.Button new_button;
+    private Gtk.Button back_button;
     private Gdk.Pixbuf? day_pixbuf;
     private Gdk.Pixbuf? night_pixbuf;
     private ContentView content_view;
@@ -272,16 +272,19 @@ public class MainPanel : Gtk.Stack, Clocks.Clock {
         day_pixbuf = Utils.load_image ("day.png");
         night_pixbuf = Utils.load_image ("night.png");
 
-        new_button = new Gd.HeaderSimpleButton ();
-
         // Translators: "New" refers to a world clock
-        new_button.label = _("New");
+        new_button = new Gtk.Button.with_label (_("New"));
+        new_button.get_style_context ().add_class ("text-button");
+        new_button.valign = Gtk.Align.CENTER;
         new_button.no_show_all = true;
         new_button.action_name = "win.new";
         header_bar.pack_start (new_button);
 
-        back_button = new Gd.HeaderSimpleButton ();
-        back_button.symbolic_icon_name = "go-previous-symbolic";
+        back_button = new Gtk.Button ();
+        var back_button_image = new Gtk.Image.from_icon_name ("go-previous-symbolic", Gtk.IconSize.MENU);
+        back_button.valign = Gtk.Align.CENTER;
+        back_button.get_style_context ().add_class ("image-button");
+        back_button.set_image (back_button_image);
         back_button.no_show_all = true;
         back_button.clicked.connect (() => {
             visible_child = content_view;


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