[gitg] Use a box in the header to show the stack items.



commit b743aa91dea4e7075ff47ffd402cec21f78aaf19
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Thu Feb 21 14:13:57 2013 +0100

    Use a box in the header to show the stack items.

 gitg/gitg-ui-elements.vala       |   66 +++++++++++++++++++++----------------
 gitg/gitg-window.vala            |   18 ++++------
 gitg/resources/ui/gitg-window.ui |   43 +++---------------------
 3 files changed, 51 insertions(+), 76 deletions(-)
---
diff --git a/gitg/gitg-ui-elements.vala b/gitg/gitg-ui-elements.vala
index b22154b..1d25fc8 100644
--- a/gitg/gitg-ui-elements.vala
+++ b/gitg/gitg-ui-elements.vala
@@ -25,7 +25,7 @@ public class UIElements<T>
        private class ActiveUIElement
        {
                public GitgExt.UIElement element;
-               public Gtk.RadioToolButton? navigation_button;
+               public Gtk.RadioButton? navigation_button;
 
                public ActiveUIElement(GitgExt.UIElement e)
                {
@@ -37,15 +37,15 @@ public class UIElements<T>
        private HashTable<string, ActiveUIElement> d_available_elements;
        private HashTable<string, GitgExt.UIElement> d_elements;
        private List<ActiveUIElement> d_available_sorted;
-       private Gtk.Toolbar? d_toolbar;
+       private Gtk.Box? d_box;
        private ActiveUIElement? d_current;
        private Gd.Stack d_stack;
 
        public signal void activated(GitgExt.UIElement element);
 
-       private Gtk.RadioToolButton? create_toolbar_button(GitgExt.UIElement e)
+       private Gtk.RadioButton? create_header_button(GitgExt.UIElement e)
        {
-               if (d_toolbar == null)
+               if (d_box == null)
                {
                        return null;
                }
@@ -57,25 +57,28 @@ public class UIElements<T>
                        return null;
                }
 
-               var img = new Gtk.Image.from_gicon(icon, d_toolbar.get_icon_size());
+               var img = new Gtk.Image.from_gicon(icon, Gtk.IconSize.MENU);
                img.show();
 
-               Gtk.RadioToolButton button;
+               Gtk.RadioButton button;
 
-               if (d_toolbar.get_n_items() != 0)
+               if (d_box.get_children().length() != 0)
                {
-                       var ic = d_toolbar.get_nth_item(0);
-                       button = new Gtk.RadioToolButton.from_widget(ic as Gtk.RadioToolButton);
+                       var ic = d_box.get_children();
+                       button = new Gtk.RadioButton.from_widget(ic.data as Gtk.RadioButton);
                }
                else
                {
-                       button = new Gtk.RadioToolButton(null);
+                       button = new Gtk.RadioButton(null);
                }
 
                e.bind_property("enabled", button, "sensitive", BindingFlags.DEFAULT | 
BindingFlags.SYNC_CREATE);
 
-               button.set_icon_widget(img);
-               button.set_label(e.display_name);
+               button.set_mode(false);
+               button.set_image(img);
+
+               var context = button.get_style_context();
+               context.add_class("image-button");
 
                button.show();
 
@@ -202,7 +205,7 @@ public class UIElements<T>
 
        private void add_available(GitgExt.UIElement e)
        {
-               Gtk.RadioToolButton? button = create_toolbar_button(e);
+               Gtk.RadioButton? button = create_header_button(e);
                ActiveUIElement ae = new ActiveUIElement(e);
 
                ae.navigation_button = button;
@@ -213,16 +216,17 @@ public class UIElements<T>
                                return a.element.negotiate_order(b.element);
                        });
 
-                       d_toolbar.insert(button, d_available_sorted.index(ae));
+                       d_box.pack_start(button);
+                       d_box.reorder_child(button, d_available_sorted.index(ae));
                        update_visibility();
-               }
 
-               button.toggled.connect((b) => {
-                       if (b.active)
-                       {
-                               set_current_impl(ae.element);
-                       }
-               });
+                       button.toggled.connect((b) => {
+                               if (b.active)
+                               {
+                                       set_current_impl(ae.element);
+                               }
+                       });
+               }
 
                d_stack.add(ae.element.widget);
                d_available_elements.insert(e.id, ae);
@@ -268,15 +272,15 @@ public class UIElements<T>
                remove_ui_element(obj as GitgExt.UIElement);
        }
 
-       private void on_toolbar_add_remove(Gtk.Widget toolbar,
-                                          Gtk.Widget item)
+       private void on_box_add_remove(Gtk.Widget box,
+                                      Gtk.Widget item)
        {
                update_visibility();
        }
 
        private void update_visibility()
        {
-               d_toolbar.visible = (d_toolbar.get_n_items() > 1);
+               d_box.visible = (d_box.get_children().length() > 1);
        }
 
        public delegate bool ForeachUIElementFunc(GitgExt.UIElement element);
@@ -296,19 +300,23 @@ public class UIElements<T>
 
        public UIElements(Peas.ExtensionSet extensions,
                          Gd.Stack? stack = null,
-                         Gtk.Toolbar? toolbar = null)
+                         Gtk.Box? box = null)
        {
                d_extensions = extensions;
-               d_toolbar = toolbar;
+               d_box = box;
                d_stack = stack;
 
                d_available_elements = new HashTable<string, ActiveUIElement>(str_hash, str_equal);
                d_elements = new HashTable<string, GitgExt.UIElement>(str_hash, str_equal);
 
-               if (d_toolbar != null)
+               if (d_box != null)
                {
-                       d_toolbar.add.connect(on_toolbar_add_remove);
-                       d_toolbar.remove.connect(on_toolbar_add_remove);
+                       var context = d_box.get_style_context();
+                       context.add_class("linked");
+                       context.add_class("raised");
+
+                       d_box.add.connect(on_box_add_remove);
+                       d_box.remove.connect(on_box_add_remove);
 
                        update_visibility();
                }
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index 27b6040..8104173 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -30,12 +30,12 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
        private UIElements<GitgExt.View> d_views;
        private UIElements<GitgExt.Panel> d_panels;
 
+
+       // Widgets
        private Gd.HeaderBar d_header_bar;
        private Gtk.MenuButton d_config;
 
-       // Widgets
-       private Gtk.Toolbar d_toolbar_views;
-       private Gtk.Toolbar d_toolbar_panels;
+       private Gtk.Box d_header_box;
 
        private Gtk.Paned d_paned_views;
        private Gtk.Paned d_paned_panels;
@@ -79,10 +79,10 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
        private void parser_finished(Gtk.Builder builder)
        {
                // Extract widgets from the builder
-               d_toolbar_views = builder.get_object("toolbar_views") as Gtk.Toolbar;
-               d_paned_views = builder.get_object("paned_views") as Gtk.Paned;
+               d_header_bar = builder.get_object("header-bar") as Gd.HeaderBar;
+               d_header_box = builder.get_object("header-bar-box") as Gtk.Box;
 
-               d_toolbar_panels = builder.get_object("toolbar_panels") as Gtk.Toolbar;
+               d_paned_views = builder.get_object("paned_views") as Gtk.Paned;
                d_paned_panels = builder.get_object("paned_panels") as Gtk.Paned;
 
                d_stack_view = builder.get_object("stack_view") as Gd.Stack;
@@ -94,7 +94,6 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
                var model = Resource.load_object<MenuModel>("ui/gitg-menus.ui", "win-menu");
                d_config.menu_model = model;
 
-               d_header_bar = builder.get_object("header-bar") as Gd.HeaderBar;
                var search_button = builder.get_object("search-button") as Gd.HeaderToggleButton;
                var revealer = builder.get_object("search-revealer") as Gd.Revealer;
                var entry = builder.get_object("search-entry") as Gd.TaggedEntry;
@@ -182,8 +181,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
                                                                            typeof(GitgExt.View),
                                                                            "application",
                                                                            this),
-                                                      d_stack_view,
-                                                      d_toolbar_views);
+                                                      d_stack_view);
 
                d_views.activated.connect(on_view_activated);
 
@@ -192,7 +190,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
                                                                               "application",
                                                                               this),
                                                         d_stack_panel,
-                                                        d_toolbar_panels);
+                                                        d_header_box);
 
                d_panels.activated.connect(on_panel_activated);
 
diff --git a/gitg/resources/ui/gitg-window.ui b/gitg/resources/ui/gitg-window.ui
index 8d83e0e..d896e1f 100644
--- a/gitg/resources/ui/gitg-window.ui
+++ b/gitg/resources/ui/gitg-window.ui
@@ -28,6 +28,12 @@
               </packing>
             </child>
             <child>
+              <object class="GtkBox" id="header-bar-box"/>
+              <packing>
+                <property name="pack_type">end</property>
+              </packing>
+            </child>
+            <child>
               <object class="GdHeaderMenuButton" id="button_config">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
@@ -126,25 +132,6 @@
                     <property name="can_focus">False</property>
                     <property name="hexpand">True</property>
                     <child>
-                      <object class="GtkToolbar" id="toolbar_views">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="hexpand">True</property>
-                        <property name="toolbar_style">icons</property>
-                        <property name="show_arrow">False</property>
-                        <property name="icon_size">1</property>
-                        <style>
-                          <class name="inline-toolbar"/>
-                        </style>
-                      </object>
-                      <packing>
-                        <property name="left_attach">0</property>
-                        <property name="top_attach">0</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
-                      </packing>
-                    </child>
-                    <child>
                       <object class="GtkScrolledWindow" id="scrolled_window_navigation">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
@@ -171,24 +158,6 @@
                         <property name="height">1</property>
                       </packing>
                     </child>
-                    <child>
-                      <object class="GtkToolbar" id="toolbar_panels">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="hexpand">True</property>
-                        <property name="toolbar_style">icons</property>
-                        <property name="icon_size">2</property>
-                        <style>
-                          <class name="inline-toolbar"/>
-                        </style>
-                      </object>
-                      <packing>
-                        <property name="left_attach">0</property>
-                        <property name="top_attach">2</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
-                      </packing>
-                    </child>
                   </object>
                 </child>
               </object>


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