Merge lp:~unity-team/unity/browse-in-nautilus into lp:unity

Proposed by Mikkel Kamstrup Erlandsen
Status: Merged
Approved by: Neil J. Patel
Approved revision: no longer in the source branch.
Merged at revision: 509
Proposed branch: lp:~unity-team/unity/browse-in-nautilus
Merge into: lp:unity
Diff against target: 332 lines (+272/-2)
4 files modified
unity-private/Makefile.am (+1/-0)
unity-private/places/places-place-search-bar.vala (+48/-1)
unity-private/places/places-place-search-extra-action.vala (+220/-0)
unity-private/places/places-place.vala (+3/-1)
To merge this branch: bzr merge lp:~unity-team/unity/browse-in-nautilus
Reviewer Review Type Date Requested Status
Neil J. Patel Pending
Review via email: mp+35658@code.launchpad.net

Description of the change

Please note the FIXME at the bottom here. Also note that you'll need latest lp:unity-place-files and lp:unity-asset-pool in order to test this:

Adds support for the UnityExtraAction hint. Which can be used for place daemons to register a small icon that launches some extra feature for the currently displayed dataset.

In particular this is used by the files daemon to show a small "Browse current folder in Nautilus" button when in folder browsing mode.

NJPATEL FIXME: The ExtraAction widget which I am are packing in the search bar needs to be right aligned. I could not figure out how to do that.

To post a comment you must log in.
Revision history for this message
Neil J. Patel (njpatel) wrote :

Approved pending the inclusion of the hide_unity call

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'unity-private/Makefile.am'
2--- unity-private/Makefile.am 2010-09-13 15:09:55 +0000
3+++ unity-private/Makefile.am 2010-09-16 14:37:48 +0000
4@@ -107,6 +107,7 @@
5 places/places-place.vala \
6 places/places-place-search-bar.vala \
7 places/places-place-search-entry.vala \
8+ places/places-place-search-extra-action.vala \
9 places/places-place-search-navigation.vala \
10 places/places-place-search-sections-bar.vala \
11 places/places-trash-controller.vala \
12
13=== modified file 'unity-private/places/places-place-search-bar.vala'
14--- unity-private/places/places-place-search-bar.vala 2010-09-13 22:00:38 +0000
15+++ unity-private/places/places-place-search-bar.vala 2010-09-16 14:37:48 +0000
16@@ -32,6 +32,7 @@
17 private PlaceSearchNavigation navigation;
18 public PlaceSearchEntry entry;
19 public PlaceSearchSectionsBar sections;
20+ public PlaceSearchExtraAction extra_action;
21
22 public PlaceSearchBar ()
23 {
24@@ -63,7 +64,17 @@
25
26 sections = new PlaceSearchSectionsBar ();
27 pack (sections, false, true);
28- entry.show ();
29+ sections.show ();
30+
31+ /* We need a dummy to be able to space the action label */
32+ var space = new Clutter.Rectangle.with_color ({255, 255, 255, 0});
33+ pack (space, true, true);
34+ space.show ();
35+
36+ extra_action = new PlaceSearchExtraAction ();
37+ pack (extra_action, false, true);
38+ extra_action.hide (); /* hidden by default */
39+ extra_action.activated.connect (on_extra_action_activated);
40
41 bg = new PlaceSearchBarBackground (navigation, entry);
42 set_background (bg);
43@@ -126,6 +137,30 @@
44 active_entry.set_search (text, hints);
45 }
46 }
47+
48+ private void on_extra_action_activated ()
49+ {
50+ if (active_entry is PlaceEntry)
51+ {
52+ /* The UnityExtraAction spec mandates that we send the special URI
53+ * "." when the extra action is triggered */
54+ ActivationStatus result = active_entry.parent.activate (".", "");
55+
56+ switch (result)
57+ {
58+ case ActivationStatus.ACTIVATED_SHOW_DASH:
59+ break;
60+ case ActivationStatus.NOT_ACTIVATED:
61+ case ActivationStatus.ACTIVATED_HIDE_DASH:
62+ case ActivationStatus.ACTIVATED_FALLBACK:
63+ global_shell.hide_unity ();
64+ break;
65+ default:
66+ warning ("Unexpected activation status: %u", result);
67+ break;
68+ }
69+ }
70+ }
71
72 /*
73 * Public Methods
74@@ -146,6 +181,18 @@
75 navigation.set_active_entry (entry);
76 this.entry.set_active_entry (entry);
77 this.entry.text.grab_key_focus ();
78+
79+ if (entry.hints != null)
80+ {
81+ if (entry.hints["UnityExtraAction"] != null)
82+ {
83+ extra_action.set_icon_from_gicon_string (
84+ entry.hints["UnityExtraAction"]);
85+ extra_action.show ();
86+ }
87+ else
88+ extra_action.hide ();
89+ }
90 }
91 }
92
93
94=== added file 'unity-private/places/places-place-search-extra-action.vala'
95--- unity-private/places/places-place-search-extra-action.vala 1970-01-01 00:00:00 +0000
96+++ unity-private/places/places-place-search-extra-action.vala 2010-09-16 14:37:48 +0000
97@@ -0,0 +1,220 @@
98+/*
99+ * Copyright (C) 2010 Canonical Ltd
100+ *
101+ * This program is free software: you can redistribute it and/or modify
102+ * it under the terms of the GNU General Public License version 3 as
103+ * published by the Free Software Foundation.
104+ *
105+ * This program is distributed in the hope that it will be useful,
106+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
107+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
108+ * GNU General Public License for more details.
109+ *
110+ * You should have received a copy of the GNU General Public License
111+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
112+ *
113+ * Authored by
114+ * Neil Jagdish Patel <neil.patel@canonical.com>
115+ * Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
116+ *
117+ */
118+
119+using Unity;
120+
121+namespace Unity.Places
122+{
123+ public class PlaceSearchExtraAction : Ctk.Bin
124+ {
125+ static const float PADDING = 4.0f;
126+
127+ private CairoCanvas bg;
128+ public Ctk.Image image;
129+ private Clutter.Color color;
130+ private Ctk.EffectGlow glow;
131+
132+ public float destroy_factor {
133+ get { return _destroy_factor; }
134+ set { _destroy_factor = value; queue_relayout (); }
135+ }
136+
137+ public float resize_factor {
138+ get { return _resize_factor; }
139+ set { _resize_factor = value; queue_relayout (); }
140+ }
141+
142+ public signal void activated ();
143+
144+ private float _destroy_factor = 1.0f;
145+ private float _resize_factor = 1.0f;
146+ private float _last_width = 0.0f;
147+ private float _resize_width = 0.0f;
148+
149+ public PlaceSearchExtraAction ()
150+ {
151+ Object (reactive:true);
152+ }
153+
154+ construct
155+ {
156+ color.alpha = 255;
157+
158+ padding = { PADDING, PADDING, PADDING, PADDING };
159+
160+ bg = new CairoCanvas (paint_bg);
161+ set_background (bg);
162+ bg.show ();
163+
164+ glow = new Ctk.EffectGlow ();
165+ glow.set_color ({ 255, 255, 255, 255 });
166+ glow.set_factor (1.0f);
167+ glow.set_margin (5);
168+ //add_effect (glow);
169+
170+ image = new Ctk.Image (22);
171+ add_actor (image);
172+ image.show ();
173+ }
174+
175+ public void set_icon_from_gicon_string (string icon_string)
176+ {
177+ PixbufCache.get_default ().set_image_from_gicon_string (image,
178+ icon_string,
179+ 22);
180+ glow.set_invalidate_effect_cache (true);
181+ }
182+
183+ private override void get_preferred_width (float for_height,
184+ out float min_width,
185+ out float nat_width)
186+ {
187+ float mw, nw;
188+
189+ base.get_preferred_width (for_height, out mw, out nw);
190+
191+ min_width = (mw + padding.right + padding.left) * _destroy_factor;
192+ nat_width = (nw + padding.right + padding.left) * _destroy_factor;
193+
194+ if (_last_width ==0.0f)
195+ _last_width = nat_width;
196+
197+ if (_last_width != nat_width && _resize_factor == 1.0)
198+ {
199+ _resize_factor = 0.0f;
200+ animate (Clutter.AnimationMode.EASE_OUT_QUAD, 100,
201+ "resize_factor", 1.0f);
202+
203+ _resize_width = _last_width;
204+ _last_width = nat_width;
205+ }
206+
207+ if (_resize_factor != 1.0f)
208+ {
209+ min_width = _resize_width + ((min_width - _resize_width) * _resize_factor);
210+ nat_width = _resize_width + ((nat_width - _resize_width) * _resize_factor);
211+ }
212+ }
213+
214+ private override bool enter_event (Clutter.Event e)
215+ {
216+ state = Ctk.ActorState.STATE_PRELIGHT;
217+ bg.update ();
218+ return true;
219+ }
220+
221+ private override bool leave_event (Clutter.Event e)
222+ {
223+ state = Ctk.ActorState.STATE_NORMAL;
224+ bg.update ();
225+ return true;
226+ }
227+
228+ private override bool button_press_event (Clutter.Event e)
229+ {
230+ state = Ctk.ActorState.STATE_SELECTED;
231+ bg.update ();
232+ return false;
233+ }
234+
235+ private override bool button_release_event (Clutter.Event e)
236+ {
237+ state = Ctk.ActorState.STATE_PRELIGHT;
238+ bg.update ();
239+ activated ();
240+ return false;
241+ }
242+
243+ private void paint_bg (Cairo.Context cr, int width, int height)
244+ {
245+ cr.set_operator (Cairo.Operator.CLEAR);
246+ cr.paint ();
247+
248+ cr.set_operator (Cairo.Operator.OVER);
249+ cr.set_line_width (1.5);
250+ cr.set_source_rgba (1.0, 1.0, 1.0, 0.0);
251+
252+ cr.translate (0.5, 0.5);
253+
254+ var x = 0;
255+ var y = 0;
256+ width -= 1;
257+ height -= 1;
258+ var radius = 10;
259+
260+ cr.move_to (x, y + radius);
261+ cr.curve_to (x, y,
262+ x, y,
263+ x + radius, y);
264+ cr.line_to (width - radius, y);
265+ cr.curve_to (width, y,
266+ width, y,
267+ width, y + radius);
268+ cr.line_to (width, height - radius);
269+ cr.curve_to (width, height,
270+ width, height,
271+ width - radius, height);
272+ cr.line_to (x + radius, height);
273+ cr.curve_to (x, height,
274+ x, height,
275+ x, height - radius);
276+ cr.close_path ();
277+
278+ if (state == Ctk.ActorState.STATE_SELECTED)
279+ {
280+ cr.set_source_rgba (1.0, 1.0, 1.0, 1.0);
281+ }
282+ else if (state == Ctk.ActorState.STATE_PRELIGHT)
283+ {
284+ var pattern = new Cairo.Surface.similar (cr.get_target (),
285+ Cairo.Content.COLOR_ALPHA,
286+ 4, 4);
287+ var context = new Cairo.Context (pattern);
288+
289+ context.set_operator (Cairo.Operator.CLEAR);
290+ context.paint ();
291+
292+ context.set_line_width (0.2);
293+ context.set_operator (Cairo.Operator.OVER);
294+ context.set_source_rgba (1.0, 1.0, 1.0, 0.85);
295+
296+ context.move_to (0, 0);
297+ context.line_to (4, 4);
298+
299+ context.stroke ();
300+
301+ var pat = new Cairo.Pattern.for_surface (pattern);
302+ pat.set_extend (Cairo.Extend.REPEAT);
303+ cr.set_source (pat);
304+ }
305+ else
306+ {
307+ cr.set_source_rgba (1.0, 1.0, 1.0, 0.0);
308+ }
309+
310+ cr.fill_preserve ();
311+
312+ cr.set_source_rgba (1.0, 1.0, 1.0,
313+ state == Ctk.ActorState.STATE_NORMAL ? 0.0 : 0.5);
314+ cr.stroke ();
315+ }
316+ }
317+}
318
319=== modified file 'unity-private/places/places-place.vala'
320--- unity-private/places/places-place.vala 2010-09-14 15:47:48 +0000
321+++ unity-private/places/places-place.vala 2010-09-16 14:37:48 +0000
322@@ -217,7 +217,9 @@
323 {
324 bool remote_activation = false;
325
326- if (uri_regex != null && uri_regex.match (uri))
327+ if (uri == ".")
328+ remote_activation = true;
329+ else if (uri_regex != null && uri_regex.match (uri))
330 remote_activation = true;
331 else if (mime_regex != null && mime_regex.match (mimetype))
332 remote_activation = true;