Merge lp:~jeremywootten/pantheon-files/fix-select-when-scrolled-regression into lp:~elementary-apps/pantheon-files/trunk

Proposed by Jeremy Wootten
Status: Merged
Approved by: David Hewitt
Approved revision: 2516
Merged at revision: 2529
Proposed branch: lp:~jeremywootten/pantheon-files/fix-select-when-scrolled-regression
Merge into: lp:~elementary-apps/pantheon-files/trunk
Diff against target: 144 lines (+58/-30)
3 files modified
src/View/AbstractDirectoryView.vala (+1/-25)
src/View/AbstractTreeView.vala (+24/-0)
src/View/IconView.vala (+33/-5)
To merge this branch: bzr merge lp:~jeremywootten/pantheon-files/fix-select-when-scrolled-regression
Reviewer Review Type Date Requested Status
David Hewitt code, function Approve
Review via email: mp+318655@code.launchpad.net

Commit message

Implement separate is_on_icon () method for IconView

Description of the change

This branch fixes a fairly serious regression in the selection of items in Icon View using the selection helper, which no longer works properly when the view is scrolled.

This was due to the same code being used to determine whether the pointer was on the icon or helper for all the views, but there are subtle differences in the way IconView renders the items and the coordinates it supplies to the renderer meaning that a separate slightly different method has to be used.

To post a comment you must log in.
Revision history for this message
David Hewitt (davidmhewitt) wrote :

Can confirm that it fixes the bug and selection in the other two views remains working as intended.

review: Approve (code, function)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/View/AbstractDirectoryView.vala'
2--- src/View/AbstractDirectoryView.vala 2017-02-15 18:54:50 +0000
3+++ src/View/AbstractDirectoryView.vala 2017-03-01 17:49:39 +0000
4@@ -3482,31 +3482,6 @@
5 unselect_all ();
6 }
7
8- protected bool is_on_icon (int x, int y, int orig_x, int orig_y, ref bool on_helper) {
9- /* orig_x and orig_y must be top left hand corner of icon (excluding helper) */
10- int x_offset = x - orig_x;
11- int y_offset = y - orig_y;
12-
13-
14- bool on_icon = (x_offset >= 0 &&
15- x_offset <= icon_size &&
16- y_offset >= 0 &&
17- y_offset <= icon_size);
18-
19- on_helper = false;
20- if (icon_renderer.selection_helpers) {
21- int x_helper_offset = x - icon_renderer.helper_x;
22- int y_helper_offset = y - icon_renderer.helper_y;
23-
24- on_helper = (x_helper_offset >= 0 &&
25- x_helper_offset <= icon_renderer.helper_size &&
26- y_helper_offset >= 0 &&
27- y_helper_offset <= icon_renderer.helper_size);
28- }
29-
30- return on_icon;
31- }
32-
33 protected void invert_selection () {
34 GLib.List<Gtk.TreeRowReference> selected_row_refs = null;
35
36@@ -3560,6 +3535,7 @@
37 protected abstract void thaw_tree ();
38 protected new abstract void freeze_child_notify ();
39 protected new abstract void thaw_child_notify ();
40+ protected abstract bool is_on_icon (int x, int y, int orig_x, int orig_y, ref bool on_helper);
41
42 /** Unimplemented methods
43 * fm_directory_view_parent_set () - purpose unclear
44
45=== modified file 'src/View/AbstractTreeView.vala'
46--- src/View/AbstractTreeView.vala 2017-02-07 19:38:46 +0000
47+++ src/View/AbstractTreeView.vala 2017-03-01 17:49:39 +0000
48@@ -321,5 +321,29 @@
49 protected override void thaw_child_notify () {
50 tree.thaw_child_notify ();
51 }
52+
53+ protected override bool is_on_icon (int x, int y, int orig_x, int orig_y, ref bool on_helper) {
54+ /* orig_x and orig_y must be top left hand corner of icon (excluding helper) */
55+ int x_offset = x - orig_x;
56+ int y_offset = y - orig_y;
57+
58+ bool on_icon = (x_offset >= 0 &&
59+ x_offset <= icon_size &&
60+ y_offset >= 0 &&
61+ y_offset <= icon_size);
62+
63+ on_helper = false;
64+ if (icon_renderer.selection_helpers) {
65+ int x_helper_offset = x - icon_renderer.helper_x;
66+ int y_helper_offset = y - icon_renderer.helper_y;
67+
68+ on_helper = (x_helper_offset >= 0 &&
69+ x_helper_offset <= icon_renderer.helper_size &&
70+ y_helper_offset >= 0 &&
71+ y_helper_offset <= icon_renderer.helper_size);
72+ }
73+
74+ return on_icon;
75+ }
76 }
77 }
78
79=== modified file 'src/View/IconView.vala'
80--- src/View/IconView.vala 2017-02-08 12:48:45 +0000
81+++ src/View/IconView.vala 2017-03-01 17:49:39 +0000
82@@ -225,10 +225,10 @@
83 if (x >= rect.x &&
84 x <= rect.x + rect.width &&
85 y >= rect.y &&
86- y <= rect.y + (r as Marlin.TextRenderer).text_height)
87+ y <= rect.y + (r as Marlin.TextRenderer).text_height) {
88
89 zone = ClickZone.NAME;
90- else if (rubberband) {
91+ } else if (rubberband) {
92 /* Fake location outside centre bottom of item for rubberbanding */
93 event.x = rect.x + rect.width / 2;
94 event.y = rect.y + rect.height + 10 + (int)(get_vadjustment ().value);
95@@ -238,11 +238,11 @@
96 bool on_helper = false;
97 bool on_icon = is_on_icon (x, y, area.x, area.y, ref on_helper);
98
99- if (on_helper)
100+ if (on_helper) {
101 zone = ClickZone.HELPER;
102- else if (on_icon)
103+ } else if (on_icon) {
104 zone = ClickZone.ICON;
105- else if (rubberband) {
106+ } else if (rubberband) {
107 /* Fake location outside centre top of item for rubberbanding */
108 event.x = rect.x + rect.width / 2;
109 event.y = rect.y - 10 + (int)(get_vadjustment ().value);
110@@ -440,6 +440,34 @@
111 }
112 }
113
114+ protected override bool is_on_icon (int x, int y, int orig_x, int orig_y, ref bool on_helper) {
115+ /* orig_x and orig_y must be top left hand corner of icon (excluding helper) */
116+ int x_offset = x - orig_x;
117+ int y_offset = y - orig_y;
118+
119+ bool on_icon = (x_offset >= 0 &&
120+ x_offset <= icon_size &&
121+ y_offset >= 0 &&
122+ y_offset <= icon_size);
123+
124+ on_helper = false;
125+ if (icon_renderer.selection_helpers) {
126+ int x_helper_offset = x - icon_renderer.helper_x;
127+ /* IconView provide IconRenderer with bin coords not widget coords (unlike TreeView) so we have to
128+ * correct for scrolling */
129+ int y_helper_offset = y - icon_renderer.helper_y + (int)(get_vadjustment ().value);
130+
131+ on_helper = (x_helper_offset >= 0 &&
132+ x_helper_offset <= icon_renderer.helper_size &&
133+ y_helper_offset >= 0 &&
134+ y_helper_offset <= icon_renderer.helper_size);
135+
136+ }
137+
138+ return on_icon;
139+ }
140+
141+
142 /* When Icon View is automatically adjusting column number it does not expose the actual number of
143 * columns (get_columns () returns -1). So we have to write our own method. This is the only way
144 * (I can think of) that works on row 0.

Subscribers

People subscribed via source and target branches

to all changes: