Fix deprecations with replacemnt and reindent touched files.

CQTexperiment
Dzmitry Neviadomski 2021-01-27 05:30:19 +03:00
parent 70a22e9611
commit a0afe85130
5 changed files with 455 additions and 455 deletions

View File

@ -101,17 +101,17 @@
{ {
BOOL shouldHandleMediaKeyEventLocally = ![SPMediaKeyTap usesGlobalMediaKeyTap]; BOOL shouldHandleMediaKeyEventLocally = ![SPMediaKeyTap usesGlobalMediaKeyTap];
if(shouldHandleMediaKeyEventLocally && [event type] == NSSystemDefined && [event subtype] == 8 ) if(shouldHandleMediaKeyEventLocally && [event type] == NSEventTypeSystemDefined && [event subtype] == 8 )
{ {
[self mediaKeyTap:nil receivedMediaKeyEvent:event]; [self mediaKeyTap:nil receivedMediaKeyEvent:event];
} }
[super sendEvent: event]; [super sendEvent: event];
} }
-(void)mediaKeyTap:(SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event; -(void)mediaKeyTap:(SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event;
{ {
NSAssert([event type] == NSSystemDefined && [event subtype] == SPSystemDefinedEventMediaKeys, @"Unexpected NSEvent in mediaKeyTap:receivedMediaKeyEvent:"); NSAssert([event type] == NSEventTypeSystemDefined && [event subtype] == SPSystemDefinedEventMediaKeys, @"Unexpected NSEvent in mediaKeyTap:receivedMediaKeyEvent:");
int keyCode = (([event data1] & 0xFFFF0000) >> 16); int keyCode = (([event data1] & 0xFFFF0000) >> 16);
int keyFlags = ([event data1] & 0x0000FFFF); int keyFlags = ([event data1] & 0x0000FFFF);

View File

@ -15,62 +15,62 @@
- (void)awakeFromNib - (void)awakeFromNib
{ {
[self setDoubleAction:@selector(addToPlaylistExternal:)]; [self setDoubleAction:@selector(addToPlaylistExternal:)];
[self setTarget:[self delegate]]; [self setTarget:[self delegate]];
} }
- (void)keyDown:(NSEvent *)e - (void)keyDown:(NSEvent *)e
{ {
unsigned int modifiers = [e modifierFlags] & (NSCommandKeyMask | NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask); unsigned int modifiers = [e modifierFlags] & (NSEventModifierFlagCommand | NSEventModifierFlagShift | NSEventModifierFlagControl | NSEventModifierFlagOption);
NSString *characters = [e characters]; NSString *characters = [e characters];
unichar c; unichar c;
if ([characters length] == 1) if ([characters length] == 1)
{ {
c = [characters characterAtIndex:0]; c = [characters characterAtIndex:0];
if (modifiers == 0 && (c == NSEnterCharacter || c == NSCarriageReturnCharacter)) if (modifiers == 0 && (c == NSEnterCharacter || c == NSCarriageReturnCharacter))
{ {
[(FileTreeController *)[self delegate] addToPlaylistExternal:self]; [(FileTreeController *)[self delegate] addToPlaylistExternal:self];
return; return;
} }
else if (modifiers == 0 && c == ' ') else if (modifiers == 0 && c == ' ')
{ {
[(FileTreeController *)[self delegate] playPauseResume:self]; [(FileTreeController *)[self delegate] playPauseResume:self];
return; return;
} }
} }
[super keyDown:e]; [super keyDown:e];
return; return;
} }
// enables right-click selection for "Show in Finder" contextual menu // enables right-click selection for "Show in Finder" contextual menu
-(NSMenu*)menuForEvent:(NSEvent*)event -(NSMenu*)menuForEvent:(NSEvent*)event
{ {
//Find which row is under the cursor //Find which row is under the cursor
[[self window] makeFirstResponder:self]; [[self window] makeFirstResponder:self];
NSPoint menuPoint = [self convertPoint:[event locationInWindow] fromView:nil]; NSPoint menuPoint = [self convertPoint:[event locationInWindow] fromView:nil];
NSInteger iRow = [self rowAtPoint:menuPoint]; NSInteger iRow = [self rowAtPoint:menuPoint];
NSMenu* contextMenu = [self menu]; NSMenu* contextMenu = [self menu];
/* Update the file tree selection before showing menu /* Update the file tree selection before showing menu
Preserves the selection if the row under the mouse is selected (to allow for 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 */ multiple items to be selected), otherwise selects the row under the mouse */
BOOL currentRowIsSelected = [[self selectedRowIndexes] containsIndex:iRow]; BOOL currentRowIsSelected = [[self selectedRowIndexes] containsIndex:iRow];
if (iRow == -1) if (iRow == -1)
{ {
[self deselectAll:self]; [self deselectAll:self];
} }
else if (!currentRowIsSelected) else if (!currentRowIsSelected)
{ {
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:iRow] byExtendingSelection:NO]; [self selectRowIndexes:[NSIndexSet indexSetWithIndex:iRow] byExtendingSelection:NO];
} }
return contextMenu; return contextMenu;
} }
@end @end

View File

@ -23,181 +23,181 @@
- (void)awakeFromNib - (void)awakeFromNib
{ {
[[self menu] setAutoenablesItems:NO]; [[self menu] setAutoenablesItems:NO];
// Configure bindings to scale font size and row height // Configure bindings to scale font size and row height
NSControlSize s = NSSmallControlSize; NSControlSize s = NSControlSizeSmall;
NSFont *f = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:s]]; NSFont *f = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:s]];
// NSFont *bf = [[NSFontManager sharedFontManager] convertFont:f toHaveTrait:NSBoldFontMask]; // NSFont *bf = [[NSFontManager sharedFontManager] convertFont:f toHaveTrait:NSBoldFontMask];
for (NSTableColumn *col in [self tableColumns]) { for (NSTableColumn *col in [self tableColumns]) {
[[col dataCell] setControlSize:s]; [[col dataCell] setControlSize:s];
[[col dataCell] setFont:f]; [[col dataCell] setFont:f];
} }
//Set up formatters //Set up formatters
NSFormatter *secondsFormatter = [[SecondsFormatter alloc] init]; NSFormatter *secondsFormatter = [[SecondsFormatter alloc] init];
[[[self tableColumnWithIdentifier:@"length"] dataCell] setFormatter:secondsFormatter]; [[[self tableColumnWithIdentifier:@"length"] dataCell] setFormatter:secondsFormatter];
NSFormatter *indexFormatter = [[IndexFormatter alloc] init]; NSFormatter *indexFormatter = [[IndexFormatter alloc] init];
[[[self tableColumnWithIdentifier:@"index"] dataCell] setFormatter:indexFormatter]; [[[self tableColumnWithIdentifier:@"index"] dataCell] setFormatter:indexFormatter];
NSFormatter *blankZeroFormatter = [[BlankZeroFormatter alloc] init]; NSFormatter *blankZeroFormatter = [[BlankZeroFormatter alloc] init];
[[[self tableColumnWithIdentifier:@"track"] dataCell] setFormatter:blankZeroFormatter]; [[[self tableColumnWithIdentifier:@"track"] dataCell] setFormatter:blankZeroFormatter];
[[[self tableColumnWithIdentifier:@"year"] dataCell] setFormatter:blankZeroFormatter]; [[[self tableColumnWithIdentifier:@"year"] dataCell] setFormatter:blankZeroFormatter];
//end setting up formatters //end setting up formatters
[self setVerticalMotionCanBeginDrag:YES]; [self setVerticalMotionCanBeginDrag:YES];
//Set up header context menu //Set up header context menu
headerContextMenu = [[NSMenu alloc] initWithTitle:@"Playlist Header Context Menu"]; headerContextMenu = [[NSMenu alloc] initWithTitle:@"Playlist Header Context Menu"];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"identifier" ascending:YES]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"identifier" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
int visibleTableColumns = 0; int visibleTableColumns = 0;
int menuIndex = 0; int menuIndex = 0;
for (NSTableColumn *col in [[self tableColumns] sortedArrayUsingDescriptors: sortDescriptors]) for (NSTableColumn *col in [[self tableColumns] sortedArrayUsingDescriptors: sortDescriptors])
{ {
NSString *title; NSString *title;
if ([[col identifier] isEqualToString:@"status"]) if ([[col identifier] isEqualToString:@"status"])
{ {
title = @"Status"; title = @"Status";
} }
else if ([[col identifier] isEqualToString:@"index"]) else if ([[col identifier] isEqualToString:@"index"])
{ {
title = @"Index"; title = @"Index";
} }
else else
{ {
title = [[col headerCell] title]; title = [[col headerCell] title];
} }
NSMenuItem *contextMenuItem = [headerContextMenu insertItemWithTitle:title action:@selector(toggleColumn:) keyEquivalent:@"" atIndex:menuIndex]; NSMenuItem *contextMenuItem = [headerContextMenu insertItemWithTitle:title action:@selector(toggleColumn:) keyEquivalent:@"" atIndex:menuIndex];
[contextMenuItem setTarget:self]; [contextMenuItem setTarget:self];
[contextMenuItem setRepresentedObject:col]; [contextMenuItem setRepresentedObject:col];
[contextMenuItem setState:([col isHidden] ? NSOffState : NSOnState)]; [contextMenuItem setState:([col isHidden] ? NSOffState : NSOnState)];
visibleTableColumns += ![col isHidden]; visibleTableColumns += ![col isHidden];
menuIndex++; menuIndex++;
} }
if (visibleTableColumns == 0) { if (visibleTableColumns == 0) {
for (NSTableColumn *col in [self tableColumns]) { for (NSTableColumn *col in [self tableColumns]) {
[col setHidden:NO]; [col setHidden:NO];
} }
} }
[[self headerView] setMenu:headerContextMenu]; [[self headerView] setMenu:headerContextMenu];
} }
- (IBAction)toggleColumn:(id)sender - (IBAction)toggleColumn:(id)sender
{ {
id tc = [sender representedObject]; id tc = [sender representedObject];
if ([sender state] == NSOffState) if ([sender state] == NSOffState)
{ {
[sender setState:NSOnState]; [sender setState:NSOnState];
[tc setHidden: NO]; [tc setHidden: NO];
} }
else else
{ {
[sender setState:NSOffState]; [sender setState:NSOffState];
[tc setHidden: YES]; [tc setHidden: YES];
} }
} }
- (BOOL)acceptsFirstResponder - (BOOL)acceptsFirstResponder
{ {
return YES; return YES;
} }
- (BOOL)resignFirstResponder - (BOOL)resignFirstResponder
{ {
return YES; return YES;
} }
- (BOOL)acceptsFirstMouse:(NSEvent *)mouseDownEvent - (BOOL)acceptsFirstMouse:(NSEvent *)mouseDownEvent
{ {
return NO; return NO;
} }
- (void)mouseDown:(NSEvent *)e - (void)mouseDown:(NSEvent *)e
{ {
[super mouseDown:e]; [super mouseDown:e];
if ([e type] == NSLeftMouseDown && [e clickCount] == 2 && [[self selectedRowIndexes] count] == 1) if ([e type] == NSEventTypeLeftMouseDown && [e clickCount] == 2 && [[self selectedRowIndexes] count] == 1)
{ {
[playbackController play:self]; [playbackController play:self];
} }
} }
// enables right-click selection for "Show in Finder" contextual menu // enables right-click selection for "Show in Finder" contextual menu
-(NSMenu*)menuForEvent:(NSEvent*)event -(NSMenu*)menuForEvent:(NSEvent*)event
{ {
//Find which row is under the cursor //Find which row is under the cursor
[[self window] makeFirstResponder:self]; [[self window] makeFirstResponder:self];
NSPoint menuPoint = [self convertPoint:[event locationInWindow] fromView:nil]; NSPoint menuPoint = [self convertPoint:[event locationInWindow] fromView:nil];
NSInteger iRow = [self rowAtPoint:menuPoint]; NSInteger iRow = [self rowAtPoint:menuPoint];
NSMenu* tableViewMenu = [self menu]; NSMenu* tableViewMenu = [self menu];
/* Update the table selection before showing menu /* Update the table selection before showing menu
Preserves the selection if the row under the mouse is selected (to allow for 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 */ multiple items to be selected), otherwise selects the row under the mouse */
BOOL currentRowIsSelected = [[self selectedRowIndexes] containsIndex:iRow]; BOOL currentRowIsSelected = [[self selectedRowIndexes] containsIndex:iRow];
if (!currentRowIsSelected) { if (!currentRowIsSelected) {
if (iRow == -1) if (iRow == -1)
{ {
[self deselectAll:self]; [self deselectAll:self];
} }
else else
{ {
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:iRow] byExtendingSelection:NO]; [self selectRowIndexes:[NSIndexSet indexSetWithIndex:iRow] byExtendingSelection:NO];
} }
} }
if ([self numberOfSelectedRows] <=0) if ([self numberOfSelectedRows] <=0)
{ {
//No rows are selected, so the table should be displayed with all items disabled //No rows are selected, so the table should be displayed with all items disabled
int i; int i;
for (i=0;i<[tableViewMenu numberOfItems];i++) { for (i=0;i<[tableViewMenu numberOfItems];i++) {
[[tableViewMenu itemAtIndex:i] setEnabled:NO]; [[tableViewMenu itemAtIndex:i] setEnabled:NO];
} }
} }
return tableViewMenu; return tableViewMenu;
} }
- (void)keyDown:(NSEvent *)e - (void)keyDown:(NSEvent *)e
{ {
unsigned int modifiers = [e modifierFlags] & (NSCommandKeyMask | NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask); unsigned int modifiers = [e modifierFlags] & (NSEventModifierFlagCommand | NSEventModifierFlagShift | NSEventModifierFlagControl | NSEventModifierFlagOption);
NSString *characters = [e characters]; NSString *characters = [e characters];
unichar c; unichar c;
if ([characters length] != 1) if ([characters length] != 1)
{ {
[super keyDown:e]; [super keyDown:e];
return; return;
} }
c = [characters characterAtIndex:0]; c = [characters characterAtIndex:0];
if (modifiers == 0 && (c == NSDeleteCharacter || c == NSBackspaceCharacter || c == NSDeleteFunctionKey)) if (modifiers == 0 && (c == NSDeleteCharacter || c == NSBackspaceCharacter || c == NSDeleteFunctionKey))
{ {
[playlistController remove:self]; [playlistController remove:self];
} }
else if (modifiers == 0 && c == ' ') else if (modifiers == 0 && c == ' ')
{ {
[playbackController playPauseResume:self]; [playbackController playPauseResume:self];
} }
else if (modifiers == 0 && (c == NSEnterCharacter || c == NSCarriageReturnCharacter)) else if (modifiers == 0 && (c == NSEnterCharacter || c == NSCarriageReturnCharacter))
{ {
[playbackController play:self]; [playbackController play:self];
} }
else if (modifiers == 0 && c == NSLeftArrowFunctionKey) else if (modifiers == 0 && c == NSLeftArrowFunctionKey)
{ {
[playbackController eventSeekBackward:self]; [playbackController eventSeekBackward:self];
@ -206,31 +206,31 @@
{ {
[playbackController eventSeekForward:self]; [playbackController eventSeekForward:self];
} }
// Escape // Escape
else if (modifiers == 0 && c == 0x1b) else if (modifiers == 0 && c == 0x1b)
{ {
[playlistController clearFilterPredicate:self]; [playlistController clearFilterPredicate:self];
} }
else else
{ {
[super keyDown:e]; [super keyDown:e];
} }
} }
- (IBAction)scrollToCurrentEntry:(id)sender - (IBAction)scrollToCurrentEntry:(id)sender
{ {
[self scrollRowToVisible:[[playlistController currentEntry] index]]; [self scrollRowToVisible:[[playlistController currentEntry] index]];
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:[[playlistController currentEntry] index]] byExtendingSelection:NO]; [self selectRowIndexes:[NSIndexSet indexSetWithIndex:[[playlistController currentEntry] index]] byExtendingSelection:NO];
} }
- (IBAction)undo:(id)sender - (IBAction)undo:(id)sender
{ {
[[playlistController undoManager] undo]; [[playlistController undoManager] undo];
} }
- (IBAction)redo:(id)sender - (IBAction)redo:(id)sender
{ {
[[playlistController undoManager] redo]; [[playlistController undoManager] redo];
} }
- (IBAction)copy:(id)sender - (IBAction)copy:(id)sender
@ -257,7 +257,7 @@
[tracks setObject:track forKey:[NSString stringWithFormat:@"%lu", i]]; [tracks setObject:track forKey:[NSString stringWithFormat:@"%lu", i]];
++i; ++i;
} }
NSMutableDictionary * itunesPlist = [NSMutableDictionary dictionaryWithObjectsAndKeys:tracks, @"Tracks", nil]; NSMutableDictionary * itunesPlist = [NSMutableDictionary dictionaryWithObjectsAndKeys:tracks, @"Tracks", nil];
[pboard setPropertyList:itunesPlist forType:iTunesDropType]; [pboard setPropertyList:itunesPlist forType:iTunesDropType];
@ -279,69 +279,69 @@
[self copy:sender]; [self copy:sender];
[playlistController removeObjectsAtArrangedObjectIndexes:[playlistController selectionIndexes]]; [playlistController removeObjectsAtArrangedObjectIndexes:[playlistController selectionIndexes]];
if ([playlistController shuffle] != ShuffleOff) if ([playlistController shuffle] != ShuffleOff)
[playlistController resetShuffleList]; [playlistController resetShuffleList];
} }
- (IBAction)paste:(id)sender - (IBAction)paste:(id)sender
{ {
// 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 = [NSPasteboard generalPasteboard]; NSPasteboard *pboard = [NSPasteboard generalPasteboard];
NSString *bestType = [pboard availableTypeFromArray:supportedTypes]; NSString *bestType = [pboard availableTypeFromArray:supportedTypes];
NSMutableArray *acceptedURLs = [[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:[pboard dataForType:CogUrlsPboardType]]; NSArray *urls = [NSUnarchiver unarchiveObjectWithData:[pboard dataForType:CogUrlsPboardType]];
DLog(@"URLS: %@", urls); DLog(@"URLS: %@", urls);
//[playlistLoader insertURLs: urls atIndex:row sort:YES]; //[playlistLoader insertURLs: urls atIndex:row sort:YES];
[acceptedURLs 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)
if ([bestType isEqualToString:NSFilenamesPboardType]) { if ([bestType isEqualToString:NSFilenamesPboardType]) {
NSMutableArray *urls = [[NSMutableArray alloc] init]; NSMutableArray *urls = [[NSMutableArray alloc] init];
for (NSString *file in [pboard propertyListForType:NSFilenamesPboardType]) for (NSString *file in [pboard propertyListForType:NSFilenamesPboardType])
{ {
[urls addObject:[NSURL fileURLWithPath:file]]; [urls addObject:[NSURL fileURLWithPath:file]];
} }
//[playlistLoader insertURLs:urls atIndex:row sort:YES];
[acceptedURLs addObjectsFromArray:urls];
}
// 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! //[playlistLoader insertURLs:urls atIndex:row sort:YES];
NSMutableArray *urls = [[NSMutableArray alloc] init]; [acceptedURLs addObjectsFromArray:urls];
}
// Get files from an iTunes drop
if ([bestType isEqualToString:iTunesDropType]) {
NSDictionary *iTunesDict = [pboard propertyListForType:iTunesDropType];
NSDictionary *tracks = [iTunesDict valueForKey:@"Tracks"];
for (NSDictionary *trackInfo in [tracks allValues]) { // Convert the iTunes URLs to URLs....MWAHAHAH!
[urls addObject:[NSURL URLWithString:[trackInfo valueForKey:@"Location"]]]; NSMutableArray *urls = [[NSMutableArray alloc] init];
}
for (NSDictionary *trackInfo in [tracks allValues]) {
//[playlistLoader insertURLs:urls atIndex:row sort:YES]; [urls addObject:[NSURL URLWithString:[trackInfo valueForKey:@"Location"]]];
[acceptedURLs addObjectsFromArray:urls]; }
}
//[playlistLoader insertURLs:urls atIndex:row sort:YES];
if ([acceptedURLs count]) [acceptedURLs addObjectsFromArray:urls];
{ }
if ([acceptedURLs count])
{
NSUInteger row = [[playlistController content] count]; NSUInteger row = [[playlistController content] count];
[playlistController willInsertURLs:acceptedURLs origin:URLOriginInternal]; [playlistController willInsertURLs:acceptedURLs origin:URLOriginInternal];
NSArray* entries = [playlistLoader insertURLs:acceptedURLs atIndex:(int)row sort:NO]; NSArray* entries = [playlistLoader insertURLs:acceptedURLs atIndex:(int)row sort:NO];
[playlistLoader didInsertURLs:entries origin:URLOriginInternal]; [playlistLoader didInsertURLs:entries origin:URLOriginInternal];
if ([playlistController shuffle] != ShuffleOff) if ([playlistController shuffle] != ShuffleOff)
[playlistController resetShuffleList]; [playlistController resetShuffleList];
} }
} }
- (IBAction)delete:(id)sender - (IBAction)delete:(id)sender
@ -352,22 +352,22 @@
-(BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem -(BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem
{ {
SEL action = [anItem action]; SEL action = [anItem action];
if (action == @selector(undo:)) if (action == @selector(undo:))
{ {
if ([[playlistController undoManager] canUndo]) if ([[playlistController undoManager] canUndo])
return YES; return YES;
else else
return NO; return NO;
} }
if (action == @selector(redo:)) if (action == @selector(redo:))
{ {
if ([[playlistController undoManager] canRedo]) if ([[playlistController undoManager] canRedo])
return YES; return YES;
else else
return NO; return NO;
} }
if (action == @selector(cut:) || action == @selector(copy:) || action == @selector(delete:)) if (action == @selector(cut:) || action == @selector(copy:) || action == @selector(delete:))
{ {
if ([[playlistController selectionIndexes] count] == 0) if ([[playlistController selectionIndexes] count] == 0)
@ -378,7 +378,7 @@
if (action == @selector(paste:)) if (action == @selector(paste:))
{ {
NSPasteboard *pboard = [NSPasteboard generalPasteboard]; NSPasteboard *pboard = [NSPasteboard generalPasteboard];
NSArray *supportedTypes = [NSArray arrayWithObjects:CogUrlsPboardType, NSFilenamesPboardType, iTunesDropType, nil]; NSArray *supportedTypes = [NSArray arrayWithObjects:CogUrlsPboardType, NSFilenamesPboardType, iTunesDropType, nil];
NSString *bestType = [pboard availableTypeFromArray:supportedTypes]; NSString *bestType = [pboard availableTypeFromArray:supportedTypes];
@ -388,20 +388,20 @@
else else
return NO; return NO;
} }
if (action == @selector(scrollToCurrentEntry:) && (([playbackController playbackStatus] == kCogStatusStopped) || ([playbackController playbackStatus] == kCogStatusStopping))) if (action == @selector(scrollToCurrentEntry:) && (([playbackController playbackStatus] == kCogStatusStopped) || ([playbackController playbackStatus] == kCogStatusStopping)))
return NO; return NO;
return [super validateUserInterfaceItem:anItem]; return [super validateUserInterfaceItem:anItem];
} }
#if 0 #if 0
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal
{ {
if (isLocal) if (isLocal)
return NSDragOperationNone; return NSDragOperationNone;
else else
return NSDragOperationCopy; return NSDragOperationCopy;
} }
#endif #endif

View File

@ -47,8 +47,8 @@
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
if (image != nil) { if (image != nil) {
NSSize imageSize; NSSize imageSize;
NSRect imageFrame; NSRect imageFrame;
imageSize = [image size]; imageSize = [image size];
NSDivideRect(cellFrame, &imageFrame, &cellFrame, 3 + imageSize.width, NSMinXEdge); NSDivideRect(cellFrame, &imageFrame, &cellFrame, 3 + imageSize.width, NSMinXEdge);
@ -58,10 +58,10 @@
} }
imageFrame.origin.x += 3; imageFrame.origin.x += 3;
imageFrame.size = imageSize; imageFrame.size = imageSize;
imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2); imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2);
[image drawInRect:imageFrame fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil]; [image drawInRect:imageFrame fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1.0 respectFlipped:YES hints:nil];
} }
[super drawWithFrame:cellFrame inView:controlView]; [super drawWithFrame:cellFrame inView:controlView];
} }
@ -72,4 +72,4 @@
return cellSize; return cellSize;
} }
@end @end

View File

@ -1,54 +1,54 @@
/* /*
File: OpenURLPanel.m File: OpenURLPanel.m
Originally introduced at WWDC 2004 at Originally introduced at WWDC 2004 at
Session 214, "Programming QuickTime with Cocoa." Session 214, "Programming QuickTime with Cocoa."
Sample code is explained in detail in Sample code is explained in detail in
"QTKit Programming Guide" documentation. "QTKit Programming Guide" documentation.
Copyright: © Copyright 2004, 2005 Apple Computer, Inc. Copyright: © Copyright 2004, 2005 Apple Computer, Inc.
All rights reserved. All rights reserved.
Disclaimer: IMPORTANT: This Apple software is supplied to you by Disclaimer: IMPORTANT: This Apple software is supplied to you by
Apple Computer, Inc. ("Apple") in consideration of your agreement to the Apple Computer, Inc. ("Apple") in consideration of your agreement to the
following terms, and your use, installation, modification or following terms, and your use, installation, modification or
redistribution of this Apple software constitutes acceptance of these redistribution of this Apple software constitutes acceptance of these
terms. If you do not agree with these terms, please do not use, terms. If you do not agree with these terms, please do not use,
install, modify or redistribute this Apple software. install, modify or redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive subject to these terms, Apple grants you a personal, non-exclusive
license, under AppleÕs copyrights in this original Apple software (the license, under AppleÕs copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple "Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms; Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software. text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Computer, Neither the name, trademarks, service marks or logos of Apple Computer,
Inc. may be used to endorse or promote products derived from the Apple Inc. may be used to endorse or promote products derived from the Apple
Software without specific prior written permission from Apple. Except Software without specific prior written permission from Apple. Except
as expressly stated in this notice, no other rights or licenses, express as expressly stated in this notice, no other rights or licenses, express
or implied, are granted by Apple herein, including but not limited to or implied, are granted by Apple herein, including but not limited to
any patent rights that may be infringed by your derivative works or by any patent rights that may be infringed by your derivative works or by
other works in which the Apple Software may be incorporated. other works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#import "OpenURLPanel.h" #import "OpenURLPanel.h"
@ -66,10 +66,10 @@ static OpenURLPanel *openURLPanel = nil;
// class methods // class methods
+ (id)openURLPanel + (id)openURLPanel
{ {
if (openURLPanel == nil) if (openURLPanel == nil)
openURLPanel = [[self alloc] init]; openURLPanel = [[self alloc] init];
return openURLPanel; return openURLPanel;
} }
- (id)init - (id)init
@ -78,84 +78,84 @@ static OpenURLPanel *openURLPanel = nil;
{ {
// init // init
[self setURLArray:[NSMutableArray arrayWithCapacity:10]]; [self setURLArray:[NSMutableArray arrayWithCapacity:10]];
// listen for app termination notifications // listen for app termination notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(writeURLs:) name:NSApplicationWillTerminateNotification object:NSApp]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(writeURLs:) name:NSApplicationWillTerminateNotification object:NSApp];
} }
return self; return self;
} }
- (void)dealloc - (void)dealloc
{ {
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
[self setURLArray:nil]; [self setURLArray:nil];
} }
// getters // getters
- (NSString *)urlString - (NSString *)urlString
{ {
NSString *urlString = nil; NSString *urlString = nil;
// get the url // get the url
urlString = [mUrlComboBox stringValue]; urlString = [mUrlComboBox stringValue];
if (urlString == nil) if (urlString == nil)
urlString = [mUrlComboBox objectValueOfSelectedItem]; urlString = [mUrlComboBox objectValueOfSelectedItem];
if ([urlString length] == 0) if ([urlString length] == 0)
urlString = nil; urlString = nil;
return urlString; return urlString;
} }
- (NSURL *)url - (NSURL *)url
{ {
NSURL *url = nil; NSURL *url = nil;
NSString *urlString; NSString *urlString;
// get the url // get the url
urlString = [self urlString]; urlString = [self urlString];
if (urlString) if (urlString)
url = [NSURL URLWithString:urlString]; url = [NSURL URLWithString:urlString];
return url; return url;
} }
// setters // setters
- (void)setURLArray:(NSMutableArray *)urlLArray - (void)setURLArray:(NSMutableArray *)urlLArray
{ {
mUrlArray = urlLArray; mUrlArray = urlLArray;
} }
// delegates // delegates
- (void)awakeFromNib - (void)awakeFromNib
{ {
NSArray *urls; NSArray *urls;
// restore the previous urls // restore the previous urls
urls = [[NSUserDefaults standardUserDefaults] objectForKey:kUserDefaultURLsKey]; urls = [[NSUserDefaults standardUserDefaults] objectForKey:kUserDefaultURLsKey];
[mUrlArray addObjectsFromArray:urls]; [mUrlArray addObjectsFromArray:urls];
if (urls) if (urls)
[mUrlComboBox addItemsWithObjectValues:urls]; [mUrlComboBox addItemsWithObjectValues:urls];
} }
// notifications // notifications
- (void)writeURLs:(NSNotification *)notification - (void)writeURLs:(NSNotification *)notification
{ {
NSUserDefaults *userDefaults; NSUserDefaults *userDefaults;
if ([mUrlArray count]) if ([mUrlArray count])
{ {
// init // init
userDefaults = [NSUserDefaults standardUserDefaults]; userDefaults = [NSUserDefaults standardUserDefaults];
// write out the urls // write out the urls
[userDefaults setObject:mUrlArray forKey:kUserDefaultURLsKey]; [userDefaults setObject:mUrlArray forKey:kUserDefaultURLsKey];
[userDefaults synchronize]; [userDefaults synchronize];
} }
} }
// actions // actions
@ -163,91 +163,91 @@ typedef id (*myIMP)(id, SEL, ...);
- (IBAction)doOpenURL:(id)sender - (IBAction)doOpenURL:(id)sender
{ {
NSString *urlString; NSString *urlString;
NSURL *url; NSURL *url;
BOOL informDelegate = YES; BOOL informDelegate = YES;
myIMP callback; myIMP callback;
if ([sender tag] == NSModalResponseOK)
{
// validate the URL
url = [self url];
urlString = [self urlString];
if (url)
{
// save the url
if (![mUrlArray containsObject:urlString])
{
// save the url
[mUrlArray addObject:urlString];
// add the url to the combo box
[mUrlComboBox addItemWithObjectValue:urlString];
// remove the oldest url if the maximum has been exceeded
if ([mUrlArray count] > kMaximumURLs)
{
[mUrlArray removeObjectAtIndex:0];
[mUrlComboBox removeItemAtIndex:0];
}
}
else
{
// move the url to the bottom of the list
[mUrlArray removeObject:urlString];
[mUrlArray addObject:urlString];
[mUrlComboBox removeItemWithObjectValue:urlString];
[mUrlComboBox addItemWithObjectValue:urlString];
}
}
else
{
if (mIsSheet)
NSRunAlertPanel(NSLocalizedString(@"InvalidURLShort", @""), NSLocalizedString(@"InvalidURLLong", @""), nil, nil, nil);
else
NSBeginAlertSheet(NSLocalizedString(@"InvalidURLShort", @""), nil, nil, nil, mPanel, nil, nil, nil, nil, NSLocalizedString(@"InvalidURLLong", @""));
if ([sender tag] == NSOKButton) informDelegate = NO;
{ }
// validate the URL }
url = [self url];
urlString = [self urlString]; // inform the delegate
if (informDelegate && mDelegate && mDidEndSelector)
if (url) {
{ callback = (myIMP) [mDelegate methodForSelector:mDidEndSelector];
// save the url callback(mDelegate, mDidEndSelector, self, [sender tag], mContextInfo);
if (![mUrlArray containsObject:urlString])
{ [self close];
// save the url }
[mUrlArray addObject:urlString];
// add the url to the combo box
[mUrlComboBox addItemWithObjectValue:urlString];
// remove the oldest url if the maximum has been exceeded
if ([mUrlArray count] > kMaximumURLs)
{
[mUrlArray removeObjectAtIndex:0];
[mUrlComboBox removeItemAtIndex:0];
}
}
else
{
// move the url to the bottom of the list
[mUrlArray removeObject:urlString];
[mUrlArray addObject:urlString];
[mUrlComboBox removeItemWithObjectValue:urlString];
[mUrlComboBox addItemWithObjectValue:urlString];
}
}
else
{
if (mIsSheet)
NSRunAlertPanel(NSLocalizedString(@"InvalidURLShort", @""), NSLocalizedString(@"InvalidURLLong", @""), nil, nil, nil);
else
NSBeginAlertSheet(NSLocalizedString(@"InvalidURLShort", @""), nil, nil, nil, mPanel, nil, nil, nil, nil, NSLocalizedString(@"InvalidURLLong", @""));
informDelegate = NO;
}
}
// inform the delegate
if (informDelegate && mDelegate && mDidEndSelector)
{
callback = (myIMP) [mDelegate methodForSelector:mDidEndSelector];
callback(mDelegate, mDidEndSelector, self, [sender tag], mContextInfo);
[self close];
}
} }
// methods // methods
- (void)beginSheetWithWindow:(NSWindow *)window delegate:(id)delegate didEndSelector:(SEL)didEndSelector contextInfo:(void *)contextInfo - (void)beginSheetWithWindow:(NSWindow *)window delegate:(id)delegate didEndSelector:(SEL)didEndSelector contextInfo:(void *)contextInfo
{ {
// will this run as a sheet // will this run as a sheet
mIsSheet = (window ? YES : NO); mIsSheet = (window ? YES : NO);
// save the delegate, did end selector, and context info // save the delegate, did end selector, and context info
mDelegate = delegate; mDelegate = delegate;
mDidEndSelector = (didEndSelector); mDidEndSelector = (didEndSelector);
mContextInfo = contextInfo; mContextInfo = contextInfo;
NSArray *objects; NSArray *objects;
// load the bundle (if necessary) // load the bundle (if necessary)
if (mPanel == nil) if (mPanel == nil)
[[NSBundle mainBundle] loadNibNamed:@"OpenURLPanel" owner:self topLevelObjects:&objects]; [[NSBundle mainBundle] loadNibNamed:@"OpenURLPanel" owner:self topLevelObjects:&objects];
// start the sheet (or window) // start the sheet (or window)
[NSApp beginSheet:mPanel modalForWindow:window modalDelegate:nil didEndSelector:nil contextInfo:nil]; [NSApp beginSheet:mPanel modalForWindow:window modalDelegate:nil didEndSelector:nil contextInfo:nil];
} }
- (void)close - (void)close
{ {
// close it down // close it down
[NSApp endSheet:mPanel]; [NSApp endSheet:mPanel];
[mPanel close]; [mPanel close];
} }
@end @end