[gnome-boxes] topbar: Split out collection toolbar



commit 0278545111b7b0fab9b8452b9b535ccffac5014d
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu Jun 5 22:40:29 2014 +0200

    topbar: Split out collection toolbar
    
    Put collection toolbar code and UI definition into a seperate class and
    template, respectively.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=726252

 data/gnome-boxes.gresource.xml |    1 +
 data/ui/collection-toolbar.ui  |  102 ++++++++++++++++++++++++++++++++++++
 data/ui/topbar.ui              |  112 +---------------------------------------
 src/Makefile.am                |    1 +
 src/collection-toolbar.vala    |   88 +++++++++++++++++++++++++++++++
 src/topbar.vala                |   56 ++------------------
 6 files changed, 199 insertions(+), 161 deletions(-)
---
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
index 40a73ab..17f975d 100644
--- a/data/gnome-boxes.gresource.xml
+++ b/data/gnome-boxes.gresource.xml
@@ -8,6 +8,7 @@
     <file>icons/boxes-gray.png</file>
     <file preprocess="xml-stripblanks">ui/app-window.ui</file>
     <file preprocess="xml-stripblanks">ui/auth-notification.ui</file>
+    <file preprocess="xml-stripblanks">ui/collection-toolbar.ui</file>
     <file preprocess="xml-stripblanks">ui/display-page.ui</file>
     <file preprocess="xml-stripblanks">ui/display-toolbar.ui</file>
     <file preprocess="xml-stripblanks">ui/empty-boxes.ui</file>
diff --git a/data/ui/collection-toolbar.ui b/data/ui/collection-toolbar.ui
new file mode 100644
index 0000000..8066f68
--- /dev/null
+++ b/data/ui/collection-toolbar.ui
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.9 -->
+  <template class="BoxesCollectionToolbar" parent="GtkHeaderBar">
+    <property name="visible">True</property>
+    <property name="show-close-button">True</property>
+    <style>
+      <class name="titlebar"/>
+      <class name="menubar"/>
+    </style>
+
+    <child>
+      <object class="GtkButton" id="new_btn">
+        <property name="visible">True</property>
+        <property name="valign">center</property>
+        <property name="use-underline">True</property>
+        <property name="label" translatable="yes">_New</property>
+        <signal name="clicked" handler="on_new_btn_clicked"/>
+        <style>
+          <class name="text-button"/>
+        </style>
+      </object>
+    </child>
+
+    <child>
+      <object class="GtkButton" id="back_btn">
+        <property name="visible">True</property>
+        <property name="valign">center</property>
+        <property name="use-underline">True</property>
+        <signal name="clicked" handler="on_back_btn_clicked"/>
+        <style>
+          <class name="image-button"/>
+        </style>
+        <child internal-child="accessible">
+          <object class="AtkObject" id="a11y-button1">
+            <property name="accessible-name" translatable="yes">Back</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkImage" id="back_image">
+            <property name="visible">True</property>
+          </object>
+        </child>
+      </object>
+    </child>
+
+    <child>
+      <object class="GtkButton" id="select_btn">
+        <property name="visible">True</property>
+        <property name="valign">center</property>
+        <property name="use-underline">True</property>
+        <signal name="clicked" handler="on_select_btn_clicked"/>
+        <style>
+          <class name="image-button"/>
+        </style>
+        <child internal-child="accessible">
+          <object class="AtkObject" id="a11y-button3">
+            <property name="accessible-name" translatable="yes">Select Items</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkImage" id="select_image">
+            <property name="visible">True</property>
+            <property name="icon-name">object-select-symbolic</property>
+            <property name="icon-size">1</property>
+          </object>
+        </child>
+      </object>
+
+      <packing>
+        <property name="pack-type">end</property>
+      </packing>
+    </child>
+
+    <child>
+      <object class="GtkToggleButton" id="search_btn">
+        <property name="visible">True</property>
+        <property name="valign">center</property>
+        <property name="use-underline">True</property>
+        <style>
+          <class name="image-button"/>
+        </style>
+        <child internal-child="accessible">
+          <object class="AtkObject" id="a11y-button2">
+            <property name="accessible-name" translatable="yes">Search</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkImage" id="search_image">
+            <property name="visible">True</property>
+            <property name="icon-name">edit-find-symbolic</property>
+            <property name="icon-size">1</property>
+          </object>
+        </child>
+      </object>
+
+      <packing>
+        <property name="pack-type">end</property>
+      </packing>
+    </child>
+  </template>
+</interface>
diff --git a/data/ui/topbar.ui b/data/ui/topbar.ui
index 494219d..3ad0d44 100644
--- a/data/ui/topbar.ui
+++ b/data/ui/topbar.ui
@@ -10,117 +10,7 @@
 
     <!-- Collection -->
     <child>
-      <object class="GtkBox" id="collection_hbox">
-        <property name="visible">True</property>
-        <property name="orientation">horizontal</property>
-        <property name="spacing">0</property>
-
-        <child>
-          <object class="GtkHeaderBar" id="collection_toolbar">
-            <property name="visible">True</property>
-            <property name="show-close-button">True</property>
-            <style>
-              <class name="titlebar"/>
-              <class name="menubar"/>
-            </style>
-
-            <child>
-              <object class="GtkButton" id="new_btn">
-                <property name="visible">True</property>
-                <property name="valign">center</property>
-                <property name="use-underline">True</property>
-                <property name="label" translatable="yes">_New</property>
-                <signal name="clicked" handler="on_new_btn_clicked"/>
-                <style>
-                  <class name="text-button"/>
-                </style>
-              </object>
-            </child>
-
-            <child>
-              <object class="GtkButton" id="back_btn">
-                <property name="visible">True</property>
-                <property name="valign">center</property>
-                <property name="use-underline">True</property>
-                <signal name="clicked" handler="on_back_btn_clicked"/>
-                <style>
-                  <class name="image-button"/>
-                </style>
-                <child internal-child="accessible">
-                  <object class="AtkObject" id="a11y-button1">
-                    <property name="accessible-name" translatable="yes">Back</property>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkImage" id="back_image">
-                    <property name="visible">True</property>
-                  </object>
-                </child>
-              </object>
-            </child>
-
-            <child>
-              <object class="GtkButton" id="select_btn">
-                <property name="visible">True</property>
-                <property name="valign">center</property>
-                <property name="use-underline">True</property>
-                <signal name="clicked" handler="on_select_btn_clicked"/>
-                <style>
-                  <class name="image-button"/>
-                </style>
-                <child internal-child="accessible">
-                  <object class="AtkObject" id="a11y-button3">
-                    <property name="accessible-name" translatable="yes">Select Items</property>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkImage" id="select_image">
-                    <property name="visible">True</property>
-                    <property name="icon-name">object-select-symbolic</property>
-                    <property name="icon-size">1</property>
-                  </object>
-                </child>
-              </object>
-
-              <packing>
-                <property name="pack-type">end</property>
-              </packing>
-            </child>
-
-            <child>
-              <object class="GtkToggleButton" id="search_btn">
-                <property name="visible">True</property>
-                <property name="valign">center</property>
-                <property name="use-underline">True</property>
-                <style>
-                  <class name="image-button"/>
-                </style>
-                <child internal-child="accessible">
-                  <object class="AtkObject" id="a11y-button2">
-                    <property name="accessible-name" translatable="yes">Search</property>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkImage" id="search_image">
-                    <property name="visible">True</property>
-                    <property name="icon-name">edit-find-symbolic</property>
-                    <property name="icon-size">1</property>
-                  </object>
-                </child>
-              </object>
-
-              <packing>
-                <property name="pack-type">end</property>
-              </packing>
-            </child>
-          </object>
-
-          <packing>
-            <property name="expand">True</property>
-            <property name="fill">True</property>
-            <property name="padding">0</property>
-          </packing>
-        </child>
+      <object class="BoxesCollectionToolbar" id="collection_toolbar">
       </object>
 
       <packing>
diff --git a/src/Makefile.am b/src/Makefile.am
index 2504934..34dc1f7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -97,6 +97,7 @@ gnome_boxes_SOURCES =                         \
        auth-notification.vala                  \
        collection-view.vala                    \
        collection.vala                         \
+       collection-toolbar.vala                 \
        display-page.vala                       \
        display-toolbar.vala                    \
        display.vala                            \
diff --git a/src/collection-toolbar.vala b/src/collection-toolbar.vala
new file mode 100644
index 0000000..ab6f38a
--- /dev/null
+++ b/src/collection-toolbar.vala
@@ -0,0 +1,88 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+using Gtk;
+
+[GtkTemplate (ui = "/org/gnome/Boxes/ui/collection-toolbar.ui")]
+private class Boxes.CollectionToolbar: HeaderBar {
+    [GtkChild]
+    private Button search_btn;
+    [GtkChild]
+    private Button select_btn;
+    [GtkChild]
+    private Button back_btn;
+    [GtkChild]
+    private Image back_image;
+    [GtkChild]
+    private Button new_btn;
+
+    construct {
+        var back_icon = (get_direction () == TextDirection.RTL)? "go-previous-rtl-symbolic" :
+                                                                 "go-previous-symbolic";
+        back_image.set_from_icon_name (back_icon, IconSize.MENU);
+
+        App.app.notify["ui-state"].connect (ui_state_changed);
+    }
+
+    public void setup_ui () {
+        assert (App.window != null);
+        assert (App.window.searchbar != null);
+
+        update_select_btn ();
+        App.app.collection.item_added.connect (update_select_btn);
+        App.app.collection.item_removed.connect (update_select_btn);
+
+        update_search_btn ();
+        App.app.collection.item_added.connect (update_search_btn);
+        App.app.collection.item_removed.connect (update_search_btn);
+
+        search_btn.bind_property ("active", App.window.searchbar, "search-mode-enabled", 
BindingFlags.BIDIRECTIONAL);
+    }
+
+    [GtkCallback]
+    private void on_new_btn_clicked () {
+        App.app.set_state (UIState.WIZARD);
+    }
+
+    [GtkCallback]
+    private void on_back_btn_clicked () {
+        App.app.set_state (UIState.COLLECTION);
+    }
+
+    [GtkCallback]
+    private void on_select_btn_clicked () {
+        App.app.selection_mode = true;
+    }
+
+    private void update_search_btn () {
+        search_btn.sensitive = App.app.collection.items.length != 0;
+    }
+
+    private void update_select_btn () {
+        select_btn.sensitive = App.app.collection.items.length != 0;
+    }
+
+    public void click_back_button () {
+        back_btn.clicked ();
+    }
+
+    private void ui_state_changed () {
+        switch (App.app.ui_state) {
+        case UIState.COLLECTION:
+            back_btn.hide ();
+            select_btn.show ();
+            search_btn.show ();
+            new_btn.show ();
+            break;
+
+        case UIState.CREDS:
+            new_btn.hide ();
+            back_btn.show ();
+            select_btn.hide ();
+            search_btn.hide ();
+            break;
+
+        default:
+            break;
+        }
+    }
+
+}
diff --git a/src/topbar.vala b/src/topbar.vala
index 6926a65..a6d5356 100644
--- a/src/topbar.vala
+++ b/src/topbar.vala
@@ -26,21 +26,11 @@ private class Boxes.Topbar: Gtk.Stack, Boxes.UI {
     public Gtk.Button wizard_create_btn;
 
     [GtkChild]
-    private Gtk.Button search_btn;
-    [GtkChild]
     private Gtk.Button search2_btn;
     [GtkChild]
-    private Gtk.Button select_btn;
-    [GtkChild]
-    private Gtk.Button back_btn;
-    [GtkChild]
-    private Gtk.Image back_image;
-    [GtkChild]
-    private Gtk.Button new_btn;
-    [GtkChild]
     private Gtk.Label selection_menu_button_label;
     [GtkChild]
-    private Gtk.HeaderBar collection_toolbar;
+    private CollectionToolbar collection_toolbar;
     [GtkChild]
     private DisplayToolbar display_toolbar;
 
@@ -55,7 +45,7 @@ private class Boxes.Topbar: Gtk.Stack, Boxes.UI {
         case UIState.PROPERTIES:
             break;
         case UIState.CREDS:
-            back_btn.clicked ();
+            collection_toolbar.click_back_button ();
             break;
         case UIState.WIZARD:
             if (App.window.wizard.page != WizardPage.INTRODUCTION)
@@ -88,8 +78,8 @@ private class Boxes.Topbar: Gtk.Stack, Boxes.UI {
         get { return _status; }
         set {
             _status = value;
-            collection_toolbar.set_title (_status);
-            display_toolbar.set_title (_status);
+            collection_toolbar.set_title (_status??"");
+            display_toolbar.set_title (_status??"");
         }
     }
 
@@ -120,22 +110,14 @@ private class Boxes.Topbar: Gtk.Stack, Boxes.UI {
     }
 
     public void setup_ui () {
-        var back_icon = (get_direction () == Gtk.TextDirection.RTL)? "go-previous-rtl-symbolic" :
-                                                                     "go-previous-symbolic";
-        back_image.set_from_icon_name (back_icon, Gtk.IconSize.MENU);
-
         assert (App.window != null);
         assert (App.window.searchbar != null);
-        search_btn.bind_property ("active", App.window.searchbar, "search-mode-enabled", 
BindingFlags.BIDIRECTIONAL);
         search2_btn.bind_property ("active", App.window.searchbar, "search-mode-enabled", 
BindingFlags.BIDIRECTIONAL);
 
         App.app.notify["selection-mode"].connect (() => {
             page = App.app.selection_mode ?
                 TopbarPage.SELECTION : page = TopbarPage.COLLECTION;
         });
-        update_select_btn ();
-        App.app.collection.item_added.connect (update_select_btn);
-        App.app.collection.item_removed.connect (update_select_btn);
         update_selection_label ();
 
         var toolbar = App.window.display_page.toolbar;
@@ -145,17 +127,14 @@ private class Boxes.Topbar: Gtk.Stack, Boxes.UI {
         update_search_btn ();
         App.app.collection.item_added.connect (update_search_btn);
         App.app.collection.item_removed.connect (update_search_btn);
+
+        collection_toolbar.setup_ui ();
     }
 
     private void update_search_btn () {
-        search_btn.sensitive = App.app.collection.items.length != 0;
         search2_btn.sensitive = App.app.collection.items.length != 0;
     }
 
-    private void update_select_btn () {
-        select_btn.sensitive = App.app.collection.items.length != 0;
-    }
-
     private void update_selection_label () {
         var items = App.app.selected_items.length ();
         if (items > 0) {
@@ -171,18 +150,10 @@ private class Boxes.Topbar: Gtk.Stack, Boxes.UI {
         switch (ui_state) {
         case UIState.COLLECTION:
             page = TopbarPage.COLLECTION;
-            back_btn.hide ();
-            select_btn.show ();
-            search_btn.show ();
-            new_btn.show ();
             break;
 
         case UIState.CREDS:
             page = TopbarPage.COLLECTION;
-            new_btn.hide ();
-            back_btn.show ();
-            select_btn.hide ();
-            search_btn.hide ();
             break;
 
         case UIState.DISPLAY:
@@ -206,21 +177,6 @@ private class Boxes.Topbar: Gtk.Stack, Boxes.UI {
     }
 
     [GtkCallback]
-    private void on_new_btn_clicked () {
-        App.app.set_state (UIState.WIZARD);
-    }
-
-    [GtkCallback]
-    private void on_back_btn_clicked () {
-        App.app.set_state (UIState.COLLECTION);
-    }
-
-    [GtkCallback]
-    private void on_select_btn_clicked () {
-        App.app.selection_mode = true;
-    }
-
-    [GtkCallback]
     private void on_cancel_btn_clicked () {
         App.app.selection_mode = false;
     }


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