[gnome-clocks/wip/headerbar] Port to GdHeaderBar



commit 3606c150c81f29099d2edfe87b3a9b7db393210e
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Fri Mar 8 11:29:50 2013 +0100

    Port to GdHeaderBar

 configure.ac     |    3 ++-
 src/alarm.vala   |    3 +--
 src/widgets.vala |   52 +++++++++++++++++++++++++++++-----------------------
 src/window.ui    |    1 -
 src/window.vala  |   21 +++++++--------------
 src/world.vala   |    3 +--
 6 files changed, 40 insertions(+), 43 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index db6bf44..549c7d4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -54,8 +54,9 @@ PKG_CHECK_MODULES(CLOCKS, [
 
 LIBGD_INIT([
     static
-    main-toolbar
+    header-bar
     stack
+    stack-switcher
     vapi
 ])
 
diff --git a/src/alarm.vala b/src/alarm.vala
index 86010f3..c10fa82 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -624,8 +624,7 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
             content_view.update_toolbar ();
             break;
         case Toolbar.Mode.STANDALONE:
-            toolbar.set_labels_menu (null);
-            toolbar.set_labels (GLib.Markup.escape_text (ringing_panel.alarm.name), null);
+            toolbar.title = GLib.Markup.escape_text (ringing_panel.alarm.name);
             break;
         default:
             assert_not_reached ();
diff --git a/src/widgets.vala b/src/widgets.vala
index bdf7fec..b9027a9 100644
--- a/src/widgets.vala
+++ b/src/widgets.vala
@@ -18,7 +18,7 @@
 
 namespace Clocks {
 
-public class Toolbar : Gd.MainToolbar {
+public class Toolbar : Gd.HeaderBar {
     public enum Mode {
         NORMAL,
         SELECTION,
@@ -26,7 +26,7 @@ public class Toolbar : Gd.MainToolbar {
     }
 
     private List<Gtk.Widget> buttons;
-    private List<Clock> clocks;
+    private Gd.StackSwitcher stack_switcher;
 
     [CCode (notify = false)]
     public Mode mode {
@@ -38,7 +38,7 @@ public class Toolbar : Gd.MainToolbar {
             if (_mode != value) {
                 _mode = value;
 
-                show_modes = (_mode == Mode.NORMAL);
+                custom_title = (_mode == Mode.NORMAL) ? stack_switcher : null;
 
                 if (_mode == Mode.SELECTION) {
                     get_style_context ().add_class ("selection-mode");
@@ -53,27 +53,30 @@ public class Toolbar : Gd.MainToolbar {
 
     private Mode _mode;
 
-    public signal void clock_changed (Clock clock);
-
-    public void add_clock (Clock clock) {
-        var button = add_mode (clock.label) as Gtk.ToggleButton;
-        clocks.prepend (clock);
-        button.toggled.connect(() => {
-            if (button.active) {
-                clock_changed (clock);
-            }
-        });
+    public void set_stack (Gd.Stack stack) {
+        if (stack_switcher == null) {
+            stack_switcher = new Gd.StackSwitcher ();
+        }
+        stack_switcher.set_stack (stack);
+        custom_title = stack_switcher;
     }
 
-    // we wrap add_button so that we can keep track of which
-    // buttons to remove in clear() without removing the radio buttons
-    public new Gtk.Button add_button (string? icon_name, string? label, bool pack_start) {
-        var button = base.add_button (icon_name, label, pack_start);
+    public Gtk.Button add_button (string? icon_name, string? label, bool should_pack_start) {
+        var button = new Gd.HeaderSimpleButton ();
+        button.label = label;
+        button.symbolic_icon_name = icon_name;
+
+        if (should_pack_start) {
+            pack_start (button);
+        } else {
+            pack_end (button);
+        }
+
         buttons.prepend (button);
         return (Gtk.Button) button;
     }
 
-    public new void clear () {
+    public void clear () {
         foreach (Gtk.Widget button in buttons) {
             button.destroy ();
         }
@@ -370,6 +373,7 @@ public class ContentView : Gtk.Bin {
     private Gtk.Widget empty_page;
     private IconView icon_view;
     private Toolbar main_toolbar;
+    private Gd.HeaderMenuButton selection_button;
     private GLib.MenuModel selection_menu;
     private Gtk.Toolbar selection_toolbar;
     private Gtk.Overlay overlay;
@@ -405,6 +409,7 @@ public class ContentView : Gtk.Bin {
                 main_toolbar.mode = Toolbar.Mode.SELECTION;
             } else if (icon_view.mode == IconView.Mode.NORMAL) {
                 main_toolbar.mode = Toolbar.Mode.NORMAL;
+                selection_button = null;
             }
         });
 
@@ -418,7 +423,7 @@ public class ContentView : Gtk.Bin {
             } else {
                 label = ngettext ("%d selected", "%d selected", n_items).printf (n_items);
             }
-            main_toolbar.set_labels (label, null);
+            selection_button.label = label;
 
             if (n_items != 0) {
                 fade_in (selection_toolbar);
@@ -564,9 +569,12 @@ public class ContentView : Gtk.Bin {
     public void update_toolbar () {
         switch (main_toolbar.mode) {
         case Toolbar.Mode.SELECTION:
+            selection_button = new Gd.HeaderMenuButton ();
+            selection_button.label = _("Click on items to select them");
+            selection_button.menu_model = selection_menu;
+            main_toolbar.custom_title = selection_button;
+
             var done_button = main_toolbar.add_button (null, _("Done"), false);
-            main_toolbar.set_labels (_("Click on items to select them"), null);
-            main_toolbar.set_labels_menu (selection_menu);
             done_button.get_style_context ().add_class ("suggested-action");
             done_button.clicked.connect (() => {
                 icon_view.mode = IconView.Mode.NORMAL;
@@ -574,8 +582,6 @@ public class ContentView : Gtk.Bin {
             done_button.show ();
             break;
         case Toolbar.Mode.NORMAL:
-            main_toolbar.set_labels (null, null);
-            main_toolbar.set_labels_menu (null);
             var select_button = main_toolbar.add_button ("object-select-symbolic", null, false);
             select_button.clicked.connect (() => {
                 icon_view.mode = IconView.Mode.SELECTION;
diff --git a/src/window.ui b/src/window.ui
index bd293c4..1118846 100644
--- a/src/window.ui
+++ b/src/window.ui
@@ -8,7 +8,6 @@
       <object class="ClocksToolbar" id="toolbar">
         <property name="visible">True</property>
         <property name="vexpand">False</property>
-        <property name="show-modes">True</property>
         <style>
           <class name="menubar"/>
         </style>
diff --git a/src/window.vala b/src/window.vala
index d25046e..6179754 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -59,19 +59,12 @@ public class Window : Gtk.ApplicationWindow {
         stopwatch = new Stopwatch.MainPanel (toolbar);
         timer = new Timer.MainPanel (toolbar);
 
-        toolbar.add_clock (world);
-        toolbar.add_clock (alarm);
-        toolbar.add_clock (stopwatch);
-        toolbar.add_clock (timer);
-
-        stack.add (world);
-        stack.add (alarm);
-        stack.add (stopwatch);
-        stack.add (timer);
-
-        toolbar.clock_changed.connect ((c) => {
-            stack.visible_child = (Gtk.Widget) c;
-        });
+        stack.add_titled (world, world.label, world.label);
+        stack.add_titled (alarm, alarm.label, alarm.label);
+        stack.add_titled (stopwatch, stopwatch.label, stopwatch.label);
+        stack.add_titled (timer, timer.label, timer.label);
+
+        toolbar.set_stack (stack);
 
         stack.notify["visible-child"].connect (() => {
             update_toolbar ();
@@ -95,7 +88,7 @@ public class Window : Gtk.ApplicationWindow {
         });
 
         stack.visible_child = world;
-        world.update_toolbar ();
+        update_toolbar ();
 
         add (main_panel);
         show_all ();
diff --git a/src/world.vala b/src/world.vala
index f0ea607..047e4fa 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -368,8 +368,7 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
             content_view.update_toolbar ();
             break;
         case Toolbar.Mode.STANDALONE:
-            toolbar.set_labels_menu (null);
-            toolbar.set_labels (GLib.Markup.escape_text (standalone.location.name), null);
+            toolbar.title = GLib.Markup.escape_text (standalone.location.name);
             var back_button = toolbar.add_button ("go-previous-symbolic", null, true);
             back_button.clicked.connect (() => {
                 visible_child = content_view;


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