[gnome-games] collection-view: Add search support for collections-page
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] collection-view: Add search support for collections-page
- Date: Tue, 25 Aug 2020 11:11:56 +0000 (UTC)
commit 49b38e76544e9f61f216c25645a8a21a52756e0b
Author: Neville <nevilleantony98 gmail com>
Date: Sat Aug 22 16:01:42 2020 +0530
collection-view: Add search support for collections-page
Refactors some code to add search functionality for collections page.
The search is flexible and will adapt with respect to which page is
being currently viewed.
data/ui/collection-view.ui | 5 +--
src/ui/collection-view.vala | 76 ++++++++++++++++++++++++++++-----------------
2 files changed, 51 insertions(+), 30 deletions(-)
---
diff --git a/data/ui/collection-view.ui b/data/ui/collection-view.ui
index 25f81fae0..0ee775977 100644
--- a/data/ui/collection-view.ui
+++ b/data/ui/collection-view.ui
@@ -11,6 +11,7 @@
<signal name="notify::is-subview-open" handler="update_bottom_bar"/>
<signal name="notify::is-selection-mode" handler="on_selection_mode_changed"/>
<signal name="notify::is-empty-collection" handler="on_empty_collection_changed"/>
+ <signal name="notify::search-mode" handler="on_search_mode_changed"/>
<child>
<object class="GtkStack" id="header_bar_stack">
<property name="visible">True</property>
@@ -30,7 +31,7 @@
<property name="centering-policy">strict</property>
<child>
<object class="GtkButton" id="add_game">
- <property name="visible" bind-source="GamesCollectionView"
bind-property="is-search-available"/>
+ <property name="visible" bind-source="GamesCollectionView"
bind-property="is-add-available"/>
<property name="valign">center</property>
<property name="action-name">app.add-game-files</property>
<style>
@@ -108,7 +109,7 @@
</child>
<child>
<object class="GtkToggleButton" id="search">
- <property name="visible" bind-source="GamesCollectionView"
bind-property="is-search-available"/>
+ <property name="visible">True</property>
<property name="valign">center</property>
<property name="active" bind-source="GamesCollectionView"
bind-property="search-mode" bind-flags="bidirectional"/>
<property name="sensitive" bind-source="GamesCollectionView"
bind-property="is-empty-collection" bind-flags="bidirectional|invert-boolean"/>
diff --git a/src/ui/collection-view.vala b/src/ui/collection-view.vala
index 2cf063472..04fe71d8f 100644
--- a/src/ui/collection-view.vala
+++ b/src/ui/collection-view.vala
@@ -95,9 +95,7 @@ private class Games.CollectionView : Gtk.Box, UiView {
else
filtering_terms = value.split (" ");
- platforms_page.set_filter (filtering_terms);
- games_page.set_filter (filtering_terms);
- collections_page.set_filter (filtering_terms);
+ update_search_filters ();
}
}
@@ -138,6 +136,7 @@ private class Games.CollectionView : Gtk.Box, UiView {
public bool is_collection_rename_valid { get; set; }
public bool show_game_actions { get; set; }
public bool show_remove_action_button { get; set; }
+ public bool is_add_available { get; set; }
private CollectionManager collection_manager;
private KonamiCode konami_code;
@@ -176,7 +175,7 @@ private class Games.CollectionView : Gtk.Box, UiView {
action_group.add_action_entries (action_entries, this);
window.insert_action_group ("view", action_group);
- update_search_availablity ();
+ update_add_game_availablity ();
update_available_selection_actions ();
}
@@ -207,8 +206,6 @@ private class Games.CollectionView : Gtk.Box, UiView {
if ((keyval == Gdk.Key.f || keyval == Gdk.Key.F) &&
(event.state & default_modifiers) == Gdk.ModifierType.CONTROL_MASK &&
- (viewstack.visible_child != collections_page ||
- collections_page.is_subpage_open) &&
!collections_page.is_collection_empty &&
!is_empty_collection) {
if (!search_mode)
@@ -234,10 +231,8 @@ private class Games.CollectionView : Gtk.Box, UiView {
return true;
}
- if ((viewstack.visible_child == collections_page
- && !collections_page.is_subpage_open) ||
- is_empty_collection ||
- (collections_page.is_subpage_open && collections_page.is_collection_empty))
+ if (is_empty_collection || (collections_page.is_subpage_open &&
+ collections_page.is_collection_empty))
return false;
return search_bar.handle_event (event);
@@ -336,10 +331,6 @@ private class Games.CollectionView : Gtk.Box, UiView {
}
}
- public void update_search_availablity () {
- is_search_available = viewstack.visible_child != collections_page;
- }
-
public void run_search (string query) {
search_mode = true;
search_bar.run_search (query);
@@ -455,10 +446,24 @@ private class Games.CollectionView : Gtk.Box, UiView {
!collections_page.is_subpage_open;
}
+ private void update_add_game_availablity () {
+ is_add_available = viewstack.visible_child != collections_page;
+ }
+
+ private void update_search_filters () {
+ if (viewstack.visible_child == games_page)
+ games_page.set_filter (filtering_terms);
+ else if (viewstack.visible_child == platforms_page)
+ platforms_page.set_filter (filtering_terms);
+ else
+ collections_page.set_filter (filtering_terms);
+ }
+
[GtkCallback]
private void on_collection_subpage_opened () {
update_bottom_bar ();
update_available_selection_actions ();
+ search_mode = false;
}
[GtkCallback]
@@ -584,18 +589,39 @@ private class Games.CollectionView : Gtk.Box, UiView {
else
collections_page.reset_scroll_position ();
+ filtering_text = null;
+
+ if (search_mode) {
+ on_search_text_notify ();
+ }
+
update_selection_availability ();
- update_search_availablity ();
+ update_add_game_availablity ();
update_available_selection_actions ();
}
[GtkCallback]
private void on_search_text_notify () {
filtering_text = search_bar.text;
- if (found_games ())
- empty_stack.visible_child = viewstack;
- else
+
+ bool is_search_empty;
+ EmptySearch.SearchItem search_item;
+ if (viewstack.visible_child != collections_page) {
+ is_search_empty = games_page.is_search_empty || platforms_page.is_search_empty;
+ search_item = EmptySearch.SearchItem.GAME;
+ }
+ else {
+ is_search_empty = collections_page.is_search_empty;
+ search_item = collections_page.is_subpage_open ? EmptySearch.SearchItem.GAME:
+ EmptySearch.SearchItem.COLLECTION;
+ }
+
+ if (is_search_empty) {
empty_stack.visible_child = empty_search;
+ empty_search.search_item = search_item;
+ }
+ else
+ empty_stack.visible_child = viewstack;
// Changing the filtering_text for the PlatformsPage might
// cause the currently selected sidebar row to become empty and therefore
@@ -604,15 +630,10 @@ private class Games.CollectionView : Gtk.Box, UiView {
search_bar.focus_entry ();
}
- private bool found_games () {
- for (int i = 0; i < game_model.get_n_items (); i++) {
- var game = game_model.get_item (i) as Game;
-
- if (game.matches_search_terms (filtering_terms))
- return true;
- }
-
- return false;
+ [GtkCallback]
+ private void on_search_mode_changed () {
+ if (!search_mode)
+ empty_stack.visible_child = viewstack;
}
[GtkCallback]
@@ -627,7 +648,6 @@ private class Games.CollectionView : Gtk.Box, UiView {
update_bottom_bar ();
update_selection_availability ();
- update_search_availablity ();
}
[GtkCallback]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]