[gnome-games/wip/exalm/search-provider: 883/886] application: Add --search command line option



commit 533112f1ab9cde47a03331ef61afeeebacf5c55c
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Wed Feb 12 14:01:40 2020 +0500

    application: Add --search command line option
    
    This will allow search provider to launch search in the app window.

 src/ui/application-window.vala |  7 +++++++
 src/ui/application.vala        | 13 ++++++++++++-
 src/ui/collection-box.vala     |  4 ++++
 src/ui/collection-view.vala    |  5 +++++
 src/ui/search-bar.vala         |  4 ++++
 5 files changed, 32 insertions(+), 1 deletion(-)
---
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index d7689441..e2d2a985 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -104,6 +104,13 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                set_help_overlay (new ShortcutsWindow ());
        }
 
+       public void run_search (string query) {
+               if (current_view != collection_view)
+                       return;
+
+               collection_view.run_search (query);
+       }
+
        public void show_error (string error_message) {
                collection_view.show_error (error_message);
        }
diff --git a/src/ui/application.vala b/src/ui/application.vala
index 2c54c6f5..56555f1c 100644
--- a/src/ui/application.vala
+++ b/src/ui/application.vala
@@ -26,7 +26,8 @@ public class Games.Application : Gtk.Application {
        };
 
        private const OptionEntry[] option_entries = {
-               { "", 0, 0, OptionArg.FILENAME_ARRAY },
+               { "search", 0, 0, OptionArg.STRING_ARRAY,   null, N_("Search term") },
+               { "",       0, 0, OptionArg.FILENAME_ARRAY },
                { null },
        };
 
@@ -223,6 +224,16 @@ public class Games.Application : Gtk.Application {
 
                activate ();
 
+               if ("search" in options) {
+                       var terms_variant = options.lookup_value ("search", VariantType.STRING_ARRAY);
+                       if (terms_variant != null) {
+                               var terms = terms_variant.get_strv ();
+                               window.run_search (string.joinv (" ", terms));
+                       }
+
+                       return 0;
+               }
+
                var files_variant = options.lookup_value ("", VariantType.BYTESTRING_ARRAY);
                if (files_variant != null) {
                        var filenames = files_variant.get_bytestring_array ();
diff --git a/src/ui/collection-box.vala b/src/ui/collection-box.vala
index 49c0299b..ecc23789 100644
--- a/src/ui/collection-box.vala
+++ b/src/ui/collection-box.vala
@@ -190,6 +190,10 @@ private class Games.CollectionBox : Gtk.Box {
                return search_bar.handle_event (event);
        }
 
+       public void run_search (string query) {
+               search_bar.run_search (query);
+       }
+
        [GtkCallback]
        private void update_bottom_bar () {
                view_switcher_bar.reveal = is_showing_bottom_bar && (!is_folded || !is_subview_open);
diff --git a/src/ui/collection-view.vala b/src/ui/collection-view.vala
index f17b6289..63bfa1d5 100644
--- a/src/ui/collection-view.vala
+++ b/src/ui/collection-view.vala
@@ -161,4 +161,9 @@ private class Games.CollectionView : Object, UiView {
                        critical (e.message);
                }
        }
+
+       public void run_search (string query) {
+               search_mode = true;
+               box.run_search (query);
+       }
 }
diff --git a/src/ui/search-bar.vala b/src/ui/search-bar.vala
index 6b1f0b12..fa06fea6 100644
--- a/src/ui/search-bar.vala
+++ b/src/ui/search-bar.vala
@@ -28,6 +28,10 @@ private class Games.SearchBar : Gtk.Bin {
                entry.grab_focus_without_selecting ();
        }
 
+       public void run_search (string query) {
+               entry.text = query;
+       }
+
        public bool handle_event (Gdk.Event event) {
                return search_bar.handle_event (event);
        }


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