Cleaned up modified add behavior.

CQTexperiment
vspader 2009-02-28 14:22:33 -08:00
parent 1fcf3bb2ff
commit 03937f480b
7 changed files with 54 additions and 58 deletions

View File

@ -171,8 +171,8 @@ increase/decrease as long as the user holds the left/right, plus/minus button */
{ {
if (returnCode == NSOKButton) if (returnCode == NSOKButton)
{ {
[playlistLoader willInsertFiles:[panel URLs] origin:OpenFromOpenPanel]; [playlistLoader willInsertURLs:[panel URLs] origin:URLOriginInternal];
[playlistLoader didInsertFiles:[playlistLoader addURLs:[panel URLs] sort:YES] origin:OpenFromOpenPanel]; [playlistLoader didInsertURLs:[playlistLoader addURLs:[panel URLs] sort:YES] origin:URLOriginInternal];
} }
} }
@ -207,8 +207,8 @@ increase/decrease as long as the user holds the left/right, plus/minus button */
{ {
if (returnCode == NSOKButton) if (returnCode == NSOKButton)
{ {
[playlistLoader willInsertFiles:[NSArray arrayWithObject:[panel url]] origin:OpenFromOpenUrlPanel]; [playlistLoader willInsertURLs:[NSArray arrayWithObject:[panel url]] origin:URLOriginExternal];
[playlistLoader didInsertFiles:[playlistLoader addURLs:[NSArray arrayWithObject:[panel url]] sort:NO] origin:OpenFromOpenUrlPanel]; [playlistLoader didInsertURLs:[playlistLoader addURLs:[NSArray arrayWithObject:[panel url]] sort:NO] origin:URLOriginExternal];
} }
} }
@ -285,8 +285,8 @@ increase/decrease as long as the user holds the left/right, plus/minus button */
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{ {
NSArray* urls = [NSArray arrayWithObject:[NSURL fileURLWithPath:filename]]; NSArray* urls = [NSArray arrayWithObject:[NSURL fileURLWithPath:filename]];
[playlistLoader willInsertFiles:urls origin:OpenFromFinder]; [playlistLoader willInsertURLs:urls origin:URLOriginExternal];
[playlistLoader didInsertFiles:[playlistLoader addURLs:urls sort:NO] origin:OpenFromFinder]; [playlistLoader didInsertURLs:[playlistLoader addURLs:urls sort:NO] origin:URLOriginExternal];
return YES; return YES;
} }
@ -299,8 +299,8 @@ increase/decrease as long as the user holds the left/right, plus/minus button */
{ {
[urls addObject:[NSURL fileURLWithPath:filename]]; [urls addObject:[NSURL fileURLWithPath:filename]];
} }
[playlistLoader willInsertFiles:urls origin:OpenFromFinder]; [playlistLoader willInsertURLs:urls origin:URLOriginExternal];
[playlistLoader didInsertFiles:[playlistLoader addURLs:urls sort:YES] origin:OpenFromFinder]; [playlistLoader didInsertURLs:[playlistLoader addURLs:urls sort:YES] origin:URLOriginExternal];
[theApplication replyToOpenOrPrint:NSApplicationDelegateReplySuccess]; [theApplication replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
} }

View File

@ -24,19 +24,9 @@ typedef enum {
} RepeatMode; } RepeatMode;
typedef enum { typedef enum {
OpenPlaylist_related = 0, URLOriginInternal = 0,
LoadPlaylist, URLOriginExternal,
DropOnPlaylist, } URLOrigin;
OpenFromOpenPanel,
OpenFromOpenUrlPanel,
OpenPlaylist_related_end,
OpenFinder_Related, //meta-value
OpenFromFinder,
OpenFromFileTree,
OpenFromSpotlight, //?
OpenFinder_Related_end,
} AddedFilesSource;
@interface PlaylistController : DNDArrayController { @interface PlaylistController : DNDArrayController {
IBOutlet PlaylistLoader *playlistLoader; IBOutlet PlaylistLoader *playlistLoader;
@ -103,8 +93,8 @@ typedef enum {
- (PlaylistEntry *)entryAtIndex:(int)i; - (PlaylistEntry *)entryAtIndex:(int)i;
// Event inlets: // Event inlets:
- (void)willInsertFiles:(NSArray*)urls origin:(AddedFilesSource)src; - (void)willInsertURLs:(NSArray*)urls origin:(URLOrigin)origin;
- (void)didInsertFiles:(NSArray*)entries origin:(AddedFilesSource)src; - (void)didInsertURLs:(NSArray*)urls origin:(URLOrigin)origin;
// queue methods // queue methods
- (IBAction)toggleQueued:(id)sender; - (IBAction)toggleQueued:(id)sender;

View File

@ -204,18 +204,18 @@
// Determine the type of object that was dropped // Determine the type of object that was dropped
NSArray *supportedtypes = [NSArray arrayWithObjects:CogUrlsPboardType, NSFilenamesPboardType, iTunesDropType, nil]; NSArray *supportedTypes = [NSArray arrayWithObjects:CogUrlsPboardType, NSFilenamesPboardType, iTunesDropType, nil];
NSPasteboard *pboard = [info draggingPasteboard]; NSPasteboard *pboard = [info draggingPasteboard];
NSString *bestType = [pboard availableTypeFromArray:supportedtypes]; NSString *bestType = [pboard availableTypeFromArray:supportedTypes];
NSMutableArray *accept_urls = [[NSMutableArray alloc] init]; NSMutableArray *acceptedURLs = [[NSMutableArray alloc] init];
// Get files from an file drawer drop // Get files from an file drawer drop
if ([bestType isEqualToString:CogUrlsPboardType]) { if ([bestType isEqualToString:CogUrlsPboardType]) {
NSArray *urls = [NSUnarchiver unarchiveObjectWithData:[[info draggingPasteboard] dataForType:CogUrlsPboardType]]; NSArray *urls = [NSUnarchiver unarchiveObjectWithData:[[info draggingPasteboard] dataForType:CogUrlsPboardType]];
NSLog(@"URLS: %@", urls); NSLog(@"URLS: %@", urls);
//[playlistLoader insertURLs: urls atIndex:row sort:YES]; //[playlistLoader insertURLs: urls atIndex:row sort:YES];
[accept_urls addObjectsFromArray:urls]; [acceptedURLs addObjectsFromArray:urls];
} }
// Get files from a normal file drop (such as from Finder) // Get files from a normal file drop (such as from Finder)
@ -228,7 +228,7 @@
} }
//[playlistLoader insertURLs:urls atIndex:row sort:YES]; //[playlistLoader insertURLs:urls atIndex:row sort:YES];
[accept_urls addObjectsFromArray:urls]; [acceptedURLs addObjectsFromArray:urls];
[urls release]; [urls release];
} }
@ -245,20 +245,23 @@
} }
//[playlistLoader insertURLs:urls atIndex:row sort:YES]; //[playlistLoader insertURLs:urls atIndex:row sort:YES];
[accept_urls addObjectsFromArray:urls]; [acceptedURLs addObjectsFromArray:urls];
[urls release]; [urls release];
} }
if ([accept_urls count]) if ([acceptedURLs count])
{ {
[self willInsertFiles:accept_urls origin:DropOnPlaylist]; [self willInsertURLs:acceptedURLs origin:URLOriginInternal];
if (![[entriesController entries] count])
if (![[entriesController entries] count]) {
row = 0; row = 0;
NSArray* entries = [playlistLoader insertURLs:accept_urls atIndex:row sort:YES];
[self didInsertFiles:entries origin:DropOnPlaylist];
} }
[accept_urls release]; NSArray* entries = [playlistLoader insertURLs:acceptedURLs atIndex:row sort:YES];
[self didInsertURLs:entries origin:URLOriginInternal];
}
[acceptedURLs release];
if ([self shuffle] == YES) if ([self shuffle] == YES)
[self resetShuffleList]; [self resetShuffleList];
@ -787,7 +790,7 @@
} }
// Event inlets: // Event inlets:
- (void)willInsertFiles:(NSArray*)urls origin:(AddedFilesSource)src - (void)willInsertURLs:(NSArray*)urls origin:(URLOrigin)origin
{ {
if (![urls count]) if (![urls count])
return; return;
@ -802,18 +805,21 @@
NSLog(@"Behavior: %@", [[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesBehavior"]); NSLog(@"Behavior: %@", [[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesBehavior"]);
NSLog(@"Altered Behavior: %@", [[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesAlteredBehavior"]); NSLog(@"Altered Behavior: %@", [[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesAlteredBehavior"]);
if (src >= OpenFinder_Related && src <= OpenFinder_Related_end) if (origin == URLOriginExternal) {
//possible settings are "clearAndPlay", "enqueue", "enqueueAndPlay" //possible settings are "clearAndPlay", "enqueue", "enqueueAndPlay"
should_clean = (!modifier1_pressed && ![[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesBehavior"] compare:@"clearAndPlay"]) should_clean = (!modifier1_pressed && ![[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesBehavior"] compare:@"clearAndPlay"])
|| ( modifier1_pressed && ![[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesAlteredBehavior"] compare:@"clearAndPlay"]); || ( modifier1_pressed && ![[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesAlteredBehavior"] compare:@"clearAndPlay"]);
if (src >= OpenPlaylist_related && src <= OpenPlaylist_related_end) }
else {
should_clean = modifier1_pressed; should_clean = modifier1_pressed;
}
if (should_clean)
if (should_clean) {
[self clear:self]; [self clear:self];
}
} }
- (void)didInsertFiles:(NSArray*)entries origin:(AddedFilesSource)src - (void)didInsertURLs:(NSArray*)entries origin:(URLOrigin)origin
{ {
if (![entries count]) if (![entries count])
return; return;
@ -825,19 +831,19 @@
modifier1_pressed |= ((mods & kCGEventFlagMaskShift)!=0); modifier1_pressed |= ((mods & kCGEventFlagMaskShift)!=0);
bool should_autoplay = false; bool should_autoplay = false;
if (src >= OpenFinder_Related && src <= OpenFinder_Related_end) if (origin == URLOriginExternal)
should_autoplay = (!modifier1_pressed && (![[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesBehavior"] compare:@"clearAndPlay"] should_autoplay = (!modifier1_pressed && (![[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesBehavior"] compare:@"clearAndPlay"]
|| ![[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesBehavior"] compare:@"enqueueAndPlay"])) || ![[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesBehavior"] compare:@"enqueueAndPlay"]))
|| ( modifier1_pressed && (![[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesAlteredBehavior"] compare:@"clearAndPlay"] || ( modifier1_pressed && (![[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesAlteredBehavior"] compare:@"clearAndPlay"]
|| ![[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesAlteredBehavior"] compare:@"enqueueAndPlay"])); || ![[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesAlteredBehavior"] compare:@"enqueueAndPlay"]));
if (src >= OpenPlaylist_related && src <= OpenPlaylist_related_end) if (origin == URLOriginInternal)
should_autoplay = modifier1_pressed; should_autoplay = modifier1_pressed;
//Auto start playback //Auto start playback
if (should_autoplay && [[entriesController entries] count] > 0) { if (should_autoplay && [[entriesController entries] count] > 0) {
[[entries objectAtIndex:0] setValuesForKeysWithDictionary:[playlistLoader readEntryInfo:[entries objectAtIndex:0]]]; [[entries objectAtIndex:0] setValuesForKeysWithDictionary:[playlistLoader readEntryInfo:[entries objectAtIndex:0]]];
[playbackController playEntry: [entries objectAtIndex:0]]; [playbackController playEntry: [entries objectAtIndex:0]];
} }
} }

View File

@ -45,7 +45,7 @@ typedef enum {
- (NSArray *)acceptableContainerTypes; - (NSArray *)acceptableContainerTypes;
// Event inlets (passed to playlist controler): // Event inlets (passed to playlist controler):
- (void)willInsertFiles:(NSArray*)urls origin:(AddedFilesSource)src; - (void)willInsertURLs:(NSArray*)urls origin:(URLOrigin)origin;
- (void)didInsertFiles:(NSArray*)entries origin:(AddedFilesSource)src; - (void)didInsertURLs:(NSArray*)entries origin:(URLOrigin)origin;
@end @end

View File

@ -406,13 +406,13 @@
return [AudioPlayer containerTypes]; return [AudioPlayer containerTypes];
} }
- (void)willInsertFiles:(NSArray*)urls origin:(AddedFilesSource)src - (void)willInsertURLs:(NSArray*)urls origin:(URLOrigin)origin
{ {
[playlistController willInsertFiles:urls origin:src]; [playlistController willInsertURLs:urls origin:origin];
} }
- (void)didInsertFiles:(NSArray*)entries origin:(AddedFilesSource)src - (void)didInsertURLs:(NSArray*)urls origin:(URLOrigin)origin
{ {
[playlistController didInsertFiles:entries origin:src]; [playlistController didInsertURLs:urls origin:origin];
} }
@end @end

View File

@ -75,8 +75,8 @@
- (void) addToPlaylist:(NSArray *)urls - (void) addToPlaylist:(NSArray *)urls
{ {
[playlistLoader willInsertFiles:urls origin:OpenFromFileTree]; [playlistLoader willInsertURLs:urls origin:URLOriginExternal];
[playlistLoader didInsertFiles:[playlistLoader addURLs:urls sort:YES] origin:OpenFromFileTree]; [playlistLoader didInsertURLs:[playlistLoader addURLs:urls sort:YES] origin:URLOriginExternal];
} }

View File

@ -277,8 +277,8 @@ static NSPredicate * musicOnlyPredicate = nil;
if ([tracks count] == 0) if ([tracks count] == 0)
tracks = playlistController.arrangedObjects; tracks = playlistController.arrangedObjects;
[playlistLoader willInsertFiles:[tracks valueForKey:@"URL"] origin:OpenFromSpotlight]; [playlistLoader willInsertURLs:[tracks valueForKey:@"URL"] origin:URLOriginExternal];
[playlistLoader didInsertFiles:[playlistLoader addURLs:[tracks valueForKey:@"URL"] sort:NO] origin:OpenFromSpotlight]; [playlistLoader didInsertURLs:[playlistLoader addURLs:[tracks valueForKey:@"URL"] sort:NO] origin:URLOriginExternal];
[self.query enableUpdates]; [self.query enableUpdates];
} }