[gnome-games] games-page: Add is-search-empty property



commit ac60e1bd8607a58016f2421d0dac027842945dfd
Author: Neville <nevilleantony98 gmail com>
Date:   Sat Aug 22 19:48:31 2020 +0530

    games-page: Add is-search-empty property
    
    This can be useful to see if current search doesn't return any results.

 data/ui/platforms-page.ui  |  1 +
 src/ui/games-page.vala     | 21 +++++++++++++++++++++
 src/ui/platforms-page.vala |  1 +
 3 files changed, 23 insertions(+)
---
diff --git a/data/ui/platforms-page.ui b/data/ui/platforms-page.ui
index 7e4c9c802..7ad8216af 100644
--- a/data/ui/platforms-page.ui
+++ b/data/ui/platforms-page.ui
@@ -56,6 +56,7 @@
             <property name="visible">True</property>
             <property name="expand">True</property>
             <property name="is-selection-mode" bind-source="GamesPlatformsPage" 
bind-property="is-selection-mode"/>
+            <property name="is-search-empty" bind-source="GamesPlatformsPage" 
bind-property="is-search-empty" bind-flags="bidirectional"/>
             <signal name="game-activated" handler="on_game_activated"/>
           </object>
         </child>
diff --git a/src/ui/games-page.vala b/src/ui/games-page.vala
index a78ddf086..2df582268 100644
--- a/src/ui/games-page.vala
+++ b/src/ui/games-page.vala
@@ -61,6 +61,8 @@ private class Games.GamesPage : Gtk.Bin {
        [GtkChild]
        private GamepadBrowse gamepad_browse;
 
+       public bool is_search_empty { get; set; }
+
        static construct {
                set_css_name ("gamesgamespage");
        }
@@ -114,6 +116,7 @@ private class Games.GamesPage : Gtk.Bin {
        public void set_filter (string[] filtering_terms) {
                this.filtering_terms = filtering_terms;
                flow_box.invalidate_filter ();
+               update_is_search_empty ();
        }
 
        public void reset_scroll_position () {
@@ -255,6 +258,24 @@ private class Games.GamesPage : Gtk.Bin {
                return game.matches_search_terms (filtering_terms);
        }
 
+       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;
+       }
+
+       private void update_is_search_empty () {
+               if (filtering_terms == null || filtering_terms.length == 0)
+                       is_search_empty = false;
+
+               is_search_empty = !found_games ();
+       }
+
        [GtkCallback]
        private void on_size_allocate (Gtk.Allocation allocation) {
                // If the window's width is less than half the width of a 1920×1080
diff --git a/src/ui/platforms-page.vala b/src/ui/platforms-page.vala
index 3542e225c..fc445c892 100644
--- a/src/ui/platforms-page.vala
+++ b/src/ui/platforms-page.vala
@@ -50,6 +50,7 @@ private class Games.PlatformsPage : Gtk.Bin {
        public bool is_subview_open { get; set; }
        public string subview_title { get; set; }
        public bool is_selection_mode { get; set; }
+       public bool is_search_empty { get; set; }
 
        construct {
                games_page.set_game_filter (filter_game);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]