[gnome-boxes] topbar: Split out selection toolbar



commit f870802f18353580a4e8c287c74f8e4ac4fb6758
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Fri Jun 6 10:11:01 2014 +0200

    topbar: Split out selection toolbar
    
    Put selection 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/selection-toolbar.ui   |  122 +++++++++++++++++++++++++++++++++++++
 data/ui/topbar.ui              |  132 +---------------------------------------
 src/Makefile.am                |    1 +
 src/selection-toolbar.vala     |   49 +++++++++++++++
 src/topbar.vala                |   37 +----------
 6 files changed, 177 insertions(+), 165 deletions(-)
---
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
index 17f975d..e29afe7 100644
--- a/data/gnome-boxes.gresource.xml
+++ b/data/gnome-boxes.gresource.xml
@@ -18,6 +18,7 @@
     <file preprocess="xml-stripblanks">ui/properties-toolbar.ui</file>
     <file preprocess="xml-stripblanks">ui/searchbar.ui</file>
     <file preprocess="xml-stripblanks">ui/selectionbar.ui</file>
+    <file preprocess="xml-stripblanks">ui/selection-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>
diff --git a/data/ui/selection-toolbar.ui b/data/ui/selection-toolbar.ui
new file mode 100644
index 0000000..dfe2472
--- /dev/null
+++ b/data/ui/selection-toolbar.ui
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.9 -->
+  <template class="BoxesSelectionToolbar" parent="GtkHeaderBar">
+    <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="menu_button">
+        <property name="visible">True</property>
+        <property name="valign">center</property>
+        <property name="menu-model">selection-menu</property>
+
+        <child>
+          <object class="GtkGrid" id="selection_menu_button_grid">
+            <property name="visible">True</property>
+            <property name="column-spacing">6</property>
+
+            <child>
+              <object class="GtkLabel" id="menu_button_label">
+                <property name="visible">True</property>
+              </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="GtkArrow" id="selection_menu_button_arrow">
+                <property name="visible">True</property>
+                <property name="arrow-type">down</property>
+                <property name="shadow-type">none</property>
+              </object>
+
+              <packing>
+                <property name="left-attach">1</property>
+                <property name="top-attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+        </child>
+
+        <style>
+          <class name="selection-menu"/>
+        </style>
+      </object>
+    </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>
+
+    <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-button4">
+            <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>
+
+  <menu id="selection-menu">
+    <section>
+      <item>
+        <attribute name="action">app.select-all</attribute>
+        <attribute name="label" translatable="yes">Select All</attribute>
+        <attribute name="accel">&lt;Primary&gt;a</attribute>
+      </item>
+      <item>
+        <attribute name="action">app.select-running</attribute>
+        <attribute name="label" translatable="yes">Select Running</attribute>
+      </item>
+      <item>
+        <attribute name="action">app.select-none</attribute>
+        <attribute name="label" translatable="yes">Select None</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
diff --git a/data/ui/topbar.ui b/data/ui/topbar.ui
index 3ad0d44..5770a9e 100644
--- a/data/ui/topbar.ui
+++ b/data/ui/topbar.ui
@@ -20,119 +20,7 @@
 
     <!-- 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>
-
-                <child>
-                  <object class="GtkGrid" id="selection_menu_button_grid">
-                    <property name="visible">True</property>
-                    <property name="column-spacing">6</property>
-
-                    <child>
-                      <object class="GtkLabel" id="selection_menu_button_label">
-                        <property name="visible">True</property>
-                      </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="GtkArrow" id="selection_menu_button_arrow">
-                        <property name="visible">True</property>
-                        <property name="arrow-type">down</property>
-                        <property name="shadow-type">none</property>
-                      </object>
-
-                      <packing>
-                        <property name="left-attach">1</property>
-                        <property name="top-attach">0</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
-                      </packing>
-                    </child>
-                  </object>
-                </child>
-
-                <style>
-                  <class name="selection-menu"/>
-                </style>
-              </object>
-            </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>
-
-            <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>
-          </object>
-
-          <packing>
-            <property name="expand">True</property>
-            <property name="fill">True</property>
-            <property name="padding">0</property>
-          </packing>
-        </child>
+      <object class="BoxesSelectionToolbar" id="selection_toolbar">
       </object>
 
       <packing>
@@ -272,22 +160,4 @@
     </widgets>
   </object>
 
-  <menu id="selection-menu">
-    <section>
-      <item>
-        <attribute name="action">app.select-all</attribute>
-        <attribute name="label" translatable="yes">Select All</attribute>
-        <attribute name="accel">&lt;Primary&gt;a</attribute>
-      </item>
-      <item>
-        <attribute name="action">app.select-running</attribute>
-        <attribute name="label" translatable="yes">Select Running</attribute>
-      </item>
-      <item>
-        <attribute name="action">app.select-none</attribute>
-        <attribute name="label" translatable="yes">Select None</attribute>
-      </item>
-    </section>
-  </menu>
-
 </interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index 34dc1f7..f27a527 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -122,6 +122,7 @@ gnome_boxes_SOURCES =                               \
        remote-machine.vala                     \
        searchbar.vala                          \
        selectionbar.vala                       \
+       selection-toolbar.vala                  \
        sidebar.vala                            \
        spice-display.vala                      \
        topbar.vala                             \
diff --git a/src/selection-toolbar.vala b/src/selection-toolbar.vala
new file mode 100644
index 0000000..997861f
--- /dev/null
+++ b/src/selection-toolbar.vala
@@ -0,0 +1,49 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+using Gtk;
+
+[GtkTemplate (ui = "/org/gnome/Boxes/ui/selection-toolbar.ui")]
+private class Boxes.SelectionToolbar: HeaderBar {
+    [GtkChild]
+    private Button search_btn;
+    [GtkChild]
+    private Label menu_button_label;
+
+    [GtkCallback]
+    private void on_cancel_btn_clicked () {
+        App.app.selection_mode = false;
+    }
+
+    construct {
+        App.app.notify["selected-items"].connect (() => {
+            update_selection_label ();
+        });
+    }
+
+    public void setup_ui () {
+        assert (App.window != null);
+        assert (App.window.searchbar != null);
+
+        update_selection_label ();
+
+        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);
+    }
+
+    private void update_selection_label () {
+        var items = App.app.selected_items.length ();
+        if (items > 0) {
+            // This goes with the "Click on items to select them" string and is about selection of items 
(boxes)
+            // when the main collection view is in selection mode.
+            menu_button_label.label = ngettext ("%d selected", "%d selected", items).printf (items);
+        } else {
+            menu_button_label.label = _("(Click on items to select them)");
+        }
+    }
+
+    private void update_search_btn () {
+        search_btn.sensitive = App.app.collection.items.length != 0;
+    }
+}
diff --git a/src/topbar.vala b/src/topbar.vala
index a6d5356..26d14c2 100644
--- a/src/topbar.vala
+++ b/src/topbar.vala
@@ -26,12 +26,10 @@ private class Boxes.Topbar: Gtk.Stack, Boxes.UI {
     public Gtk.Button wizard_create_btn;
 
     [GtkChild]
-    private Gtk.Button search2_btn;
-    [GtkChild]
-    private Gtk.Label selection_menu_button_label;
-    [GtkChild]
     private CollectionToolbar collection_toolbar;
     [GtkChild]
+    private SelectionToolbar selection_toolbar;
+    [GtkChild]
     private DisplayToolbar display_toolbar;
 
     [GtkChild]
@@ -103,47 +101,23 @@ private class Boxes.Topbar: Gtk.Stack, Boxes.UI {
     construct {
         notify["ui-state"].connect (ui_state_changed);
 
-        App.app.notify["selected-items"].connect (() => {
-            update_selection_label ();
-        });
         transition_type = Gtk.StackTransitionType.CROSSFADE; // FIXME: Why this won't work from .ui file?
     }
 
     public void setup_ui () {
         assert (App.window != null);
-        assert (App.window.searchbar != null);
-        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_selection_label ();
 
         var toolbar = App.window.display_page.toolbar;
         toolbar.bind_property ("title", display_toolbar, "title", BindingFlags.SYNC_CREATE);
         toolbar.bind_property ("subtitle", display_toolbar, "subtitle", BindingFlags.SYNC_CREATE);
 
-        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 () {
-        search2_btn.sensitive = App.app.collection.items.length != 0;
-    }
-
-    private void update_selection_label () {
-        var items = App.app.selected_items.length ();
-        if (items > 0) {
-            // This goes with the "Click on items to select them" string and is about selection of items 
(boxes)
-            // when the main collection view is in selection mode.
-            selection_menu_button_label.label = ngettext ("%d selected", "%d selected", items).printf 
(items);
-        } else {
-            selection_menu_button_label.label = _("(Click on items to select them)");
-        }
+        selection_toolbar.setup_ui ();
     }
 
     private void ui_state_changed () {
@@ -175,9 +149,4 @@ private class Boxes.Topbar: Gtk.Stack, Boxes.UI {
             break;
         }
     }
-
-    [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]