Fixed the delete key in the prefs table view.
[MenuTunes.git] / PreferencesController.m
index 086e2ec..c2af444 100755 (executable)
@@ -1,10 +1,20 @@
 #import "PreferencesController.h"
 #import "MainController.h"
+#import "StatusWindow.h"
+#import "CustomMenuTableView.h"
+
 #import <ITKit/ITHotKeyCenter.h>
 #import <ITKit/ITKeyCombo.h>
 #import <ITKit/ITWindowPositioning.h>
 #import <ITKit/ITKeyBroadcaster.h>
 
+#import <ITKit/ITCutWindowEffect.h>
+#import <ITKit/ITDissolveWindowEffect.h>
+#import <ITKit/ITSlideHorizontallyWindowEffect.h>
+#import <ITKit/ITSlideVerticallyWindowEffect.h>
+#import <ITKit/ITPivotWindowEffect.h>
+
+
 #define SENDER_STATE (([sender state] == NSOnState) ? YES : NO)
 
 /*************************************************************************/
@@ -96,7 +106,6 @@ static PreferencesController *prefs = nil;
     [window setLevel:NSStatusWindowLevel];
     [window center];
     [window makeKeyAndOrderFront:self];
-    [NSApp activateIgnoringOtherApps:YES];
 }
 
 - (IBAction)changeGeneralSetting:(id)sender
@@ -122,11 +131,14 @@ static PreferencesController *prefs = nil;
     } else if ( [sender tag] == 1090) {
         [df setBool:SENDER_STATE forKey:@"showTrackRating"];
     }
+    
     [df synchronize];
 }
 
 - (IBAction)changeStatusWindowSetting:(id)sender
 {
+    StatusWindow *sw = [StatusWindow sharedWindow];
+
     if ( [sender tag] == 2010) {
         [df setInteger:[sender selectedRow] forKey:@"statusWindowVerticalPosition"];
         [df setInteger:[sender selectedColumn] forKey:@"statusWindowHorizontalPosition"];
@@ -134,19 +146,61 @@ static PreferencesController *prefs = nil;
     } else if ( [sender tag] == 2020) {
         // update screen selection
     } else if ( [sender tag] == 2030) {
-        // Update appearance effect
+        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 ) {
+            NSLog(@"dflhgldf");
+            [sw setEntryEffect:[[[ITPivotWindowEffect alloc] initWithWindow:sw] autorelease]];
+        }
+
+        [[sw entryEffect] setEffectTime:time];
+        
     } else if ( [sender tag] == 2040) {
-        // Update Vanish Effect
+        int effectTag = [[sender selectedItem] tag];
+        float time = ([df floatForKey:@"statusWindowVanishSpeed"] ? [df floatForKey:@"statusWindowVanishSpeed"] : 0.8);
+        
+        [df setInteger:[[sender selectedItem] tag] forKey:@"statusWindowVanishEffect"];
+        
+        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) {
-        // Update appearance speed
+        float newTime = (-([sender floatValue]));
+        [df setFloat:newTime forKey:@"statusWindowAppearanceSpeed"];
+        [[sw entryEffect] setEffectTime:newTime];
     } else if ( [sender tag] == 2060) {
-        // Update vanish speed
+        float newTime = (-([sender floatValue]));
+        [df setFloat:newTime forKey:@"statusWindowVanishSpeed"];
+        [[sw exitEffect] setEffectTime:newTime];
     } else if ( [sender tag] == 2070) {
-        // Update vanish delay
+        [df setFloat:[sender floatValue] forKey:@"statusWindowVanishDelay"];
+        [sw setExitDelay:[sender floatValue]];
     } else if ( [sender tag] == 2080) {
-        // Update "Song Info window when song changes" setting.
         [df setBool:SENDER_STATE forKey:@"showSongInfoOnChange"];
     }
+    
+    [df synchronize];
 }
 
 - (IBAction)changeHotKey:(id)sender
@@ -303,31 +357,32 @@ static PreferencesController *prefs = nil;
                 if ( NSRunAlertPanel(NSLocalizedString(@"duplicateCombo", @"Duplicate Key Combo") , NSLocalizedString(@"duplicateCombo_msg", @"The specified key combo is already in use..."), NSLocalizedString(@"replace", @"Replace"), NSLocalizedString(@"cancel", @"Cancel"), nil) ) {
                     [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:currentHotKey];
                     if ([enumKey isEqualToString:@"PlayPause"]) {
-                        [playPauseButton setTitle:@""];
+                        [playPauseButton setTitle:@"(None)"];
                     } else if ([enumKey isEqualToString:@"NextTrack"]) {
-                        [nextTrackButton setTitle:@""];
+                        [nextTrackButton setTitle:@"(None)"];
                     } else if ([enumKey isEqualToString:@"PrevTrack"]) {
-                        [previousTrackButton setTitle:@""];
+                        [previousTrackButton setTitle:@"(None)"];
                     } else if ([enumKey isEqualToString:@"ShowPlayer"]) {
-                        [showPlayerButton setTitle:@""];
+                        [showPlayerButton setTitle:@"(None)"];
                     } else if ([enumKey isEqualToString:@"TrackInfo"]) {
-                        [trackInfoButton setTitle:@""];
+                        [trackInfoButton setTitle:@"(None)"];
                     } else if ([enumKey isEqualToString:@"UpcomingSongs"]) {
-                        [upcomingSongsButton setTitle:@""];
+                        [upcomingSongsButton setTitle:@"(None)"];
                     } else if ([enumKey isEqualToString:@"IncrementVolume"]) {
-                        [volumeIncrementButton setTitle:@""];
+                        [volumeIncrementButton setTitle:@"(None)"];
                     } else if ([enumKey isEqualToString:@"DecrementVolume"]) {
-                        [volumeDecrementButton setTitle:@""];
+                        [volumeDecrementButton setTitle:@"(None)"];
                     } else if ([enumKey isEqualToString:@"IncrementRating"]) {
-                        [ratingIncrementButton setTitle:@""];
+                        [ratingIncrementButton setTitle:@"(None)"];
                     } else if ([enumKey isEqualToString:@"DecrementRating"]) {
-                        [ratingDecrementButton setTitle:@""];
+                        [ratingDecrementButton setTitle:@"(None)"];
                     } else if ([enumKey isEqualToString:@"ToggleShuffle"]) {
-                        [toggleShuffleButton setTitle:@""];
+                        [toggleShuffleButton setTitle:@"(None)"];
                     } else if ([enumKey isEqualToString:@"ToggleLoop"]) {
-                        [toggleLoopButton setTitle:@""];
+                        [toggleLoopButton setTitle:@"(None)"];
                     }
                     [df setObject:[[ITKeyCombo clearKeyCombo] plistRepresentation] forKey:enumKey];
+                    [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:enumKey];
                 } else {
                     return;
                 }
@@ -368,6 +423,27 @@ static PreferencesController *prefs = nil;
     [self cancelHotKey:sender];
 }
 
+- (void)deletePressedInTableView:(NSTableView *)tableView
+{
+    if (tableView == menuTableView) {
+        int selRow = [tableView selectedRow];
+        if (selRow != - 1) {
+            NSString *object = [myItems objectAtIndex:selRow];
+            
+            if ([object isEqualToString:@"preferences"]) {
+                NSBeep();
+                return;
+            }
+            
+            if (![object isEqualToString:@"separator"])
+                [availableItems addObject:object];
+            [myItems removeObjectAtIndex:selRow];
+            [menuTableView reloadData];
+            [allTableView reloadData];
+        }
+        [self changeMenus:self];
+    }
+}
 
 
 /*************************************************************************/
@@ -396,7 +472,7 @@ static PreferencesController *prefs = nil;
     
     string = [combo description];
     if (string == nil) {
-        string = @"";
+        string = @"(None)";
     }
     [keyComboField setStringValue:string];
 }
@@ -442,6 +518,7 @@ static PreferencesController *prefs = nil;
     id            anItem;
     // Set the list of items you can have.
     availableItems = [[NSMutableArray alloc] initWithObjects:
+        @"separator",
         @"trackInfo",
         @"upcomingSongs",
         @"playlists",
@@ -453,7 +530,7 @@ static PreferencesController *prefs = nil;
         @"fastForward",
         @"rewind",
         @"showPlayer",
-        @"separator",
+        @"quit",
         nil];
     
     // Get our preferred menu
@@ -602,6 +679,7 @@ static PreferencesController *prefs = nil;
     [artistCheckbox setState:[df boolForKey:@"showArtist"] ? NSOnState : NSOffState];
     [trackTimeCheckbox setState:[df boolForKey:@"showTime"] ? NSOnState : NSOffState];
     [trackNumberCheckbox setState:[df boolForKey:@"showTrackNumber"] ? NSOnState : NSOffState];
+    [ratingCheckbox setState:[df boolForKey:@"showTrackRating"] ? NSOnState : NSOffState];
     
     // Set the launch at login checkbox state
     [df synchronize];
@@ -624,57 +702,31 @@ static PreferencesController *prefs = nil;
 
 - (void)setLaunchesAtLogin:(BOOL)flag
 {
-    if ( flag ) {
-        NSMutableDictionary *loginwindow;
-        NSMutableArray *loginarray;
-        ComponentInstance temp = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
-        int i;
-        BOOL skip = NO;
-
-        [df synchronize];
-        loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
-        loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
-
-        for (i = 0; i < [loginarray count]; i++) {
-            NSDictionary *tempDict = [loginarray objectAtIndex:i];
-            if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
-                skip = YES;
-            }
-        }
-
-        if (!skip) {
-            AEDesc scriptDesc, resultDesc;
-            NSString *script = [NSString stringWithFormat:@"tell application \"System Events\"\nmake new login item at end of login items with properties {path:\"%@\", kind:\"APPLICATION\"}\nend tell", [[NSBundle mainBundle] bundlePath]];
-
-            AECreateDesc(typeChar, [script cString], [script cStringLength],
-                         &scriptDesc);
-
-            OSADoScript(temp, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
-
-            AEDisposeDesc(&scriptDesc);
-            AEDisposeDesc(&resultDesc);
-            CloseComponent(temp);
-        }
-
+    NSMutableDictionary *loginwindow;
+    NSMutableArray *loginarray;
+    
+    [df synchronize];
+    loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
+    loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
+    
+    if (flag) {
+        NSDictionary *itemDict = [NSDictionary dictionaryWithObjectsAndKeys:
+        [[NSBundle mainBundle] bundlePath], @"Path",
+        [NSNumber numberWithInt:0], @"Hide", nil];
+        [loginarray addObject:itemDict];
     } else {
-        NSMutableDictionary *loginwindow;
-        NSMutableArray *loginarray;
         int i;
-
-        [df synchronize];
-        loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
-        loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
-
         for (i = 0; i < [loginarray count]; i++) {
             NSDictionary *tempDict = [loginarray objectAtIndex:i];
             if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
                 [loginarray removeObjectAtIndex:i];
-                [df setPersistentDomain:loginwindow forName:@"loginwindow"];
-                [df synchronize];
                 break;
             }
         }
     }
+    [df setPersistentDomain:loginwindow forName:@"loginwindow"];
+    [df synchronize];
+    [loginwindow release];
 }
 
 
@@ -802,7 +854,7 @@ static PreferencesController *prefs = nil;
         
         if ([[[info draggingPasteboard] types] containsObject:@"MenuTableViewPboardType"]) {
             NSString *item = [myItems objectAtIndex:[[[info draggingPasteboard] stringForType:@"MenuTableViewPboardType"] intValue]];
-            if ([item isEqualToString:@"Preferences"] || [item isEqualToString:@"Quit"]) {
+            if ([item isEqualToString:@"preferences"]) {
                 return NSDragOperationNone;
             }
         }