From f67bc00d93a633389ad7af1404338cddaa44022d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 23 Nov 2021 14:57:03 -0800 Subject: [PATCH] SearchView: Add placeholder --- src/SlingshotView.vala | 26 +++++++-------- src/Views/SearchView.vala | 67 +++++++++++++++++++++++++++++++++++---- 2 files changed, 72 insertions(+), 21 deletions(-) diff --git a/src/SlingshotView.vala b/src/SlingshotView.vala index 3de9afbf..f04a540d 100644 --- a/src/SlingshotView.vala +++ b/src/SlingshotView.vala @@ -71,9 +71,10 @@ public class Slingshot.SlingshotView : Gtk.Grid { view_selector_revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_RIGHT; view_selector_revealer.add (view_selector); - search_entry = new Gtk.SearchEntry (); - search_entry.placeholder_text = _("Search Apps"); - search_entry.hexpand = true; + search_entry = new Gtk.SearchEntry () { + placeholder_text = _("Search Apps and Actions"), + hexpand = true + }; search_entry.secondary_icon_tooltip_markup = Granite.markup_accel_tooltip ( {"BackSpace"}, _("Clear all") ); @@ -126,7 +127,7 @@ public class Slingshot.SlingshotView : Gtk.Grid { }); focus_in_event.connect (() => { - search_entry.grab_focus (); + grab_focus (); return Gdk.EVENT_PROPAGATE; }); @@ -141,7 +142,12 @@ public class Slingshot.SlingshotView : Gtk.Grid { search.begin (search_entry.text); }); - search_entry.grab_focus (); + search_entry.focus_in_event.connect (() => { + if (modality != Modality.SEARCH_VIEW) { + set_modality (Modality.SEARCH_VIEW); + } + }); + search_entry.activate.connect (search_entry_activated); category_view.search_focus_request.connect (() => { @@ -329,12 +335,6 @@ public class Slingshot.SlingshotView : Gtk.Grid { public void show_slingshot () { search_entry.text = ""; - - /* TODO - set_focus (null); - */ - - search_entry.grab_focus (); // This is needed in order to not animate if the previous view was the search view. view_selector_revealer.transition_type = Gtk.RevealerTransitionType.NONE; stack.transition_type = Gtk.StackTransitionType.NONE; @@ -354,8 +354,6 @@ public class Slingshot.SlingshotView : Gtk.Grid { view_selector_revealer.set_reveal_child (true); stack.set_visible_child_name ("normal"); - - search_entry.grab_focus (); break; case Modality.CATEGORY_VIEW: @@ -365,8 +363,6 @@ public class Slingshot.SlingshotView : Gtk.Grid { view_selector_revealer.set_reveal_child (true); stack.set_visible_child_name ("category"); - - search_entry.grab_focus (); break; case Modality.SEARCH_VIEW: diff --git a/src/Views/SearchView.vala b/src/Views/SearchView.vala index 1d4eb0f7..042276a4 100644 --- a/src/Views/SearchView.vala +++ b/src/Views/SearchView.vala @@ -26,15 +26,51 @@ public class Slingshot.Widgets.SearchView : Gtk.ScrolledWindow { public signal void start_search (Synapse.SearchMatch search_match, Synapse.Match? target); public signal void app_launched (); - private Granite.Widgets.AlertView alert_view; private AppListBox list_box; Gee.HashMap limitator; construct { hscrollbar_policy = Gtk.PolicyType.NEVER; - alert_view = new Granite.Widgets.AlertView ("", _("Try changing search terms."), "edit-find-symbolic"); - alert_view.show_all (); + var placeholder_title = new Gtk.Label (_("Search apps, actions, and more")); + placeholder_title.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL); + + var suggest_apps = new SuggestionGrid ( + "application-default-icon", + _("Installed Apps"), + _("“Videos”") + ); + + var suggest_actions = new SuggestionGrid ( + "system-run", + _("Actions"), + _("“Check for updates”") + ); + + var suggest_settings = new SuggestionGrid ( + "preferences-desktop", + _("System Settings"), + _("“Text size”") + ); + + var suggest_bookmarks = new SuggestionGrid ( + "user-bookmarks", + _("Bookmarked Folders"), + _("“Pictures”") + ); + + var placeholder = new Gtk.Grid () { + halign = Gtk.Align.CENTER, + valign = Gtk.Align.CENTER, + row_spacing = 12, + orientation = Gtk.Orientation.VERTICAL + }; + placeholder.add (placeholder_title); + placeholder.add (suggest_apps); + placeholder.add (suggest_actions); + placeholder.add (suggest_settings); + placeholder.add (suggest_bookmarks); + placeholder.show_all (); // list box limitator = new Gee.HashMap (); @@ -42,7 +78,7 @@ public class Slingshot.Widgets.SearchView : Gtk.ScrolledWindow { list_box.activate_on_single_click = true; list_box.set_sort_func ((row1, row2) => update_sort (row1, row2)); list_box.set_header_func ((Gtk.ListBoxUpdateHeaderFunc) update_header); - list_box.set_placeholder (alert_view); + list_box.set_placeholder (placeholder); list_box.close_request.connect (() => { app_launched (); @@ -127,8 +163,6 @@ public class Slingshot.Widgets.SearchView : Gtk.ScrolledWindow { create_item (app, search_term, result_type); } - } else { - alert_view.title = _("No Results for “%s”").printf (search_term); } @@ -192,4 +226,25 @@ public class Slingshot.Widgets.SearchView : Gtk.ScrolledWindow { row.set_header (header); } + + private class SuggestionGrid : Gtk.Grid { + public SuggestionGrid (string icon_name, string title, string description) { + var icon = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.DND); + + var title_label = new Gtk.Label (title) { + xalign = 0 + }; + title_label.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL); + + var description_label = new Gtk.Label (description) { + xalign = 0 + }; + description_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); + + column_spacing = 12; + attach (icon, 0, 0, 1, 2); + attach (title_label, 1, 0); + attach (description_label, 1, 1); + } + } }