- if ( (self = [super init]) )
- {
- int i;
- NSImageCell *imgCell = [[[NSImageCell alloc] init] autorelease];
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- NSString *temp;
-
- mt = [tunes retain];
-
- //Load the nib
- [NSBundle loadNibNamed:@"Preferences" owner:self];
-
- //Show our window
- [window setLevel:NSStatusWindowLevel];
- [window center];
- [window makeKeyAndOrderFront:nil];
-
- //Set the table view cells up
- [imgCell setImageScaling:NSScaleNone];
- [[menuTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
- [[allTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
-
- //Register for drag and drop
- [menuTableView registerForDraggedTypes:[NSArray arrayWithObjects:@"MenuTableViewPboardType", @"AllTableViewPboardType", nil]];
- [allTableView registerForDraggedTypes:[NSArray arrayWithObjects:@"MenuTableViewPboardType", @"AllTableViewPboardType", nil]];
-
- //Set the list of items you can have.
- availableItems = [[NSMutableArray alloc] initWithObjects:@"Current Track Info", @"Upcoming Songs", @"Playlists", @"Play/Pause", @"Next Track", @"Previous Track", @"Fast Forward", @"Rewind", @"<separator>", nil];
-
- //Get our preferred menu
- myItems = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"menu"] mutableCopy];
- if (myItems == nil)
- {
- myItems = [[NSMutableArray alloc] initWithObjects:@"Play/Pause", @"Next Track", @"Previous Track", @"Fast Forward", @"Rewind", @"<separator>", @"Upcoming Songs", @"Playlists", @"<separator>", @"PreferencesÉ", @"Quit", @"<separator>", @"Current Track Info", nil];
- [[NSUserDefaults standardUserDefaults] setObject:myItems forKey:@"menu"];
- }
-
- //Delete items in the availableItems array that are already part of the menu
- for (i = 0; i < [myItems count]; i++)
- {
- NSString *item = [myItems objectAtIndex:i];
- if (![item isEqualToString:@"<separator>"])
- {
- [availableItems removeObject:item];
- }
- }
-
- //Items that show should a submenu image
- submenuItems = [[NSArray alloc] initWithObjects:@"Upcoming Songs", @"Playlists", nil];
-
- //Fill in the number of songs in advance to show field
- if ([defaults integerForKey:@"SongsInAdvance"])
- {
- [songsInAdvance setIntValue:[defaults integerForKey:@"SongsInAdvance"]];
- }
- else
- {
- [songsInAdvance setIntValue:5];
- }
-
- //Fill in hot key buttons
- if ([defaults objectForKey:@"PlayPause"])
- {
- playPauseCombo = [defaults keyComboForKey:@"PlayPause"];
- [playPauseButton setTitle:[playPauseCombo userDisplayRep]];
- }
- else
- {
- playPauseCombo = [[KeyCombo alloc] init];
- }
-
- if ([defaults objectForKey:@"NextTrack"])
- {
- nextTrackCombo = [defaults keyComboForKey:@"NextTrack"];
- [nextTrackButton setTitle:[nextTrackCombo userDisplayRep]];
- }
- else
- {
- nextTrackCombo = [[KeyCombo alloc] init];
- }
-
- if ([defaults objectForKey:@"PrevTrack"])
- {
- prevTrackCombo = [defaults keyComboForKey:@"PrevTrack"];
- [previousTrackButton setTitle:[prevTrackCombo userDisplayRep]];
- }
- else
- {
- prevTrackCombo = [[KeyCombo alloc] init];
- }
-
- if ([defaults objectForKey:@"TrackInfo"])
- {
- trackInfoCombo = [defaults keyComboForKey:@"TrackInfo"];
- [trackInfoButton setTitle:[trackInfoCombo userDisplayRep]];
- }
- else
- {
- trackInfoCombo = [[KeyCombo alloc] init];
- }
+ if (! prefs) {
+ prefs = [[self alloc] init];
+ }
+ return prefs;
+}
+
+- (id)init
+{
+ if ( (self = [super init]) ) {
+ ITDebugLog(@"Preferences initialized.");
+ df = [[NSUserDefaults standardUserDefaults] retain];
+ hotKeysDictionary = [[NSMutableDictionary alloc] init];
+ controller = nil;
+ }
+ return self;
+}
+
+
+/*************************************************************************/
+#pragma mark -
+#pragma mark ACCESSOR METHODS
+/*************************************************************************/
+
+- (id)controller
+{
+ return controller;
+}
+
+- (void)setController:(id)object
+{
+ [controller autorelease];
+ controller = [object retain];
+}
+
+
+/*************************************************************************/
+#pragma mark -
+#pragma mark INSTANCE METHODS
+/*************************************************************************/
+
+- (IBAction)showPrefsWindow:(id)sender
+{
+ ITDebugLog(@"Showing preferences window.");
+ if (! window) { // If window does not exist yet, then the nib hasn't been loaded.
+ ITDebugLog(@"Window doesn't exist, initial setup.");
+ [self setupWindow]; // Load in the nib, and perform any initial setup.
+ [self setupCustomizationTables]; // Setup the DnD manu config tables.
+ [self setupMenuItems]; // Setup the arrays of menu items
+ [self setupUI]; // Sets up additional UI
+ [window setDelegate:self];
+ [menuTableView reloadData];