X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/01755ec0d1d9e0d49d003bd3029162388b720cda..f78882a24de62e51f69362bdd12a972654f5d62f:/PreferencesController.m diff --git a/PreferencesController.m b/PreferencesController.m index 9690e0b..3919848 100755 --- a/PreferencesController.m +++ b/PreferencesController.m @@ -39,8 +39,11 @@ - (void)setupCustomizationTables; - (void)setupMenuItems; - (void)setupUI; -- (NSArray *)effectNamesFromDictionary:(NSDictionary *)infoDict; +- (void)setStatusWindowEntryEffect:(Class)effectClass; +- (void)setStatusWindowExitEffect:(Class)effectClass; - (void)setCustomColor:(NSColor *)color updateWell:(BOOL)update; +- (void)repopulateEffectPopupsForVerticalPosition:(ITVerticalWindowPosition)vPos horizontalPosition:(ITHorizontalWindowPosition)hPos; +- (BOOL)effect:(Class)effectClass supportsVerticalPosition:(ITVerticalWindowPosition)vPos withHorizontalPosition:(ITHorizontalWindowPosition)hPos; - (IBAction)changeMenus:(id)sender; - (void)setLaunchesAtLogin:(BOOL)flag; @end @@ -75,6 +78,9 @@ static PreferencesController *prefs = nil; if ( (self = [super init]) ) { ITDebugLog(@"Preferences initialized."); df = [[NSUserDefaults standardUserDefaults] retain]; + + effectClasses = [[ITWindowEffect effectClasses] retain]; + hotKeysArray = [[NSArray alloc] initWithObjects:@"PlayPause", @"NextTrack", @"PrevTrack", @@ -373,59 +379,64 @@ static PreferencesController *prefs = nil; { StatusWindow *sw = [StatusWindow sharedWindow]; ITDebugLog(@"Changing status window setting of tag %i", [sender tag]); + if ( [sender tag] == 2010) { + + BOOL entryEffectValid = YES; + BOOL exitEffectValid = YES; + [df setInteger:[sender selectedRow] forKey:@"statusWindowVerticalPosition"]; [df setInteger:[sender selectedColumn] forKey:@"statusWindowHorizontalPosition"]; - [sw setHorizontalPosition:[sender selectedColumn]]; [sw setVerticalPosition:[sender selectedRow]]; - // update the window's position here + [sw setHorizontalPosition:[sender selectedColumn]]; + + // Enable/disable the items in the popups. + [self repopulateEffectPopupsForVerticalPosition:[sw verticalPosition] + horizontalPosition:[sw horizontalPosition]]; + + // Make sure the effects support the new position. + entryEffectValid = ( [self effect:[[sw entryEffect] class] + supportsVerticalPosition:[sw verticalPosition] + withHorizontalPosition:[sw horizontalPosition]] ); + exitEffectValid = ( [self effect:[[sw exitEffect] class] + supportsVerticalPosition:[sw verticalPosition] + withHorizontalPosition:[sw horizontalPosition]] ); + + if ( ! entryEffectValid ) { + [appearanceEffectPopup selectItemAtIndex:[[appearanceEffectPopup menu] indexOfItemWithRepresentedObject:NSClassFromString(@"ITCutWindowEffect")]]; + [self setStatusWindowEntryEffect:NSClassFromString(@"ITCutWindowEffect")]; + } else { + [appearanceEffectPopup selectItemAtIndex:[[appearanceEffectPopup menu] indexOfItemWithRepresentedObject:[[sw entryEffect] class]]]; + } + + if ( ! exitEffectValid ) { + [vanishEffectPopup selectItemAtIndex:[[vanishEffectPopup menu] indexOfItemWithRepresentedObject:NSClassFromString(@"ITDissolveWindowEffect")]]; + [self setStatusWindowExitEffect:NSClassFromString(@"ITDissolveWindowEffect")]; + } else { + [vanishEffectPopup selectItemAtIndex:[[vanishEffectPopup menu] indexOfItemWithRepresentedObject:[[sw exitEffect] class]]]; + } + + // Update the window's position. + // Yeah, do that. + } else if ( [sender tag] == 2020) { - // update screen selection + + // Update screen selection. + } else if ( [sender tag] == 2030) { - int effectTag = [[sender selectedItem] tag]; - float time = ([df floatForKey:@"statusWindowAppearanceSpeed"] ? [df floatForKey:@"statusWindowAppearanceSpeed"] : 0.8); - [df setInteger:effectTag forKey:@"statusWindowAppearanceEffect"]; - - if ( effectTag == 2100 ) { - [sw setEntryEffect:[[[ITCutWindowEffect alloc] initWithWindow:sw] autorelease]]; - } else if ( effectTag == 2101 ) { - [sw setEntryEffect:[[[ITDissolveWindowEffect alloc] initWithWindow:sw] autorelease]]; - } else if ( effectTag == 2102 ) { - [sw setEntryEffect:[[[ITSlideVerticallyWindowEffect alloc] initWithWindow:sw] autorelease]]; - } else if ( effectTag == 2103 ) { - [sw setEntryEffect:[[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:sw] autorelease]]; - } else if ( effectTag == 2104 ) { - [sw setEntryEffect:[[[ITPivotWindowEffect alloc] initWithWindow:sw] autorelease]]; - } - - [[sw entryEffect] setEffectTime:time]; + + [self setStatusWindowEntryEffect:[[sender selectedItem] representedObject]]; } else if ( [sender tag] == 2040) { - int effectTag = [[sender selectedItem] tag]; - float time = ([df floatForKey:@"statusWindowVanishSpeed"] ? [df floatForKey:@"statusWindowVanishSpeed"] : 0.8); - - [df setInteger:[[sender selectedItem] tag] forKey:@"statusWindowVanishEffect"]; + + [self setStatusWindowExitEffect:[[sender selectedItem] representedObject]]; - if ( effectTag == 2100 ) { - [sw setExitEffect:[[[ITCutWindowEffect alloc] initWithWindow:sw] autorelease]]; - } else if ( effectTag == 2101 ) { - [sw setExitEffect:[[[ITDissolveWindowEffect alloc] initWithWindow:sw] autorelease]]; - } else if ( effectTag == 2102 ) { - [sw setExitEffect:[[[ITSlideVerticallyWindowEffect alloc] initWithWindow:sw] autorelease]]; - } else if ( effectTag == 2103 ) { - [sw setExitEffect:[[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:sw] autorelease]]; - } else if ( effectTag == 2104 ) { - [sw setExitEffect:[[[ITPivotWindowEffect alloc] initWithWindow:sw] autorelease]]; - } - - [[sw exitEffect] setEffectTime:time]; - } else if ( [sender tag] == 2050) { - float newTime = (-([sender floatValue])); + float newTime = ( -([sender floatValue]) ); [df setFloat:newTime forKey:@"statusWindowAppearanceSpeed"]; [[sw entryEffect] setEffectTime:newTime]; } else if ( [sender tag] == 2060) { - float newTime = (-([sender floatValue])); + float newTime = ( -([sender floatValue]) ); [df setFloat:newTime forKey:@"statusWindowVanishSpeed"]; [[sw exitEffect] setEffectTime:newTime]; } else if ( [sender tag] == 2070) { @@ -481,16 +492,6 @@ static PreferencesController *prefs = nil; [df synchronize]; } -- (void)setCustomColor:(NSColor *)color updateWell:(BOOL)update -{ - [(ITTSWBackgroundView *)[[StatusWindow sharedWindow] contentView] setBackgroundColor:color]; - [df setObject:[NSArchiver archivedDataWithRootObject:color] forKey:@"statusWindowBackgroundColor"]; - - if ( update ) { - [backgroundColorWell setColor:color]; - } -} - - (void)registerDefaults { BOOL found = NO; @@ -735,13 +736,11 @@ static PreferencesController *prefs = nil; - (void)setupUI { NSMutableDictionary *loginwindow; - NSMutableArray *loginarray; + NSMutableArray *loginarray; NSEnumerator *loginEnum; NSEnumerator *keyArrayEnum; NSString *serverName; NSData *colorData; - NSArray *effectClasses = [ITWindowEffect effectClasses]; -// NSEnumerator *effectEnum = [effectList objectEnumerator]; int selectedBGStyle; id anItem; @@ -789,22 +788,32 @@ static PreferencesController *prefs = nil; [launchPlayerAtLaunchCheckbox setState:[df boolForKey:@"LaunchPlayerWithMT"] ? NSOnState : NSOffState]; // Setup the positioning controls + [positionMatrix selectCellAtRow:[df integerForKey:@"statusWindowVerticalPosition"] + column:[df integerForKey:@"statusWindowHorizontalPosition"]]; // Setup effects controls // Populate the effects popups - [appearanceEffectPopup removeItemAtIndex:0]; - [vanishEffectPopup removeItemAtIndex:0]; - [appearanceEffectPopup addItemsWithTitles:[[effectList allValues] objectsForKey:@"Name"]]; // category method - [vanishEffectPopup addItemsWithTitles:[[effectList allValues] objectsForKey:@"Name"]]; // category method + [appearanceEffectPopup setAutoenablesItems:NO]; + [vanishEffectPopup setAutoenablesItems:NO]; + [self repopulateEffectPopupsForVerticalPosition:[df integerForKey:@"statusWindowVerticalPosition"] + horizontalPosition:[df integerForKey:@"statusWindowHorizontalPosition"]]; // Attempt to find the pref'd effect in the list. // If it's not there, use cut/dissolve. - + if ( [effectClasses containsObject:NSClassFromString([df stringForKey:@"statusWindowAppearanceEffect"])] ) { + [appearanceEffectPopup selectItemAtIndex:[effectClasses indexOfObject:NSClassFromString([df stringForKey:@"statusWindowAppearanceEffect"])]]; + } else { + [appearanceEffectPopup selectItemAtIndex:[effectClasses indexOfObject:NSClassFromString(@"ITCutWindowEffect")]]; + } + + if ( [effectClasses containsObject:NSClassFromString([df stringForKey:@"statusWindowVanishEffect"])] ) { + [vanishEffectPopup selectItemAtIndex:[effectClasses indexOfObject:NSClassFromString([df stringForKey:@"statusWindowVanishEffect"])]]; + } else { + [vanishEffectPopup selectItemAtIndex:[effectClasses indexOfObject:NSClassFromString(@"ITCutWindowEffect")]]; + } - [appearanceEffectPopup selectItem:[appearanceEffectPopup itemAtIndex:[appearanceEffectPopup indexOfItemWithTag:[df integerForKey:@"statusWindowAppearanceEffect"]]]]; - [vanishEffectPopup selectItem:[vanishEffectPopup itemAtIndex:[vanishEffectPopup indexOfItemWithTag:[df integerForKey:@"statusWindowVanishEffect"]]]]; - [appearanceSpeedSlider setFloatValue:-([df floatForKey:@"statusWindowAppearanceSpeed"])]; - [vanishSpeedSlider setFloatValue:-([df floatForKey:@"statusWindowVanishSpeed"])]; + [appearanceSpeedSlider setFloatValue:( -([df floatForKey:@"statusWindowAppearanceSpeed"]) )]; + [vanishSpeedSlider setFloatValue:( -([df floatForKey:@"statusWindowVanishSpeed"]) )]; [vanishDelaySlider setFloatValue:[df floatForKey:@"statusWindowVanishDelay"]]; // Setup General Controls @@ -871,9 +880,95 @@ static PreferencesController *prefs = nil; } } -- (NSArray *)effectNamesFromDictionary:(NSDictionary *)infoDict +- (void)setStatusWindowEntryEffect:(Class)effectClass { + StatusWindow *sw = [StatusWindow sharedWindow]; + + float time = ([df floatForKey:@"statusWindowAppearanceSpeed"] ? [df floatForKey:@"statusWindowAppearanceSpeed"] : 0.8); + [df setObject:NSStringFromClass(effectClass) forKey:@"statusWindowAppearanceEffect"]; + + [sw setEntryEffect:[[[effectClass alloc] initWithWindow:sw] autorelease]]; + [[sw entryEffect] setEffectTime:time]; +} + +- (void)setStatusWindowExitEffect:(Class)effectClass +{ + StatusWindow *sw = [StatusWindow sharedWindow]; + + float time = ([df floatForKey:@"statusWindowVanishSpeed"] ? [df floatForKey:@"statusWindowVanishSpeed"] : 0.8); + [df setObject:NSStringFromClass(effectClass) forKey:@"statusWindowVanishEffect"]; + + [sw setExitEffect:[[[effectClass alloc] initWithWindow:sw] autorelease]]; + [[sw exitEffect] setEffectTime:time]; +} + +- (void)setCustomColor:(NSColor *)color updateWell:(BOOL)update +{ + [(ITTSWBackgroundView *)[[StatusWindow sharedWindow] contentView] setBackgroundColor:color]; + [df setObject:[NSArchiver archivedDataWithRootObject:color] forKey:@"statusWindowBackgroundColor"]; + + if ( update ) { + [backgroundColorWell setColor:color]; + } +} + +- (void)repopulateEffectPopupsForVerticalPosition:(ITVerticalWindowPosition)vPos horizontalPosition:(ITHorizontalWindowPosition)hPos +{ + NSEnumerator *effectEnum = [effectClasses objectEnumerator]; + id anItem; + + [appearanceEffectPopup removeAllItems]; + [vanishEffectPopup removeAllItems]; + + while ( (anItem = [effectEnum nextObject]) ) { + [appearanceEffectPopup addItemWithTitle:[anItem effectName]]; + [vanishEffectPopup addItemWithTitle:[anItem effectName]]; + + [[appearanceEffectPopup lastItem] setRepresentedObject:anItem]; + [[vanishEffectPopup lastItem] setRepresentedObject:anItem]; + + if ( [self effect:anItem supportsVerticalPosition:vPos withHorizontalPosition:hPos] ) { + [[appearanceEffectPopup lastItem] setEnabled:YES]; + [[vanishEffectPopup lastItem] setEnabled:YES]; + } else { + [[appearanceEffectPopup lastItem] setEnabled:NO]; + [[vanishEffectPopup lastItem] setEnabled:NO]; + } + } + +} + +- (BOOL)effect:(Class)effectClass supportsVerticalPosition:(ITVerticalWindowPosition)vPos withHorizontalPosition:(ITHorizontalWindowPosition)hPos +{ + BOOL valid = NO; + + if ( vPos == ITWindowPositionTop ) { + if ( hPos == ITWindowPositionLeft ) { + valid = ( [[[[effectClass supportedPositions] objectForKey:@"Top"] objectForKey:@"Left"] boolValue] ) ; + } else if ( hPos == ITWindowPositionCenter ) { + valid = ( [[[[effectClass supportedPositions] objectForKey:@"Top"] objectForKey:@"Center"] boolValue] ); + } else if ( hPos == ITWindowPositionRight ) { + valid = ( [[[[effectClass supportedPositions] objectForKey:@"Top"] objectForKey:@"Right"] boolValue] ); + } + } else if ( vPos == ITWindowPositionMiddle ) { + if ( hPos == ITWindowPositionLeft ) { + valid = ( [[[[effectClass supportedPositions] objectForKey:@"Middle"] objectForKey:@"Left"] boolValue] ); + } else if ( hPos == ITWindowPositionCenter ) { + valid = ( [[[[effectClass supportedPositions] objectForKey:@"Middle"] objectForKey:@"Center"] boolValue] ); + } else if ( hPos == ITWindowPositionRight ) { + valid = ( [[[[effectClass supportedPositions] objectForKey:@"Middle"] objectForKey:@"Right"] boolValue] ); + } + } else if ( vPos == ITWindowPositionBottom ) { + if ( hPos == ITWindowPositionLeft ) { + valid = ( [[[[effectClass supportedPositions] objectForKey:@"Bottom"] objectForKey:@"Left"] boolValue] ); + } else if ( hPos == ITWindowPositionCenter ) { + valid = ( [[[[effectClass supportedPositions] objectForKey:@"Bottom"] objectForKey:@"Center"] boolValue] ); + } else if ( hPos == ITWindowPositionRight ) { + valid = ( [[[[effectClass supportedPositions] objectForKey:@"Bottom"] objectForKey:@"Right"] boolValue] ); + } + } + return valid; } - (IBAction)changeMenus:(id)sender @@ -1107,6 +1202,7 @@ static PreferencesController *prefs = nil; { [hotKeysArray release]; [hotKeysDictionary release]; + [effectClasses release]; [menuTableView setDataSource:nil]; [allTableView setDataSource:nil]; [controller release];