Merge lp:~unity-team/unity/less-flashing-places into lp:unity

Proposed by Neil J. Patel
Status: Merged
Approved by: Gord Allott
Approved revision: no longer in the source branch.
Merged at revision: 482
Proposed branch: lp:~unity-team/unity/less-flashing-places
Merge into: lp:unity
Prerequisite: lp:~canonical-dx-team/unity/batch-icon-loading
Diff against target: 311 lines (+148/-46)
3 files modified
unity-private/places/places-button.vala (+1/-0)
unity-private/places/places-default-renderer-group.vala (+48/-8)
unity-private/places/places-default-renderer-tiles.vala (+99/-38)
To merge this branch: bzr merge lp:~unity-team/unity/less-flashing-places
Reviewer Review Type Date Requested Status
Gord Allott (community) Approve
Review via email: mp+34507@code.launchpad.net

Description of the change

This branch queues requests to remove results from the views long enough to update the existing tiles if add_result comes in. This allows the views not to flash as much during searches.

It's a bit messy but I can clean up next week, nothing there should be evil (well, some might :).

To post a comment you must log in.
Revision history for this message
Gord Allott (gordallott) wrote :

seems to work okay, approved. i don't like the "button.unref (); /* Because Vala sucks and holds references when it shouldn't*/;"'s but i guess they have been there for a while

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'unity-private/places/places-button.vala'
2--- unity-private/places/places-button.vala 2010-08-26 12:34:12 +0000
3+++ unity-private/places/places-button.vala 2010-09-03 00:06:44 +0000
4@@ -128,6 +128,7 @@
5 cr.close_path (); }
6
7 private void paint_bg (Cairo.Context cr, int width, int height)
8+ requires (this is Button)
9 {
10 var x = 1;
11
12
13=== modified file 'unity-private/places/places-default-renderer-group.vala'
14--- unity-private/places/places-default-renderer-group.vala 2010-09-03 00:06:44 +0000
15+++ unity-private/places/places-default-renderer-group.vala 2010-09-03 00:06:44 +0000
16@@ -73,6 +73,9 @@
17
18 public signal void activated (string uri, string mimetype);
19
20+ private GLib.List<Tile?> cleanup_tiles = new GLib.List<Tile?> ();
21+ private uint cleanup_operation = 0;
22+
23 public DefaultRendererGroup (uint group_id,
24 string group_renderer,
25 string display_name,
26@@ -266,8 +269,18 @@
27
28 Tile button;
29
30-
31- if (group_renderer == "UnityFileInfoRenderer")
32+ if (cleanup_tiles.length () > 0)
33+ {
34+ button = cleanup_tiles.nth_data (0);
35+ button.update_details (results.get_string (iter, 0),
36+ results.get_string (iter, 1),
37+ results.get_string (iter, 3),
38+ results.get_string (iter, 4),
39+ results.get_string (iter, 5));
40+ button.iter = iter;
41+ cleanup_tiles.remove (button);
42+ }
43+ else if (group_renderer == "UnityFileInfoRenderer")
44 {
45 button = new FileInfoTile (iter,
46 results.get_string (iter, 0),
47@@ -275,6 +288,11 @@
48 results.get_string (iter, 3),
49 results.get_string (iter, 4),
50 results.get_string (iter, 5));
51+
52+ renderer.add_actor (button);
53+ button.show ();
54+ button.unref (); /* Because Vala sucks and holds references when it shouldn't*/;
55+ button.activated.connect ((u, m) => { activated (u, m); });
56 }
57 else if (group_renderer == "UnityShowcaseRenderer")
58 {
59@@ -284,6 +302,11 @@
60 results.get_string (iter, 3),
61 results.get_string (iter, 4),
62 results.get_string (iter, 5));
63+ renderer.add_actor (button);
64+ button.show ();
65+ button.unref (); /* Because Vala sucks and holds references when it shouldn't*/;
66+
67+ button.activated.connect ((u, m) => { activated (u, m); });
68 }
69 else
70 {
71@@ -293,18 +316,18 @@
72 results.get_string (iter, 3),
73 results.get_string (iter, 4),
74 results.get_string (iter, 5));
75+ renderer.add_actor (button);
76+ button.show ();
77+ button.unref (); /* Because Vala sucks and holds references when it shouldn't*/;
78+
79+ button.activated.connect ((u, m) => { activated (u, m); });
80 }
81- renderer.add_actor (button);
82- button.show ();
83- button.unref (); /* Because Vala sucks and holds references when it shouldn't*/;
84
85 if (bin_state == ExpandingBinState.EXPANDED || _always_expanded)
86 {
87 button.about_to_show ();
88 }
89
90- button.activated.connect ((u, m) => { activated (u, m); });
91-
92 add_to_n_results (1);
93
94 if (bin_state == ExpandingBinState.CLOSED)
95@@ -319,6 +342,20 @@
96 dirty = true;
97 }
98
99+ private bool cleanup_operation_callback ()
100+ {
101+ foreach (Tile? tile in cleanup_tiles)
102+ {
103+ renderer.remove_actor (tile);
104+ }
105+
106+ cleanup_tiles = null;
107+ cleanup_tiles = new GLib.List<Tile?> ();
108+
109+ cleanup_operation = 0;
110+ return false;
111+ }
112+
113 private void on_result_removed (Dee.ModelIter iter)
114 {
115 if (!interesting (iter))
116@@ -331,7 +368,10 @@
117
118 if (tile.iter == iter)
119 {
120- renderer.remove_actor (tile);
121+ cleanup_tiles.append (tile);
122+ if (cleanup_operation == 0)
123+ cleanup_operation = Timeout.add (200, cleanup_operation_callback);
124+
125 add_to_n_results (-1);
126 break;
127 }
128
129=== modified file 'unity-private/places/places-default-renderer-tiles.vala'
130--- unity-private/places/places-default-renderer-tiles.vala 2010-09-03 00:06:44 +0000
131+++ unity-private/places/places-default-renderer-tiles.vala 2010-09-03 00:06:44 +0000
132@@ -27,17 +27,22 @@
133
134 static const string DEFAULT_ICON = "text-x-preview";
135
136- public unowned Dee.ModelIter iter { get; construct; }
137+ public unowned Dee.ModelIter iter { get; construct set; }
138
139- public string display_name { get; construct; }
140- public string? icon_hint { get; construct; }
141- public string uri { get; construct; }
142- public string? mimetype { get; construct; }
143- public string? comment { get; construct; }
144+ public string display_name { get; construct set; }
145+ public string? icon_hint { get; construct set; }
146+ public string uri { get; construct set; }
147+ public string? mimetype { get; construct set; }
148+ public string? comment { get; construct set; }
149
150 public signal void activated (string uri, string mimetype);
151
152 public abstract void about_to_show ();
153+ public abstract void update_details (string uri,
154+ string? icon_hint,
155+ string? mimetype,
156+ string display_name,
157+ string? comment);
158 }
159
160 public class FileInfoTile : Tile
161@@ -92,6 +97,24 @@
162 nwidth = 210.0f;
163 }
164
165+ public override void update_details (string uri,
166+ string? icon_hint,
167+ string? mimetype,
168+ string display_name,
169+ string? comment)
170+ {
171+ this.display_name = display_name;
172+ this.icon_hint = icon_hint;
173+ this.uri = uri;
174+ this.mimetype = mimetype;
175+ this.comment = comment;
176+
177+ if (shown == false)
178+ return;
179+
180+ update_details_real ();
181+ }
182+
183 public override void about_to_show ()
184 {
185 if (shown)
186@@ -141,40 +164,42 @@
187 }
188 });
189
190- Timeout.add (0, () => {
191-
192- leaf.text = display_name;
193-
194- /* Set the parent directory */
195- var file = File.new_for_uri (uri);
196- if (file is File)
197- {
198- var parent = file.get_parent ();
199- if (parent is File)
200- {
201- folder.text = parent.get_basename ();
202- folder_button.clicked.connect (() => {
203- try {
204- activated (parent.get_uri (), "inode/directory");
205-
206- } catch (Error e) {
207- warning (@"Unable to launch parent folder: $(e.message)");
208- }
209- });
210- }
211- else
212- folder.text = "";
213- }
214- else
215- folder.text = "";
216-
217- set_icon ();
218- return false;
219- });
220-
221+ Timeout.add (0, update_details_real);
222 queue_relayout ();
223 }
224
225+ private bool update_details_real ()
226+ {
227+ leaf.text = display_name;
228+
229+ /* Set the parent directory */
230+ var file = File.new_for_uri (uri);
231+ if (file is File)
232+ {
233+ var parent = file.get_parent ();
234+ if (parent is File)
235+ {
236+ folder.text = parent.get_basename ();
237+ folder_button.clicked.connect (() => {
238+ try {
239+ activated (parent.get_uri (), "inode/directory");
240+
241+ } catch (Error e) {
242+ warning (@"Unable to launch parent folder: $(e.message)");
243+ }
244+ });
245+ }
246+ else
247+ folder.text = "";
248+ }
249+ else
250+ folder.text = "";
251+
252+ set_icon ();
253+
254+ return false;
255+ }
256+
257 private override void clicked ()
258 {
259 activated (uri, mimetype);
260@@ -371,6 +396,25 @@
261 });
262 }
263
264+ public override void update_details (string uri,
265+ string? icon_hint,
266+ string? mimetype,
267+ string display_name,
268+ string? comment)
269+ {
270+ this.display_name = display_name;
271+ this.icon_hint = icon_hint;
272+ this.uri = uri;
273+ this.mimetype = mimetype;
274+ this.comment = comment;
275+
276+ if (shown == false)
277+ return;
278+
279+ set_label (display_name);
280+ set_icon ();
281+ }
282+
283 private override void get_preferred_width (float for_height,
284 out float mwidth,
285 out float nwidth)
286@@ -456,7 +500,24 @@
287 });
288 }
289
290- private override void get_preferred_width (float for_height,
291+ public override void update_details (string uri,
292+ string? icon_hint,
293+ string? mimetype,
294+ string display_name,
295+ string? comment)
296+ {
297+ this.display_name = display_name;
298+ this.icon_hint = icon_hint;
299+ this.uri = uri;
300+ this.mimetype = mimetype;
301+ this.comment = comment;
302+
303+ if (shown == false)
304+ return;
305+
306+ set_label (display_name);
307+ set_icon ();
308+ } private override void get_preferred_width (float for_height,
309 out float mwidth,
310 out float nwidth)
311 {