[gnome-clocks] Simplify code after the HeaderBar port



commit 0aef344968353717e5c053208633cbff54e8b224
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Mar 9 11:03:27 2013 +0100

    Simplify code after the HeaderBar port
    
    Now that we use header bar, we can simplify the code: 1) the buttons can
    be created once and then just added/removed, 2) we do not need a
    GtkFrame and css to set the border under the header, 3) we do not need
    to set the "menubar" class to make the header draggable

 data/css/gnome-clocks.css |    7 ----
 src/alarm.vala            |   14 ++++++---
 src/widgets.vala          |   69 ++++++++++++++++++++------------------------
 src/window.ui             |   13 +--------
 src/world.vala            |   27 ++++++++++++------
 5 files changed, 59 insertions(+), 71 deletions(-)
---
diff --git a/data/css/gnome-clocks.css b/data/css/gnome-clocks.css
index 13b4e1d..be31a32 100644
--- a/data/css/gnome-clocks.css
+++ b/data/css/gnome-clocks.css
@@ -3,13 +3,6 @@
 @define-color clocks_stop_color_a #f44848;
 @define-color clocks_stop_color_b #ff6565;
 
-.clocks-content-view {
-    border-style: solid;
-    border-color: @borders;
-    border-width: 1px 0 0 0;
-    border-radius: 0;
-}
-
 .clocks-digital-renderer {
     background-color: transparent;
 }
diff --git a/src/alarm.vala b/src/alarm.vala
index db4472a..2f4d657 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -468,6 +468,7 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
 
     private List<Item> alarms;
     private GLib.Settings settings;
+    private Gd.HeaderSimpleButton new_button;
     private ContentView content_view;
     private RingingPanel ringing_panel;
 
@@ -477,6 +478,14 @@ public class MainPanel : Gd.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.no_show_all = true;
+        new_button.action_name = "win.new";
+        header_bar.pack_start (new_button);
+
         var builder = Utils.load_ui ("alarm.ui");
         var empty_view = builder.get_object ("empty_panel") as Gtk.Widget;
         content_view = new ContentView (empty_view, header_bar);
@@ -612,11 +621,6 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
     public void update_header_bar () {
         switch (header_bar.mode) {
         case HeaderBar.Mode.NORMAL:
-            // Translators: "New" refers to an alarm
-            var new_button = header_bar.add_button (null, _("New"), true);
-            new_button.clicked.connect (() => {
-                activate_new ();
-            });
             new_button.show ();
             content_view.update_header_bar ();
             break;
diff --git a/src/widgets.vala b/src/widgets.vala
index be15020..e3c6afd 100644
--- a/src/widgets.vala
+++ b/src/widgets.vala
@@ -25,7 +25,6 @@ public class HeaderBar : Gd.HeaderBar {
         STANDALONE
     }
 
-    private List<Gtk.Widget> buttons;
     private Gd.StackSwitcher stack_switcher;
 
     [CCode (notify = false)]
@@ -57,31 +56,16 @@ public class HeaderBar : Gd.HeaderBar {
         stack_switcher = new Gd.StackSwitcher ();
         realize.connect (() => {
             custom_title = stack_switcher;
-       });
+        });
     }
 
     public void set_stack (Gd.Stack stack) {
         stack_switcher.set_stack (stack);
     }
 
-    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 void clear () {
-        foreach (Gtk.Widget button in buttons) {
-            button.destroy ();
+        foreach (Gtk.Widget w in get_children ()) {
+            w.hide ();
         }
     }
 }
@@ -376,8 +360,10 @@ public class ContentView : Gtk.Bin {
     private Gtk.Widget empty_page;
     private IconView icon_view;
     private HeaderBar header_bar;
-    private Gd.HeaderMenuButton selection_button;
+    private Gd.HeaderSimpleButton select_button;
+    private Gd.HeaderSimpleButton done_button;
     private GLib.MenuModel selection_menu;
+    private Gd.HeaderMenuButton selection_menubutton;
     private Gtk.Toolbar selection_toolbar;
     private Gtk.Overlay overlay;
 
@@ -387,9 +373,32 @@ public class ContentView : Gtk.Bin {
 
         icon_view = new IconView ();
 
+        select_button = new Gd.HeaderSimpleButton ();
+        select_button.symbolic_icon_name = "object-select-symbolic";
+        select_button.no_show_all = true;
+        bind_property ("empty", select_button, "sensitive", BindingFlags.SYNC_CREATE | 
BindingFlags.INVERT_BOOLEAN);
+        select_button.clicked.connect (() => {
+            icon_view.mode = IconView.Mode.SELECTION;
+        });
+        header_bar.pack_end (select_button);
+
+        done_button = new Gd.HeaderSimpleButton ();
+        done_button.label = _("Done");
+        done_button.no_show_all = true;
+        done_button.get_style_context ().add_class ("suggested-action");
+        done_button.clicked.connect (() => {
+            icon_view.mode = IconView.Mode.NORMAL;
+        });
+        header_bar.pack_end (done_button);
+
         var builder = Utils.load_ui ("menu.ui");
         selection_menu = builder.get_object ("selection-menu") as GLib.MenuModel;
 
+        selection_menubutton = new Gd.HeaderMenuButton ();
+        selection_menubutton.label = _("Click on items to select them");
+        selection_menubutton.menu_model = selection_menu;
+        selection_menubutton.get_style_context ().add_class ("selection-menu");
+
         var scrolled_window = new Gtk.ScrolledWindow (null, null);
         scrolled_window.add (icon_view);
 
@@ -412,7 +421,6 @@ public class ContentView : Gtk.Bin {
                 header_bar.mode = HeaderBar.Mode.SELECTION;
             } else if (icon_view.mode == IconView.Mode.NORMAL) {
                 header_bar.mode = HeaderBar.Mode.NORMAL;
-                selection_button = null;
             }
         });
 
@@ -426,7 +434,7 @@ public class ContentView : Gtk.Bin {
             } else {
                 label = ngettext ("%d selected", "%d selected", n_items).printf (n_items);
             }
-            selection_button.label = label;
+            selection_menubutton.label = label;
 
             if (n_items != 0) {
                 fade_in (selection_toolbar);
@@ -572,26 +580,11 @@ public class ContentView : Gtk.Bin {
     public void update_header_bar () {
         switch (header_bar.mode) {
         case HeaderBar.Mode.SELECTION:
-            selection_button = new Gd.HeaderMenuButton ();
-            selection_button.label = _("Click on items to select them");
-            selection_button.menu_model = selection_menu;
-            selection_button.get_style_context ().add_class ("selection-menu");
-            header_bar.custom_title = selection_button;
-
-            var done_button = header_bar.add_button (null, _("Done"), false);
-            done_button.get_style_context ().add_class ("suggested-action");
-            done_button.clicked.connect (() => {
-                icon_view.mode = IconView.Mode.NORMAL;
-            });
+            header_bar.custom_title = selection_menubutton;
             done_button.show ();
             break;
         case HeaderBar.Mode.NORMAL:
-            var select_button = header_bar.add_button ("object-select-symbolic", null, false);
-            select_button.clicked.connect (() => {
-                icon_view.mode = IconView.Mode.SELECTION;
-            });
             select_button.show ();
-            bind_property ("empty", select_button, "sensitive", BindingFlags.SYNC_CREATE | 
BindingFlags.INVERT_BOOLEAN);
             break;
         }
     }
diff --git a/src/window.ui b/src/window.ui
index fda72fc..a6bfc5e 100644
--- a/src/window.ui
+++ b/src/window.ui
@@ -8,9 +8,6 @@
       <object class="ClocksHeaderBar" id="header_bar">
         <property name="visible">True</property>
         <property name="vexpand">False</property>
-        <style>
-          <class name="menubar"/>
-        </style>
       </object>
       <packing>
         <property name="left_attach">0</property>
@@ -20,20 +17,12 @@
       </packing>
     </child>
     <child>
-      <object class="GtkFrame" id="frame1">
+      <object class="GdStack" id="stack">
         <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="label_xalign">0</property>
         <style>
-          <class name="clocks-content-view"/>
           <class name="view"/>
           <class name="content-view"/>
         </style>
-        <child>
-          <object class="GdStack" id="stack">
-            <property name="visible">True</property>
-          </object>
-        </child>
       </object>
       <packing>
         <property name="left_attach">0</property>
diff --git a/src/world.vala b/src/world.vala
index 881eb9b..59fd9ba 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -247,6 +247,8 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
 
     private List<Item> locations;
     private GLib.Settings settings;
+    private Gd.HeaderSimpleButton new_button;
+    private Gd.HeaderSimpleButton back_button;
     private Gdk.Pixbuf? day_pixbuf;
     private Gdk.Pixbuf? night_pixbuf;
     private ContentView content_view;
@@ -261,6 +263,22 @@ public class MainPanel : Gd.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.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.no_show_all = true;
+        back_button.clicked.connect (() => {
+            visible_child = content_view;
+        });
+        header_bar.pack_start (back_button);
+
         var builder = Utils.load_ui ("world.ui");
         var empty_view = builder.get_object ("empty_panel") as Gtk.Widget;
         content_view = new ContentView (empty_view, header_bar);
@@ -356,11 +374,6 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
         header_bar.clear ();
         switch (header_bar.mode) {
         case HeaderBar.Mode.NORMAL:
-            // Translators: "New" refers to a world clock
-            var new_button = header_bar.add_button (null, _("New"), true);
-            new_button.clicked.connect (() => {
-                activate_new ();
-            });
             new_button.show ();
             content_view.update_header_bar ();
             break;
@@ -369,10 +382,6 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
             break;
         case HeaderBar.Mode.STANDALONE:
             header_bar.title = GLib.Markup.escape_text (standalone.location.name);
-            var back_button = header_bar.add_button ("go-previous-symbolic", null, true);
-            back_button.clicked.connect (() => {
-                visible_child = content_view;
-            });
             back_button.show ();
             break;
         default:


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