[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to add a defaults database to a theme ?

From: Richard Frith-Macdonald
Subject: Re: How to add a defaults database to a theme ?
Date: Fri, 10 May 2019 12:22:03 +0100

> On 10 May 2019, at 11:39, Bertrand Dekoninck <address@hidden> wrote:
> Hi, everyone, I'd like to add some default values to the rik.theme, writable 
> with the "defaults" tool.
> I wanted to add a transparency level to the top menu bar, which would be 
> editable. I thought I could do something like this :
> - (NSColor *) menuBackgroundColor
> {
>  float transparency = 1.0;
>  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
>   if ([defaults floatForKey:@"menubartransparency"])
>    {
>      transparency = [defaults floatForKey:@"menubartransparency"];
>      }
>  NSColor *color = [NSColor colorWithCalibratedRed: 0.992 green: 0.992 blue: 
> 0.992 alpha: transparency];
>  return color;
> }

The GSTheme method -menuBackgroundColor already does everything you want, so 
there's no coding to do for this.
The correct way to set a default color that should be overridable in the 
defaults system, is to add it as a default in the GSThemeDomain.
If you use Thematic.app, you have a GUI to do that for you (it tets you define 
custom colors for all the elements of your theme).
Otherwise you need to edit your bundle resources to specify the color you want 
as the menuBackgroundColor default.

> I get then a warning :  "local declaration of ‘defaults’ hides instance 
> variable"

I imagine the rik theme already adds 'defaults' as an instance variable of the 
theme, and this is just warning you that your local variable will be used 
rather than the instance variable.

> And when I read the documentation, I see that [NSUserDefaults 
> standardUserDefaults] is for the current app and user.
> A theme is not an app but a bundle. rik dosn't have such thing as an app 
> controller to initiate the database at start-up. Can I create a defaults 
> database for it, and how ? 

The defaults are defined in the GSThemeDomain dictionary of your theme's 
Info.plist and colors are defined  in various other resource files in the theme 
You can look at the GSTheme source code (GUI) and in the Thematic.app source 
code to see how it all works.
Alternatively, it might be easier to use Thematic.app to create a simple 
code-free theme where you change the color of the menus, then examine the 
resources inside that theme to see how it fits together.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]