Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up OSX screen saver configuration sheet?

I'm working on a screen saver for OSX (Mountain Lion) and I'm having trouble setting up the configuration sheet (so when the user clicks "Screen Saver Options..." within System Preferences, my options appear). There seem to be only two or three tutorials on writing OSX screen savers anywhere on the Internet, and they're all several years old so the material doesn't quite translate to OSX 10.8 and Xcode 4.

First of all, in my ScreenSaverView.m file, I have:

- (BOOL)hasConfigureSheet
{
    return NO;
}

- (NSWindow*)configureSheet
{
    return nil;
}

...and yet, in System Preferences, the "Screen Saver Options..." button is still clickable (nothing happens when it's clicked) rather than disabled as in the "Arabesque" screen saver.

What are the steps to having a configuration sheet appear when the button is clicked, and why is the button not currently disabled?


Edit:

I realized why the "Screen Saver Options..." button wasn't disabled. I had forgotten to include -(BOOL)hasConfigureSheet; in the ScreenSaverView.h file. My question about how to get the configuration sheet to appear, however, remains.

like image 702
JacobEvelyn Avatar asked Nov 26 '12 20:11

JacobEvelyn


1 Answers

First things first: Be sure to include ScreenSaver.framework in your project; it provides the necessary classes ScreenSaverView and ScreenSaverDefaults.

You say you already have a file called ScreenSaverView.m. Couple that with you also saying that you have to export your -hasConfigureSheet method in order to make the "Screen Saver Options..." button disable. This leads me to wonder if you have subclassed ScreenSaverView as you should have done. (Did you subclass NSObject instead?) ScreenSaverView exports methods such as -hasConfigureSheet for you. You should be subclassing it, and overriding the appropriate methods in it.

A couple more things:

You should have included a xib file in your project that contains the UI for your configuration sheet, and you should have provided IBOutlets in your subclass' interface to reference the panel and the UI elements it contains (those for which you actually need an outlet, that is).

Finally, your -configureSheet method should fetch the configuration sheet in a manner similar to this (in this example, configSheet would be one of your IBOutlets):

if (configSheet == nil)
{
    if ([NSBundle loadNibNamed:@"myConfigSheet" owner:self] == NO)
    {
        NSLog(@"load config sheet failed");
    }
}

// then retrieve your defaults and set up your sheet; you should
//  be working with ScreenSaverDefaults, a subclass of NSUserDefaults.

// then return 'configSheet'

Edit:

Apologies in advance if I'm about to tell you things you already know, but you did say you were having difficulties in configSheet, and so I'm simply covering all the bases.

In My_ScreensaverView.h, declare an outlet for your panel:

IBOutlet id configSheet;

Note that I used id instead of NSWindow * or NSPanel *, simply because I don't know what class you actually are using for the sheet. (Ideally, a NSPanel should be used for a sheet.)

In your nib file, make sure that the File's Owner is an instance of My_ScreensaverView. You can determine this by selecting the icon for this object and then using the Identity inspector to specify the class.

Make the connection between the configSheet outlet and the panel. One way of doing this is to hold down the Control key while dragging from the File's Owner object to the window or panel icon, then selecting configSheet from the pop-up that appears.

As always, good luck to you in your endeavors.

like image 118
Extra Savoir-Faire Avatar answered Nov 08 '22 18:11

Extra Savoir-Faire