[gnome-games] collections-page: Add search support for collections
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] collections-page: Add search support for collections
- Date: Tue, 25 Aug 2020 11:11:56 +0000 (UTC)
commit 241c1491e22c452e8f0ebdb1085f9190a0a74fa3
Author: Neville <nevilleantony98 gmail com>
Date: Sat Aug 22 15:57:43 2020 +0530
collections-page: Add search support for collections
data/ui/collections-main-page.ui | 1 +
data/ui/collections-page.ui | 2 ++
src/ui/collections-main-page.vala | 67 +++++++++++++++++++++++++++++++++++++--
src/ui/collections-page.vala | 3 ++
4 files changed, 70 insertions(+), 3 deletions(-)
---
diff --git a/data/ui/collections-main-page.ui b/data/ui/collections-main-page.ui
index 205f3e2f6..5b6383314 100644
--- a/data/ui/collections-main-page.ui
+++ b/data/ui/collections-main-page.ui
@@ -6,6 +6,7 @@
<signal name="map" after="yes" handler="on_map"/>
<signal name="unmap" after="no" handler="on_unmap"/>
<signal name="size-allocate" after="no" handler="on_size_allocate"/>
+ <signal name="notify::is-search-mode" handler="on_search_mode_changed"/>
<child>
<object class="GtkScrolledWindow" id="scrolled_window">
<property name="visible">True</property>
diff --git a/data/ui/collections-page.ui b/data/ui/collections-page.ui
index 1fdbd6d0c..4ae37f239 100644
--- a/data/ui/collections-page.ui
+++ b/data/ui/collections-page.ui
@@ -15,6 +15,8 @@
<object class="GamesCollectionsMainPage" id="collections_main_page">
<property name="visible">True</property>
<property name="is-selection-mode" bind-source="GamesCollectionsPage"
bind-property="is-selection-mode"/>
+ <property name="is-search-mode" bind-source="GamesCollectionsPage"
bind-property="is-search-mode"/>
+ <property name="is-search-empty" bind-source="GamesCollectionsPage"
bind-property="is-search-empty" bind-flags="bidirectional"/>
<signal name="collection-activated" handler="on_collection_activated"/>
</object>
</child>
diff --git a/src/ui/collections-main-page.vala b/src/ui/collections-main-page.vala
index 29bbd4820..0bffe68d8 100644
--- a/src/ui/collections-main-page.vala
+++ b/src/ui/collections-main-page.vala
@@ -13,6 +13,7 @@ private class Games.CollectionsMainPage : Gtk.Bin {
[GtkChild]
private Gtk.ScrolledWindow scrolled_window;
+ private string[] filtering_terms;
private Binding window_active_binding;
private GenericSet<CollectionIconView> selected_collections;
@@ -41,6 +42,8 @@ private class Games.CollectionsMainPage : Gtk.Bin {
}
public bool is_selection_mode { get; set; }
+ public bool is_search_mode { get; set; }
+ public bool is_search_empty { get; set; }
static construct {
set_css_name ("gamescollectionsmainpage");
@@ -107,7 +110,11 @@ private class Games.CollectionsMainPage : Gtk.Bin {
public void select_all () {
foreach (var child in flow_box.get_children ()) {
var collection_icon_view = child as CollectionIconView;
- collection_icon_view.checked = collection_icon_view.collection is UserCollection;
+ if (is_search_mode)
+ collection_icon_view.checked = filtering_terms == null ||
+ filter_collection
(collection_icon_view.collection);
+ else
+ collection_icon_view.checked = collection_icon_view.collection is
UserCollection;
}
selected_items_changed ();
@@ -155,13 +162,67 @@ private class Games.CollectionsMainPage : Gtk.Bin {
collection_model.invalidate_sort ();
}
+ public void set_filter (string[] filtering_terms) {
+ this.filtering_terms = filtering_terms;
+ invalidate_filter ();
+ update_search_empty ();
+ }
+
+ private void update_search_empty () {
+ if (!is_search_mode || filtering_terms == null) {
+ is_search_empty = false;
+ return;
+ }
+
+ for (var i = 0; i < collection_model.get_n_items (); i++) {
+ var collection = collection_model.get_item (i) as Collection;
+ var type = collection.get_collection_type ();
+
+ if (type == Collection.CollectionType.PLACEHOLDER ||
+ (type == Collection.CollectionType.AUTO && collection.is_empty))
+ continue;
+
+ if (collection.matches_search_terms (filtering_terms)) {
+ is_search_empty = false;
+ return;
+ }
+ }
+
+ is_search_empty = true;
+ }
+
+ private bool filter_collection (Collection collection) {
+ return collection.matches_search_terms (filtering_terms);
+ }
+
private bool collection_filter_func (Gtk.FlowBoxChild child) {
var collection_icon_view = child as CollectionIconView;
if (collection_icon_view == null)
return false;
- return collection_icon_view.collection.get_collection_type () != AUTO ||
- !collection_icon_view.collection.is_empty;
+ var collection = collection_icon_view.collection;
+ var type = collection.get_collection_type ();
+
+ if (is_search_mode && filtering_terms.length != 0) {
+ switch (type) {
+ case Collection.CollectionType.AUTO:
+ return !collection.is_empty && filter_collection (collection);
+
+ case Collection.CollectionType.USER:
+ return filter_collection (collection);
+
+ case Collection.CollectionType.PLACEHOLDER:
+ return false;
+ }
+ }
+
+ return !collection_icon_view.collection.is_empty || type != Collection.CollectionType.AUTO;
+ }
+
+ [GtkCallback]
+ private void on_search_mode_changed () {
+ update_search_empty ();
+ invalidate_filter ();
}
[GtkCallback]
diff --git a/src/ui/collections-page.vala b/src/ui/collections-page.vala
index 202c389d0..7b3f86fe9 100644
--- a/src/ui/collections-page.vala
+++ b/src/ui/collections-page.vala
@@ -56,6 +56,7 @@ private class Games.CollectionsPage : Gtk.Bin {
public bool is_subpage_open { get; set; }
public bool is_selection_mode { get; set; }
public bool is_showing_user_collection { get; set; }
+ public bool is_search_empty { get; set; }
public bool can_swipe_back { get; set; }
public string collection_title { get; set; }
public string removed_notification_title { get; set; }
@@ -126,6 +127,8 @@ private class Games.CollectionsPage : Gtk.Bin {
public void set_filter (string[] filtering_terms) {
if (is_subpage_open)
collections_subpage.set_filter (filtering_terms);
+ else
+ collections_main_page.set_filter (filtering_terms);
}
public Hdy.Deck get_collections_deck () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]