Added hotkeys for setting individual song ratings 0-5 stars.
[MenuTunes.git] / MainController.m
index 8cb2643..2517c39 100755 (executable)
@@ -6,6 +6,7 @@
 #import <ITKit/ITHotKeyCenter.h>
 #import <ITKit/ITHotKey.h>
 #import <ITKit/ITKeyCombo.h>
+#import <ITKit/ITCategory-NSMenu.h>
 #import "StatusWindow.h"
 #import "StatusWindowController.h"
 #import "StatusItemHack.h"
@@ -810,6 +811,20 @@ static MainController *sharedController;
         [hotKey setAction:@selector(popupMenu)];
         [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
     }
+    
+    int i;
+    for (i = 0; i <= 5; i++) {
+        NSString *curName = [NSString stringWithFormat:@"SetRating%i", i];
+        if ([df objectForKey:curName] != nil) {
+            ITDebugLog(@"Setting up set rating %i hot key.", i);
+            hotKey = [[ITHotKey alloc] init];
+            [hotKey setName:curName];
+            [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:curName]]];
+            [hotKey setTarget:self];
+            [hotKey setAction:@selector(setRating:)];
+            [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
+        }
+    }
     ITDebugLog(@"Finished setting up hot keys.");
 }
 
@@ -1078,6 +1093,13 @@ static MainController *sharedController;
     NS_ENDHANDLER
 }
 
+- (void)setRating:(ITHotKey *)sender
+{
+    float rating = ([[sender name] characterAtIndex:9] - 48) / 5.0;
+    [self selectSongRating:rating];
+    [statusWindowController showRatingWindowWithRating:rating];
+}
+
 - (void)toggleLoop
 {
     NS_DURING