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];
if(shouldHandleMediaKeyEventLocally && [event type] == NSSystemDefined && [event subtype] == 8 )
{
[self mediaKeyTap:nil receivedMediaKeyEvent:event];
}
if(shouldHandleMediaKeyEventLocally && [event type] == NSEventTypeSystemDefined && [event subtype] == 8 )
{
[self mediaKeyTap:nil receivedMediaKeyEvent:event];
}
[super sendEvent: event];
[super sendEvent: 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 keyFlags = ([event data1] & 0x0000FFFF);

View File

@ -15,62 +15,62 @@
- (void)awakeFromNib
{
[self setDoubleAction:@selector(addToPlaylistExternal:)];
[self setTarget:[self delegate]];
[self setDoubleAction:@selector(addToPlaylistExternal:)];
[self setTarget:[self delegate]];
}
- (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];
unichar c;
if ([characters length] == 1)
{
c = [characters characterAtIndex:0];
if (modifiers == 0 && (c == NSEnterCharacter || c == NSCarriageReturnCharacter))
{
[(FileTreeController *)[self delegate] addToPlaylistExternal:self];
return;
}
else if (modifiers == 0 && c == ' ')
{
[(FileTreeController *)[self delegate] playPauseResume:self];
return;
}
}
[super keyDown:e];
return;
unichar c;
if ([characters length] == 1)
{
c = [characters characterAtIndex:0];
if (modifiers == 0 && (c == NSEnterCharacter || c == NSCarriageReturnCharacter))
{
[(FileTreeController *)[self delegate] addToPlaylistExternal:self];
return;
}
else if (modifiers == 0 && c == ' ')
{
[(FileTreeController *)[self delegate] playPauseResume:self];
return;
}
}
[super keyDown:e];
return;
}
// 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];
NSPoint menuPoint = [self convertPoint:[event locationInWindow] fromView:nil];
NSInteger iRow = [self rowAtPoint:menuPoint];
NSMenu* contextMenu = [self menu];
/* Update the file tree 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 */
BOOL currentRowIsSelected = [[self selectedRowIndexes] containsIndex:iRow];
if (iRow == -1)
{
[self deselectAll:self];
}
else if (!currentRowIsSelected)
{
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:iRow] byExtendingSelection:NO];
}
return contextMenu;
//Find which row is under the cursor
[[self window] makeFirstResponder:self];
NSPoint menuPoint = [self convertPoint:[event locationInWindow] fromView:nil];
NSInteger iRow = [self rowAtPoint:menuPoint];
NSMenu* contextMenu = [self menu];
/* Update the file tree 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 */
BOOL currentRowIsSelected = [[self selectedRowIndexes] containsIndex:iRow];
if (iRow == -1)
{
[self deselectAll:self];
}
else if (!currentRowIsSelected)
{
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:iRow] byExtendingSelection:NO];
}
return contextMenu;
}
@end

View File

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

View File

@ -47,8 +47,8 @@
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
if (image != nil) {
NSSize imageSize;
NSRect imageFrame;
NSSize imageSize;
NSRect imageFrame;
imageSize = [image size];
NSDivideRect(cellFrame, &imageFrame, &cellFrame, 3 + imageSize.width, NSMinXEdge);
@ -58,10 +58,10 @@
}
imageFrame.origin.x += 3;
imageFrame.size = imageSize;
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];
}
@ -72,4 +72,4 @@
return cellSize;
}
@end
@end

View File

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