Merge lp:~victored/granite/utils into lp:~elementary-pantheon/granite/granite
- utils
- Merge into granite
Proposed by
Victor Martinez
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Merged at revision: | 356 | ||||||||
Proposed branch: | lp:~victored/granite/utils | ||||||||
Merge into: | lp:~elementary-pantheon/granite/granite | ||||||||
Diff against target: |
935 lines (+264/-250) 12 files modified
lib/CMakeLists.txt (+1/-0) lib/GtkPatch/AboutDialog.vala (+5/-21) lib/Widgets/AboutDialog.vala (+8/-15) lib/Widgets/CompositedWindow.vala (+8/-19) lib/Widgets/DecoratedWindow.vala (+10/-22) lib/Widgets/ModeButton.vala (+33/-61) lib/Widgets/PopOver.vala (+3/-10) lib/Widgets/SidebarPaned.vala (+59/-45) lib/Widgets/StatusBar.vala (+4/-21) lib/Widgets/ToolButtonWithMenu.vala (+3/-14) lib/Widgets/Utils.vala (+121/-0) lib/Widgets/Welcome.vala (+9/-22) |
||||||||
To merge this branch: | bzr merge lp:~victored/granite/utils | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Cody Garver (community) | Approve | ||
Review via email: mp+121113@code.launchpad.net |
Commit message
Description of the change
Move common code to Granite.
To post a comment you must log in.
lp:~victored/granite/utils
updated
- 365. By Victor Martinez
-
Fix typo
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'lib/CMakeLists.txt' |
2 | --- lib/CMakeLists.txt 2012-08-22 22:21:28 +0000 |
3 | +++ lib/CMakeLists.txt 2012-08-24 02:03:20 +0000 |
4 | @@ -61,6 +61,7 @@ |
5 | Services/System.vala |
6 | Services/Contractor.vala |
7 | Services/IconFactory.vala |
8 | + Widgets/Utils.vala |
9 | Widgets/WrapLabel.vala |
10 | Widgets/AboutDialog.vala |
11 | Widgets/ModeButton.vala |
12 | |
13 | === modified file 'lib/GtkPatch/AboutDialog.vala' |
14 | --- lib/GtkPatch/AboutDialog.vala 2012-07-29 21:12:08 +0000 |
15 | +++ lib/GtkPatch/AboutDialog.vala 2012-08-24 02:03:20 +0000 |
16 | @@ -235,11 +235,6 @@ |
17 | private Label website_url_label; |
18 | private Button close_button; |
19 | |
20 | - // Set the markup used for big text (program name and version) |
21 | - private const string BIG_TEXT_CSS = """ |
22 | - .h2 { font: open sans light 18; } |
23 | - """; |
24 | - |
25 | private const string STYLESHEET = """ |
26 | * { |
27 | -GtkDialog-action-area-border: 12px; |
28 | @@ -259,20 +254,9 @@ |
29 | deletable = false; // Hide the window's close button when possible |
30 | set_default_response(ResponseType.CANCEL); |
31 | |
32 | - var style_provider = new CssProvider (); |
33 | - |
34 | - try { |
35 | - style_provider.load_from_data (STYLESHEET, -1); |
36 | - } catch (Error e) { |
37 | - warning ("GraniteAboutDialog: %s. The widget will not look as intended.", e.message); |
38 | - } |
39 | - |
40 | - get_style_context().add_provider(style_provider, STYLE_PROVIDER_PRIORITY_APPLICATION); |
41 | - |
42 | - var title_css = new Gtk.CssProvider (); |
43 | - try { |
44 | - title_css.load_from_data (BIG_TEXT_CSS, -1); |
45 | - } catch (Error e) { warning (e.message); } |
46 | + |
47 | + Granite.Widgets.Utils.set_theming (this, STYLESHEET, null, |
48 | + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); |
49 | |
50 | // Set the default containers |
51 | Box content_area = (Box)get_content_area(); |
52 | @@ -304,8 +288,8 @@ |
53 | name_label.halign = Gtk.Align.START; |
54 | name_label.set_line_wrap(true); |
55 | name_label.set_selectable(true); |
56 | - name_label.get_style_context ().add_provider (title_css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); |
57 | - name_label.get_style_context ().add_class ("h2"); |
58 | + |
59 | + Granite.Widgets.Utils.apply_text_style_to_label (TextStyle.H2, name_label); |
60 | |
61 | copyright_label = new Label(""); |
62 | copyright_label.set_selectable(true); |
63 | |
64 | === modified file 'lib/Widgets/AboutDialog.vala' |
65 | --- lib/Widgets/AboutDialog.vala 2012-07-12 16:04:33 +0000 |
66 | +++ lib/Widgets/AboutDialog.vala 2012-08-24 02:03:20 +0000 |
67 | @@ -86,15 +86,6 @@ |
68 | { |
69 | Box action_area = (Box) get_action_area (); |
70 | |
71 | - /* help button style */ |
72 | - var help_button_style_provider = new CssProvider(); |
73 | - try { |
74 | - help_button_style_provider.load_from_data(HELP_BUTTON_STYLESHEET, -1); |
75 | - } |
76 | - catch (Error e) { |
77 | - warning ("%s. Some widgets will not look as intended", e.message); |
78 | - } |
79 | - |
80 | var draw_ref = new Gtk.Window (); |
81 | draw_ref.get_style_context ().add_class (STYLE_CLASS_CONTENT_VIEW_WINDOW); |
82 | |
83 | @@ -114,11 +105,13 @@ |
84 | this.get_content_area ().margin_bottom = 3; |
85 | |
86 | /* help button */ |
87 | - help_button = new Button.with_label("?"); |
88 | - help_button.get_style_context ().add_class ("help_button"); |
89 | - help_button.get_style_context ().add_provider (help_button_style_provider, STYLE_PROVIDER_PRIORITY_APPLICATION); |
90 | + help_button = new Button.with_label ("?"); |
91 | + |
92 | + Utils.set_theming (help_button, HELP_BUTTON_STYLESHEET, "help_button", |
93 | + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); |
94 | + |
95 | help_button.halign = Gtk.Align.CENTER; |
96 | - help_button.pressed.connect(() => { activate_link(help); }); |
97 | + help_button.clicked.connect (() => { activate_link(help); }); |
98 | |
99 | /* Circular help button */ |
100 | help_button.size_allocate.connect ( (alloc) => { |
101 | @@ -131,12 +124,12 @@ |
102 | |
103 | /* translate button */ |
104 | translate_button = new Button.with_label(_("Translate This App")); |
105 | - translate_button.pressed.connect ( () => { activate_link(translate); }); |
106 | + translate_button.clicked.connect ( () => { activate_link(translate); }); |
107 | action_area.pack_start (translate_button, false, false, 0); |
108 | |
109 | /* bug button */ |
110 | bug_button = new Button.with_label (_("Report a Problem")); |
111 | - bug_button.pressed.connect (() => { |
112 | + bug_button.clicked.connect (() => { |
113 | try { |
114 | GLib.Process.spawn_command_line_async ("apport-bug %i".printf (Posix.getpid ())); |
115 | } catch (Error e) { |
116 | |
117 | === modified file 'lib/Widgets/CompositedWindow.vala' |
118 | --- lib/Widgets/CompositedWindow.vala 2012-01-25 02:39:54 +0000 |
119 | +++ lib/Widgets/CompositedWindow.vala 2012-08-24 02:03:20 +0000 |
120 | @@ -22,31 +22,20 @@ |
121 | |
122 | public class CompositedWindow : Gtk.Window, Gtk.Buildable { |
123 | |
124 | - private CssProvider style_provider; |
125 | - |
126 | - private const string COMPOSITED_WINDOW_STYLESHEET = """ |
127 | - .composited { |
128 | - background-color: rgba (0, 0, 0, 0.0); |
129 | - } |
130 | - """; |
131 | + private const string STYLESHEET = |
132 | + ".composited { background-color: rgba (0,0,0,0); }"; |
133 | |
134 | construct { |
135 | - |
136 | - // Set up css provider |
137 | - style_provider = new CssProvider (); |
138 | - try { |
139 | - style_provider.load_from_data (COMPOSITED_WINDOW_STYLESHEET, -1); |
140 | - } catch (Error e) { |
141 | - warning ("GraniteWidgetsCompositedWindow: %s", e.message); |
142 | - } |
143 | - |
144 | // Window properties |
145 | - set_visual (get_screen ().get_rgba_visual()); |
146 | - get_style_context().add_class("composited"); |
147 | - get_style_context ().add_provider (style_provider, 600); |
148 | app_paintable = true; |
149 | decorated = false; |
150 | resizable = false; |
151 | + |
152 | + set_visual (get_screen ().get_rgba_visual()); |
153 | + |
154 | + // Set up css provider |
155 | + Utils.set_theming (this, STYLESHEET, "composited", |
156 | + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); |
157 | } |
158 | } |
159 | } |
160 | |
161 | === modified file 'lib/Widgets/DecoratedWindow.vala' |
162 | --- lib/Widgets/DecoratedWindow.vala 2012-07-07 06:28:43 +0000 |
163 | +++ lib/Widgets/DecoratedWindow.vala 2012-08-24 02:03:20 +0000 |
164 | @@ -22,12 +22,9 @@ |
165 | |
166 | namespace Granite.Widgets { |
167 | |
168 | - [CCode (cname="get_close_pixbuf")] |
169 | - public extern Gdk.Pixbuf get_close_pixbuf (); |
170 | - |
171 | public class DecoratedWindow : CompositedWindow { |
172 | |
173 | - static const string DECORATED_WINDOW_FALLBACK_STYLESHEET = """ |
174 | + const string DECORATED_WINDOW_FALLBACK_STYLESHEET = """ |
175 | .decorated-window { |
176 | border-style:solid; |
177 | border-color:alpha (#000, 0.35); |
178 | @@ -38,27 +35,18 @@ |
179 | """; |
180 | |
181 | // Currently not overridable |
182 | - static const string DECORATED_WINDOW_STYLESHEET = """ |
183 | + const string DECORATED_WINDOW_STYLESHEET = """ |
184 | .decorated-window { border-width:1px; } |
185 | """; |
186 | |
187 | public static void set_default_theming (Gtk.Window ref_window) { |
188 | - var normal_style = new Gtk.CssProvider (); |
189 | - var fallback_style = new Gtk.CssProvider (); |
190 | - |
191 | - try { |
192 | - normal_style.load_from_data (DECORATED_WINDOW_STYLESHEET, -1); |
193 | - fallback_style.load_from_data (DECORATED_WINDOW_FALLBACK_STYLESHEET, -1); |
194 | - } catch (Error e) { |
195 | - warning (e.message); |
196 | - } |
197 | - |
198 | - ref_window.get_style_context ().add_class (STYLE_CLASS_DECORATED_WINDOW); |
199 | - |
200 | - ref_window.get_style_context ().add_provider (normal_style, |
201 | - Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); |
202 | - ref_window.get_style_context ().add_provider (fallback_style, |
203 | - Gtk.STYLE_PROVIDER_PRIORITY_FALLBACK); |
204 | + Utils.set_theming (ref_window, DECORATED_WINDOW_STYLESHEET, |
205 | + STYLE_CLASS_DECORATED_WINDOW, |
206 | + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); |
207 | + |
208 | + Utils.set_theming (ref_window, DECORATED_WINDOW_FALLBACK_STYLESHEET, |
209 | + STYLE_CLASS_DECORATED_WINDOW, |
210 | + Gtk.STYLE_PROVIDER_PRIORITY_FALLBACK); |
211 | } |
212 | |
213 | public bool show_title { get; set; default = true; } |
214 | @@ -88,7 +76,7 @@ |
215 | this.has_resize_grip = false; |
216 | this.window_position = Gtk.WindowPosition.CENTER_ON_PARENT; |
217 | |
218 | - this.close_img = get_close_pixbuf (); |
219 | + this.close_img = Utils.get_close_pixbuf (); |
220 | |
221 | this._title = new Gtk.Label (null); |
222 | this._title.halign = Gtk.Align.CENTER; |
223 | |
224 | === modified file 'lib/Widgets/ModeButton.vala' |
225 | --- lib/Widgets/ModeButton.vala 2012-02-13 03:41:28 +0000 |
226 | +++ lib/Widgets/ModeButton.vala 2012-08-24 02:03:20 +0000 |
227 | @@ -23,18 +23,22 @@ |
228 | |
229 | public class ModeButton : Gtk.Box { |
230 | |
231 | + private class Item : Gtk.ToggleButton { |
232 | + public Item () { |
233 | + can_focus = false; |
234 | + Utils.set_theming (this, ModeButton.STYLESHEET, "raised", |
235 | + ModeButton.STYLE_PRIORITY); |
236 | + } |
237 | + } |
238 | + |
239 | public signal void mode_added (int index, Gtk.Widget widget); |
240 | public signal void mode_removed (int index, Gtk.Widget widget); |
241 | public signal void mode_changed (Gtk.Widget widget); |
242 | |
243 | - // Style properties. Please note that style class names are for internal |
244 | - // use only. Theme developers should use GraniteWidgetsModeButton instead. |
245 | - internal static CssProvider style_provider; |
246 | - internal static StyleContext widget_style; |
247 | - private const int style_priority = Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION; |
248 | + private const int STYLE_PRIORITY = Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION; |
249 | |
250 | private const string STYLESHEET = """ |
251 | - .GraniteModeButton .button { |
252 | + .mode-button .button { |
253 | -GtkToolbar-button-relief: normal; |
254 | border-radius: 0 0 0 0; |
255 | border-style: solid; |
256 | @@ -44,19 +48,19 @@ |
257 | -unico-outer-stroke-radius: 0 0 0 0; |
258 | } |
259 | |
260 | - .GraniteModeButton .button:active, |
261 | - .GraniteModeButton .button:insensitive { |
262 | + .mode-button .button:active, |
263 | + .mode-button .button:insensitive { |
264 | -unico-outer-stroke-width: 1px 0 1px 0; |
265 | } |
266 | |
267 | - .GraniteModeButton .button:first-child { |
268 | + .mode-button .button:first-child { |
269 | border-radius: 3px 0 0 3px; |
270 | border-width: 1px 0 1px 1px; |
271 | |
272 | -unico-outer-stroke-width: 1px 0 1px 1px; |
273 | } |
274 | |
275 | - .GraniteModeButton .button:last-child { |
276 | + .mode-button .button:last-child { |
277 | border-radius: 0 3px 3px 0; |
278 | border-width: 1px; |
279 | |
280 | @@ -82,44 +86,22 @@ |
281 | } |
282 | |
283 | public ModeButton () { |
284 | - |
285 | - if (style_provider == null) |
286 | - { |
287 | - style_provider = new CssProvider (); |
288 | - try { |
289 | - style_provider.load_from_data (STYLESHEET, -1); |
290 | - } catch (Error e) { |
291 | - warning ("GraniteModeButton: %s. The widget will not look as intended", e.message); |
292 | - } |
293 | - } |
294 | - |
295 | - widget_style = get_style_context (); |
296 | - widget_style.add_class ("GraniteModeButton"); |
297 | + Utils.set_theming (this, STYLESHEET, "mode-button", STYLE_PRIORITY); |
298 | + |
299 | + set_visual (get_screen ().get_rgba_visual ()); |
300 | |
301 | homogeneous = true; |
302 | spacing = 0; |
303 | app_paintable = true; |
304 | - set_visual (get_screen ().get_rgba_visual ()); |
305 | - |
306 | can_focus = true; |
307 | } |
308 | |
309 | - public int append_pixbuf (Gdk.Pixbuf? pixbuf) { |
310 | - if (pixbuf == null) { |
311 | - warning ("GraniteWidgetsModeButton: Attempt to add null pixbuf failed."); |
312 | - return -1; |
313 | - } |
314 | - |
315 | + public int append_pixbuf (Gdk.Pixbuf pixbuf) { |
316 | var image = new Image.from_pixbuf (pixbuf); |
317 | return append (image); |
318 | } |
319 | |
320 | - public int append_text (string? text) { |
321 | - if (text == null) { |
322 | - warning ("GraniteWidgetsModeButton: Attempt to add null text string failed."); |
323 | - return -1; |
324 | - } |
325 | - |
326 | + public int append_text (string text) { |
327 | return append (new Gtk.Label(text)); |
328 | } |
329 | |
330 | @@ -134,12 +116,9 @@ |
331 | } |
332 | |
333 | public int append (Gtk.Widget w) { |
334 | - if (w == null) { |
335 | - warning ("GraniteWidgetsModeButton: Attempt to add null widget failed."); |
336 | - return -1; |
337 | - } |
338 | - |
339 | - var button = new ModeButtonItem (); |
340 | + var button = new Item (); |
341 | + button.add_events (Gdk.EventMask.SCROLL_MASK); |
342 | + button.scroll_event.connect (on_scroll_event); |
343 | |
344 | button.add (w); |
345 | |
346 | @@ -152,7 +131,7 @@ |
347 | add (button); |
348 | button.show_all (); |
349 | |
350 | - int item_index = (int)get_children ().length (); |
351 | + int item_index = (int)get_children ().length () - 1; |
352 | mode_added (item_index, w); // Emit the added signal |
353 | return item_index; |
354 | } |
355 | @@ -194,27 +173,20 @@ |
356 | _selected = -1; |
357 | } |
358 | |
359 | - protected override bool scroll_event (EventScroll ev) { |
360 | - if (ev.direction == Gdk.ScrollDirection.DOWN) { |
361 | - selected ++; |
362 | - } |
363 | - else if (ev.direction == Gdk.ScrollDirection.UP) { |
364 | - selected --; |
365 | + private bool on_scroll_event (Gtk.Widget widget, Gdk.EventScroll ev) { |
366 | + switch (ev.direction) { |
367 | + case Gdk.ScrollDirection.DOWN: |
368 | + case Gdk.ScrollDirection.RIGHT: |
369 | + selected ++; |
370 | + break; |
371 | + case Gdk.ScrollDirection.UP: |
372 | + case Gdk.ScrollDirection.LEFT: |
373 | + selected --; |
374 | + break; |
375 | } |
376 | |
377 | return false; |
378 | } |
379 | } |
380 | - |
381 | - private class ModeButtonItem : Gtk.ToggleButton { |
382 | - public ModeButtonItem () { |
383 | - can_focus = false; |
384 | - |
385 | - const int style_priority = Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION; |
386 | - |
387 | - get_style_context ().add_class ("raised"); |
388 | - get_style_context ().add_provider (ModeButton.style_provider, style_priority); |
389 | - } |
390 | - } |
391 | } |
392 | |
393 | |
394 | === modified file 'lib/Widgets/PopOver.vala' |
395 | --- lib/Widgets/PopOver.vala 2012-08-17 21:18:22 +0000 |
396 | +++ lib/Widgets/PopOver.vala 2012-08-24 02:03:20 +0000 |
397 | @@ -47,7 +47,6 @@ |
398 | double offset = 15.0; |
399 | const int MARGIN = 12; |
400 | Gtk.Widget menu; |
401 | - static Gtk.CssProvider style_provider; |
402 | Gtk.Box hbox; |
403 | Gtk.Box abox; |
404 | |
405 | @@ -103,20 +102,14 @@ |
406 | } |
407 | |
408 | construct { |
409 | - // Set up css provider |
410 | - style_provider = new Gtk.CssProvider (); |
411 | - try { |
412 | - style_provider.load_from_data (POPOVER_STYLESHEET, -1); |
413 | - } catch (Error e) { |
414 | - warning ("GranitePopOver: %s. The widget will not look as intended.", e.message); |
415 | - } |
416 | - |
417 | // Window properties |
418 | set_visual (get_screen ().get_rgba_visual()); |
419 | |
420 | get_style_context ().add_class ("popover"); |
421 | get_style_context ().add_class ("composited"); |
422 | - get_style_context ().add_provider_for_screen (get_screen(), style_provider, 600); |
423 | + |
424 | + Utils.set_theming_for_screen (get_screen (), POPOVER_STYLESHEET, |
425 | + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); |
426 | |
427 | app_paintable = true; |
428 | decorated = false; |
429 | |
430 | === modified file 'lib/Widgets/SidebarPaned.vala' |
431 | --- lib/Widgets/SidebarPaned.vala 2012-08-16 00:20:46 +0000 |
432 | +++ lib/Widgets/SidebarPaned.vala 2012-08-24 02:03:20 +0000 |
433 | @@ -20,12 +20,12 @@ |
434 | * Authored by: Victor Eduardo <victoreduardm@gmail.com> |
435 | */ |
436 | |
437 | -public class Granite.Widgets.SidebarPaned : Gtk.Overlay, Gtk.Orientable { |
438 | +public class Granite.Widgets.SidebarPaned : Gtk.EventBox, Gtk.Orientable { |
439 | |
440 | protected Gtk.Paned paned { get; private set; } |
441 | - private Gtk.EventBox? handle = null; |
442 | + private Gtk.Overlay overlay; |
443 | + private Gtk.EventBox handle; |
444 | private bool on_resize_mode = false; |
445 | - private Gdk.Cursor? arrow_cursor = null; |
446 | |
447 | static const string STYLE_PROP_HANDLE_SIZE = "handle-size"; |
448 | |
449 | @@ -80,8 +80,17 @@ |
450 | this.paned.add2 (child); |
451 | } |
452 | |
453 | - public new void remove (Gtk.Widget child) { |
454 | - this.paned.remove (child); |
455 | + public new void remove (Gtk.Widget widget) { |
456 | + this.paned.remove (widget); |
457 | + } |
458 | + |
459 | + public new void add (Gtk.Widget widget) { |
460 | + if (get_child1 () == null) |
461 | + add1 (widget); |
462 | + else if (get_child2 () == null) |
463 | + add2 (widget); |
464 | + else |
465 | + critical ("Container supports a maximum of two children"); |
466 | } |
467 | |
468 | public unowned Gtk.Widget? get_child1 () { |
469 | @@ -96,6 +105,14 @@ |
470 | return this.handle.get_window (); |
471 | } |
472 | |
473 | + public new void foreach (Gtk.Callback callback) { |
474 | + this.paned.foreach (callback); |
475 | + } |
476 | + |
477 | + public new void forall (Gtk.Callback callback) { |
478 | + this.paned.forall (callback); |
479 | + } |
480 | + |
481 | public new void set_direction (Gtk.TextDirection dir) { |
482 | this.paned.set_direction (dir); |
483 | base.set_direction (dir); |
484 | @@ -106,15 +123,6 @@ |
485 | return this.paned.get_direction (); |
486 | } |
487 | |
488 | - public new void set_default_direction (Gtk.TextDirection dir) { |
489 | - base.set_default_direction (dir); |
490 | - this.paned.set_default_direction (dir); |
491 | - } |
492 | - |
493 | - public new Gtk.TextDirection get_default_direction () { |
494 | - return this.paned.get_default_direction (); |
495 | - } |
496 | - |
497 | public SidebarPaned () { |
498 | this.paned.get_style_context ().add_class ("sidebar-pane-separator"); |
499 | |
500 | @@ -131,8 +139,10 @@ |
501 | } |
502 | """; |
503 | |
504 | - set_theming (this.paned, DEFAULT_STYLESHEET, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); |
505 | - set_theming (this.paned, FALLBACK_STYLESHEET, Gtk.STYLE_PROVIDER_PRIORITY_THEME); |
506 | + Utils.set_theming (this.paned, DEFAULT_STYLESHEET, "", |
507 | + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); |
508 | + Utils.set_theming (this.paned, FALLBACK_STYLESHEET, "", |
509 | + Gtk.STYLE_PROVIDER_PRIORITY_THEME); |
510 | } |
511 | |
512 | |
513 | @@ -142,19 +152,25 @@ |
514 | |
515 | construct { |
516 | push_composite_child (); |
517 | + this.overlay = new Gtk.Overlay (); |
518 | + this.overlay.set_composite_name ("overlay"); |
519 | + pop_composite_child (); |
520 | + |
521 | + push_composite_child (); |
522 | this.paned = new Gtk.Paned (Gtk.Orientation.HORIZONTAL); |
523 | this.paned.set_composite_name ("paned"); |
524 | pop_composite_child (); |
525 | |
526 | this.paned.expand = true; |
527 | |
528 | - this.add (this.paned); |
529 | - |
530 | Gdk.RGBA transparent = { 0.0, 0.0, 0.0, 0.0 }; |
531 | - this.override_background_color (0, transparent); |
532 | + overlay.override_background_color (0, transparent); |
533 | |
534 | setup_handle (); |
535 | |
536 | + this.overlay.add (this.paned); |
537 | + base.add (this.overlay); |
538 | + |
539 | this.paned.size_allocate.connect_after (on_paned_size_allocate); |
540 | |
541 | // The virtual handle will always follow the paned's position |
542 | @@ -181,7 +197,7 @@ |
543 | Gdk.RGBA transparent = { 0.0, 0.0, 0.0, 0.0 }; |
544 | this.handle.override_background_color (0, transparent); |
545 | |
546 | - this.add_overlay (handle); |
547 | + overlay.add_overlay (handle); |
548 | |
549 | this.handle.add_events (Gdk.EventMask.BUTTON_PRESS_MASK |
550 | | Gdk.EventMask.BUTTON_RELEASE_MASK); |
551 | @@ -189,29 +205,21 @@ |
552 | this.handle.button_press_event.connect (on_handle_button_press); |
553 | this.handle.button_release_event.connect (on_handle_button_release); |
554 | this.handle.grab_broken_event.connect (on_handle_grab_broken); |
555 | - this.handle.realize.connect (set_arrow_cursor); |
556 | - } |
557 | - |
558 | - protected static void set_theming (Gtk.Widget widget, string stylesheet, int priority) { |
559 | - var css_provider = new Gtk.CssProvider (); |
560 | - |
561 | - try { |
562 | - css_provider.load_from_data (stylesheet, -1); |
563 | - } |
564 | - catch (Error e) { |
565 | - warning (e.message); |
566 | - return_if_reached (); |
567 | - } |
568 | - |
569 | - widget.get_style_context ().add_provider (css_provider, priority); |
570 | + this.handle.realize.connect (set_handle_cursor); |
571 | } |
572 | |
573 | public override bool motion_notify_event (Gdk.EventMotion e) { |
574 | var device = e.device ?? Gtk.get_current_event_device (); |
575 | |
576 | if (device == null) { |
577 | - var dev_manager = this.paned.get_display ().get_device_manager (); |
578 | - device = dev_manager.list_devices (Gdk.DeviceType.MASTER).nth_data (0); |
579 | + var display = this.paned.get_display (); |
580 | + |
581 | + if (display != null) { |
582 | + var dev_manager = display.get_device_manager (); |
583 | + |
584 | + if (dev_manager != null) |
585 | + device = dev_manager.list_devices (Gdk.DeviceType.MASTER).nth_data (0); |
586 | + } |
587 | } |
588 | |
589 | if (this.on_resize_mode && device != null) { |
590 | @@ -222,7 +230,7 @@ |
591 | window.get_device_position (device, out x, out y, null); |
592 | |
593 | if (this.orientation == Gtk.Orientation.HORIZONTAL) |
594 | - pos = is_ltr() ? x : this.paned.get_allocated_width() - x; |
595 | + pos = is_ltr () ? x : this.paned.get_allocated_width () - x; |
596 | else |
597 | pos = y; |
598 | |
599 | @@ -239,8 +247,10 @@ |
600 | |
601 | private bool is_ltr () { |
602 | var dir = get_direction (); |
603 | + |
604 | if (dir == Gtk.TextDirection.NONE) |
605 | dir = get_default_direction (); |
606 | + |
607 | return dir == Gtk.TextDirection.LTR; |
608 | } |
609 | |
610 | @@ -253,12 +263,10 @@ |
611 | this.handle.set_size_request (0, 0); |
612 | |
613 | if (horizontal) { |
614 | - this.arrow_cursor = new Gdk.Cursor (Gdk.CursorType.SB_H_DOUBLE_ARROW); |
615 | this.handle.margin_top = this.handle.margin_bottom = 0; |
616 | this.handle.halign = Gtk.Align.START; |
617 | this.handle.valign = Gtk.Align.FILL; |
618 | } else { |
619 | - this.arrow_cursor = new Gdk.Cursor (Gdk.CursorType.SB_V_DOUBLE_ARROW); |
620 | this.handle.margin_left = this.handle.margin_right = 0; |
621 | this.handle.halign = Gtk.Align.FILL; |
622 | this.handle.valign = Gtk.Align.START; |
623 | @@ -268,7 +276,7 @@ |
624 | update_virtual_handle_position (); |
625 | |
626 | // Update cursor. |
627 | - set_arrow_cursor (); |
628 | + set_handle_cursor (); |
629 | } |
630 | |
631 | private void on_paned_size_allocate () { |
632 | @@ -303,10 +311,16 @@ |
633 | } |
634 | } |
635 | |
636 | - private void set_arrow_cursor () { |
637 | - var window = this.handle.get_window (); |
638 | - if (window != null && window.get_cursor () != this.arrow_cursor) |
639 | - window.set_cursor (this.arrow_cursor); |
640 | + private void set_handle_cursor () { |
641 | + Gdk.Cursor? arrow_cursor = null; |
642 | + |
643 | + var paned_handle_window = this.paned.get_handle_window (); |
644 | + if (paned_handle_window != null) |
645 | + arrow_cursor = paned_handle_window.get_cursor (); |
646 | + |
647 | + var handle_window = this.handle.get_window (); |
648 | + if (handle_window != null && handle_window.get_cursor () != arrow_cursor) |
649 | + handle_window.set_cursor (arrow_cursor); |
650 | } |
651 | |
652 | /** |
653 | |
654 | === modified file 'lib/Widgets/StatusBar.vala' |
655 | --- lib/Widgets/StatusBar.vala 2012-05-07 21:00:33 +0000 |
656 | +++ lib/Widgets/StatusBar.vala 2012-08-24 02:03:20 +0000 |
657 | @@ -28,11 +28,8 @@ |
658 | |
659 | protected const int ITEM_SPACING = 3; |
660 | |
661 | - protected Gtk.CssProvider style_provider; |
662 | - protected Gtk.StyleContext context; |
663 | - |
664 | /* This prevents the huge vertical padding */ |
665 | - private const string STATUSBAR_STYLESHEET = """ |
666 | + private const string STYLESHEET = """ |
667 | GraniteWidgetsStatusBar { |
668 | border-bottom-width: 0; |
669 | border-right-width: 0; |
670 | @@ -45,23 +42,14 @@ |
671 | """; |
672 | |
673 | public StatusBar () { |
674 | - |
675 | - style_provider = new Gtk.CssProvider (); |
676 | - |
677 | - try { |
678 | - style_provider.load_from_data (STATUSBAR_STYLESHEET, -1); |
679 | - } |
680 | - catch (Error err) { |
681 | - warning (err.message); |
682 | - } |
683 | - |
684 | /* Get rid of the "toolbar" class to avoid inheriting its style. |
685 | * We want the widget to look more like a normal statusbar. |
686 | */ |
687 | get_style_context ().remove_class (Gtk.STYLE_CLASS_TOOLBAR); |
688 | |
689 | - context = new Gtk.StyleContext (); |
690 | - context.add_provider_for_screen (get_screen (), style_provider, Gtk.STYLE_PROVIDER_PRIORITY_THEME); |
691 | + Utils.set_theming_for_screen (this.get_screen (), STYLESHEET, |
692 | + Gtk.STYLE_PROVIDER_PRIORITY_THEME); |
693 | + |
694 | |
695 | status_label = new Gtk.Label (""); |
696 | status_label.set_justify (Gtk.Justification.CENTER); |
697 | @@ -95,11 +83,6 @@ |
698 | } |
699 | |
700 | public void set_text (string text) { |
701 | - if (text == null) { |
702 | - status_label.set_text (""); |
703 | - return; |
704 | - } |
705 | - |
706 | status_label.set_text (text); |
707 | } |
708 | } |
709 | |
710 | === modified file 'lib/Widgets/ToolButtonWithMenu.vala' |
711 | --- lib/Widgets/ToolButtonWithMenu.vala 2012-01-25 08:19:48 +0000 |
712 | +++ lib/Widgets/ToolButtonWithMenu.vala 2012-08-24 02:03:20 +0000 |
713 | @@ -286,20 +286,9 @@ |
714 | |
715 | if (menu_position == MenuPosition.INSIDE_WINDOW) { |
716 | /* Get window geometry */ |
717 | - Gtk.Widget? parent_widget = get_parent (); |
718 | - Gtk.Widget? next_parent = parent_widget.get_parent (); |
719 | - |
720 | - while (true) { |
721 | - if (parent_widget != null && next_parent != null) { |
722 | - parent_widget = parent_widget.get_parent(); |
723 | - next_parent = parent_widget.get_parent(); |
724 | - } |
725 | - |
726 | - if (parent_widget == null || next_parent == null) |
727 | - break; |
728 | - } |
729 | - |
730 | - Allocation window_allocation; |
731 | + var parent_widget = get_toplevel (); |
732 | + |
733 | + Gtk.Allocation window_allocation; |
734 | parent_widget.get_allocation (out window_allocation); |
735 | |
736 | parent_widget.get_window ().get_origin (out x, out y); |
737 | |
738 | === added file 'lib/Widgets/Utils.vala' |
739 | --- lib/Widgets/Utils.vala 1970-01-01 00:00:00 +0000 |
740 | +++ lib/Widgets/Utils.vala 2012-08-24 02:03:20 +0000 |
741 | @@ -0,0 +1,121 @@ |
742 | +// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- |
743 | +/* |
744 | + * Copyright (c) 2012 Granite Developers |
745 | + * |
746 | + * This library is free software; you can redistribute it and/or |
747 | + * modify it under the terms of the GNU Lesser General Public License as |
748 | + * published by the Free Software Foundation; either version 2 of the |
749 | + * License, or (at your option) any later version. |
750 | + * |
751 | + * This is distributed in the hope that it will be useful, |
752 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
753 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
754 | + * Lesser General Public License for more details. |
755 | + * |
756 | + * You should have received a copy of the GNU Lesser General Public |
757 | + * License along with this program; see the file COPYING. If not, |
758 | + * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
759 | + * Boston, MA 02111-1307, USA. |
760 | + */ |
761 | + |
762 | +public enum Granite.TextStyle { |
763 | + TITLE, |
764 | + H1, |
765 | + H2, |
766 | + H3; |
767 | + |
768 | + public string get_stylesheet (out string style_class = null) { |
769 | + switch (this) { |
770 | + case TITLE: |
771 | + style_class = "title"; |
772 | + return @".$style_class { font: raleway 36; }"; |
773 | + case H1: |
774 | + style_class = "h1"; |
775 | + return @".$style_class { font: open sans bold 24; }"; |
776 | + case H2: |
777 | + style_class = "h2"; |
778 | + return @".$style_class { font: open sans light 18; }"; |
779 | + case H3: |
780 | + style_class = "h3"; |
781 | + return @".$style_class { font: open sans bold 12; }"; |
782 | + default: |
783 | + assert_not_reached (); |
784 | + } |
785 | + } |
786 | +} |
787 | + |
788 | +namespace Granite.Widgets.Utils { |
789 | + |
790 | + [CCode (cname="get_close_pixbuf")] |
791 | + public extern Gdk.Pixbuf get_close_pixbuf (); |
792 | + |
793 | + |
794 | + /** |
795 | + * Applies the stylesheet to the widget |
796 | + */ |
797 | + public void set_theming (Gtk.Widget widget, string stylesheet, |
798 | + string? class_name, int priority) { |
799 | + var css_provider = get_css_provider (stylesheet); |
800 | + |
801 | + var context = widget.get_style_context (); |
802 | + |
803 | + if (css_provider != null) |
804 | + context.add_provider (css_provider, priority); |
805 | + |
806 | + if (class_name != null && class_name.strip () != "") |
807 | + context.add_class (class_name); |
808 | + } |
809 | + |
810 | + /** |
811 | + * Applies a stylesheet to the given screen. This will affects all the |
812 | + * widgets which are part of that screen. |
813 | + */ |
814 | + public void set_theming_for_screen (Gdk.Screen screen, string stylesheet, int priority) { |
815 | + var provider = get_css_provider (stylesheet); |
816 | + |
817 | + if (provider != null) |
818 | + Gtk.StyleContext.add_provider_for_screen (screen, provider, priority); |
819 | + } |
820 | + |
821 | + /** |
822 | + * @return a new {@link Gtk.CssProvider}, or null in case the parsing of |
823 | + * @stylesheet failed. |
824 | + */ |
825 | + public Gtk.CssProvider? get_css_provider (string stylesheet) { |
826 | + Gtk.CssProvider provider = new Gtk.CssProvider (); |
827 | + |
828 | + try { |
829 | + provider.load_from_data (stylesheet, -1); |
830 | + } |
831 | + catch (Error e) { |
832 | + warning ("Could not create CSS Provider: %s\nStylesheet:\n%s", |
833 | + e.message, stylesheet); |
834 | + return null; |
835 | + } |
836 | + |
837 | + return provider; |
838 | + } |
839 | + |
840 | + |
841 | + /** |
842 | + * Text Style |
843 | + */ |
844 | + |
845 | + public void apply_text_style_to_label (TextStyle text_style, Gtk.Label label) { |
846 | + var style_provider = new Gtk.CssProvider (); |
847 | + var style_context = label.get_style_context (); |
848 | + |
849 | + string style_class, stylesheet; |
850 | + stylesheet = text_style.get_stylesheet (out style_class); |
851 | + style_context.add_class (style_class); |
852 | + |
853 | + try { |
854 | + style_provider.load_from_data (stylesheet, -1); |
855 | + } catch (Error err) { |
856 | + warning ("Couldn't apply style to label: %s", err.message); |
857 | + return; |
858 | + } |
859 | + |
860 | + style_context.add_provider (style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); |
861 | + } |
862 | +} |
863 | |
864 | === modified file 'lib/Widgets/Welcome.vala' |
865 | --- lib/Widgets/Welcome.vala 2012-03-18 23:07:11 +0000 |
866 | +++ lib/Widgets/Welcome.vala 2012-08-24 02:03:20 +0000 |
867 | @@ -30,10 +30,6 @@ |
868 | protected Gtk.Box options; |
869 | |
870 | public Welcome (string title_text, string subtitle_text) { |
871 | - string _title_text = title_text; |
872 | - string _subtitle_text = subtitle_text; |
873 | - _title_text = _title_text.replace("&", "&"); |
874 | - _subtitle_text = _subtitle_text.replace("&", "&"); |
875 | |
876 | Gtk.Box content = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); |
877 | |
878 | @@ -47,22 +43,20 @@ |
879 | content.pack_start (new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0), true, true, 0); |
880 | |
881 | // Labels |
882 | - var title = new Gtk.Label ("<span weight='medium' size='14700'>" + _title_text + "</span>"); |
883 | - |
884 | - title.get_style_context().add_class ("title"); |
885 | - |
886 | - title.use_markup = true; |
887 | + var title = new Gtk.Label (title_text); |
888 | + Utils.apply_text_style_to_label (TextStyle.H1, title); |
889 | + |
890 | title.set_justify (Gtk.Justification.CENTER); |
891 | content.pack_start (title, false, true, 0); |
892 | |
893 | - var subtitle = new Gtk.Label ("<span weight='medium' size='11500'>" + _subtitle_text + "</span>"); |
894 | - subtitle.use_markup = true; |
895 | + var subtitle = new Gtk.Label (subtitle_text); |
896 | + Utils.apply_text_style_to_label (TextStyle.H2, subtitle); |
897 | + |
898 | subtitle.sensitive = false; |
899 | subtitle.set_justify (Gtk.Justification.CENTER); |
900 | + |
901 | content.pack_start (subtitle, false, true, 2); |
902 | |
903 | - subtitle.get_style_context().add_class("subtitle"); |
904 | - |
905 | // Options wrapper |
906 | this.options = new Gtk.Box (Gtk.Orientation.VERTICAL, 8); |
907 | var options_wrapper = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); |
908 | @@ -110,25 +104,18 @@ |
909 | } |
910 | |
911 | public int append_with_image (Gtk.Image? image, string option_text, string description_text) { |
912 | - string _option_text = option_text; |
913 | - string _description_text = description_text; |
914 | - _option_text = _option_text.replace ("&", "&"); |
915 | - _description_text = _description_text.replace ("&", "&"); |
916 | - |
917 | // Option label |
918 | - var label = new Gtk.Label ("<span weight='medium' size='11700'>" + _option_text + "</span>"); |
919 | + var label = new Gtk.Label (Markup.printf_escaped ("<span weight='medium' size='11700'>%s</span>", option_text)); |
920 | label.use_markup = true; |
921 | label.halign = Gtk.Align.START; |
922 | label.valign = Gtk.Align.CENTER; |
923 | - label.get_style_context().add_class ("option-title"); |
924 | |
925 | // Description label |
926 | - var description = new Gtk.Label ("<span weight='medium' size='11400'>" + _description_text + "</span>"); |
927 | + var description = new Gtk.Label (Markup.printf_escaped ("<span weight='medium' size='11400'>%s</span>", description_text)); |
928 | description.use_markup = true; |
929 | description.halign = Gtk.Align.START; |
930 | description.valign = Gtk.Align.CENTER; |
931 | description.sensitive = false; |
932 | - description.get_style_context().add_class ("option-description"); |
933 | |
934 | // Button |
935 | var button = new Gtk.Button (); |
Nice!