[gnome-boxes/wip/ui-files] Move Topbar widget setup to .ui files



commit 2f7057f452a7bf32004dcc53cc985c7312f91a3b
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue Jan 7 18:36:48 2014 +0000

    Move Topbar widget setup to .ui files

 data/gnome-boxes.gresource.xml |    1 +
 data/ui/topbar.ui              |  280 ++++++++++++++++++++++++++++++++++++++++
 src/app.vala                   |    2 +-
 src/properties.vala            |    2 +-
 src/topbar.vala                |  173 +++++++------------------
 src/wizard.vala                |    2 +-
 6 files changed, 333 insertions(+), 127 deletions(-)
---
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
index 67fdb49..8fc071f 100644
--- a/data/gnome-boxes.gresource.xml
+++ b/data/gnome-boxes.gresource.xml
@@ -6,6 +6,7 @@
     <file>icons/boxes-create.png</file>
     <file>icons/boxes-dark.png</file>
     <file>icons/boxes-gray.png</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>
     <file preprocess="xml-stripblanks">ui/wizard-media-entry.ui</file>
diff --git a/data/ui/topbar.ui b/data/ui/topbar.ui
new file mode 100644
index 0000000..527543a
--- /dev/null
+++ b/data/ui/topbar.ui
@@ -0,0 +1,280 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.9 -->
+  <template class="BoxesTopbar" parent="GtkNotebook">
+    <property name="visible">True</property>
+    <property name="show-tabs">False</property>
+
+    <!-- Separate page for each UI state and mode -->
+
+    <!-- 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="GtkSpinner" id="spinner">
+                <property name="visible">True</property>
+                <property name="hexpand">True</property>
+                <property name="vexpand">True</property>
+                <property name="active">True</property>
+                <property name="margin">6</property>
+              </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>
+
+            <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>
+          </object>
+
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="padding">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+
+    <!-- Collection (selection mode) -->
+    <child>
+      <object class="GtkBox" id="selection_hbox">
+        <property name="visible">True</property>
+        <property name="orientation">horizontal</property>
+        <property name="spacing">0</property>
+
+        <child>
+          <object class="GtkHeaderBar" id="selection_toolbar">
+            <property name="visible">True</property>
+            <property name="show-close-button">False</property>
+            <style>
+              <class name="selection-mode"/>
+              <class name="titlebar"/>
+              <class name="menubar"/>
+            </style>
+
+            <child type="title">
+              <object class="GtkMenuButton" id="selection_menu_button">
+                <property name="visible">True</property>
+                <property name="valign">center</property>
+                <property name="menu-model">selection-menu</property>
+
+                <style>
+                  <class name="selection-mode"/>
+                  <class name="titlebar"/>
+                  <class name="menubar"/>
+                </style>
+              </object>
+            </child>
+
+            <child>
+              <object class="GtkToggleButton" id="search2_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-button4">
+                    <property name="accessible-name" translatable="yes">Search</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkImage" id="search2_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>
+
+            <child>
+              <object class="GtkButton" id="cancel_btn">
+                <property name="visible">True</property>
+                <property name="valign">center</property>
+                <property name="use-underline">True</property>
+                <property name="label" translatable="yes">_Cancel</property>
+                <signal name="clicked" handler="on_cancel_btn_clicked"/>
+                <style>
+                  <class name="text-button"/>
+                </style>
+              </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>
+    </child>
+
+    <!-- Wizard -->
+    <child>
+      <object class="GtkBox" id="wizard_hbox">
+        <property name="visible">True</property>
+        <property name="orientation">horizontal</property>
+        <property name="spacing">0</property>
+      </object>
+    </child>
+
+    <!-- Properties -->
+    <child>
+      <object class="GtkBox" id="props_hbox">
+        <property name="visible">True</property>
+        <property name="orientation">horizontal</property>
+        <property name="spacing">0</property>
+      </object>
+    </child>
+
+    <!-- Display -->
+    <child>
+      <object class="GtkBox" id="display_hbox">
+        <property name="visible">True</property>
+        <property name="orientation">horizontal</property>
+        <property name="spacing">0</property>
+      </object>
+    </child>
+  </template>
+
+  <!-- We need a sizegroup to ensure the spinner is the same size as the buttons so it centers correctly -->
+  <object class="GtkSizeGroup" id="spinner_sizegroup">
+    <property name="mode">horizontal</property>
+    <widgets>
+      <widget name="spinner"/>
+      <widget name="select_btn"/>
+    </widgets>
+  </object>
+
+  <menu id="selection-menu">
+    <section>
+      <item>
+        <attribute name="action">win.select-all</attribute>
+        <attribute name="label" translatable="yes">Select All</attribute>
+        <attribute name="accel">&lt;Primary&gt;a</attribute>
+      </item>
+      <item>
+        <attribute name="action">win.select-running</attribute>
+        <attribute name="label" translatable="yes">Select Running</attribute>
+      </item>
+      <item>
+        <attribute name="action">win.select-none</attribute>
+        <attribute name="label" translatable="yes">Select None</attribute>
+      </item>
+    </section>
+  </menu>
+
+</interface>
diff --git a/src/app.vala b/src/app.vala
index f3fe83f..93960a2 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -584,7 +584,7 @@ private class Boxes.App: GLib.Object, Boxes.UI {
 
         stage.add_child (vbox_actor);
 
-        window.set_titlebar (topbar.widget);
+        window.set_titlebar (topbar);
 
         searchbar_revealer = new Boxes.Revealer (true);
         searchbar_revealer.resize = true;
diff --git a/src/properties.vala b/src/properties.vala
index 7f4f319..748d942 100644
--- a/src/properties.vala
+++ b/src/properties.vala
@@ -220,7 +220,7 @@ private class Boxes.Properties: GLib.Object, Boxes.UI {
         gtk_actor.y_expand = true;
 
         /* topbar */
-        var hbox = App.app.topbar.notebook.get_nth_page (Boxes.TopbarPage.PROPERTIES) as Gtk.Box;
+        var hbox = App.app.topbar.get_nth_page (Boxes.TopbarPage.PROPERTIES) as Gtk.Box;
 
         toolbar = new Gtk.HeaderBar ();
         toolbar.get_style_context ().add_class (Gtk.STYLE_CLASS_MENUBAR);
diff --git a/src/topbar.vala b/src/topbar.vala
index 0256025..279509b 100644
--- a/src/topbar.vala
+++ b/src/topbar.vala
@@ -10,7 +10,8 @@ public enum Boxes.TopbarPage {
     DISPLAY
 }
 
-private class Boxes.Topbar: GLib.Object, Boxes.UI {
+[GtkTemplate (ui = "/org/gnome/Boxes/ui/topbar.ui")]
+private class Boxes.Topbar: Gtk.Notebook, Boxes.UI {
     // FIXME: This is really redundant now that App is using widget property
     // instead but parent Boxes.UI currently requires an actor. Hopefully
     // soon we can move more towards new Gtk classes and Boxes.UI requires
@@ -26,19 +27,27 @@ private class Boxes.Topbar: GLib.Object, Boxes.UI {
     public UIState previous_ui_state { get; protected set; }
     public UIState ui_state { get; protected set; }
 
-    public Gtk.Widget widget { get { return notebook; } }
-    public Notebook notebook;
-
+    [GtkChild]
     private Gtk.Spinner spinner;
+    [GtkChild]
     private Gtk.Button search_btn;
+    [GtkChild]
     private Gtk.Button search2_btn;
+    [GtkChild]
     private Gtk.Button select_btn;
-    private Gtk.Button cancel_btn;
+    [GtkChild]
     private Gtk.Button back_btn;
+    [GtkChild]
+    private Gtk.Image back_image;
+    [GtkChild]
     private Gtk.Button new_btn;
+    [GtkChild]
     private Gtk.MenuButton selection_menu_button;
-    private Gtk.HeaderBar selection_toolbar;
+    [GtkChild]
     private Gtk.HeaderBar collection_toolbar;
+    [GtkChild]
+    private Gtk.Box display_hbox;
+
     private Gtk.HeaderBar display_toolbar;
 
     public string? _status;
@@ -62,133 +71,29 @@ private class Boxes.Topbar: GLib.Object, Boxes.UI {
     }
 
     private void setup_topbar () {
-        notebook = new Gtk.Notebook ();
-
-        /* TopbarPage.COLLECTION */
-        var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
-        notebook.append_page (hbox, null);
-
-        var toolbar = new Gtk.HeaderBar ();
-        toolbar.get_style_context ().add_class ("titlebar");
-        collection_toolbar = toolbar;
-        toolbar.get_style_context ().add_class (Gtk.STYLE_CLASS_MENUBAR);
-        toolbar.show_close_button = true;
-        hbox.pack_start (toolbar, true, true, 0);
-
-        new_btn = new Gtk.Button.with_mnemonic (_("_New"));
-        new_btn.valign = Gtk.Align.CENTER;
-        new_btn.get_style_context ().add_class ("text-button");
-        toolbar.pack_start (new_btn);
-        new_btn.clicked.connect ((button) => { App.app.set_state (UIState.WIZARD); });
-
-        var back_icon = (toolbar.get_direction () == Gtk.TextDirection.RTL)? "go-previous-rtl-symbolic" :
-                                                                             "go-previous-symbolic";
-        var back_image = new Gtk.Image.from_icon_name (back_icon, Gtk.IconSize.MENU);
-        back_btn = new Gtk.Button ();
-        back_btn.set_image (back_image);
-        back_btn.valign = Gtk.Align.CENTER;
-        back_btn.get_style_context ().add_class ("image-button");
-        toolbar.pack_start (back_btn);
-        back_btn.get_accessible ().set_name (_("Back"));
-        back_btn.clicked.connect ((button) => { App.app.set_state (UIState.COLLECTION); });
-
-        // We need a sizegroup to ensure the spinner is the same size
-        // as the buttons so it centers correctly
-        var spinner_sizegroup = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
-
-        spinner = new Gtk.Spinner ();
-        spinner.start ();
-        spinner.hexpand = true;
-        spinner.vexpand = true;
-        spinner.margin = 6;
-        toolbar.pack_end (spinner);
-        spinner_sizegroup.add_widget (spinner);
-
-        var search_image = new Gtk.Image.from_icon_name ("edit-find-symbolic", Gtk.IconSize.MENU);
-        search_btn = new Gtk.ToggleButton ();
-        search_btn.set_image (search_image);
-        search_btn.valign = Gtk.Align.CENTER;
-        search_btn.get_style_context ().add_class ("image-button");
-        toolbar.pack_end (search_btn);
-        search_btn.get_accessible ().set_name (_("Search"));
+        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);
+
         search_btn.bind_property ("active", App.app.searchbar, "visible", BindingFlags.BIDIRECTIONAL);
+        search2_btn.bind_property ("active", App.app.searchbar, "visible", BindingFlags.BIDIRECTIONAL);
 
-        var select_image = new Gtk.Image.from_icon_name ("object-select-symbolic", Gtk.IconSize.MENU);
-        select_btn = new Gtk.Button ();
-        select_btn.set_image (select_image);
-        select_btn.valign = Gtk.Align.CENTER;
-        select_btn.get_style_context ().add_class ("image-button");
-        toolbar.pack_end (select_btn);
-        select_btn.get_accessible ().set_name (_("Select Items"));
-        spinner_sizegroup.add_widget (select_btn);
-        select_btn.clicked.connect (() => {
-            App.app.selection_mode = true;
-        });
         App.app.notify["selection-mode"].connect (() => {
-            notebook.page = App.app.selection_mode ?
-                TopbarPage.SELECTION : notebook.page = TopbarPage.COLLECTION;
+            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);
-
-        /* TopbarPage.SELECTION */
-        hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
-        notebook.append_page (hbox, null);
-        selection_toolbar = new Gtk.HeaderBar ();
-        selection_toolbar.get_style_context ().add_class ("selection-mode");
-        selection_toolbar.get_style_context ().add_class (Gtk.STYLE_CLASS_MENUBAR);
-        selection_toolbar.get_style_context ().add_class ("titlebar");
-
-        var menu = new GLib.Menu ();
-        menu.append (_("Select All"), "app.select-all");
-        menu.append (_("Select Running"), "app.select-running");
-        menu.append (_("Select None"), "app.select-none");
-
-        selection_menu_button = new Gtk.MenuButton ();
-        selection_menu_button.valign = Gtk.Align.CENTER;
-        selection_menu_button.set_menu_model (menu);
-        selection_toolbar.set_custom_title (selection_menu_button);
-        hbox.pack_start (selection_toolbar, true, true, 0);
-
         update_selection_label ();
 
-        search_image = new Gtk.Image.from_icon_name ("edit-find-symbolic", Gtk.IconSize.MENU);
-        search2_btn = new Gtk.ToggleButton ();
-        search2_btn.set_image (search_image);
-        search2_btn.valign = Gtk.Align.CENTER;
-        search2_btn.get_style_context ().add_class ("image-button");
-        selection_toolbar.pack_end (search2_btn);
-        search2_btn.bind_property ("active", App.app.searchbar, "visible", BindingFlags.BIDIRECTIONAL);
-
-        cancel_btn = new Gtk.Button.with_mnemonic (_("_Cancel"));
-        cancel_btn.valign = Gtk.Align.CENTER;
-        cancel_btn.get_style_context ().add_class ("text-button");
-        selection_toolbar.pack_end (cancel_btn);
-        cancel_btn.clicked.connect (() => {
-            App.app.selection_mode = false;
-        });
-
-        /* TopbarPage.WIZARD */
-        hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
-        notebook.append_page (hbox, null);
-
-        /* TopbarPage.PROPERTIES */
-        hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
-        notebook.append_page (hbox, null);
-
-        /* TopbarPage.DISPLAY */
-        hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
         display_toolbar = App.app.display_page.title_toolbar;
-        hbox.pack_start (display_toolbar, true, true, 0);
-        notebook.append_page (hbox, null);
+        display_hbox.pack_start (display_toolbar, true, true, 0);
+        display_toolbar.show_all ();
 
         update_search_btn ();
         App.app.collection.item_added.connect (update_search_btn);
         App.app.collection.item_removed.connect (update_search_btn);
-
-        notebook.show_tabs = false;
-        notebook.show_all ();
     }
 
     private void update_search_btn () {
@@ -214,7 +119,7 @@ private class Boxes.Topbar: GLib.Object, Boxes.UI {
     private void ui_state_changed () {
         switch (ui_state) {
         case UIState.COLLECTION:
-            notebook.page = TopbarPage.COLLECTION;
+            page = TopbarPage.COLLECTION;
             back_btn.hide ();
             spinner.hide ();
             select_btn.show ();
@@ -223,7 +128,7 @@ private class Boxes.Topbar: GLib.Object, Boxes.UI {
             break;
 
         case UIState.CREDS:
-            notebook.page = TopbarPage.COLLECTION;
+            page = TopbarPage.COLLECTION;
             new_btn.hide ();
             back_btn.show ();
             spinner.show ();
@@ -232,20 +137,40 @@ private class Boxes.Topbar: GLib.Object, Boxes.UI {
             break;
 
         case UIState.DISPLAY:
-            notebook.page = TopbarPage.DISPLAY;
+            page = TopbarPage.DISPLAY;
             spinner.hide ();
             break;
 
         case UIState.PROPERTIES:
-            notebook.page = TopbarPage.PROPERTIES;
+            page = TopbarPage.PROPERTIES;
             break;
 
         case UIState.WIZARD:
-            notebook.page = TopbarPage.WIZARD;
+            page = TopbarPage.WIZARD;
             break;
 
         default:
             break;
         }
     }
+
+    [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;
+    }
 }
diff --git a/src/wizard.vala b/src/wizard.vala
index d31cf08..d43ac93 100644
--- a/src/wizard.vala
+++ b/src/wizard.vala
@@ -566,7 +566,7 @@ private class Boxes.Wizard: Gtk.Notebook, Boxes.UI {
         gtk_actor.y_expand = true;
 
         /* topbar */
-        var hbox = App.app.topbar.notebook.get_nth_page (Boxes.TopbarPage.WIZARD) as Gtk.Box;
+        var hbox = App.app.topbar.get_nth_page (Boxes.TopbarPage.WIZARD) as Gtk.Box;
 
         var toolbar = new Gtk.HeaderBar ();
         toolbar.get_style_context ().add_class (Gtk.STYLE_CLASS_MENUBAR);


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