[gnome-boxes] Add CollectionFilterSwitcher widget
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Add CollectionFilterSwitcher widget
- Date: Tue, 18 Aug 2015 16:15:09 +0000 (UTC)
commit bcede69a814281610eef06dee7479a47bd28afbb
Author: Adrien Plazas <kekun plazas laposte net>
Date: Thu Jul 2 10:20:21 2015 +0200
Add CollectionFilterSwitcher widget
Add CollectionFilterSwitcher class, a widget offering a box of linked
toggle buttons allowing user to switch different filtering functions on
a provided CollectionFilter.
This will be used in the next commit as header for the main window to
implement quick ready-made search toggles.
https://bugzilla.gnome.org/show_bug.cgi?id=751710
data/gnome-boxes.gresource.xml | 1 +
data/ui/collection-filter-switcher.ui | 49 +++++++++++++++++++++++++++
src/Makefile.am | 1 +
src/collection-filter-switcher.vala | 60 +++++++++++++++++++++++++++++++++
4 files changed, 111 insertions(+), 0 deletions(-)
---
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
index af12211..3db3ddd 100644
--- a/data/gnome-boxes.gresource.xml
+++ b/data/gnome-boxes.gresource.xml
@@ -7,6 +7,7 @@
<file>icons/empty-boxes.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-filter-switcher.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>
diff --git a/data/ui/collection-filter-switcher.ui b/data/ui/collection-filter-switcher.ui
new file mode 100644
index 0000000..5a8de58
--- /dev/null
+++ b/data/ui/collection-filter-switcher.ui
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="BoxesCollectionFilterSwitcher" parent="GtkButtonBox">
+ <property name="visible">True</property>
+ <property name="homogeneous">True</property>
+ <style>
+ <class name="linked"/>
+ </style>
+
+ <child>
+ <object class="GtkToggleButton" id="all_button">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">All</property>
+ <signal name="toggled" handler="activate_button"/>
+ </object>
+
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <object class="GtkToggleButton" id="local_button">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Local</property>
+ <signal name="toggled" handler="activate_button"/>
+ </object>
+
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <object class="GtkToggleButton" id="remote_button">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Remote</property>
+ <signal name="toggled" handler="activate_button"/>
+ </object>
+
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+ </template>
+</interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index e22575f..3796b9a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -103,6 +103,7 @@ gnome_boxes_SOURCES = \
auth-notification.vala \
collection-view.vala \
collection.vala \
+ collection-filter-switcher.vala \
collection-toolbar.vala \
display-page.vala \
display-toolbar.vala \
diff --git a/src/collection-filter-switcher.vala b/src/collection-filter-switcher.vala
new file mode 100644
index 0000000..46bf99c
--- /dev/null
+++ b/src/collection-filter-switcher.vala
@@ -0,0 +1,60 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+
+[GtkTemplate (ui = "/org/gnome/Boxes/ui/collection-filter-switcher.ui")]
+private class Boxes.CollectionFilterSwitcher: Gtk.ButtonBox {
+ [GtkChild]
+ private Gtk.ToggleButton all_button;
+ [GtkChild]
+ private Gtk.ToggleButton local_button;
+ [GtkChild]
+ private Gtk.ToggleButton remote_button;
+
+ private Gtk.ToggleButton active_button;
+ private CollectionFilter filter;
+
+ public void setup_ui (AppWindow window) {
+ filter = window.view.filter;
+ assert (filter != null);
+
+ all_button.active = true;
+ activate_button (all_button);
+
+ filter.filter_func = null;
+ }
+
+ private unowned CollectionFilterFunc? get_filter_func () {
+ if (active_button == all_button)
+ return null;
+ if (active_button == local_button)
+ return local_filter_func;
+ if (active_button == remote_button)
+ return remote_filter_func;
+ else
+ return null;
+ }
+
+ private bool local_filter_func (Boxes.CollectionItem item) {
+ return (item is Machine) && (item as Machine).is_local;
+ }
+
+ private bool remote_filter_func (Boxes.CollectionItem item) {
+ return (item is Machine) && !(item as Machine).is_local;
+ }
+
+ [GtkCallback]
+ private void activate_button (Gtk.ToggleButton button) {
+ if (button == active_button)
+ return;
+
+ if (button.active)
+ active_button = button;
+
+ foreach (var child in get_children ()) {
+ var toggle_button = child as Gtk.ToggleButton;
+ if (toggle_button != null)
+ toggle_button.active = toggle_button == active_button;
+ }
+
+ filter.filter_func = get_filter_func ();
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]