[gnome-games/wip/exalm/views: 7/14] application-window: Handle search in CollectionView



commit 9641645028c687ca05c1e3c5c0c4ed14a06904b2
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Thu Oct 4 19:40:00 2018 +0500

    application-window: Handle search in CollectionView

 src/ui/application-window.vala | 36 ++++--------------------------------
 src/ui/collection-view.vala    | 26 +++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 33 deletions(-)
---
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index b075d507..59b30dbd 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -39,8 +39,6 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                                collection_view.is_view_active = false;
                                display_view.is_view_active = true;
 
-                               search_mode = false;
-
                                break;
                        }
 
@@ -61,12 +59,6 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                }
        }
 
-       private bool _search_mode;
-       public bool search_mode {
-               get { return _search_mode; }
-               set { _search_mode = value && (ui_state == UiState.COLLECTION); }
-       }
-
        public bool loading_notification { get; set; }
 
        [GtkChild]
@@ -81,9 +73,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
        private Settings settings;
 
-       private Binding box_search_binding;
        private Binding box_fullscreen_binding;
-       private Binding header_bar_search_binding;
        private Binding header_bar_fullscreen_binding;
        private Binding loading_notification_binding;
 
@@ -126,12 +116,8 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                if (settings.get_boolean ("window-maximized"))
                        maximize ();
 
-               box_search_binding = bind_property ("search-mode", collection_view.collection_box, 
"search-mode",
-                                                   BindingFlags.BIDIRECTIONAL);
                loading_notification_binding = bind_property ("loading-notification", 
collection_view.collection_box, "loading-notification",
                                                              BindingFlags.DEFAULT);
-               header_bar_search_binding = bind_property ("search-mode", 
collection_view.collection_header_bar, "search-mode",
-                                                          BindingFlags.BIDIRECTIONAL);
 
                box_fullscreen_binding = bind_property ("is-fullscreen", display_view.display_box, 
"is-fullscreen",
                                                        BindingFlags.BIDIRECTIONAL);
@@ -222,7 +208,10 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                        return true;
                }
 
-               return handle_collection_key_event (event) || handle_display_key_event (event);
+               if (ui_state == UiState.COLLECTION)
+                       return collection_view.on_key_pressed (event);
+
+               return handle_display_key_event (event);
        }
 
        [GtkCallback]
@@ -589,23 +578,6 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                return true;
        }
 
-       private bool handle_collection_key_event (Gdk.EventKey event) {
-               if (ui_state != UiState.COLLECTION)
-                       return false;
-
-               var default_modifiers = Gtk.accelerator_get_default_mod_mask ();
-
-               if ((event.keyval == Gdk.Key.f || event.keyval == Gdk.Key.F) &&
-                   (event.state & default_modifiers) == Gdk.ModifierType.CONTROL_MASK) {
-                       if (!search_mode)
-                               search_mode = true;
-
-                       return true;
-               }
-
-               return collection_view.collection_box.search_bar_handle_event (event);
-       }
-
        private bool handle_display_key_event (Gdk.EventKey event) {
                if (ui_state != UiState.DISPLAY)
                        return false;
diff --git a/src/ui/collection-view.vala b/src/ui/collection-view.vala
index 695fb369..cc0b3590 100644
--- a/src/ui/collection-view.vala
+++ b/src/ui/collection-view.vala
@@ -22,6 +22,9 @@ private class Games.CollectionView: Gtk.Bin, ApplicationView {
                                return;
 
                        _is_view_active = value;
+
+                       if (!is_view_active)
+                               search_mode = false;
                }
        }
 
@@ -41,15 +44,26 @@ private class Games.CollectionView: Gtk.Bin, ApplicationView {
                }
        }
 
+       public bool search_mode { get; set; }
        public bool is_collection_empty { get; set; }
 
+       private Binding box_search_binding;
        private Binding box_empty_collection_binding;
+       private Binding header_bar_search_binding;
        private Binding header_bar_empty_collection_binding;
 
        construct {
                collection_header_bar.viewstack = collection_box.viewstack;
                is_collection_empty = true;
 
+               box_search_binding = bind_property ("search-mode", collection_box,
+                                                   "search-mode",
+                                                   BindingFlags.BIDIRECTIONAL);
+               header_bar_search_binding = bind_property ("search-mode",
+                                                          collection_header_bar,
+                                                          "search-mode",
+                                                          BindingFlags.BIDIRECTIONAL);
+
                box_empty_collection_binding = bind_property ("is-collection-empty",
                                                              collection_box,
                                                              "is-collection-empty",
@@ -69,7 +83,17 @@ private class Games.CollectionView: Gtk.Bin, ApplicationView {
        }
 
        public bool on_key_pressed (Gdk.EventKey event) {
-               return false;
+               var default_modifiers = Gtk.accelerator_get_default_mod_mask ();
+
+               if ((event.keyval == Gdk.Key.f || event.keyval == Gdk.Key.F) &&
+                   (event.state & default_modifiers) == Gdk.ModifierType.CONTROL_MASK) {
+                       if (!search_mode)
+                               search_mode = true;
+
+                       return true;
+               }
+
+               return collection_box.search_bar_handle_event (event);
        }
 
        public bool gamepad_button_press_event (Manette.Event event) {


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