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"
|
2006-01-20 15:22:03 +00:00
|
|
|
#import "PlaybackController.h"
|
2005-06-02 18:16:43 +00:00
|
|
|
#import "PlaylistController.h"
|
|
|
|
|
2007-03-14 02:28:30 +00:00
|
|
|
#import "IndexFormatter.h"
|
|
|
|
#import "SecondsFormatter.h"
|
2008-03-04 00:43:47 +00:00
|
|
|
#import "BlankZeroFormatter.h"
|
2008-02-16 19:40:34 +00:00
|
|
|
#import "PlaylistEntry.h"
|
2007-03-14 02:28:30 +00:00
|
|
|
|
2008-02-23 22:20:14 +00:00
|
|
|
#import "CogAudio/Status.h"
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
@implementation PlaylistView
|
|
|
|
|
2006-04-28 23:19:14 +00:00
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
2007-05-23 11:08:56 +00:00
|
|
|
[[self menu] setAutoenablesItems:NO];
|
|
|
|
|
2008-02-18 10:28:24 +00:00
|
|
|
// Configure bindings to scale font size and row height
|
2008-02-18 00:11:38 +00:00
|
|
|
NSControlSize s = NSSmallControlSize;
|
2006-04-28 23:19:14 +00:00
|
|
|
NSFont *f = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:s]];
|
2008-02-18 00:11:38 +00:00
|
|
|
// NSFont *bf = [[NSFontManager sharedFontManager] convertFont:f toHaveTrait:NSBoldFontMask];
|
2008-02-23 13:57:33 +00:00
|
|
|
|
2008-03-01 15:04:46 +00:00
|
|
|
for (NSTableColumn *col in [self tableColumns]) {
|
2008-02-18 00:11:38 +00:00
|
|
|
[[col dataCell] setControlSize:s];
|
|
|
|
[[col dataCell] setFont:f];
|
2006-04-28 23:19:14 +00:00
|
|
|
}
|
2007-03-14 02:28:30 +00:00
|
|
|
|
2007-03-14 03:16:37 +00:00
|
|
|
//Set up formatters
|
2007-03-14 02:28:30 +00:00
|
|
|
NSFormatter *secondsFormatter = [[SecondsFormatter alloc] init];
|
|
|
|
[[[self tableColumnWithIdentifier:@"length"] dataCell] setFormatter:secondsFormatter];
|
|
|
|
[secondsFormatter release];
|
|
|
|
|
|
|
|
NSFormatter *indexFormatter = [[IndexFormatter alloc] init];
|
|
|
|
[[[self tableColumnWithIdentifier:@"index"] dataCell] setFormatter:indexFormatter];
|
|
|
|
[indexFormatter release];
|
2008-03-04 00:43:47 +00:00
|
|
|
|
|
|
|
NSFormatter *blankZeroFormatter = [[BlankZeroFormatter alloc] init];
|
|
|
|
[[[self tableColumnWithIdentifier:@"track"] dataCell] setFormatter:blankZeroFormatter];
|
|
|
|
[[[self tableColumnWithIdentifier:@"year"] dataCell] setFormatter:blankZeroFormatter];
|
|
|
|
[blankZeroFormatter release];
|
2007-03-14 03:16:37 +00:00
|
|
|
//end setting up formatters
|
|
|
|
|
2006-04-29 00:03:28 +00:00
|
|
|
[self setVerticalMotionCanBeginDrag:YES];
|
2007-03-14 03:16:37 +00:00
|
|
|
|
|
|
|
//Set up header context menu
|
|
|
|
headerContextMenu = [[NSMenu alloc] initWithTitle:@"Playlist Header Context Menu"];
|
|
|
|
|
2008-03-01 02:48:12 +00:00
|
|
|
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"identifier" ascending:YES];
|
2007-03-14 03:16:37 +00:00
|
|
|
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
|
2008-02-16 01:44:01 +00:00
|
|
|
[sortDescriptor release];
|
|
|
|
|
|
|
|
int visibleTableColumns = 0;
|
2007-03-14 03:16:37 +00:00
|
|
|
int menuIndex = 0;
|
2008-02-18 10:28:24 +00:00
|
|
|
for (NSTableColumn *col in [[self tableColumns] sortedArrayUsingDescriptors: sortDescriptors])
|
|
|
|
{
|
2008-03-01 02:48:12 +00:00
|
|
|
NSString *title;
|
|
|
|
if ([[col identifier] isEqualToString:@"status"])
|
|
|
|
{
|
|
|
|
title = @"Status";
|
|
|
|
}
|
|
|
|
else if ([[col identifier] isEqualToString:@"index"])
|
|
|
|
{
|
|
|
|
title = @"Index";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
title = [[col headerCell] title];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMenuItem *contextMenuItem = [headerContextMenu insertItemWithTitle:title action:@selector(toggleColumn:) keyEquivalent:@"" atIndex:menuIndex];
|
2007-03-14 03:16:37 +00:00
|
|
|
|
|
|
|
[contextMenuItem setTarget:self];
|
|
|
|
[contextMenuItem setRepresentedObject:col];
|
2008-01-24 01:44:24 +00:00
|
|
|
[contextMenuItem setState:([col isHidden] ? NSOffState : NSOnState)];
|
2007-03-14 03:16:37 +00:00
|
|
|
|
2008-02-16 01:44:01 +00:00
|
|
|
visibleTableColumns += ![col isHidden];
|
2007-03-14 03:16:37 +00:00
|
|
|
menuIndex++;
|
|
|
|
}
|
2008-02-16 01:44:01 +00:00
|
|
|
|
|
|
|
if (visibleTableColumns == 0) {
|
|
|
|
for (NSTableColumn *col in [self tableColumns]) {
|
|
|
|
[col setHidden:NO];
|
|
|
|
}
|
|
|
|
}
|
2007-03-14 03:16:37 +00:00
|
|
|
|
|
|
|
[[self headerView] setMenu:headerContextMenu];
|
2006-06-19 00:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-17 19:33:31 +00:00
|
|
|
- (IBAction)toggleColumn:(id)sender
|
2006-06-19 00:39:41 +00:00
|
|
|
{
|
2007-02-17 19:33:31 +00:00
|
|
|
id tc = [sender representedObject];
|
2007-02-17 18:29:20 +00:00
|
|
|
|
|
|
|
if ([sender state] == NSOffState)
|
|
|
|
{
|
|
|
|
[sender setState:NSOnState];
|
2006-06-19 00:39:41 +00:00
|
|
|
|
2008-01-24 01:44:24 +00:00
|
|
|
[tc setHidden: NO];
|
2007-02-17 18:29:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[sender setState:NSOffState];
|
2008-01-24 01:44:24 +00:00
|
|
|
|
|
|
|
[tc setHidden: YES];
|
2007-02-17 18:29:20 +00:00
|
|
|
}
|
2006-06-19 00:39:41 +00:00
|
|
|
}
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
- (BOOL)acceptsFirstResponder
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
2007-02-18 18:59:23 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
- (BOOL)resignFirstResponder
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2005-06-30 17:46:07 +00:00
|
|
|
- (BOOL)acceptsFirstMouse:(NSEvent *)mouseDownEvent
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
- (void)mouseDown:(NSEvent *)e
|
|
|
|
{
|
2007-05-27 14:04:42 +00:00
|
|
|
[super mouseDown:e];
|
|
|
|
|
2008-02-16 14:09:19 +00:00
|
|
|
if ([e type] == NSLeftMouseDown && [e clickCount] == 2 && [[self selectedRowIndexes] count] == 1)
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
2006-01-20 15:22:03 +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
|
|
|
|
-(NSMenu*)menuForEvent:(NSEvent*)event
|
|
|
|
{
|
|
|
|
//Find which row is under the cursor
|
|
|
|
[[self window] makeFirstResponder:self];
|
2008-02-10 16:16:45 +00:00
|
|
|
NSPoint menuPoint = [self convertPoint:[event locationInWindow] fromView:nil];
|
2008-02-16 16:13:21 +00:00
|
|
|
NSInteger iRow = [self rowAtPoint:menuPoint];
|
2008-03-11 23:31:19 +00:00
|
|
|
NSMenu* tableViewMenu = [self menu];
|
2006-05-23 15:12:24 +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 */
|
2008-02-16 16:13:21 +00:00
|
|
|
BOOL currentRowIsSelected = [[self selectedRowIndexes] containsIndex:iRow];
|
2007-05-23 11:08:56 +00:00
|
|
|
if (!currentRowIsSelected) {
|
2008-02-16 16:13:21 +00:00
|
|
|
if (iRow == -1)
|
2007-05-23 11:08:56 +00:00
|
|
|
{
|
|
|
|
[self deselectAll:self];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-03 08:00:58 +00:00
|
|
|
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:iRow] byExtendingSelection:NO];
|
2007-05-23 11:08:56 +00:00
|
|
|
}
|
|
|
|
}
|
2007-07-11 01:20:32 +00:00
|
|
|
|
2006-05-23 15:12:24 +00:00
|
|
|
if ([self numberOfSelectedRows] <=0)
|
|
|
|
{
|
|
|
|
//No rows are selected, so the table should be displayed with all items disabled
|
|
|
|
int i;
|
2007-05-23 11:08:56 +00:00
|
|
|
for (i=0;i<[tableViewMenu numberOfItems];i++) {
|
2006-05-23 15:12:24 +00:00
|
|
|
[[tableViewMenu itemAtIndex:i] setEnabled:NO];
|
2007-05-23 11:08:56 +00:00
|
|
|
}
|
2006-05-23 15:12:24 +00:00
|
|
|
}
|
2008-02-16 16:13:21 +00:00
|
|
|
|
2008-03-11 23:31:19 +00:00
|
|
|
return tableViewMenu;
|
2006-05-23 15:12:24 +00:00
|
|
|
}
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
- (void)keyDown:(NSEvent *)e
|
|
|
|
{
|
2008-02-10 16:16:45 +00:00
|
|
|
unsigned int modifiers = [e modifierFlags] & (NSCommandKeyMask | NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask);
|
|
|
|
NSString *characters = [e characters];
|
|
|
|
unichar c;
|
2007-07-11 01:20:32 +00:00
|
|
|
|
2008-02-10 16:16:45 +00:00
|
|
|
if ([characters length] != 1)
|
|
|
|
{
|
2007-05-26 14:09:03 +00:00
|
|
|
[super keyDown:e];
|
2005-06-02 18:16:43 +00:00
|
|
|
|
|
|
|
return;
|
2007-05-26 14:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c = [characters characterAtIndex:0];
|
|
|
|
if (modifiers == 0 && (c == NSDeleteCharacter || c == NSBackspaceCharacter || c == NSDeleteFunctionKey))
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
|
|
|
[playlistController remove:self];
|
|
|
|
}
|
2007-05-26 14:09:03 +00:00
|
|
|
else if (modifiers == 0 && c == ' ')
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
2006-01-20 15:22:03 +00:00
|
|
|
[playbackController playPauseResume:self];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
2007-05-26 14:09:03 +00:00
|
|
|
else if (modifiers == 0 && (c == NSEnterCharacter || c == NSCarriageReturnCharacter))
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
2006-01-20 15:22:03 +00:00
|
|
|
[playbackController play:self];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
2008-02-10 16:16:45 +00:00
|
|
|
// Escape
|
|
|
|
else if (modifiers == 0 && c == 0x1b)
|
|
|
|
{
|
2007-05-26 14:09:03 +00:00
|
|
|
[playlistController clearFilterPredicate:self];
|
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
[super keyDown:e];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-26 14:09:03 +00:00
|
|
|
- (IBAction)scrollToCurrentEntry:(id)sender
|
|
|
|
{
|
2008-02-23 22:20:14 +00:00
|
|
|
[self scrollRowToVisible:[[playlistController currentEntry] index]];
|
2013-10-03 08:00:58 +00:00
|
|
|
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:[[playlistController currentEntry] index]] byExtendingSelection:NO];
|
2007-05-26 14:09:03 +00:00
|
|
|
}
|
|
|
|
|
2008-02-10 17:13:30 +00:00
|
|
|
- (IBAction)undo:(id)sender
|
|
|
|
{
|
|
|
|
[[playlistController undoManager] undo];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)redo:(id)sender
|
|
|
|
{
|
|
|
|
[[playlistController undoManager] redo];
|
|
|
|
}
|
|
|
|
|
2008-02-10 19:35:58 +00:00
|
|
|
|
|
|
|
-(BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem
|
2008-02-10 17:13:30 +00:00
|
|
|
{
|
2008-02-10 19:35:58 +00:00
|
|
|
SEL action = [anItem action];
|
2008-02-10 17:13:30 +00:00
|
|
|
|
2008-02-10 20:32:46 +00:00
|
|
|
if (action == @selector(undo:))
|
|
|
|
{
|
|
|
|
if ([[playlistController undoManager] canUndo])
|
|
|
|
return YES;
|
|
|
|
else
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
if (action == @selector(redo:))
|
|
|
|
{
|
|
|
|
if ([[playlistController undoManager] canRedo])
|
|
|
|
return YES;
|
|
|
|
else
|
|
|
|
return NO;
|
|
|
|
}
|
2008-02-23 22:20:14 +00:00
|
|
|
|
|
|
|
if (action == @selector(scrollToCurrentEntry:) && ([playbackController playbackStatus] == kCogStatusStopped))
|
|
|
|
return NO;
|
|
|
|
|
2008-02-10 19:35:58 +00:00
|
|
|
return [super validateUserInterfaceItem:anItem];
|
2008-02-10 17:13:30 +00:00
|
|
|
}
|
|
|
|
|
2008-02-24 15:47:04 +00:00
|
|
|
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal
|
|
|
|
{
|
|
|
|
if (isLocal)
|
|
|
|
return NSDragOperationNone;
|
|
|
|
else
|
|
|
|
return NSDragOperationCopy;
|
|
|
|
}
|
|
|
|
|
2008-03-04 01:14:51 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
@end
|