[baobab/import-export: 3/7] Reimplement toolbar using GdMainToolbar



commit 18d80e685b012271999d11bebb2cfeee52df1669
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Sat Sep 8 00:06:27 2012 +0200

    Reimplement toolbar using GdMainToolbar

 libgd                     |    2 +-
 src/baobab-main-window.ui |  151 ++++++++++++++-------------------------------
 src/baobab-window.vala    |   54 +++++++++-------
 3 files changed, 77 insertions(+), 130 deletions(-)
---
diff --git a/libgd b/libgd
index 0ce531c..43ace41 160000
--- a/libgd
+++ b/libgd
@@ -1 +1 @@
-Subproject commit 0ce531c94dd59d00e51bc3d5ed94af6d4d143783
+Subproject commit 43ace412caeb5025d423c48869438c2587990e21
diff --git a/src/baobab-main-window.ui b/src/baobab-main-window.ui
index f1376a9..250895a 100644
--- a/src/baobab-main-window.ui
+++ b/src/baobab-main-window.ui
@@ -1,122 +1,63 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkButtonBox" id="scan-button-box">
+    <property name="visible">True</property>
+    <property name="orientation">horizontal</property>
+    <style>
+      <class name="linked"/>
+    </style>
+    <child>
+      <object class="GtkButton" id="scan-folder-button">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="has_tooltip">True</property>
+        <property name="tooltip_markup" translatable="yes">Scan a folder</property>
+        <property name="tooltip_text" translatable="yes">Scan a folder</property>
+        <property name="use_action_appearance">False</property>
+        <property name="action_name">win.scan-folder</property>
+        <property name="label" translatable="yes">Scan Folder</property>
+        <property name="use_underline">True</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkButton" id="scan-remote-button">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="has_tooltip">True</property>
+        <property name="tooltip_markup" translatable="yes">Scan a remote folder</property>
+        <property name="tooltip_text" translatable="yes">Scan a remote folder</property>
+        <property name="use_action_appearance">False</property>
+        <property name="action_name">win.scan-remote</property>
+        <property name="label" translatable="yes">Scan Remote Folder</property>
+        <property name="use_underline">True</property>
+      </object>
+    </child>
+  </object>
   <object class="GtkGrid" id="window-contents">
     <property name="visible">True</property>
     <property name="orientation">vertical</property>
     <child>
-      <object class="GtkToolbar" id="toolbar">
+      <object class="GdMainToolbar" id="home-toolbar">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="show_arrow">False</property>
+        <property name="vexpand">False</property>
         <style>
+          <class name="menubar"/>
           <class name="baobab-toolbar"/>
+        </style>
+      </object>
+    </child>
+    <child>
+      <object class="GdMainToolbar" id="result-toolbar">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="vexpand">False</property>
+        <style>
+          <class name="menubar"/>
           <class name="baobab-toolbar"/>
         </style>
-        <child>
-          <object class="GtkToolItem" id="home-page-toolitem">
-            <property name="visible">True</property>
-            <child>
-              <object class="GtkButtonBox" id="scan-buttonbox">
-                <property name="visible">True</property>
-                <property name="layout_style">start</property>
-                <style>
-                  <class name="linked"/>
-                </style>
-                <child>
-                  <object class="GtkButton" id="scan-folder-button">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="has_tooltip">True</property>
-                    <property name="tooltip_markup" translatable="yes">Scan a folder</property>
-                    <property name="tooltip_text" translatable="yes">Scan a folder</property>
-                    <property name="use_action_appearance">False</property>
-                    <property name="action_name">win.scan-folder</property>
-                    <property name="label" translatable="yes">Scan Folder</property>
-                    <property name="use_underline">True</property>
-                    <!--<property name="stock_id">gtk-directory</property>-->
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkButton" id="scan-remote-button">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="has_tooltip">True</property>
-                    <property name="tooltip_markup" translatable="yes">Scan a remote folder</property>
-                    <property name="tooltip_text" translatable="yes">Scan a remote folder</property>
-                    <property name="use_action_appearance">False</property>
-                    <property name="action_name">win.scan-remote</property>
-                    <property name="label" translatable="yes">Scan Remote Folder</property>
-                    <property name="use_underline">True</property>
-                    <!--<property name="stock_id">gtk-network</property>-->
-                  </object>
-                </child>
-              </object>
-            </child>
-          </object>
-        </child>
-        <child>
-          <object class="GtkToolButton" id="show-home-page-button">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="has_tooltip">True</property>
-            <property name="tooltip_markup" translatable="yes">Show all locations</property>
-            <property name="tooltip_text" translatable="yes">Show all locations</property>
-            <property name="use_action_appearance">False</property>
-            <property name="action_name">win.show-home-page</property>
-            <property name="icon_name">go-previous-symbolic</property>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="homogeneous">True</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkToolItem" id="toolbar-label-toolitem">
-            <property name="visible">True</property>
-            <property name="hexpand">True</property>
-            <child>
-              <object class="GtkLabel" id="toolbar-label">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label"></property>
-                <property name="selectable">True</property>
-                <property name="halign">GTK_ALIGN_CENTER</property>
-                <property name="ellipsize">end</property>
-                <property name="single_line_mode">True</property>
-                <attributes>
-                  <attribute name="weight" value="bold"/>
-                </attributes>
-              </object>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">True</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkToolButton" id="rescan-button">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="has_tooltip">True</property>
-            <property name="tooltip_markup" translatable="yes">Reload</property>
-            <property name="tooltip_text" translatable="yes">Reload</property>
-            <property name="use_action_appearance">False</property>
-            <property name="action_name">win.reload</property>
-            <property name="icon_name">view-refresh-symbolic</property>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="homogeneous">True</property>
-          </packing>
-        </child>
       </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="GtkInfoBar" id="infobar">
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 4157503..8a4cc0a 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -25,12 +25,11 @@ namespace Baobab {
     public class Window : Gtk.ApplicationWindow {
         Settings ui_settings;
         Gtk.Notebook main_notebook;
-        Gtk.Toolbar toolbar;
+        Gd.MainToolbar home_toolbar;
+        Gd.MainToolbar result_toolbar;
         Gtk.Button scan_remote;
-        Gtk.ToolItem toolbar_home_toolitem;
-        Gtk.ToolButton toolbar_show_home_page;
-        Gtk.Label toolbar_label;
-        Gtk.ToolButton toolbar_rescan;
+        Gtk.Button stop_button;
+        Gtk.Button show_home_page_button;
         Gtk.InfoBar infobar;
         Gtk.Label infobar_primary;
         Gtk.Label infobar_secondary;
@@ -117,12 +116,6 @@ namespace Baobab {
 
             // Cache some objects from the builder.
             main_notebook = builder.get_object ("main-notebook") as Gtk.Notebook;
-            toolbar = builder.get_object ("toolbar") as Gtk.Toolbar;
-            scan_remote = builder.get_object ("scan-remote-button") as Gtk.Button;
-            toolbar_home_toolitem = builder.get_object ("home-page-toolitem") as Gtk.ToolItem;
-            toolbar_show_home_page = builder.get_object ("show-home-page-button") as Gtk.ToolButton;
-            toolbar_label = builder.get_object ("toolbar-label") as Gtk.Label;
-            toolbar_rescan = builder.get_object ("rescan-button") as Gtk.ToolButton;
             infobar = builder.get_object ("infobar") as Gtk.InfoBar;
             infobar_primary = builder.get_object ("infobar-primary-label") as Gtk.Label;
             infobar_secondary = builder.get_object ("infobar-secondary-label") as Gtk.Label;
@@ -134,6 +127,25 @@ namespace Baobab {
             treemap_chart = builder.get_object ("treemap-chart") as Chart;
             spinner = builder.get_object ("spinner") as Gtk.Spinner;
 
+            // Home page toolbar
+            var toolbar = builder.get_object ("home-toolbar") as Gd.MainToolbar;
+            home_toolbar = toolbar;
+            var button_box = builder.get_object ("scan-button-box") as Gtk.ButtonBox;
+            scan_remote = builder.get_object ("scan-remote-button") as Gtk.Button;
+            toolbar.add_widget (button_box, true);
+            toolbar.show_all ();
+
+            // Result page toolbar
+            toolbar = builder.get_object ("result-toolbar") as Gd.MainToolbar;
+            result_toolbar = toolbar;
+            show_home_page_button = toolbar.add_button ("go-previous-symbolic", null, true) as Gtk.Button;
+            show_home_page_button.action_name = "win.show-home-page";
+            stop_button = toolbar.add_button ("process-stop-symbolic", null, true) as Gtk.Button;
+            stop_button.action_name = "win.show-home-page";
+            var button = toolbar.add_button ("view-refresh-symbolic", null, false) as Gtk.Button;
+            button.action_name = "win.reload";
+            toolbar.show_all ();
+
             location_list.set_adjustment (location_scroll.get_vadjustment ());
             location_list.set_action (on_scan_location_activate);
             location_list.update ();
@@ -145,9 +157,6 @@ namespace Baobab {
             var infobar_close_button = builder.get_object ("infobar-close-button") as Gtk.Button;
             infobar_close_button.clicked.connect (() => { clear_message (); });
 
-            // To make it draggable like a primary toolbar
-            toolbar.get_style_context ().add_class (Gtk.STYLE_CLASS_MENUBAR);
-
             ui_settings = Application.get_ui_settings ();
             lookup_action ("active-chart").change_state (ui_settings.get_value ("active-chart"));
 
@@ -461,8 +470,8 @@ namespace Baobab {
                 (lookup_action ("active-chart") as SimpleAction).set_enabled (false);
                 chart_notebook.page = ChartPage.SPINNER;
                 spinner.start ();
-                toolbar_show_home_page.icon_name = "process-stop-symbolic";
-                toolbar_show_home_page.tooltip_markup = _("Cancel");
+                show_home_page_button.hide ();
+                stop_button.show ();
             } else {
                 enable_drop ();
                 rings_chart.thaw_updates ();
@@ -470,8 +479,8 @@ namespace Baobab {
                 (lookup_action ("active-chart") as SimpleAction).set_enabled (true);
                 spinner.stop ();
                 lookup_action ("active-chart").change_state (ui_settings.get_value ("active-chart"));
-                toolbar_show_home_page.icon_name = "go-previous-symbolic";
-                toolbar_show_home_page.tooltip_markup = _("Show all locations");
+                show_home_page_button.show ();
+                stop_button.hide ();
             }
 
             var window = get_window ();
@@ -486,19 +495,16 @@ namespace Baobab {
         }
 
         void set_ui_state (UIPage page, bool busy) {
-            toolbar_home_toolitem.visible = (page == UIPage.HOME);
-            toolbar_show_home_page.visible = (page == UIPage.RESULT);
-            toolbar_label.visible = (page == UIPage.RESULT);
-            toolbar_rescan.visible = (page == UIPage.RESULT);
+            home_toolbar.visible = (page == UIPage.HOME);
+            result_toolbar.visible = (page == UIPage.RESULT);
 
             set_busy (busy);
 
             if (page == UIPage.HOME) {
-                toolbar_label.set_text ("");
                 var action = lookup_action ("reload") as SimpleAction;
                 action.set_enabled (false);
             } else {
-                toolbar_label.set_text (active_location.name);
+                result_toolbar.set_labels (active_location.name, null);
             }
 
             main_notebook.page = page;



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