Merge lp:~donadigo/slingshot/search-quicklist into lp:~elementary-pantheon/slingshot/trunk

Proposed by Adam Bieńkowski on 2015-09-20
Status: Merged
Approved by: Daniel Fore on 2015-09-29
Approved revision: 580
Merged at revision: 584
Proposed branch: lp:~donadigo/slingshot/search-quicklist
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 198 lines (+103/-5)
3 files modified
lib/synapse-plugins/desktop-file-plugin.vala (+60/-0)
src/Widgets/SearchItem.vala (+10/-4)
src/Widgets/SearchView.vala (+33/-1)
To merge this branch: bzr merge lp:~donadigo/slingshot/search-quicklist
Reviewer Review Type Date Requested Status
Florian Angermeier (community) code Approve on 2015-09-24
Daniel Fore ux 2015-09-20 Approve on 2015-09-20
elementary Pantheon team code 2015-09-20 Pending
Review via email: mp+271755@code.launchpad.net

Commit message

Add functionality to search quicklist items

Description of the change

Fixes bug #888776. Search in quicklist items. The implementation is in desktop-file-plugin because it has already what is needed for such functionality. I also followed the slingshot plugin code style.

To post a comment you must log in.
578. By Adam Bieńkowski on 2015-09-20

Cleaned code a bit

Daniel Fore (danrabbit) wrote :

Actions don't seem to activate with 'enter'

See inline comment about commented code

review: Needs Fixing
579. By Adam Bieńkowski on 2015-09-20

Fixed: action won't launch by pressing enter

580. By Adam Bieńkowski on 2015-09-20

Remove unreachable catch

Daniel Fore (danrabbit) wrote :

Works for me™

We should at some point decide how to deal with duplicate items and to explicitly label apps without being redundant. But since we're at the beginning of the cycle, I don't think we should block the merge on it.

Probably still needs a legit code review :)

review: Approve (ux)

Thanks for taking the time and working on this! :-)

See inline comments for some Code Guide issues.

review: Needs Fixing
Rico Tzschichholz (ricotz) wrote :

> Thanks for taking the time and working on this! :-)
>
> See inline comments for some Code Guide issues.

@fraang: Please take a look at the rest of the synapse source (which was copied from synapse upstream) and think about your request to enforce the elementary-codestyle on it.

So it is not reasonable for files in lib/synapse-plugins/ to follow the elementary-codestyle.

Adam Bieńkowski (donadigo) wrote :

As Rico said I followed the general style of Synapse plugins and this is intentionable. Any other problems that I need to fix with this branch?

Works fine. :-) Approved!

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/synapse-plugins/desktop-file-plugin.vala'
2--- lib/synapse-plugins/desktop-file-plugin.vala 2015-04-27 14:10:52 +0000
3+++ lib/synapse-plugins/desktop-file-plugin.vala 2015-09-20 17:52:04 +0000
4@@ -35,6 +35,37 @@
5
6 }
7
8+ public class ActionMatch : Object, Match
9+ {
10+ public string title { get; construct set; }
11+ public string icon_name { get; construct set; default = ""; }
12+ public string description { get; set; default = ""; }
13+ public bool has_thumbnail { get; construct set; default = false; }
14+ public string thumbnail_path { get; construct set; }
15+ public MatchType match_type { get; construct set; }
16+ public string? filename { get; construct set; }
17+
18+ public AppInfo? app_info { get; set; default = null; }
19+ public bool needs_terminal { get; set; default = false; }
20+
21+ private string action_name;
22+
23+ public ActionMatch (string desktop_id, string action_name)
24+ {
25+ var desktop_app_info = new DesktopAppInfo (desktop_id);
26+ this.title = desktop_app_info.get_action_name (action_name);
27+ this.icon_name = desktop_app_info.get_icon ().to_string ();
28+ this.description = "";
29+ this.app_info = desktop_app_info;
30+ this.action_name = action_name;
31+ }
32+
33+ public void execute (Match? match)
34+ {
35+ ((DesktopAppInfo) app_info).launch_action (action_name, new AppLaunchContext ());
36+ }
37+ }
38+
39 private class DesktopFileMatch: Object, Match, ApplicationMatch
40 {
41 // for Match interface
42@@ -193,6 +224,35 @@
43 break;
44 }
45 }
46+
47+ string id = dfm.desktop_id.replace ("application://", "");
48+ var desktop_app_info = new DesktopAppInfo (id);
49+ string[] actions = desktop_app_info.list_actions ();
50+ foreach (string action in actions) {
51+ string title = desktop_app_info.get_action_name (action).down ();
52+ foreach (var matcher in matchers)
53+ {
54+ MatchInfo action_info;
55+ if (matcher.key.match (title, 0, out action_info)
56+ || title.contains (q.query_string_folded)
57+ || title.has_prefix (q.query_string))
58+ {
59+ var am = new ActionMatch (id, action);
60+ results.add (am, compute_relevancy (dfm, Match.Score.INCREMENT_SMALL));
61+ matched = true;
62+ break;
63+ }
64+
65+ else if (action_info.is_partial_match ())
66+ {
67+ var am = new ActionMatch (id, action);
68+ results.add (am, compute_relevancy (dfm, Match.Score.INCREMENT_SMALL));
69+ matched = true;
70+ break;
71+ }
72+ }
73+ }
74+
75 if (!matched && (comment.down ().contains (q.query_string_folded)
76 || generic_name.down ().contains (q.query_string_folded)))
77 {
78
79=== modified file 'src/Widgets/SearchItem.vala'
80--- src/Widgets/SearchItem.vala 2015-05-28 16:15:08 +0000
81+++ src/Widgets/SearchItem.vala 2015-09-20 17:52:04 +0000
82@@ -29,15 +29,21 @@
83
84 private Cancellable? cancellable = null;
85 public bool dragging = false; //prevent launching
86+ public bool action = false;
87
88 public signal bool launch_app ();
89
90- public SearchItem (Backend.App app, string search_term = "") {
91+ public SearchItem (Backend.App app, string search_term = "", bool action = false, string action_title = "") {
92 Object (app: app);
93
94+ this.action = action;
95 get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
96
97- var markup = Backend.SynapseSearch.markup_string_with_search (app.name, search_term);
98+ string markup;
99+ if (action)
100+ markup = action_title;
101+ else
102+ markup = Backend.SynapseSearch.markup_string_with_search (app.name, search_term);
103
104 name_label = new Gtk.Label (markup);
105 name_label.set_ellipsize (Pango.EllipsizeMode.END);
106@@ -67,7 +73,8 @@
107
108 add (box);
109
110- launch_app.connect (app.launch);
111+ if (!action)
112+ launch_app.connect (app.launch);
113
114 var app_match = app.match as Synapse.ApplicationMatch;
115 if (app_match != null) {
116@@ -85,7 +92,6 @@
117 sel.set_uris ({File.new_for_path (app_match.filename).get_uri ()});
118 });
119 }
120-
121 }
122
123 public override void destroy () {
124
125=== modified file 'src/Widgets/SearchView.vala'
126--- src/Widgets/SearchView.vala 2015-06-03 19:10:24 +0000
127+++ src/Widgets/SearchView.vala 2015-09-20 17:52:04 +0000
128@@ -132,6 +132,8 @@
129 // We assign 9 as the id for settings results
130 if (match is Synapse.SwitchboardPlugin.SwitchboardObject)
131 type = 9;
132+ else if (match is Synapse.DesktopFilePlugin.ActionMatch)
133+ type = 10;
134
135 if ((list = categories.get (type)) == null) {
136 list = new Gee.LinkedList<Synapse.Match> ();
137@@ -183,6 +185,9 @@
138 case 9:
139 label = _("Settings");
140 break;
141+ case 10:
142+ label = _("Application Actions");
143+ break;
144 }
145
146 var header = new Gtk.Label (label);
147@@ -199,6 +204,12 @@
148 for (var i = 0; i < limit && i < list.size; i++) {
149 var match = list.get (i);
150
151+ if (type == 10) {
152+ show_action (new Backend.App.from_synapse_match (match));
153+ n_results++;
154+ continue;
155+ }
156+
157 // expand the actions we get for UNKNOWN
158 if (match.match_type == Synapse.MatchType.UNKNOWN) {
159 var actions = Backend.SynapseSearch.find_actions_for_match (match);
160@@ -234,6 +245,24 @@
161
162 }
163
164+ private void show_action (Backend.App app) {
165+ var search_item = new SearchItem (app, "", true, app.match.title);
166+ app.start_search.connect ((search, target) => start_search (search, target));
167+ search_item.button_release_event.connect (() => {
168+ if (!search_item.dragging) {
169+ ((Synapse.DesktopFilePlugin.ActionMatch) app.match).execute (null);
170+ app_launched ();
171+ }
172+
173+ return true;
174+ });
175+
176+ main_box.pack_start (search_item, false, false);
177+ search_item.show_all ();
178+
179+ items[app] = search_item;
180+ }
181+
182 public void toggle_context (bool show) {
183 var prev_y = vadjustment.value;
184
185@@ -332,9 +361,12 @@
186 * @return indicates whether slingshot should now be hidden
187 */
188 public bool launch_selected () {
189+ if (selected_app.action) {
190+ ((Synapse.DesktopFilePlugin.ActionMatch) selected_app.app.match).execute (null);
191+ return true;
192+ }
193
194 return selected_app.launch_app ();
195-
196 }
197
198 }

Subscribers

People subscribed via source and target branches