2005-06-02 18:16:43 +00:00
|
|
|
//
|
|
|
|
// PlaylistView.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 3/20/05.
|
2005-07-02 21:02:06 +00:00
|
|
|
// Copyright 2005 Vincent Spader All rights reserved.
|
2005-06-02 18:16:43 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "PlaylistView.h"
|
|
|
|
|
2021-02-19 05:23:13 +00:00
|
|
|
#import <Carbon/Carbon.h>
|
|
|
|
|
2008-03-04 00:43:47 +00:00
|
|
|
#import "BlankZeroFormatter.h"
|
2021-01-30 23:14:08 +00:00
|
|
|
#import "IndexFormatter.h"
|
2008-02-16 19:40:34 +00:00
|
|
|
#import "PlaylistEntry.h"
|
2021-01-30 23:14:08 +00:00
|
|
|
#import "SecondsFormatter.h"
|
2007-03-14 02:28:30 +00:00
|
|
|
|
2008-02-23 22:20:14 +00:00
|
|
|
#import "CogAudio/Status.h"
|
|
|
|
|
2013-10-13 05:08:34 +00:00
|
|
|
#import "Logging.h"
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
@implementation PlaylistView
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)awakeFromNib {
|
2021-01-27 02:30:19 +00:00
|
|
|
[[self menu] setAutoenablesItems:NO];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2008-02-18 10:28:24 +00:00
|
|
|
// Configure bindings to scale font size and row height
|
2021-01-27 02:30:19 +00:00
|
|
|
NSControlSize s = NSControlSizeSmall;
|
|
|
|
NSFont *f = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:s]];
|
2008-02-18 00:11:38 +00:00
|
|
|
// NSFont *bf = [[NSFontManager sharedFontManager] convertFont:f toHaveTrait:NSBoldFontMask];
|
2021-10-02 07:40:10 +00:00
|
|
|
|
|
|
|
NSArray<NSTableColumn *> *columns = [[NSSet setWithArray:[self tableColumns]] allObjects];
|
|
|
|
|
|
|
|
if ([columns count] < [[self tableColumns] count]) {
|
|
|
|
// borkage in saved state
|
|
|
|
NSArray<NSTableColumn *> *borkCols = [[self tableColumns] copy];
|
|
|
|
for (NSTableColumn *col in borkCols) {
|
|
|
|
[self removeTableColumn:col];
|
|
|
|
}
|
|
|
|
for (NSTableColumn *col in columns) {
|
|
|
|
[self addTableColumn:col];
|
|
|
|
}
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2021-10-02 07:40:10 +00:00
|
|
|
for (NSTableColumn *col in columns) {
|
2008-02-18 00:11:38 +00:00
|
|
|
[[col dataCell] setControlSize:s];
|
|
|
|
[[col dataCell] setFont:f];
|
2021-01-27 02:30:19 +00:00
|
|
|
}
|
2021-05-08 22:13:49 +00:00
|
|
|
|
|
|
|
// Set up formatters
|
|
|
|
NSFormatter *secondsFormatter = [[SecondsFormatter alloc] init];
|
|
|
|
[[[self tableColumnWithIdentifier:@"length"] dataCell] setFormatter:secondsFormatter];
|
|
|
|
|
|
|
|
NSFormatter *indexFormatter = [[IndexFormatter alloc] init];
|
|
|
|
[[[self tableColumnWithIdentifier:@"index"] dataCell] setFormatter:indexFormatter];
|
|
|
|
|
|
|
|
NSFormatter *blankZeroFormatter = [[BlankZeroFormatter alloc] init];
|
|
|
|
[[[self tableColumnWithIdentifier:@"track"] dataCell] setFormatter:blankZeroFormatter];
|
|
|
|
[[[self tableColumnWithIdentifier:@"year"] dataCell] setFormatter:blankZeroFormatter];
|
|
|
|
// end setting up formatters
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2021-01-27 02:30:19 +00:00
|
|
|
[self setVerticalMotionCanBeginDrag:YES];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
// Set up header context menu
|
2021-01-27 02:30:19 +00:00
|
|
|
headerContextMenu = [[NSMenu alloc] initWithTitle:@"Playlist Header Context Menu"];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"identifier"
|
|
|
|
ascending:YES];
|
|
|
|
NSArray *sortDescriptors = @[sortDescriptor];
|
|
|
|
|
2021-01-27 02:30:19 +00:00
|
|
|
int visibleTableColumns = 0;
|
|
|
|
int menuIndex = 0;
|
2021-10-02 07:40:10 +00:00
|
|
|
for (NSTableColumn *col in [columns sortedArrayUsingDescriptors:sortDescriptors]) {
|
2021-01-27 02:30:19 +00:00
|
|
|
NSString *title;
|
2021-01-30 23:14:08 +00:00
|
|
|
if ([[col identifier] isEqualToString:@"status"]) {
|
2021-01-27 02:30:19 +00:00
|
|
|
title = @"Status";
|
2021-01-30 23:14:08 +00:00
|
|
|
} else if ([[col identifier] isEqualToString:@"index"]) {
|
2021-01-27 02:30:19 +00:00
|
|
|
title = @"Index";
|
2021-01-30 23:14:08 +00:00
|
|
|
} else {
|
2021-01-27 02:30:19 +00:00
|
|
|
title = [[col headerCell] title];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
NSMenuItem *contextMenuItem =
|
|
|
|
[headerContextMenu insertItemWithTitle:title
|
|
|
|
action:@selector(toggleColumn:)
|
|
|
|
keyEquivalent:@""
|
|
|
|
atIndex:menuIndex];
|
|
|
|
|
2021-01-27 02:30:19 +00:00
|
|
|
[contextMenuItem setTarget:self];
|
|
|
|
[contextMenuItem setRepresentedObject:col];
|
2021-01-30 23:14:08 +00:00
|
|
|
[contextMenuItem setState:([col isHidden] ? NSControlStateValueOff : NSControlStateValueOn)];
|
|
|
|
|
2021-01-27 02:30:19 +00:00
|
|
|
visibleTableColumns += ![col isHidden];
|
|
|
|
menuIndex++;
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2021-01-27 02:30:19 +00:00
|
|
|
if (visibleTableColumns == 0) {
|
2021-10-02 07:40:10 +00:00
|
|
|
for (NSTableColumn *col in columns) {
|
2021-01-27 02:30:19 +00:00
|
|
|
[col setHidden:NO];
|
|
|
|
}
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2021-01-27 02:30:19 +00:00
|
|
|
[[self headerView] setMenu:headerContextMenu];
|
2006-06-19 00:39:41 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)toggleColumn:(id)sender {
|
2021-01-27 02:30:19 +00:00
|
|
|
id tc = [sender representedObject];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
if ([sender state] == NSControlStateValueOff) {
|
|
|
|
[sender setState:NSControlStateValueOn];
|
|
|
|
|
|
|
|
[tc setHidden:NO];
|
|
|
|
} else {
|
|
|
|
[sender setState:NSControlStateValueOff];
|
|
|
|
|
|
|
|
[tc setHidden:YES];
|
2021-01-27 02:30:19 +00:00
|
|
|
}
|
2006-06-19 00:39:41 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (BOOL)acceptsFirstResponder {
|
2021-01-27 02:30:19 +00:00
|
|
|
return YES;
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
2007-02-18 18:59:23 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (BOOL)resignFirstResponder {
|
2021-01-27 02:30:19 +00:00
|
|
|
return YES;
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (BOOL)acceptsFirstMouse:(NSEvent *)mouseDownEvent {
|
2021-01-27 02:30:19 +00:00
|
|
|
return NO;
|
2005-06-30 17:46:07 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)mouseDown:(NSEvent *)e {
|
2021-01-27 02:30:19 +00:00
|
|
|
[super mouseDown:e];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
if ([e type] == NSEventTypeLeftMouseDown && [e clickCount] == 2 &&
|
|
|
|
[[self selectedRowIndexes] count] == 1) {
|
2021-01-27 02:30:19 +00:00
|
|
|
[playbackController play:self];
|
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2006-05-23 15:12:24 +00:00
|
|
|
// enables right-click selection for "Show in Finder" contextual menu
|
2021-01-30 23:14:08 +00:00
|
|
|
- (NSMenu *)menuForEvent:(NSEvent *)event {
|
|
|
|
// Find which row is under the cursor
|
2021-01-27 02:30:19 +00:00
|
|
|
[[self window] makeFirstResponder:self];
|
2021-01-30 23:14:08 +00:00
|
|
|
NSPoint menuPoint = [self convertPoint:[event locationInWindow] fromView:nil];
|
2021-01-27 02:30:19 +00:00
|
|
|
NSInteger iRow = [self rowAtPoint:menuPoint];
|
2021-01-30 23:14:08 +00:00
|
|
|
NSMenu *tableViewMenu = [self menu];
|
|
|
|
|
2021-01-27 02:30:19 +00:00
|
|
|
/* Update the table selection before showing menu
|
|
|
|
Preserves the selection if the row under the mouse is selected (to allow for
|
|
|
|
multiple items to be selected), otherwise selects the row under the mouse */
|
2021-01-30 23:14:08 +00:00
|
|
|
BOOL currentRowIsSelected = [[self selectedRowIndexes] containsIndex:(NSUInteger) iRow];
|
2021-01-27 02:30:19 +00:00
|
|
|
if (!currentRowIsSelected) {
|
2021-01-30 23:14:08 +00:00
|
|
|
if (iRow == -1) {
|
2021-01-27 02:30:19 +00:00
|
|
|
[self deselectAll:self];
|
2021-01-30 23:14:08 +00:00
|
|
|
} else {
|
|
|
|
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:(NSUInteger) iRow] byExtendingSelection:NO];
|
2021-01-27 02:30:19 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
if ([self numberOfSelectedRows] <= 0) {
|
|
|
|
// No rows are selected, so the table should be displayed with all items disabled
|
2021-01-27 02:30:19 +00:00
|
|
|
int i;
|
2021-01-30 23:14:08 +00:00
|
|
|
for (i = 0; i < [tableViewMenu numberOfItems]; i++) {
|
2021-01-27 02:30:19 +00:00
|
|
|
[[tableViewMenu itemAtIndex:i] setEnabled:NO];
|
|
|
|
}
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2021-01-27 02:30:19 +00:00
|
|
|
return tableViewMenu;
|
2006-05-23 15:12:24 +00:00
|
|
|
}
|
|
|
|
|
2021-02-19 05:23:13 +00:00
|
|
|
- (void)keyDown:(NSEvent *)event {
|
|
|
|
BOOL modifiersUsed =([event modifierFlags] & (NSEventModifierFlagShift |
|
|
|
|
NSEventModifierFlagControl |
|
|
|
|
NSEventModifierFlagOption |
|
|
|
|
NSEventModifierFlagCommand)) ? YES : NO;
|
|
|
|
if (modifiersUsed) {
|
|
|
|
[super keyDown:event];
|
2021-01-27 02:30:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2021-02-19 05:23:13 +00:00
|
|
|
switch ([event keyCode]) {
|
|
|
|
case kVK_Space:
|
|
|
|
[playbackController playPauseResume:self];
|
|
|
|
break;
|
|
|
|
case kVK_Escape:
|
|
|
|
[playlistController clearFilterPredicate:self];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kVK_Delete:
|
|
|
|
case kVK_ForwardDelete:
|
|
|
|
[playlistController remove:self];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kVK_LeftArrow:
|
|
|
|
[playbackController eventSeekBackward:self];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kVK_RightArrow:
|
|
|
|
[playbackController eventSeekForward:self];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kVK_Return:
|
|
|
|
[playbackController play:self];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
[super keyDown:event];
|
|
|
|
break;
|
2021-01-27 02:30:19 +00:00
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)scrollToCurrentEntry:(id)sender {
|
2021-01-27 02:30:19 +00:00
|
|
|
[self scrollRowToVisible:[[playlistController currentEntry] index]];
|
2021-01-30 23:14:08 +00:00
|
|
|
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:(NSUInteger) [[playlistController currentEntry] index]]
|
|
|
|
byExtendingSelection:NO];
|
2007-05-26 14:09:03 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)undo:(id)sender {
|
2021-01-27 02:30:19 +00:00
|
|
|
[[playlistController undoManager] undo];
|
2008-02-10 17:13:30 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)redo:(id)sender {
|
2021-01-27 02:30:19 +00:00
|
|
|
[[playlistController undoManager] redo];
|
2008-02-10 17:13:30 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)copy:(id)sender {
|
2013-10-13 05:08:34 +00:00
|
|
|
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
|
|
|
|
[pboard clearContents];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
NSArray *entries =
|
|
|
|
[[playlistController content] objectsAtIndexes:[playlistController selectionIndexes]];
|
|
|
|
NSUInteger capacity = [entries count];
|
|
|
|
NSMutableArray *selectedURLs = [NSMutableArray arrayWithCapacity:capacity];
|
|
|
|
|
|
|
|
for (PlaylistEntry *pe in entries) {
|
2013-10-13 05:08:34 +00:00
|
|
|
[selectedURLs addObject:[pe URL]];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
NSError *error;
|
2021-09-23 07:49:51 +00:00
|
|
|
NSData *data;
|
|
|
|
if (@available(macOS 10.13, *)) {
|
|
|
|
data = [NSKeyedArchiver archivedDataWithRootObject:selectedURLs
|
|
|
|
requiringSecureCoding:YES
|
|
|
|
error:&error];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data = [NSArchiver archivedDataWithRootObject:selectedURLs];
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
if (!data) {
|
|
|
|
DLog(@"Error: %@", error);
|
|
|
|
}
|
|
|
|
[pboard setData:data forType:CogUrlsPboardType];
|
|
|
|
|
|
|
|
NSMutableDictionary *tracks = [NSMutableDictionary dictionaryWithCapacity:capacity];
|
|
|
|
|
2013-10-13 05:08:34 +00:00
|
|
|
unsigned long i = 0;
|
2021-01-30 23:14:08 +00:00
|
|
|
for (NSURL *url in selectedURLs) {
|
|
|
|
tracks[[NSString stringWithFormat:@"%lu", i++]] = @{@"Location": [url absoluteString]};
|
2013-10-13 05:08:34 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
NSDictionary *itunesPlist = @{@"Tracks": tracks};
|
|
|
|
|
2013-10-13 05:08:34 +00:00
|
|
|
[pboard setPropertyList:itunesPlist forType:iTunesDropType];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
NSMutableArray *filePaths = [NSMutableArray array];
|
|
|
|
|
|
|
|
for (NSURL *url in selectedURLs) {
|
|
|
|
if ([url isFileURL]) {
|
|
|
|
[filePaths addObject:url];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([filePaths count]) {
|
|
|
|
[pboard writeObjects:filePaths];
|
2013-10-13 05:08:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)cut:(id)sender {
|
2013-10-13 05:08:34 +00:00
|
|
|
[self copy:sender];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2013-10-13 05:08:34 +00:00
|
|
|
[playlistController removeObjectsAtArrangedObjectIndexes:[playlistController selectionIndexes]];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
if ([playlistController shuffle] != ShuffleOff) [playlistController resetShuffleList];
|
2013-10-13 05:08:34 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)paste:(id)sender {
|
2021-01-27 02:30:19 +00:00
|
|
|
// Determine the type of object that was dropped
|
2021-09-23 07:49:51 +00:00
|
|
|
NSPasteboardType fileType;
|
|
|
|
if (@available(macOS 10.13, *)) {
|
|
|
|
fileType = NSPasteboardTypeFileURL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fileType = NSFilenamesPboardType;
|
|
|
|
}
|
|
|
|
NSArray *supportedTypes = @[CogUrlsPboardType, fileType, iTunesDropType];
|
2021-01-27 02:30:19 +00:00
|
|
|
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
|
2021-01-30 23:14:08 +00:00
|
|
|
NSPasteboardType bestType = [pboard availableTypeFromArray:supportedTypes];
|
2021-04-30 01:16:24 +00:00
|
|
|
#ifdef _DEBUG
|
2021-01-30 23:14:08 +00:00
|
|
|
DLog(@"All types:");
|
|
|
|
for (NSPasteboardType type in [pboard types]) {
|
|
|
|
DLog(@" Type: %@", type);
|
|
|
|
}
|
|
|
|
DLog(@"Supported types:");
|
|
|
|
for (NSPasteboardType type in supportedTypes) {
|
|
|
|
DLog(@" Type: %@", type);
|
|
|
|
}
|
|
|
|
DLog(@"Best type: %@", bestType);
|
2021-04-30 01:16:24 +00:00
|
|
|
#endif
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
NSMutableArray *acceptedURLs = [NSMutableArray array];
|
|
|
|
|
2021-01-27 02:30:19 +00:00
|
|
|
// Get files from an file drawer drop
|
|
|
|
if ([bestType isEqualToString:CogUrlsPboardType]) {
|
2021-01-30 23:14:08 +00:00
|
|
|
NSError *error;
|
|
|
|
NSData *data = [pboard dataForType:CogUrlsPboardType];
|
|
|
|
NSArray *urls;
|
|
|
|
if (@available(macOS 11.0, *)) {
|
|
|
|
urls = [NSKeyedUnarchiver unarchivedArrayOfObjectsOfClass:[NSURL class]
|
|
|
|
fromData:data
|
|
|
|
error:&error];
|
|
|
|
} else {
|
2021-09-23 07:49:51 +00:00
|
|
|
if (@available(macOS 10.13, *)) {
|
|
|
|
NSSet *allowed = [NSSet setWithArray:@[[NSArray class], [NSURL class]]];
|
|
|
|
urls = [NSKeyedUnarchiver unarchivedObjectOfClasses:allowed
|
|
|
|
fromData:data
|
|
|
|
error:&error];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
urls = [NSUnarchiver unarchiveObjectWithData:data];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
}
|
|
|
|
if (!urls) {
|
|
|
|
DLog(@"%@", error);
|
|
|
|
} else {
|
|
|
|
DLog(@"URLS: %@", urls);
|
|
|
|
}
|
2021-01-27 02:30:19 +00:00
|
|
|
//[playlistLoader insertURLs: urls atIndex:row sort:YES];
|
|
|
|
[acceptedURLs addObjectsFromArray:urls];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2021-01-27 02:30:19 +00:00
|
|
|
// Get files from a normal file drop (such as from Finder)
|
2021-09-23 07:49:51 +00:00
|
|
|
if ([bestType isEqualToString:fileType]) {
|
2021-01-27 02:30:19 +00:00
|
|
|
NSMutableArray *urls = [[NSMutableArray alloc] init];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2021-09-23 07:49:51 +00:00
|
|
|
for (NSString *file in [pboard propertyListForType:fileType]) {
|
2021-01-27 02:30:19 +00:00
|
|
|
[urls addObject:[NSURL fileURLWithPath:file]];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2021-01-27 02:30:19 +00:00
|
|
|
//[playlistLoader insertURLs:urls atIndex:row sort:YES];
|
|
|
|
[acceptedURLs addObjectsFromArray:urls];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2021-01-27 02:30:19 +00:00
|
|
|
// Get files from an iTunes drop
|
|
|
|
if ([bestType isEqualToString:iTunesDropType]) {
|
|
|
|
NSDictionary *iTunesDict = [pboard propertyListForType:iTunesDropType];
|
|
|
|
NSDictionary *tracks = [iTunesDict valueForKey:@"Tracks"];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2021-01-27 02:30:19 +00:00
|
|
|
// Convert the iTunes URLs to URLs....MWAHAHAH!
|
|
|
|
NSMutableArray *urls = [[NSMutableArray alloc] init];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2021-01-27 02:30:19 +00:00
|
|
|
for (NSDictionary *trackInfo in [tracks allValues]) {
|
|
|
|
[urls addObject:[NSURL URLWithString:[trackInfo valueForKey:@"Location"]]];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2021-01-27 02:30:19 +00:00
|
|
|
//[playlistLoader insertURLs:urls atIndex:row sort:YES];
|
|
|
|
[acceptedURLs addObjectsFromArray:urls];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
if ([acceptedURLs count]) {
|
2013-10-13 05:08:34 +00:00
|
|
|
NSUInteger row = [[playlistController content] count];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2013-10-13 05:08:34 +00:00
|
|
|
[playlistController willInsertURLs:acceptedURLs origin:URLOriginInternal];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
NSArray *entries = [playlistLoader insertURLs:acceptedURLs atIndex:(int) row sort:NO];
|
2021-01-27 02:30:19 +00:00
|
|
|
[playlistLoader didInsertURLs:entries origin:URLOriginInternal];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
if ([playlistController shuffle] != ShuffleOff) [playlistController resetShuffleList];
|
2021-01-27 02:30:19 +00:00
|
|
|
}
|
2013-10-13 05:08:34 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)delete:(id)sender {
|
2013-10-13 05:08:34 +00:00
|
|
|
[playlistController removeObjectsAtArrangedObjectIndexes:[playlistController selectionIndexes]];
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem {
|
2021-01-27 02:30:19 +00:00
|
|
|
SEL action = [anItem action];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
if (action == @selector(undo:)) {
|
|
|
|
return [[playlistController undoManager] canUndo];
|
2021-01-27 02:30:19 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
if (action == @selector(redo:)) {
|
|
|
|
return [[playlistController undoManager] canRedo];
|
2021-01-27 02:30:19 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
if (action == @selector(cut:) || action == @selector(copy:) || action == @selector(delete:)) {
|
|
|
|
return [[playlistController selectionIndexes] count] != 0;
|
2013-10-13 05:08:34 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
if (action == @selector(paste:)) {
|
2013-10-13 05:08:34 +00:00
|
|
|
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
|
2021-09-23 07:49:51 +00:00
|
|
|
|
|
|
|
NSPasteboardType fileType;
|
|
|
|
if (@available(macOS 10.13, *)) {
|
|
|
|
fileType = NSPasteboardTypeFileURL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fileType = NSFilenamesPboardType;
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2021-09-23 07:49:51 +00:00
|
|
|
NSArray *supportedTypes = @[CogUrlsPboardType, fileType, iTunesDropType];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2013-10-13 05:08:34 +00:00
|
|
|
NSString *bestType = [pboard availableTypeFromArray:supportedTypes];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
return bestType != nil;
|
2013-10-13 05:08:34 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
if (action == @selector(scrollToCurrentEntry:) &&
|
2021-02-06 21:20:03 +00:00
|
|
|
(([playbackController playbackStatus] == CogStatusStopped) ||
|
|
|
|
([playbackController playbackStatus] == CogStatusStopping)))
|
2021-01-27 02:30:19 +00:00
|
|
|
return NO;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2021-01-27 02:30:19 +00:00
|
|
|
return [super validateUserInterfaceItem:anItem];
|
2008-02-10 17:13:30 +00:00
|
|
|
}
|
|
|
|
|
2018-06-28 10:59:59 +00:00
|
|
|
#if 0
|
2008-02-24 15:47:04 +00:00
|
|
|
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal
|
|
|
|
{
|
2021-01-27 02:30:19 +00:00
|
|
|
if (isLocal)
|
|
|
|
return NSDragOperationNone;
|
|
|
|
else
|
|
|
|
return NSDragOperationCopy;
|
2008-02-24 15:47:04 +00:00
|
|
|
}
|
2018-06-28 10:59:59 +00:00
|
|
|
#endif
|
2008-02-24 15:47:04 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
@end
|