Merge lp:~jeremywootten/pantheon-files/fix-1537536-search-selection-in-icon-view into lp:~elementary-apps/pantheon-files/trunk

Proposed by Jeremy Wootten
Status: Merged
Approved by: Danielle Foré
Approved revision: 2103
Merged at revision: 2106
Proposed branch: lp:~jeremywootten/pantheon-files/fix-1537536-search-selection-in-icon-view
Merge into: lp:~elementary-apps/pantheon-files/trunk
Diff against target: 151 lines (+38/-15)
3 files modified
libwidgets/View/LocationBar.vala (+5/-7)
libwidgets/View/SearchResults.vala (+19/-6)
src/View/ViewContainer.vala (+14/-2)
To merge this branch: bzr merge lp:~jeremywootten/pantheon-files/fix-1537536-search-selection-in-icon-view
Reviewer Review Type Date Requested Status
Adam Bieńkowski (community) code / tests Approve
Review via email: mp+291222@code.launchpad.net

Commit message

Stop emission of cursor-changed signals when clearing search list

Description of the change

This branch stops "cursor-changed" signals being emitted when clearing the search list, which was causing unexpected selections when no matches were found.

To post a comment you must log in.
Revision history for this message
Adam Bieńkowski (donadigo) wrote :

Looks good, I am no longer getting strange selections.

review: Approve (code / tests)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libwidgets/View/LocationBar.vala'
2--- libwidgets/View/LocationBar.vala 2016-02-11 11:12:03 +0000
3+++ libwidgets/View/LocationBar.vala 2016-04-07 10:13:59 +0000
4@@ -28,7 +28,7 @@
5 public bool search_mode {get; private set;}
6
7 public signal void reload_request ();
8- public signal void focus_file_request (File file);
9+ public signal void focus_file_request (File? file);
10 public signal void escape ();
11
12 public LocationBar () {
13@@ -65,15 +65,13 @@
14 }
15
16 private void on_search_results_first_match_found (GLib.File? file) {
17- if (file != null) {
18- focus_file_request (file);
19- }
20+ focus_file_request (file);
21 }
22+
23 private void on_search_results_cursor_changed (GLib.File? file) {
24- if (file != null) {
25- focus_file_request (file);
26- }
27+ focus_file_request (file);
28 }
29+
30 private void on_search_results_realize () {
31 (get_toplevel () as Gtk.Window).get_group ().add_window (search_results); /*Is this necessary every popup? */
32 }
33
34=== modified file 'libwidgets/View/SearchResults.vala'
35--- libwidgets/View/SearchResults.vala 2016-02-11 11:12:03 +0000
36+++ libwidgets/View/SearchResults.vala 2016-04-07 10:13:59 +0000
37@@ -327,7 +327,6 @@
38 }
39 }
40
41-
42 bool on_button_press_event (Gdk.EventButton e) {
43 if (e.x >= 0 && e.y >= 0 && e.x < get_allocated_width () && e.y < get_allocated_height ()) {
44 view.event (e);
45@@ -616,12 +615,14 @@
46
47 is_grabbing = true;
48 }
49- /* Also pair signal connect and disconnect */
50- view.cursor_changed.connect (on_cursor_changed);
51+ /* Paired with disconnect function in popdown () */
52+ connect_view_cursor_changed_signal ();
53 }
54
55 void popdown ()
56 {
57+ /* Paired with connect function in popup () */
58+ disconnect_view_cursor_changed_signal ();
59 if (is_grabbing) {
60 if (device == null) {
61 /* 'device' can become null during searching for reasons as yet unidentified. This ensures
62@@ -635,8 +636,7 @@
63 Gtk.device_grab_remove (this, device);
64 is_grabbing = false;
65 }
66- /* Also pair signal connect and disconnect */
67- view.cursor_changed.disconnect (on_cursor_changed);
68+
69 hide ();
70 }
71
72@@ -770,6 +770,9 @@
73
74 protected void clear ()
75 {
76+ /* Disconnect the cursor-changed signal so that it does not get emitted when entries removed
77+ * causing incorrect files to get selected in icon view */
78+ disconnect_view_cursor_changed_signal ();
79 Gtk.TreeIter parent, iter;
80 for (var valid = list.get_iter_first (out parent); valid; valid = list.iter_next (ref parent)) {
81 if (!list.iter_nth_child (out iter, parent, 0))
82@@ -779,6 +782,8 @@
83 }
84
85 resize_popup ();
86+ /* Reconnect signal */
87+ connect_view_cursor_changed_signal ();
88 }
89
90
91@@ -797,10 +802,11 @@
92
93 filter.refilter ();
94
95- select_first ();
96 if (local_search_finished && global_search_finished && list_empty ()) {
97 view.get_selection ().unselect_all ();
98 first_match_found (null);
99+ } else {
100+ select_first ();
101 }
102
103 if (local_search_finished && global_search_finished) {
104@@ -999,6 +1005,13 @@
105 public bool has_popped_up () {
106 return is_grabbing;
107 }
108+
109+ private void connect_view_cursor_changed_signal () {
110+ view.cursor_changed.connect (on_cursor_changed);
111+ }
112+ private void disconnect_view_cursor_changed_signal () {
113+ view.cursor_changed.disconnect (on_cursor_changed);
114+ }
115 }
116 }
117
118
119=== modified file 'src/View/ViewContainer.vala'
120--- src/View/ViewContainer.vala 2016-03-06 10:18:25 +0000
121+++ src/View/ViewContainer.vala 2016-04-07 10:13:59 +0000
122@@ -404,15 +404,27 @@
123 if (aslot != null)
124 aslot.set_frozen_state (is_frozen);
125 }
126+
127+ private void set_all_selected (bool select_all) {
128+ var aslot = get_current_slot ();
129+ if (aslot != null) {
130+ aslot.set_all_selected (select_all);
131+ }
132+ }
133
134- public void focus_location (GLib.File loc,
135+ public void focus_location (GLib.File? loc,
136 bool no_path_change = false,
137 bool unselect_others = false) {
138
139 /* This function navigates to another folder if necessary if
140 * select_in_current_only is not set to true.
141 */
142- assert (loc != null);
143+
144+ /* Search can generate null focus requests if no match - deselect previous search selection */
145+ if (loc == null) {
146+ set_all_selected (false);
147+ return;
148+ }
149
150 if (location.equal (loc)) {
151 return;

Subscribers

People subscribed via source and target branches

to all changes: