[gnome-boxes/wip/ui-files: 14/26] Move Selectionbar UI setup to .ui file
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/wip/ui-files: 14/26] Move Selectionbar UI setup to .ui file
- Date: Sun, 2 Feb 2014 10:13:19 +0000 (UTC)
commit 2ae5f9d2765c3a9365cc4d9dfba281416509093f
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Thu Jan 30 20:35:48 2014 +0000
Move Selectionbar UI setup to .ui file
data/gnome-boxes.gresource.xml | 1 +
data/ui/selectionbar.ui | 96 ++++++++++++++++++++++++++++++++
src/selectionbar.vala | 120 +++++++++++++++++----------------------
3 files changed, 149 insertions(+), 68 deletions(-)
---
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
index 0c77de1..8ba393a 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/selectionbar.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/selectionbar.ui b/data/ui/selectionbar.ui
new file mode 100644
index 0000000..047a41b
--- /dev/null
+++ b/data/ui/selectionbar.ui
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.9 -->
+ <template class="BoxesSelectionbar" parent="GtkRevealer">
+ <property name="visible">True</property>
+ <property name="transition-type">slide-up</property>
+
+ <child>
+ <object class="GtkHeaderBar" id="headerbar">
+ <property name="visible">True</property>
+ <style>
+ <class name="titlebar"/>
+ </style>
+
+ <!-- Favorite button -->
+ <child>
+ <object class="GtkToggleButton" id="favorite_btn">
+ <property name="visible">True</property>
+ <property name="valign">center</property>
+ <signal name="clicked" handler="on_favorite_btn_clicked"/>
+ <style>
+ <class name="image-button"/>
+ </style>
+
+ <child>
+ <object class="GtkImage" id="favorite_image">
+ <property name="visible">True</property>
+ <property name="icon-name">emblem-favorite-symbolic</property>
+ <property name="icon-size">1</property>
+ </object>
+ </child>
+ </object>
+
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
+
+ <!-- Pause button -->
+ <child>
+ <object class="GtkButton" id="pause_btn">
+ <property name="visible">True</property>
+ <property name="valign">center</property>
+ <property name="use-underline">True</property>
+ <property name="label" translatable="yes">P_ause</property>
+ <signal name="clicked" handler="on_pause_btn_clicked"/>
+ <style>
+ <class name="text-button"/>
+ </style>
+ </object>
+
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
+
+ <!-- Remove button -->
+ <child>
+ <object class="GtkButton" id="remove_btn">
+ <property name="visible">True</property>
+ <property name="valign">center</property>
+ <property name="use-underline">True</property>
+ <property name="label" translatable="yes">_Delete</property>
+ <signal name="clicked" handler="on_remove_btn_clicked"/>
+ <style>
+ <class name="text-button"/>
+ </style>
+ </object>
+
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
+
+ <!-- Properties button -->
+ <child>
+ <object class="GtkButton" id="properties_btn">
+ <property name="visible">True</property>
+ <property name="valign">center</property>
+ <property name="use-underline">True</property>
+ <property name="label" translatable="yes">_Properties</property>
+ <signal name="clicked" handler="on_properties_btn_clicked"/>
+ <style>
+ <class name="text-button"/>
+ </style>
+ </object>
+
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
+
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/selectionbar.vala b/src/selectionbar.vala
index 766753f..0fa045e 100644
--- a/src/selectionbar.vala
+++ b/src/selectionbar.vala
@@ -2,77 +2,18 @@
using Clutter;
using Gtk;
+[GtkTemplate (ui = "/org/gnome/Boxes/ui/selectionbar.ui")]
private class Boxes.Selectionbar: Gtk.Revealer {
- private Gtk.HeaderBar headerbar;
+ [GtkChild]
private Gtk.ToggleButton favorite_btn;
+ [GtkChild]
private Gtk.Button pause_btn;
+ [GtkChild]
private Gtk.Button remove_btn;
+ [GtkChild]
private Gtk.Button properties_btn;
- private ulong favorite_btn_clicked_handler;
public Selectionbar () {
- transition_type = Gtk.RevealerTransitionType.SLIDE_UP;
-
- headerbar = new Gtk.HeaderBar ();
- headerbar.get_style_context ().add_class ("titlebar");
- add (headerbar);
-
- favorite_btn = new Gtk.ToggleButton ();
- headerbar.pack_start (favorite_btn);
- favorite_btn.image = new Gtk.Image.from_icon_name ("emblem-favorite-symbolic", Gtk.IconSize.MENU);
- favorite_btn.valign = Gtk.Align.CENTER;
- favorite_btn.get_style_context ().add_class ("image-button");
- favorite_btn_clicked_handler = favorite_btn.clicked.connect (() => {
- foreach (var item in App.app.selected_items) {
- var machine = item as Machine;
- if (machine == null)
- continue;
- machine.config.set_category ("favorite", favorite_btn.active);
- }
-
- App.app.selection_mode = false;
- });
-
- pause_btn = new Gtk.Button.with_mnemonic (_("P_ause"));
- pause_btn.valign = Gtk.Align.CENTER;
- headerbar.pack_start (pause_btn);
- pause_btn.get_style_context ().add_class ("text-button");
- pause_btn.clicked.connect (() => {
- foreach (var item in App.app.selected_items) {
- var machine = item as Machine;
- if (machine == null)
- continue;
- machine.save.begin ( (obj, result) => {
- try {
- machine.save.end (result);
- } catch (GLib.Error e) {
- App.app.notificationbar.display_error (_("Pausing '%s' failed").printf
(machine.name));
- }
- });
- }
-
- pause_btn.sensitive = false;
- App.app.selection_mode = false;
- });
-
- remove_btn = new Gtk.Button.with_mnemonic (_("_Delete"));
- remove_btn.valign = Gtk.Align.CENTER;
- headerbar.pack_start (remove_btn);
- remove_btn.get_style_context ().add_class ("text-button");
- remove_btn.clicked.connect (() => {
- App.app.remove_selected_items ();
- });
-
- properties_btn = new Gtk.Button.with_mnemonic (_("_Properties"));
- properties_btn.valign = Gtk.Align.CENTER;
- headerbar.pack_end (properties_btn);
- properties_btn.get_style_context ().add_class ("text-button");
- properties_btn.clicked.connect (() => {
- App.app.show_properties ();
- });
-
- show_all ();
-
App.app.notify["selection-mode"].connect (() => {
reveal_child = App.app.selection_mode;
});
@@ -85,6 +26,51 @@ private class Boxes.Selectionbar: Gtk.Revealer {
});
}
+ private bool ignore_favorite_btn_clicks;
+ [GtkCallback]
+ private void on_favorite_btn_clicked () {
+ if (ignore_favorite_btn_clicks)
+ return;
+
+ foreach (var item in App.app.selected_items) {
+ var machine = item as Machine;
+ if (machine == null)
+ continue;
+ machine.config.set_category ("favorite", favorite_btn.active);
+ }
+
+ App.app.selection_mode = false;
+ }
+
+ [GtkCallback]
+ private void on_pause_btn_clicked () {
+ foreach (var item in App.app.selected_items) {
+ var machine = item as Machine;
+ if (machine == null)
+ continue;
+ machine.save.begin ( (obj, result) => {
+ try {
+ machine.save.end (result);
+ } catch (GLib.Error e) {
+ App.app.notificationbar.display_error (_("Pausing '%s' failed").printf (machine.name));
+ }
+ });
+ }
+
+ pause_btn.sensitive = false;
+ App.app.selection_mode = false;
+ }
+
+ [GtkCallback]
+ private void on_remove_btn_clicked () {
+ App.app.remove_selected_items ();
+ }
+
+ [GtkCallback]
+ private void on_properties_btn_clicked () {
+ App.app.show_properties ();
+ }
+
private void update_favorite_btn () {
var active = false;
var sensitive = App.app.selected_items.length () > 0;
@@ -103,12 +89,10 @@ private class Boxes.Selectionbar: Gtk.Revealer {
}
}
- // Block the handler so that the selected items won't get added to the
- // "favorite" category while changing the status of the button.
- SignalHandler.block (favorite_btn, favorite_btn_clicked_handler);
+ ignore_favorite_btn_clicks = true;
favorite_btn.active = active;
favorite_btn.sensitive = sensitive;
- SignalHandler.unblock (favorite_btn, favorite_btn_clicked_handler);
+ ignore_favorite_btn_clicks = false;
}
private void update_properties_btn () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]