Merge lp:~jeremywootten/slingshot/fix-1565134-cannot-drag-from-search into lp:~elementary-pantheon/slingshot/trunk

Proposed by Jeremy Wootten on 2016-06-15
Status: Merged
Merged at revision: 667
Proposed branch: lp:~jeremywootten/slingshot/fix-1565134-cannot-drag-from-search
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 122 lines (+56/-24)
2 files modified
src/Widgets/SearchItem.vala (+6/-17)
src/Widgets/SearchView.vala (+50/-7)
To merge this branch: bzr merge lp:~jeremywootten/slingshot/fix-1565134-cannot-drag-from-search
Reviewer Review Type Date Requested Status
elementary Pantheon team 2016-06-15 Pending
Review via email: mp+297448@code.launchpad.net

Description of the change

This branch implements drag handling by the search view.

Dragging between Slingshot search view and Plank functions. Slingshot closes on drag end.

To post a comment you must log in.
660. By Jeremy Wootten on 2016-06-15

Enable drag from search view

Jeremy Wootten (jeremywootten) wrote :

r660 overwritten with amendments to deal with rows without an app uri.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Widgets/SearchItem.vala'
2--- src/Widgets/SearchItem.vala 2016-04-21 18:23:20 +0000
3+++ src/Widgets/SearchItem.vala 2016-06-15 13:30:05 +0000
4@@ -39,10 +39,9 @@
5 public Backend.App app { get; construct; }
6 public ResultType result_type { public get; construct; }
7
8- public bool dragging = false; //prevent launching
9-
10 private Gtk.Label name_label;
11- private Gtk.Image icon;
12+ public Gtk.Image icon { public get; private set; }
13+ public string? app_uri { get; private set; }
14 private Cancellable? cancellable = null;
15
16 public SearchItem (Backend.App app, string search_term = "", ResultType result_type = ResultType.UNKNOWN) {
17@@ -89,24 +88,14 @@
18
19 add (grid);
20
21- if (result_type != SearchItem.ResultType.APP_ACTIONS)
22+ if (result_type != SearchItem.ResultType.APP_ACTIONS) {
23 launch_app.connect (app.launch);
24+ }
25
26+ app_uri = null;
27 var app_match = app.match as Synapse.ApplicationMatch;
28 if (app_match != null) {
29- Gtk.TargetEntry dnd = {"text/uri-list", 0, 0};
30- Gtk.drag_source_set (this, Gdk.ModifierType.BUTTON1_MASK, {dnd},
31- Gdk.DragAction.COPY);
32- this.drag_begin.connect ( (ctx) => {
33- this.dragging = true;
34- Gtk.drag_set_icon_gicon (ctx, app.icon, 0, 0);
35- });
36- this.drag_end.connect ( () => {
37- this.dragging = false;
38- });
39- this.drag_data_get.connect ( (ctx, sel, info, time) => {
40- sel.set_uris ({File.new_for_path (app_match.filename).get_uri ()});
41- });
42+ app_uri = File.new_for_path (app_match.filename).get_uri ();
43 }
44 }
45
46
47=== modified file 'src/Widgets/SearchView.vala'
48--- src/Widgets/SearchView.vala 2016-05-04 02:46:59 +0000
49+++ src/Widgets/SearchView.vala 2016-06-15 13:30:05 +0000
50@@ -33,6 +33,9 @@
51 private Gtk.ListBox list_box;
52 Gee.HashMap<SearchItem.ResultType, uint> limitator;
53
54+ private bool dragging = false;
55+ private string? drag_uri = null;
56+
57 public SearchView () {
58
59 }
60@@ -46,15 +49,55 @@
61 list_box.activate_on_single_click = true;
62 list_box.set_sort_func ((row1, row2) => update_sort (row1, row2));
63 list_box.set_header_func ((Gtk.ListBoxUpdateHeaderFunc) update_header);
64+ list_box.set_selection_mode (Gtk.SelectionMode.BROWSE);
65 list_box.row_activated.connect ((row) => {
66 var search_item = row as SearchItem;
67- if (search_item.result_type == SearchItem.ResultType.APP_ACTIONS || search_item.result_type == SearchItem.ResultType.LINK) {
68- search_item.app.match.execute (null);
69- } else {
70- search_item.app.launch ();
71- }
72-
73- app_launched ();
74+ if (!dragging) {
75+ if (search_item.result_type == SearchItem.ResultType.APP_ACTIONS || search_item.result_type == SearchItem.ResultType.LINK) {
76+ search_item.app.match.execute (null);
77+ } else {
78+ search_item.app.launch ();
79+ }
80+
81+ app_launched ();
82+ }
83+ });
84+
85+ // Drag support
86+ Gtk.TargetEntry dnd = {"text/uri-list", 0, 0};
87+ Gtk.drag_source_set (list_box, Gdk.ModifierType.BUTTON1_MASK, {dnd}, Gdk.DragAction.COPY);
88+
89+ list_box.motion_notify_event.connect ((event) => {
90+ if (!dragging) {
91+ list_box.select_row (list_box.get_row_at_y ((int)event.y));
92+ }
93+ return false;
94+ });
95+
96+ list_box.drag_begin.connect ( (ctx) => {
97+ var sr = list_box.get_selected_rows ();
98+ if (sr.length () > 0) {
99+ var di = (SearchItem)(sr.first ().data);
100+ drag_uri = di.app_uri;
101+ if (drag_uri != null);
102+ dragging = true;
103+ Gtk.drag_set_icon_gicon (ctx, di.icon.gicon, 0, 0);
104+ }
105+ }
106+ });
107+
108+ list_box.drag_end.connect ( () => {
109+ if (drag_uri != null) {
110+ app_launched (); /* This causes indicator to close */
111+ }
112+ dragging = false;
113+ drag_uri = null;
114+ });
115+
116+ list_box.drag_data_get.connect ( (ctx, sel, info, time) => {
117+ if (drag_uri != null) {
118+ sel.set_uris ({drag_uri});
119+ }
120 });
121
122 // alert view

Subscribers

People subscribed via source and target branches