[gnome-games] Display "No results" page for search
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] Display "No results" page for search
- Date: Mon, 10 Feb 2020 18:19:09 +0000 (UTC)
commit 4bbccda90143f9927818c5efa877ea94636ec9e2
Author: Veerasamy Sevagen <sevagenv gmail com>
Date: Mon Feb 10 18:18:53 2020 +0000
Display "No results" page for search
data/org.gnome.Games.gresource.xml | 1 +
data/ui/collection-box.ui | 5 ++++
data/ui/empty-search.ui | 49 ++++++++++++++++++++++++++++++++++++++
src/meson.build | 1 +
src/ui/collection-box.vala | 37 +++++++++++++++++++++-------
src/ui/collection-icon-view.vala | 13 ++++------
src/ui/empty-search.vala | 5 ++++
src/ui/platforms-view.vala | 16 +++++--------
8 files changed, 101 insertions(+), 26 deletions(-)
---
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index 04ceb341..74e89ab6 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -18,6 +18,7 @@
<file preprocess="xml-stripblanks">ui/display-box.ui</file>
<file preprocess="xml-stripblanks">ui/display-header-bar.ui</file>
<file preprocess="xml-stripblanks">ui/empty-collection.ui</file>
+ <file preprocess="xml-stripblanks">ui/empty-search.ui</file>
<file preprocess="xml-stripblanks">ui/error-display.ui</file>
<file preprocess="xml-stripblanks">ui/error-info-bar.ui</file>
<file preprocess="xml-stripblanks">ui/fullscreen-box.ui</file>
diff --git a/data/ui/collection-box.ui b/data/ui/collection-box.ui
index e26ad5e9..9168a806 100644
--- a/data/ui/collection-box.ui
+++ b/data/ui/collection-box.ui
@@ -32,6 +32,11 @@
<style>
<class name="background"/>
</style>
+ <child>
+ <object class="GamesEmptySearch" id="empty_search">
+ <property name="visible">True</property>
+ </object>
+ </child>
<child>
<object class="GamesEmptyCollection" id="empty_collection">
<property name="visible">True</property>
diff --git a/data/ui/empty-search.ui b/data/ui/empty-search.ui
new file mode 100644
index 00000000..e366e293
--- /dev/null
+++ b/data/ui/empty-search.ui
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="3.24"/>
+ <template class="GamesEmptySearch" parent="GtkBox">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="pixel-size">128</property>
+ <property name="margin-bottom">6</property>
+ <property name="valign">center</property>
+ <property name="icon_name">edit-find-symbolic</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">No games found</property>
+ <property name="justify">center</property>
+ <property name="wrap">True</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ <attribute name="scale" value="2"/>
+ </attributes>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Try a different search.</property>
+ <property name="justify">left</property>
+ <property name="wrap">true</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/meson.build b/src/meson.build
index c751641c..f26016e6 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -109,6 +109,7 @@ vala_sources = [
'ui/display-header-bar.vala',
'ui/display-view.vala',
'ui/empty-collection.vala',
+ 'ui/empty-search.vala',
'ui/error-display.vala',
'ui/error-info-bar.vala',
'ui/flash-box.vala',
diff --git a/src/ui/collection-box.vala b/src/ui/collection-box.vala
index b35bd7dc..81f6181c 100644
--- a/src/ui/collection-box.vala
+++ b/src/ui/collection-box.vala
@@ -15,6 +15,8 @@ private class Games.CollectionBox : Gtk.Box {
[GtkChild]
private EmptyCollection empty_collection;
[GtkChild]
+ private EmptySearch empty_search;
+ [GtkChild]
private CollectionIconView collection_view;
[GtkChild]
private PlatformsView platform_view;
@@ -41,6 +43,19 @@ private class Games.CollectionBox : Gtk.Box {
}
}
+ public string[] filtering_terms;
+ public string filtering_text {
+ set {
+ if (value == null)
+ filtering_terms = null;
+ else
+ filtering_terms = value.split (" ");
+
+ platform_view.set_filter (filtering_terms);
+ collection_view.set_filter (filtering_terms);
+ }
+ }
+
public bool is_folded { get; set; }
public bool is_showing_bottom_bar { get; set; }
public bool is_subview_open { get; set; }
@@ -112,6 +127,15 @@ private class Games.CollectionBox : Gtk.Box {
return collection_view.gamepad_button_release_event (event);
}
+ public bool found_games () {
+ for (int i = 0; i < collection.get_n_items (); i++) {
+ var game = collection.get_item (i) as Game;
+ if (game.matches_search_terms (filtering_terms))
+ return true;
+ }
+ return false;
+ }
+
public bool gamepad_absolute_axis_event (Manette.Event event) {
if (!get_mapped ())
return false;
@@ -134,22 +158,19 @@ private class Games.CollectionBox : Gtk.Box {
[GtkCallback]
private void on_visible_child_changed () {
- if (viewstack.visible_child == platform_view)
- platform_view.filtering_text = search_bar.text;
- else {
- collection_view.filtering_text = search_bar.text;
+ if (viewstack.visible_child == collection_view)
collection_view.reset_scroll_position ();
- }
is_subview_open = false;
}
[GtkCallback]
private void on_search_text_notify () {
- if (viewstack.visible_child == platform_view)
- platform_view.filtering_text = search_bar.text;
+ filtering_text = search_bar.text;
+ if (found_games ())
+ empty_stack.visible_child = viewstack;
else
- collection_view.filtering_text = search_bar.text;
+ empty_stack.visible_child = empty_search;
// Changing the filtering_text for the PlatformView might
// cause the currently selected sidebar row to become empty and therefore
diff --git a/src/ui/collection-icon-view.vala b/src/ui/collection-icon-view.vala
index ec736c62..7f4248e6 100644
--- a/src/ui/collection-icon-view.vala
+++ b/src/ui/collection-icon-view.vala
@@ -5,14 +5,6 @@ private class Games.CollectionIconView : Gtk.Bin {
public signal void game_activated (Game game);
private string[] filtering_terms;
- public string filtering_text {
- set {
- if (value != null)
- filtering_terms = value.split (" ");
-
- flow_box.invalidate_filter ();
- }
- }
public delegate bool GameFilter (Game game);
private unowned GameFilter? game_filter;
@@ -115,6 +107,11 @@ private class Games.CollectionIconView : Gtk.Bin {
return gamepad_browse.gamepad_absolute_axis_event (event);
}
+ public void set_filter (string[] filtering_terms) {
+ this.filtering_terms = filtering_terms;
+ flow_box.invalidate_filter ();
+ }
+
public void reset_scroll_position () {
var adjustment = scrolled_window.get_vadjustment ();
adjustment.value = 0;
diff --git a/src/ui/empty-search.vala b/src/ui/empty-search.vala
new file mode 100644
index 00000000..2464e7ef
--- /dev/null
+++ b/src/ui/empty-search.vala
@@ -0,0 +1,5 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/empty-search.ui")]
+private class Games.EmptySearch : Gtk.Box {
+}
diff --git a/src/ui/platforms-view.vala b/src/ui/platforms-view.vala
index 409b579c..db774942 100644
--- a/src/ui/platforms-view.vala
+++ b/src/ui/platforms-view.vala
@@ -22,16 +22,6 @@ private class Games.PlatformsView : Gtk.Bin {
private bool has_used_gamepad;
private string[] filtering_terms;
- public string filtering_text {
- set {
- collection_view.filtering_text = value;
-
- if (value != null)
- filtering_terms = value.split (" ");
-
- hide_empty_sidebar_items ();
- }
- }
private ListModel _model;
public ListModel model {
@@ -110,6 +100,12 @@ private class Games.PlatformsView : Gtk.Bin {
is_active = false;
}
+ public void set_filter (string[] filtering_terms) {
+ this.filtering_terms = filtering_terms;
+ collection_view.set_filter (filtering_terms);
+ hide_empty_sidebar_items ();
+ }
+
public bool gamepad_button_press_event (Manette.Event event) {
if (!get_mapped ())
return false;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]