Implemented clipboard support for the playlist view
parent
1850f3be7d
commit
088594dc8c
|
@ -85,7 +85,7 @@
|
|||
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
|
||||
</tableHeaderCell>
|
||||
<imageCell key="dataCell" controlSize="small" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="9DCC8810-EF6B-49E3-96DC-98661029C60E" id="1801">
|
||||
<imageCell key="dataCell" controlSize="small" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="4B993A26-A177-4F5F-A710-C5906FE99F27" id="1801">
|
||||
<font key="font" metaFont="system"/>
|
||||
</imageCell>
|
||||
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
|
||||
|
@ -291,6 +291,7 @@
|
|||
<outlet property="menu" destination="1063" id="1065"/>
|
||||
<outlet property="playbackController" destination="705" id="719"/>
|
||||
<outlet property="playlistController" destination="218" id="261"/>
|
||||
<outlet property="playlistLoader" destination="1319" id="Euf-Ks-f21"/>
|
||||
</connections>
|
||||
</tableView>
|
||||
</subviews>
|
||||
|
@ -584,7 +585,7 @@
|
|||
<outlet property="initialFirstResponder" destination="207" id="720"/>
|
||||
<outlet property="itemLionFullscreenToggle" destination="2456" id="5yZ-Jj-awr"/>
|
||||
<outlet property="itemLionSeparator" destination="2455" id="0p5-i7-wLz"/>
|
||||
<outlet property="playlistView" destination="206" id="M6Y-oh-bGz"/>
|
||||
<outlet property="playlistView" destination="206" id="mah-wo-1nd"/>
|
||||
</connections>
|
||||
</window>
|
||||
<window title="Cog" allowsToolTipsWhenApplicationIsInactive="NO" oneShot="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="Mini Window" animationBehavior="default" id="2234" userLabel="Mini Window (Window)" customClass="MiniWindow">
|
||||
|
@ -1759,7 +1760,7 @@ Gw
|
|||
<customObject id="2434" customClass="FeedbackController"/>
|
||||
</objects>
|
||||
<resources>
|
||||
<image name="9DCC8810-EF6B-49E3-96DC-98661029C60E" width="17" height="17">
|
||||
<image name="4B993A26-A177-4F5F-A710-C5906FE99F27" width="17" height="17">
|
||||
<mutableData key="keyedArchiveRepresentation">
|
||||
YnBsaXN0MDDUAQIDBAUGRkdYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3ASAAGGoK8QDwcI
|
||||
ExQZHh8qKyw0NzpAQ1UkbnVsbNUJCgsMDQ4PEBESVk5TU2l6ZVYkY2xhc3NcTlNJbWFnZUZsYWdzVk5T
|
||||
|
|
|
@ -10,10 +10,12 @@
|
|||
|
||||
#import "PlaybackController.h"
|
||||
#import "PlaylistController.h"
|
||||
#import "PlaylistLoader.h"
|
||||
|
||||
@interface PlaylistView : NSTableView {
|
||||
IBOutlet PlaybackController *playbackController;
|
||||
IBOutlet PlaylistController *playlistController;
|
||||
IBOutlet PlaylistLoader *playlistLoader;
|
||||
|
||||
NSMenu *headerContextMenu;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
#import "CogAudio/Status.h"
|
||||
|
||||
#import "Logging.h"
|
||||
|
||||
@implementation PlaylistView
|
||||
|
||||
- (void)awakeFromNib
|
||||
|
@ -227,6 +229,132 @@
|
|||
[[playlistController undoManager] redo];
|
||||
}
|
||||
|
||||
- (IBAction)copy:(id)sender
|
||||
{
|
||||
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
|
||||
|
||||
[pboard clearContents];
|
||||
|
||||
NSMutableArray *selectedURLs = [[NSMutableArray alloc] init];
|
||||
|
||||
for (PlaylistEntry *pe in [[playlistController content] objectsAtIndexes:[playlistController selectionIndexes]])
|
||||
{
|
||||
[selectedURLs addObject:[pe URL]];
|
||||
}
|
||||
|
||||
[pboard setData:[NSArchiver archivedDataWithRootObject:selectedURLs] forType:CogUrlsPboardType];
|
||||
|
||||
NSMutableDictionary * tracks = [[NSMutableDictionary alloc] init];
|
||||
|
||||
unsigned long i = 0;
|
||||
for (NSURL *url in selectedURLs)
|
||||
{
|
||||
NSMutableDictionary * track = [NSMutableDictionary dictionaryWithObjectsAndKeys:[url absoluteString], @"Location", nil];
|
||||
[tracks setObject:track forKey:[NSString stringWithFormat:@"%lu", i]];
|
||||
++i;
|
||||
}
|
||||
|
||||
NSMutableDictionary * itunesPlist = [NSMutableDictionary dictionaryWithObjectsAndKeys:tracks, @"Tracks", nil];
|
||||
|
||||
[pboard setPropertyList:itunesPlist forType:iTunesDropType];
|
||||
|
||||
[tracks release];
|
||||
|
||||
NSMutableArray *filePaths = [[NSMutableArray alloc] init];
|
||||
|
||||
for (NSURL *url in selectedURLs)
|
||||
{
|
||||
if ([url isFileURL])
|
||||
[filePaths addObject:[url path]];
|
||||
}
|
||||
|
||||
if ([filePaths count])
|
||||
[pboard setPropertyList:filePaths forType:NSFilenamesPboardType];
|
||||
|
||||
[filePaths release];
|
||||
|
||||
[selectedURLs release];
|
||||
}
|
||||
|
||||
- (IBAction)cut:(id)sender
|
||||
{
|
||||
[self copy:sender];
|
||||
|
||||
[playlistController removeObjectsAtArrangedObjectIndexes:[playlistController selectionIndexes]];
|
||||
|
||||
if ([playlistController shuffle] != ShuffleOff)
|
||||
[playlistController resetShuffleList];
|
||||
}
|
||||
|
||||
- (IBAction)paste:(id)sender
|
||||
{
|
||||
// Determine the type of object that was dropped
|
||||
NSArray *supportedTypes = [NSArray arrayWithObjects:CogUrlsPboardType, NSFilenamesPboardType, iTunesDropType, nil];
|
||||
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
|
||||
NSString *bestType = [pboard availableTypeFromArray:supportedTypes];
|
||||
|
||||
NSMutableArray *acceptedURLs = [[NSMutableArray alloc] init];
|
||||
|
||||
// Get files from an file drawer drop
|
||||
if ([bestType isEqualToString:CogUrlsPboardType]) {
|
||||
NSArray *urls = [NSUnarchiver unarchiveObjectWithData:[pboard dataForType:CogUrlsPboardType]];
|
||||
DLog(@"URLS: %@", urls);
|
||||
//[playlistLoader insertURLs: urls atIndex:row sort:YES];
|
||||
[acceptedURLs addObjectsFromArray:urls];
|
||||
}
|
||||
|
||||
// Get files from a normal file drop (such as from Finder)
|
||||
if ([bestType isEqualToString:NSFilenamesPboardType]) {
|
||||
NSMutableArray *urls = [[NSMutableArray alloc] init];
|
||||
|
||||
for (NSString *file in [pboard propertyListForType:NSFilenamesPboardType])
|
||||
{
|
||||
[urls addObject:[NSURL fileURLWithPath:file]];
|
||||
}
|
||||
|
||||
//[playlistLoader insertURLs:urls atIndex:row sort:YES];
|
||||
[acceptedURLs addObjectsFromArray:urls];
|
||||
[urls release];
|
||||
}
|
||||
|
||||
// Get files from an iTunes drop
|
||||
if ([bestType isEqualToString:iTunesDropType]) {
|
||||
NSDictionary *iTunesDict = [pboard propertyListForType:iTunesDropType];
|
||||
NSDictionary *tracks = [iTunesDict valueForKey:@"Tracks"];
|
||||
|
||||
// Convert the iTunes URLs to URLs....MWAHAHAH!
|
||||
NSMutableArray *urls = [[NSMutableArray alloc] init];
|
||||
|
||||
for (NSDictionary *trackInfo in [tracks allValues]) {
|
||||
[urls addObject:[NSURL URLWithString:[trackInfo valueForKey:@"Location"]]];
|
||||
}
|
||||
|
||||
//[playlistLoader insertURLs:urls atIndex:row sort:YES];
|
||||
[acceptedURLs addObjectsFromArray:urls];
|
||||
[urls release];
|
||||
}
|
||||
|
||||
if ([acceptedURLs count])
|
||||
{
|
||||
NSUInteger row = [[playlistController content] count];
|
||||
|
||||
[playlistController willInsertURLs:acceptedURLs origin:URLOriginInternal];
|
||||
|
||||
NSArray* entries = [playlistLoader insertURLs:acceptedURLs atIndex:row sort:NO];
|
||||
[playlistLoader didInsertURLs:entries origin:URLOriginInternal];
|
||||
|
||||
if ([playlistController shuffle] != ShuffleOff)
|
||||
[playlistController resetShuffleList];
|
||||
}
|
||||
|
||||
[acceptedURLs release];
|
||||
}
|
||||
|
||||
- (IBAction)delete:(id)sender
|
||||
{
|
||||
[playlistController removeObjectsAtArrangedObjectIndexes:[playlistController selectionIndexes]];
|
||||
}
|
||||
|
||||
|
||||
-(BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem
|
||||
{
|
||||
|
@ -246,6 +374,26 @@
|
|||
else
|
||||
return NO;
|
||||
}
|
||||
if (action == @selector(cut:) || action == @selector(copy:) || action == @selector(delete:))
|
||||
{
|
||||
if ([[playlistController selectionIndexes] count] == 0)
|
||||
return NO;
|
||||
else
|
||||
return YES;
|
||||
}
|
||||
if (action == @selector(paste:))
|
||||
{
|
||||
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
|
||||
|
||||
NSArray *supportedTypes = [NSArray arrayWithObjects:CogUrlsPboardType, NSFilenamesPboardType, iTunesDropType, nil];
|
||||
|
||||
NSString *bestType = [pboard availableTypeFromArray:supportedTypes];
|
||||
|
||||
if (bestType != nil)
|
||||
return YES;
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (action == @selector(scrollToCurrentEntry:) && ([playbackController playbackStatus] == kCogStatusStopped))
|
||||
return NO;
|
||||
|
|
Loading…
Reference in New Issue