Merge lp://staging/~psybers/do/gconf-notify into lp://staging/do
- gconf-notify
- Merge into trunk
Proposed by
Robert Dyer
Status: | Merged |
---|---|
Approved by: | Alex Launi |
Approved revision: | 1305 |
Merged at revision: | 1296 |
Proposed branch: | lp://staging/~psybers/do/gconf-notify |
Merge into: | lp://staging/do |
Diff against target: | None lines |
To merge this branch: | bzr merge lp://staging/~psybers/do/gconf-notify |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alex Launi (community) | Approve | ||
Review via email:
|
This proposal supersedes a proposal from 2009-08-28.
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Robert Dyer (psybers) wrote : Posted in a previous version of this proposal | # |
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Robert Dyer (psybers) wrote : | # |
This lets the preferences objects be notified by GConf when things change.
A lot of places we cache the .get() from preferences in a field and then the property's get{} returns that. This is done for performance (in places) and makes perfect sense. However, we can now do that *and* be notified by GConf when a setting changed and thus update our cached copy! Horray!
Re-submitted after adding in proper usage of this new event for other classes such as the docklet service and the bezeled theme.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Robert Dyer (psybers) wrote : | # |
Bah, pushed with some writelines. Removed in 1303. :-)
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Alex Launi (alexlauni) wrote : | # |
looks good to me after our talk in irc
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Do.Interface.Linux.AnimationBase/src/Do.Interface/Do.Interface.AnimationBase/BezelDrawingArea.cs' |
2 | --- Do.Interface.Linux.AnimationBase/src/Do.Interface/Do.Interface.AnimationBase/BezelDrawingArea.cs 2009-06-24 03:58:55 +0000 |
3 | +++ Do.Interface.Linux.AnimationBase/src/Do.Interface/Do.Interface.AnimationBase/BezelDrawingArea.cs 2009-08-28 08:53:14 +0000 |
4 | @@ -56,6 +56,18 @@ |
5 | #region Static Area |
6 | static IPreferences prefs = Services.Preferences.Get<BezelDrawingArea> (); |
7 | public static event EventHandler ThemeChanged; |
8 | + |
9 | + static BezelDrawingArea() |
10 | + { |
11 | + prefs.PreferencesChanged += HandlePreferencesChanged; |
12 | + } |
13 | + |
14 | + static void HandlePreferencesChanged (object o, PreferencesChangedEventArgs e) |
15 | + { |
16 | + if (e.Key == "Animated" || e.Key == "WindowRadius") |
17 | + return; |
18 | + OnThemeChanged (); |
19 | + } |
20 | |
21 | public static bool Animated { |
22 | get { |
23 | @@ -72,7 +84,6 @@ |
24 | } |
25 | set { |
26 | prefs.Set<string> ("TitleRenderer", value); |
27 | - OnThemeChanged (); |
28 | } |
29 | } |
30 | |
31 | @@ -82,7 +93,6 @@ |
32 | } |
33 | set { |
34 | prefs.Set<string> ("PaneRenderer", value); |
35 | - OnThemeChanged (); |
36 | } |
37 | } |
38 | |
39 | @@ -92,7 +102,6 @@ |
40 | } |
41 | set { |
42 | prefs.Set<string> ("WindowRenderer", value); |
43 | - OnThemeChanged (); |
44 | } |
45 | } |
46 | |
47 | @@ -102,7 +111,6 @@ |
48 | } |
49 | set { |
50 | prefs.Set<string> ("BackgroundColor", value); |
51 | - OnThemeChanged (); |
52 | } |
53 | } |
54 | |
55 | @@ -112,7 +120,6 @@ |
56 | } |
57 | set { |
58 | prefs.Set<int> ("WindowRadius", Math.Max (-1, value)); |
59 | - OnThemeChanged (); |
60 | } |
61 | } |
62 | |
63 | @@ -122,7 +129,6 @@ |
64 | } |
65 | set { |
66 | prefs.Set<bool> ("Shadow", value); |
67 | - OnThemeChanged (); |
68 | } |
69 | } |
70 | |
71 | @@ -135,7 +141,6 @@ |
72 | public static void ResetBackgroundStyle () |
73 | { |
74 | prefs.Set<string> ("BackgroundColor", "default"); |
75 | - OnThemeChanged (); |
76 | } |
77 | |
78 | private static void OnThemeChanged () |
79 | @@ -404,7 +409,6 @@ |
80 | TextUtility = new TextRenderer (this); |
81 | |
82 | DoubleBuffered = false; |
83 | - prefs = Services.Preferences.Get<BezelDrawingArea> (); |
84 | this.preview = preview; |
85 | this.theme = theme; |
86 | |
87 | |
88 | === modified file 'Do.Interface.Linux.Docky/src/Docky.Core/Docky.Core.Default/DockletService.cs' |
89 | --- Do.Interface.Linux.Docky/src/Docky.Core/Docky.Core.Default/DockletService.cs 2009-05-19 18:51:02 +0000 |
90 | +++ Do.Interface.Linux.Docky/src/Docky.Core/Docky.Core.Default/DockletService.cs 2009-08-28 09:09:09 +0000 |
91 | @@ -50,6 +50,7 @@ |
92 | docklet.Enable (); |
93 | |
94 | docklets [docklet] = !docklets [docklet]; |
95 | + SaveConfiguration (); |
96 | OnAppletVisibilityChanged (); |
97 | return true; |
98 | } |
99 | @@ -83,15 +84,27 @@ |
100 | public DockletService() |
101 | { |
102 | prefs = Services.Preferences.Get<DockletService> (); |
103 | + prefs.PreferencesChanged += HandlePreferencesChanged; |
104 | |
105 | AddinManager.AddExtensionNodeHandler (ExtensionPath, HandleDockletsChanged); |
106 | |
107 | BuildDocklets (); |
108 | } |
109 | |
110 | + void HandlePreferencesChanged (object sender, PreferencesChangedEventArgs args) |
111 | + { |
112 | + Console.WriteLine("key = " + args.Key); |
113 | + Console.WriteLine("val = " + args.Value); |
114 | + if (args.Key != "ActiveApplets") |
115 | + return; |
116 | + BuildDocklets (); |
117 | + OnAppletVisibilityChanged (); |
118 | + } |
119 | + |
120 | void HandleDockletsChanged (object sender, ExtensionNodeEventArgs args) |
121 | { |
122 | BuildDocklets (); |
123 | + SaveConfiguration (); |
124 | OnAppletVisibilityChanged (); |
125 | } |
126 | |
127 | @@ -124,12 +137,12 @@ |
128 | foreach (AbstractDockletItem abi in ActiveDocklets) { |
129 | s += abi.GetType ().Name + ";"; |
130 | } |
131 | - prefs.Set ("ActiveApplets", s); |
132 | + if (s != prefs.Get ("ActiveApplets", "ClockDockItem;")) |
133 | + prefs.Set ("ActiveApplets", s); |
134 | } |
135 | |
136 | void OnAppletVisibilityChanged () |
137 | { |
138 | - SaveConfiguration (); |
139 | if (AppletVisibilityChanged != null) |
140 | AppletVisibilityChanged (this, EventArgs.Empty); |
141 | } |
142 | |
143 | === modified file 'Do.Interface.Linux.Docky/src/Docky.Interface/Docky.Interface.Items/ClockDockItem.cs' |
144 | --- Do.Interface.Linux.Docky/src/Docky.Interface/Docky.Interface.Items/ClockDockItem.cs 2009-08-20 08:27:24 +0000 |
145 | +++ Do.Interface.Linux.Docky/src/Docky.Interface/Docky.Interface.Items/ClockDockItem.cs 2009-08-28 05:42:11 +0000 |
146 | @@ -107,6 +107,20 @@ |
147 | cal_painter = new CalendarPainter (this); |
148 | Core.DockServices.PainterService.RegisterPainter (cal_painter); |
149 | GLib.Timeout.Add (1000, ClockUpdateTimer); |
150 | + prefs.PreferencesChanged += HandlePreferencesChanged; |
151 | + } |
152 | + |
153 | + void HandlePreferencesChanged (object o, PreferencesChangedEventArgs e) |
154 | + { |
155 | + if (e.Key == "ClockTheme") |
156 | + current_theme = (string)e.OldValue; |
157 | + if (e.Key == "ShowDate") |
158 | + show_date = (bool)e.OldValue; |
159 | + if (e.Key == "ShowDigital") |
160 | + digital = (bool)e.OldValue; |
161 | + if (e.Key == "ShowMilitary") |
162 | + show_military = (bool)e.OldValue; |
163 | + RedrawIcon(); |
164 | } |
165 | |
166 | bool ClockUpdateTimer () |
167 | |
168 | === modified file 'Do.Interface.Linux.Docky/src/Docky.Utilities/DockPreferences.cs' |
169 | --- Do.Interface.Linux.Docky/src/Docky.Utilities/DockPreferences.cs 2009-06-19 04:32:13 +0000 |
170 | +++ Do.Interface.Linux.Docky/src/Docky.Utilities/DockPreferences.cs 2009-08-28 06:46:50 +0000 |
171 | @@ -56,6 +56,28 @@ |
172 | return true; |
173 | }); |
174 | } |
175 | + prefs.PreferencesChanged += HandlePreferencesChanged; |
176 | + } |
177 | + |
178 | + static void HandlePreferencesChanged (object o, PreferencesChangedEventArgs e) { |
179 | + if (e.Key == "IndicateMultipleWindows") |
180 | + SetIndicateMultipleWindows ((bool)e.Value); |
181 | + if (e.Key == "ZoomPercent") |
182 | + SetZoomPercent ((double)e.Value); |
183 | + if (e.Key == "EnableZoom") |
184 | + SetZoomEnabled ((bool)e.Value); |
185 | + if (e.Key == "IconSize") |
186 | + SetIconSize ((int)e.Value); |
187 | + if (e.Key == "SummonTime") |
188 | + SetSummonTime (new TimeSpan (0, 0, 0, 0, (int)e.Value)); |
189 | + if (e.Key == "AutomaticIcons") |
190 | + SetAutomaticIcons ((int)e.Value); |
191 | + if (e.Key == "Monitor") |
192 | + SetMonitor (Math.Max (0, (int)e.Value)); |
193 | + if (e.Key == "Orientation") |
194 | + SetOrientation ((DockOrientation) Enum.Parse (typeof (DockOrientation), (string)e.Value)); |
195 | + if (e.Key == "AutohideType") |
196 | + SetAutohideType ((AutohideType) Enum.Parse (typeof (AutohideType), (string)e.Value)); |
197 | } |
198 | |
199 | public static int TextWidth { |
200 | @@ -70,34 +92,52 @@ |
201 | public static bool IndicateMultipleWindows { |
202 | get { return indicate_multiple_windows; } |
203 | set { |
204 | - prefs.Set ("IndicateMultipleWindows", value); |
205 | - indicate_multiple_windows = value; |
206 | + if (SetIndicateMultipleWindows (value)) |
207 | + prefs.Set ("IndicateMultipleWindows", value); |
208 | } |
209 | } |
210 | + static bool SetIndicateMultipleWindows (bool val) |
211 | + { |
212 | + if (indicate_multiple_windows == val) return false; |
213 | + indicate_multiple_windows = val; |
214 | + return true; |
215 | + } |
216 | |
217 | static double zoom_percent = Math.Round (prefs.Get ("ZoomPercent", 2.0), 1); |
218 | public static double ZoomPercent { |
219 | get { return ZoomEnabled ? zoom_percent : 1; } |
220 | set { |
221 | - if (value < 1) |
222 | - value = 1; |
223 | - prefs.Set ("ZoomPercent", value); |
224 | - zoom_percent = value; |
225 | - if (IconSizeChanged != null) |
226 | - IconSizeChanged (); |
227 | + if (SetZoomPercent (value)) |
228 | + prefs.Set ("ZoomPercent", value); |
229 | } |
230 | } |
231 | + static bool SetZoomPercent (double val) |
232 | + { |
233 | + if (val < 1) |
234 | + val = 1; |
235 | + if (zoom_percent == val) return false; |
236 | + zoom_percent = val; |
237 | + if (IconSizeChanged != null) |
238 | + IconSizeChanged (); |
239 | + return true; |
240 | + } |
241 | |
242 | static bool enable_zoom = prefs.Get ("EnableZoom", true); |
243 | public static bool ZoomEnabled { |
244 | get { return enable_zoom; } |
245 | set { |
246 | - prefs.Set ("EnableZoom", value); |
247 | - enable_zoom = value; |
248 | - if (IconSizeChanged != null) |
249 | - IconSizeChanged (); |
250 | + if (SetZoomEnabled (value)) |
251 | + prefs.Set ("EnableZoom", value); |
252 | } |
253 | } |
254 | + static bool SetZoomEnabled (bool val) |
255 | + { |
256 | + if (enable_zoom == val) return false; |
257 | + enable_zoom = val; |
258 | + if (IconSizeChanged != null) |
259 | + IconSizeChanged (); |
260 | + return true; |
261 | + } |
262 | |
263 | public static int FullIconSize { |
264 | get { |
265 | @@ -120,20 +160,25 @@ |
266 | public static int IconSize { |
267 | get { return Math.Min (icon_size, MaxIconSize); } |
268 | set { |
269 | - if (value < 24) |
270 | - value = 24; |
271 | - if (value > 128) |
272 | - value = 128; |
273 | - |
274 | - if (value == icon_size) |
275 | - return; |
276 | - |
277 | - prefs.Set ("IconSize", value); |
278 | - icon_size = value; |
279 | - if (IconSizeChanged != null) |
280 | - IconSizeChanged (); |
281 | + if (SetIconSize (value)) |
282 | + prefs.Set ("IconSize", value); |
283 | } |
284 | } |
285 | + static bool SetIconSize (int val) |
286 | + { |
287 | + if (val < 24) |
288 | + val = 24; |
289 | + if (val > 128) |
290 | + val = 128; |
291 | + |
292 | + if (val == icon_size) |
293 | + return false; |
294 | + |
295 | + icon_size = val; |
296 | + if (IconSizeChanged != null) |
297 | + IconSizeChanged (); |
298 | + return true; |
299 | + } |
300 | |
301 | /// <summary> |
302 | /// Currently returns ZoomPercent. This is useful in the future case where we wish to optimize for best |
303 | @@ -151,24 +196,36 @@ |
304 | public static TimeSpan SummonTime { |
305 | get { return summon_time; } |
306 | set { |
307 | - prefs.Set ("SummonTime", value.TotalMilliseconds); |
308 | - summon_time = value; |
309 | + if (SetSummonTime (value)) |
310 | + prefs.Set ("SummonTime", value.TotalMilliseconds); |
311 | } |
312 | } |
313 | + static bool SetSummonTime (TimeSpan val) |
314 | + { |
315 | + if (summon_time == val) return false; |
316 | + summon_time = val; |
317 | + return true; |
318 | + } |
319 | |
320 | static int automatic_icons = prefs.Get ("AutomaticIcons", 5); |
321 | public static int AutomaticIcons { |
322 | get { return automatic_icons; } |
323 | set { |
324 | - if (value < 0) |
325 | - value = 0; |
326 | - prefs.Set ("AutomaticIcons", value); |
327 | - automatic_icons = value; |
328 | - |
329 | - if (AutomaticIconsChanged != null) |
330 | - AutomaticIconsChanged (); |
331 | + if (SetAutomaticIcons (value)) |
332 | + prefs.Set ("AutomaticIcons", value); |
333 | } |
334 | } |
335 | + static bool SetAutomaticIcons (int val) |
336 | + { |
337 | + if (val < 0) |
338 | + val = 0; |
339 | + if (automatic_icons == val) return false; |
340 | + automatic_icons = val; |
341 | + |
342 | + if (AutomaticIconsChanged != null) |
343 | + AutomaticIconsChanged (); |
344 | + return true; |
345 | + } |
346 | |
347 | static int monitor = Math.Max (0, prefs.Get ("Monitor", 0)); |
348 | public static int Monitor { |
349 | @@ -177,19 +234,25 @@ |
350 | return monitor; |
351 | } |
352 | set { |
353 | - if (monitor == value) |
354 | - return; |
355 | - |
356 | - if (value >= Gdk.Screen.Default.NMonitors || value < 0) |
357 | - value = 0; |
358 | - monitor = value; |
359 | - prefs.Set ("Monitor", value); |
360 | - |
361 | - Interface.LayoutUtils.Recalculate (); |
362 | - if (MonitorChanged != null) |
363 | - MonitorChanged (); |
364 | + if (SetMonitor (value)) |
365 | + prefs.Set ("Monitor", value); |
366 | } |
367 | } |
368 | + static bool SetMonitor (int val) |
369 | + { |
370 | + if (val >= Gdk.Screen.Default.NMonitors || val < 0) |
371 | + val = 0; |
372 | + |
373 | + if (monitor == val) |
374 | + return false; |
375 | + |
376 | + monitor = val; |
377 | + |
378 | + Interface.LayoutUtils.Recalculate (); |
379 | + if (MonitorChanged != null) |
380 | + MonitorChanged (); |
381 | + return true; |
382 | + } |
383 | |
384 | static DockOrientation orientation = (DockOrientation) Enum.Parse (typeof (DockOrientation), prefs.Get ("Orientation", DockOrientation.Bottom.ToString ())); |
385 | public static DockOrientation Orientation { |
386 | @@ -200,27 +263,37 @@ |
387 | return orientation; |
388 | } |
389 | set { |
390 | - if (orientation == value) |
391 | - return; |
392 | - orientation = value; |
393 | - prefs.Set ("Orientation", value.ToString ()); |
394 | - if (OrientationChanged != null) |
395 | - OrientationChanged (); |
396 | + if (SetOrientation (value)) |
397 | + prefs.Set ("Orientation", value.ToString ()); |
398 | } |
399 | } |
400 | + static bool SetOrientation (DockOrientation val) |
401 | + { |
402 | + if (orientation == val) |
403 | + return false; |
404 | + orientation = val; |
405 | + if (OrientationChanged != null) |
406 | + OrientationChanged (); |
407 | + return true; |
408 | + } |
409 | |
410 | static AutohideType hide = (AutohideType) Enum.Parse (typeof (AutohideType), prefs.Get ("AutohideType", AutohideType.None.ToString ())); |
411 | public static AutohideType AutohideType { |
412 | get { return hide; } |
413 | set { |
414 | - if (hide == value) |
415 | - return; |
416 | - hide = value; |
417 | - prefs.Set ("AutohideType", value.ToString ()); |
418 | - if (AutohideChanged != null) |
419 | - AutohideChanged (); |
420 | + if (SetAutohideType (value)) |
421 | + prefs.Set ("AutohideType", value.ToString ()); |
422 | } |
423 | } |
424 | + static bool SetAutohideType (AutohideType val) |
425 | + { |
426 | + if (hide == val) |
427 | + return false; |
428 | + hide = val; |
429 | + if (AutohideChanged != null) |
430 | + AutohideChanged (); |
431 | + return true; |
432 | + } |
433 | |
434 | #region blacklists |
435 | static List<string> item_blacklist = DeserializeBlacklist (); |
436 | |
437 | === modified file 'Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/GConfPreferencesService.cs' |
438 | --- Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/GConfPreferencesService.cs 2009-01-18 00:47:28 +0000 |
439 | +++ Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/GConfPreferencesService.cs 2009-08-28 06:44:14 +0000 |
440 | @@ -38,6 +38,12 @@ |
441 | { |
442 | RootPath = rootPath; |
443 | client = new GConf.Client (); |
444 | + client.AddNotify (RootPath, new GConf.NotifyEventHandler (HandleGConfChanged)); |
445 | + } |
446 | + |
447 | + void HandleGConfChanged (object sender, GConf.NotifyEventArgs args) |
448 | + { |
449 | + OnPreferencesChanged (args.Key.Substring(RootPath.Length + 1), null, args.Value); |
450 | } |
451 | |
452 | string AbsolutePathForKey (string key) |
453 | @@ -46,9 +52,23 @@ |
454 | return key; |
455 | return string.Format ("{0}/{1}", RootPath, key); |
456 | } |
457 | - |
458 | + |
459 | + bool IgnoreNextEvent { get; set; } |
460 | + |
461 | + void OnPreferencesChanged (string key, object oldValue, object newValue) |
462 | + { |
463 | + if (IgnoreNextEvent) { |
464 | + IgnoreNextEvent = false; |
465 | + return; |
466 | + } |
467 | + if (PreferencesChanged == null) return; |
468 | + PreferencesChanged (this, new PreferencesChangedEventArgs (key, oldValue, newValue)); |
469 | + } |
470 | + |
471 | #region IPreferencesService |
472 | |
473 | + public event EventHandler<PreferencesChangedEventArgs> PreferencesChanged; |
474 | + |
475 | public bool Set<T> (string key, T val) |
476 | { |
477 | bool success = true; |
478 | @@ -59,6 +79,7 @@ |
479 | Log.Debug (e.StackTrace); |
480 | success = false; |
481 | } |
482 | + IgnoreNextEvent = success; |
483 | return success; |
484 | } |
485 | |
486 | |
487 | === modified file 'Do.Platform/src/Do.Platform/Do.Platform.Common/DictionaryPreferencesService.cs' |
488 | --- Do.Platform/src/Do.Platform/Do.Platform.Common/DictionaryPreferencesService.cs 2009-01-18 00:47:28 +0000 |
489 | +++ Do.Platform/src/Do.Platform/Do.Platform.Common/DictionaryPreferencesService.cs 2009-08-28 05:42:11 +0000 |
490 | @@ -35,8 +35,16 @@ |
491 | Store = new Dictionary<string, object> (); |
492 | } |
493 | |
494 | + void OnPreferencesChanged (string key, object oldValue, object newValue) |
495 | + { |
496 | + if (PreferencesChanged == null) return; |
497 | + PreferencesChanged (this, new PreferencesChangedEventArgs (key, oldValue, newValue)); |
498 | + } |
499 | + |
500 | #region IPreferencesService |
501 | |
502 | + public event EventHandler<PreferencesChangedEventArgs> PreferencesChanged; |
503 | + |
504 | public bool Set<T> (string key, T val) |
505 | { |
506 | Store [key] = val; |
507 | |
508 | === modified file 'Do.Platform/src/Do.Platform/Do.Platform.Default/PreferencesService.cs' |
509 | --- Do.Platform/src/Do.Platform/Do.Platform.Default/PreferencesService.cs 2008-12-18 18:39:06 +0000 |
510 | +++ Do.Platform/src/Do.Platform/Do.Platform.Default/PreferencesService.cs 2009-08-28 05:42:11 +0000 |
511 | @@ -29,6 +29,8 @@ |
512 | |
513 | #region IPreferencesService |
514 | |
515 | + public event EventHandler<PreferencesChangedEventArgs> PreferencesChanged; |
516 | + |
517 | public bool Set<T> (string key, T val) |
518 | { |
519 | Log.Debug ("Default IPreferencesService cannot set key \"{0}\".", key); |
520 | |
521 | === modified file 'Do.Platform/src/Do.Platform/Do.Platform.Preferences/PreferencesImplementation.cs' |
522 | --- Do.Platform/src/Do.Platform/Do.Platform.Preferences/PreferencesImplementation.cs 2009-01-08 18:12:28 +0000 |
523 | +++ Do.Platform/src/Do.Platform/Do.Platform.Preferences/PreferencesImplementation.cs 2009-08-28 06:40:00 +0000 |
524 | @@ -38,12 +38,19 @@ |
525 | { |
526 | Service = service; |
527 | SecureService = new SecurePreferencesServiceWrapper (secureService); |
528 | - } |
529 | - |
530 | - void OnPreferencesChanged (string key, object oldValue) |
531 | + Service.PreferencesChanged += HandlePreferencesChanged; |
532 | + } |
533 | + |
534 | + void HandlePreferencesChanged (object o, PreferencesChangedEventArgs e) |
535 | + { |
536 | + if (e.Key.Length <= OwnerString.Length + 1 || e.Key.Substring(0, OwnerString.Length) != OwnerString) return; |
537 | + OnPreferencesChanged (e.Key.Substring(OwnerString.Length + 1), e.OldValue, e.Value); |
538 | + } |
539 | + |
540 | + void OnPreferencesChanged (string key, object oldValue, object newValue) |
541 | { |
542 | if (PreferencesChanged == null) return; |
543 | - PreferencesChanged (this, new PreferencesChangedEventArgs (key, oldValue)); |
544 | + PreferencesChanged (this, new PreferencesChangedEventArgs (key, oldValue, newValue)); |
545 | } |
546 | |
547 | #region IPreferences |
548 | @@ -109,7 +116,7 @@ |
549 | oldValue = default (T); |
550 | |
551 | if (service.Set (keypath, val)) { |
552 | - OnPreferencesChanged (key, oldValue); |
553 | + OnPreferencesChanged (key, oldValue, val); |
554 | return true; |
555 | } |
556 | return false; |
557 | |
558 | === modified file 'Do.Platform/src/Do.Platform/IPreferencesService.cs' |
559 | --- Do.Platform/src/Do.Platform/IPreferencesService.cs 2008-12-18 18:39:06 +0000 |
560 | +++ Do.Platform/src/Do.Platform/IPreferencesService.cs 2009-08-28 05:42:11 +0000 |
561 | @@ -28,7 +28,9 @@ |
562 | |
563 | public interface IPreferencesService : IService |
564 | { |
565 | + event EventHandler<PreferencesChangedEventArgs> PreferencesChanged; |
566 | + |
567 | bool Set<T> (string key, T val); |
568 | bool TryGet<T> (string key, out T val); |
569 | } |
570 | -} |
571 | \ No newline at end of file |
572 | +} |
573 | |
574 | === modified file 'Do.Platform/src/Do.Platform/PreferencesChangedEventArgs.cs' |
575 | --- Do.Platform/src/Do.Platform/PreferencesChangedEventArgs.cs 2008-12-18 18:39:06 +0000 |
576 | +++ Do.Platform/src/Do.Platform/PreferencesChangedEventArgs.cs 2009-08-28 05:42:11 +0000 |
577 | @@ -26,12 +26,14 @@ |
578 | { |
579 | public string Key { get; private set; } |
580 | public object OldValue { get; private set; } |
581 | + public object Value { get; private set; } |
582 | |
583 | - public PreferencesChangedEventArgs (string key, object oldValue) |
584 | + public PreferencesChangedEventArgs (string key, object oldValue, object newValue) |
585 | { |
586 | Key = key; |
587 | OldValue = oldValue; |
588 | + Value = newValue; |
589 | } |
590 | } |
591 | |
592 | -} |
593 | \ No newline at end of file |
594 | +} |
595 | |
596 | === modified file 'Do.Platform/src/Do.Platform/SecurePreferencesWrapper.cs' |
597 | --- Do.Platform/src/Do.Platform/SecurePreferencesWrapper.cs 2008-12-18 18:39:06 +0000 |
598 | +++ Do.Platform/src/Do.Platform/SecurePreferencesWrapper.cs 2009-08-28 05:42:11 +0000 |
599 | @@ -36,6 +36,8 @@ |
600 | { |
601 | SecureService = secureService; |
602 | } |
603 | + |
604 | + public event EventHandler<PreferencesChangedEventArgs> PreferencesChanged; |
605 | |
606 | public bool Set<T> (string key, T val) |
607 | { |
608 | |
609 | === modified file 'Do/src/Do.Core/Controller.cs' |
610 | --- Do/src/Do.Core/Controller.cs 2009-08-19 07:27:08 +0000 |
611 | +++ Do/src/Do.Core/Controller.cs 2009-08-28 08:43:13 +0000 |
612 | @@ -175,7 +175,7 @@ |
613 | |
614 | void OnThemeChanged (object sender, PreferencesChangedEventArgs e) |
615 | { |
616 | - string oldTheme = e.OldValue as string, newTheme = Do.Preferences.Theme; |
617 | + string oldTheme = e.OldValue as string, newTheme = e.Value as string; |
618 | |
619 | // Only change the theme of the old and new themes are different. |
620 | if (oldTheme != newTheme) { |
This lets the preferences objects be notified by GConf when things change.
A lot of places we cache the .get() from preferences in a field and then the property's get{} returns that. This is done for performance (in places) and makes perfect sense. However, we can now do that *and* be notified by GConf when a setting changed and thus update our cached copy! Horray!