Merge lp:~sgpthomas/slingshot/no-results into lp:~elementary-pantheon/slingshot/trunk

Proposed by Sam Thomas on 2016-05-04
Status: Merged
Approved by: Daniel Fore on 2016-05-04
Approved revision: 648
Merged at revision: 648
Proposed branch: lp:~sgpthomas/slingshot/no-results
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 109 lines (+49/-29)
1 file modified
src/Widgets/SearchView.vala (+49/-29)
To merge this branch: bzr merge lp:~sgpthomas/slingshot/no-results
Reviewer Review Type Date Requested Status
elementary Pantheon team 2016-05-04 Pending
Review via email: mp+293702@code.launchpad.net

Commit message

Adds a 'no-results' view when there are no search results

Description of the change

Addresses Bug #1578003

Adds a 'no-results' view when there are no search results

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Widgets/SearchView.vala'
2--- src/Widgets/SearchView.vala 2016-02-20 17:11:51 +0000
3+++ src/Widgets/SearchView.vala 2016-05-04 02:50:24 +0000
4@@ -28,15 +28,19 @@
5 public signal void start_search (Synapse.SearchMatch search_match, Synapse.Match? target);
6 public signal void app_launched ();
7
8+ private Gtk.Stack stack;
9+ private Granite.Widgets.AlertView alert_view;
10 private Gtk.ListBox list_box;
11 Gee.HashMap<SearchItem.ResultType, uint> limitator;
12
13 public SearchView () {
14-
15+
16 }
17
18 construct {
19 hscrollbar_policy = Gtk.PolicyType.NEVER;
20+
21+ // list box
22 limitator = new Gee.HashMap<SearchItem.ResultType, uint> ();
23 list_box = new Gtk.ListBox ();
24 list_box.activate_on_single_click = true;
25@@ -53,40 +57,56 @@
26 app_launched ();
27 });
28
29- add (list_box);
30+ // alert view
31+ alert_view = new Granite.Widgets.AlertView ("", _("Try changing search terms."), "edit-find-symbolic");
32+
33+ // stack
34+ stack = new Gtk.Stack ();
35+ stack.add_named (list_box, "results");
36+ stack.add_named (alert_view, "alert");
37+
38+ add (stack);
39 }
40
41 public void set_results (Gee.List<Synapse.Match> matches, string search_term) {
42 clear ();
43- foreach (var match in matches) {
44- Backend.App app = new Backend.App.from_synapse_match (match);
45- SearchItem.ResultType result_type = (SearchItem.ResultType) match.match_type;
46- if (match is Synapse.DesktopFilePlugin.ActionMatch) {
47- result_type = SearchItem.ResultType.APP_ACTIONS;
48- } else if (match is Synapse.SwitchboardPlugin.SwitchboardObject) {
49- result_type = SearchItem.ResultType.SETTINGS;
50- } else if (match.match_type == Synapse.MatchType.GENERIC_URI) {
51- var uri = (match as Synapse.UriMatch).uri;
52- if (uri.has_prefix ("http://") || uri.has_prefix ("ftp://") || uri.has_prefix ("https://")) {
53- result_type = SearchItem.ResultType.INTERNET;
54- }
55- } else if (match is Synapse.LinkPlugin.Result) {
56- result_type = SearchItem.ResultType.LINK;
57- }
58-
59- if (result_type == SearchItem.ResultType.UNKNOWN) {
60- var actions = Backend.SynapseSearch.find_actions_for_match (match);
61- foreach (var action in actions) {
62- app = new Backend.App.from_synapse_match (action, match);
63- create_item (app, search_term, (SearchItem.ResultType) app.match.match_type);
64- }
65-
66- continue;
67- }
68-
69- create_item (app, search_term, result_type);
70+ if (matches.size > 0) {
71+ foreach (var match in matches) {
72+ Backend.App app = new Backend.App.from_synapse_match (match);
73+ SearchItem.ResultType result_type = (SearchItem.ResultType) match.match_type;
74+ if (match is Synapse.DesktopFilePlugin.ActionMatch) {
75+ result_type = SearchItem.ResultType.APP_ACTIONS;
76+ } else if (match is Synapse.SwitchboardPlugin.SwitchboardObject) {
77+ result_type = SearchItem.ResultType.SETTINGS;
78+ } else if (match.match_type == Synapse.MatchType.GENERIC_URI) {
79+ var uri = (match as Synapse.UriMatch).uri;
80+ if (uri.has_prefix ("http://") || uri.has_prefix ("ftp://") || uri.has_prefix ("https://")) {
81+ result_type = SearchItem.ResultType.INTERNET;
82+ }
83+ } else if (match is Synapse.LinkPlugin.Result) {
84+ result_type = SearchItem.ResultType.LINK;
85+ }
86+
87+ if (result_type == SearchItem.ResultType.UNKNOWN) {
88+ var actions = Backend.SynapseSearch.find_actions_for_match (match);
89+ foreach (var action in actions) {
90+ app = new Backend.App.from_synapse_match (action, match);
91+ create_item (app, search_term, (SearchItem.ResultType) app.match.match_type);
92+ }
93+
94+ continue;
95+ }
96+
97+ create_item (app, search_term, result_type);
98+ }
99+
100+ stack.set_visible_child_name ("results");
101+ } else {
102+ alert_view.title = _("No Results for ā€œ%sā€".printf (search_term));
103+ stack.set_visible_child_name ("alert");
104 }
105
106+
107 weak Gtk.ListBoxRow? first = list_box.get_row_at_index (0);
108 if (first != null) {
109 list_box.select_row (first);

Subscribers

People subscribed via source and target branches