I execute these lines to show the preferences window:
-(IBAction)showPreferences:(id)sender {
PreferencesWindowController *preferencesWindowController = [[PreferencesWindowController alloc] init];
NSNib *preferencesNib = [[NSNib alloc] initWithNibNamed:@"PreferencesWindow" bundle:nil];
[preferencesNib instantiateNibWithOwner:preferencesWindowController topLevelObjects:nil];
[NSApp activateIgnoringOtherApps:YES];
[[preferencesWindowController window] makeKeyAndOrderFront:nil];
[preferencesNib release];
}
But when the user clicks a second time on the preferences button (and the preferences window is still open) it will open up another instance of the preferences window.
How should I prevent this without hacking around with control variables? Should I edit my PreferencesWindowController to be a singleton?
My approach would be to make a PreferencesWindowController ivar in whatever class this action belongs to: