[gnome-boxes: 2/2] Move Sidebar UI setup to UI file



commit d01202a1f7daa1de1dfd88aacf64c29325467b8a
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Jan 8 22:22:24 2014 +0000

    Move Sidebar UI setup to UI file

 data/gnome-boxes.gresource.xml |    1 +
 data/ui/sidebar.ui             |  127 ++++++++++++++++++++++++++++++++++++++++
 po/POTFILES.in                 |    1 +
 src/properties.vala            |    2 +-
 src/sidebar.vala               |   69 +++++++++++++---------
 src/wizard.vala                |   30 +---------
 6 files changed, 173 insertions(+), 57 deletions(-)
---
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
index f2d59d1..0c77de1 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/display-page.ui</file>
     <file preprocess="xml-stripblanks">ui/display-toolbar.ui</file>
+    <file preprocess="xml-stripblanks">ui/sidebar.ui</file>
     <file preprocess="xml-stripblanks">ui/topbar.ui</file>
     <file preprocess="xml-stripblanks">ui/unattended-setup-box.ui</file>
     <file preprocess="xml-stripblanks">ui/wizard.ui</file>
diff --git a/data/ui/sidebar.ui b/data/ui/sidebar.ui
new file mode 100644
index 0000000..0e169a8
--- /dev/null
+++ b/data/ui/sidebar.ui
@@ -0,0 +1,127 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.9 -->
+
+  <template class="BoxesSidebar" parent="GtkNotebook">
+    <property name="visible">True</property>
+    <property name="width-request">100</property>
+    <property name="show-tabs">False</property>
+    <style>
+      <class name="sidebar"/>
+    </style>
+
+    <!-- Separate page for each UI state -->
+
+    <!-- Collection -->
+    <child>
+      <object class="GtkBox" id="collection_vbox">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">0</property>
+      </object>
+    </child>
+
+    <!-- Wizard -->
+    <child>
+      <object class="GtkBox" id="wizard_vbox">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">0</property>
+
+        <child>
+          <object class="GtkLabel" id="wizard_intro_label">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">Introduction</property>
+            <property name="margin-left">25</property>
+            <property name="halign">start</property>
+            <style>
+              <class name="boxes-step-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="padding">10</property>
+          </packing>
+        </child>
+
+        <child>
+          <object class="GtkLabel" id="wizard_source_label">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">Source Selection</property>
+            <property name="margin-left">25</property>
+            <property name="halign">start</property>
+            <style>
+              <class name="boxes-step-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="padding">10</property>
+          </packing>
+        </child>
+
+        <child>
+          <object class="GtkLabel" id="wizard_preparation_label">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">Preparation</property>
+            <property name="margin-left">25</property>
+            <property name="halign">start</property>
+            <style>
+              <class name="boxes-step-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="padding">10</property>
+          </packing>
+        </child>
+
+        <child>
+          <object class="GtkLabel" id="wizard_setup_label">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">Setup</property>
+            <property name="margin-left">25</property>
+            <property name="halign">start</property>
+            <style>
+              <class name="boxes-step-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="padding">10</property>
+          </packing>
+        </child>
+
+        <child>
+          <object class="GtkLabel" id="wizard_review_label">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">Review</property>
+            <property name="margin-left">25</property>
+            <property name="halign">start</property>
+            <style>
+              <class name="boxes-step-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="padding">10</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+
+    <!-- Properties -->
+    <child>
+      <object class="GtkBox" id="props_vbox">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">10</property>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 9aa343e..1b91fe6 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,6 +2,7 @@ data/gnome-boxes.appdata.xml.in
 data/gnome-boxes.desktop.in.in
 [type: gettext/ini]data/gnome-boxes-search-provider.ini.in
 data/org.gnome.boxes.gschema.xml.in
+[type: gettext/glade]data/ui/sidebar.ui
 [type: gettext/glade]data/ui/topbar.ui
 [type: gettext/glade]data/ui/unattended-setup-box.ui
 [type: gettext/glade]data/ui/wizard.ui
diff --git a/src/properties.vala b/src/properties.vala
index 38af5c9..0043cfc 100644
--- a/src/properties.vala
+++ b/src/properties.vala
@@ -240,7 +240,7 @@ private class Boxes.Properties: GLib.Object, Boxes.UI {
         hbox.show_all ();
 
         /* sidebar */
-        var vbox = App.app.sidebar.notebook.get_nth_page (Boxes.SidebarPage.PROPERTIES) as Gtk.Box;
+        var vbox = App.app.sidebar.get_nth_page (Boxes.SidebarPage.PROPERTIES) as Gtk.Box;
 
         tree_view = new Gtk.TreeView ();
         tree_view.get_style_context ().add_class ("boxes-bg");
diff --git a/src/sidebar.vala b/src/sidebar.vala
index 0d85b78..8305bda 100644
--- a/src/sidebar.vala
+++ b/src/sidebar.vala
@@ -9,28 +9,63 @@ private enum Boxes.SidebarPage {
     PROPERTIES,
 }
 
-private class Boxes.Sidebar: GLib.Object, Boxes.UI {
+[GtkTemplate (ui = "/org/gnome/Boxes/ui/sidebar.ui")]
+private class Boxes.Sidebar: Gtk.Notebook, Boxes.UI {
     public Clutter.Actor actor { get { return gtk_actor; } }
     public UIState previous_ui_state { get; protected set; }
     public UIState ui_state { get; protected set; }
-    public Notebook notebook;
-    private uint width;
 
     private GtkClutter.Actor gtk_actor; // the sidebar box
 
-    public Sidebar () {
-        width = 200;
+    [GtkChild]
+    private Gtk.Box wizard_vbox;
+    [GtkChild]
+    private Gtk.Label wizard_intro_label;
+    [GtkChild]
+    private Gtk.Label wizard_source_label;
+    [GtkChild]
+    private Gtk.Label wizard_preparation_label;
+    [GtkChild]
+    private Gtk.Label wizard_setup_label;
+    [GtkChild]
+    private Gtk.Label wizard_review_label;
 
+    public Sidebar () {
         notify["ui-state"].connect (ui_state_changed);
         setup_sidebar ();
     }
 
+    public void set_wizard_page (WizardPage wizard_page) {
+        foreach (var label in wizard_vbox.get_children ())
+            label.get_style_context ().remove_class ("boxes-wizard-current-page-label");
+
+        Gtk.Label current_label = null;
+        switch ((int) page_num) {
+        case WizardPage.INTRODUCTION:
+            current_label = wizard_intro_label;
+            break;
+        case WizardPage.SOURCE:
+            current_label = wizard_source_label;
+            break;
+        case WizardPage.PREPARATION:
+            current_label = wizard_preparation_label;
+            break;
+        case WizardPage.SETUP:
+            current_label = wizard_setup_label;
+            break;
+        case WizardPage.REVIEW:
+            current_label = wizard_review_label;
+            break;
+        }
+        current_label.get_style_context ().add_class ("boxes-wizard-current-page-label");
+    }
+
     private void ui_state_changed () {
         switch (ui_state) {
         case UIState.WIZARD:
         case UIState.PROPERTIES:
             App.app.sidebar_revealer.reveal ();
-            notebook.page = ui_state == UIState.WIZARD ? SidebarPage.WIZARD : SidebarPage.PROPERTIES;
+            page = ui_state == UIState.WIZARD ? SidebarPage.WIZARD : SidebarPage.PROPERTIES;
             break;
 
         default:
@@ -40,30 +75,10 @@ private class Boxes.Sidebar: GLib.Object, Boxes.UI {
     }
 
     private void setup_sidebar () {
-        notebook = new Gtk.Notebook ();
-        gtk_actor = new GtkClutter.Actor.with_contents (notebook);
+        gtk_actor = new GtkClutter.Actor.with_contents (this);
         gtk_actor.get_widget ().get_style_context ().add_class ("boxes-bg");
         gtk_actor.name = "sidebar";
         gtk_actor.x_expand = true;
         gtk_actor.y_expand = true;
-
-        notebook.get_style_context ().add_class (Gtk.STYLE_CLASS_SIDEBAR);
-        notebook.set_size_request ((int) width, 100);
-        notebook.show_tabs = false;
-
-        /* SidebarPage.COLLECTION */
-        var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
-        notebook.append_page (vbox, null);
-
-        /* SidebarPage.WIZARD */
-        vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
-        vbox.margin_top = 20;
-        notebook.append_page (vbox, null);
-
-        /* SidebarPage.PROPERTIES */
-        vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 10);
-        notebook.append_page (vbox, null);
-
-        notebook.show_all ();
     }
 }
diff --git a/src/wizard.vala b/src/wizard.vala
index ca870bc..e91ca8e 100644
--- a/src/wizard.vala
+++ b/src/wizard.vala
@@ -21,7 +21,6 @@ private class Boxes.Wizard: Gtk.Notebook, Boxes.UI {
     public UIState previous_ui_state { get; protected set; }
     public UIState ui_state { get; protected set; }
 
-    private GenericArray<Gtk.Label> steps;
     private Gtk.Button cancel_button;
     private Gtk.Button back_button;
     private Gtk.Button next_button;
@@ -129,17 +128,10 @@ private class Boxes.Wizard: Gtk.Notebook, Boxes.UI {
 
         base.switch_page (page_widget, page_num);
 
-        for (var i = 0; i < steps.length; i++) {
-            var label = steps.get (i);
-            label.get_style_context ().remove_class ("boxes-wizard-current-page-label");
-        }
-
-        steps.get (page).get_style_context ().add_class ("boxes-wizard-current-page-label");
+        App.app.sidebar.set_wizard_page ((WizardPage) page_num);
     }
 
     construct {
-        steps = new GenericArray<Gtk.Label> ();
-        steps.length = WizardPage.LAST;
         media_manager = MediaManager.get_instance ();
     }
 
@@ -492,20 +484,6 @@ private class Boxes.Wizard: Gtk.Notebook, Boxes.UI {
         return true;
     }
 
-    private void add_step (string title, WizardPage page) {
-        /* sidebar */
-        var vbox = App.app.sidebar.notebook.get_nth_page (Boxes.SidebarPage.WIZARD) as Gtk.Box;
-
-        var label = new Gtk.Label (title);
-        label.margin_left = 25;
-        label.get_style_context ().add_class ("boxes-step-label");
-        label.set_halign (Gtk.Align.START);
-        vbox.pack_start (label, false, false, 10);
-
-        vbox.show_all ();
-        steps.set (page, label);
-    }
-
     private bool skip_review_for_live;
 
     private bool skip_page (Boxes.WizardPage page) {
@@ -549,12 +527,6 @@ private class Boxes.Wizard: Gtk.Notebook, Boxes.UI {
     }
 
     private void setup_ui () {
-        add_step (_("Introduction"), WizardPage.INTRODUCTION);
-        add_step (_("Source Selection"), WizardPage.SOURCE);
-        add_step (_("Preparation"), WizardPage.PREPARATION);
-        add_step (_("Setup"), WizardPage.SETUP);
-        add_step (_("Review"), WizardPage.REVIEW);
-
         gtk_actor = new GtkClutter.Actor.with_contents (this);
         gtk_actor.get_widget ().get_style_context ().add_class ("boxes-bg");
         gtk_actor.name = "wizard";


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