From 0112532e64db3d4d72859da018e8a12e233e4612 Mon Sep 17 00:00:00 2001 From: jtbandes Date: Sat, 11 Aug 2012 20:40:36 -0700 Subject: [PATCH] Stop using deprecated NSSavePanel/NSOpenPanel methods --- .../TextMate/src/AppController Documents.mm | 10 +++++++-- Frameworks/Find/src/FFWindowController.mm | 22 ++++++++++++++----- .../src/browser/HOWebViewDelegateHelper.mm | 5 +++-- Frameworks/OakAppKit/src/OakSavePanel.mm | 14 ++++++------ .../OakFileBrowser/src/OakFileBrowser.mm | 18 +++++---------- 5 files changed, 39 insertions(+), 30 deletions(-) diff --git a/Applications/TextMate/src/AppController Documents.mm b/Applications/TextMate/src/AppController Documents.mm index 535ae495..1b208350 100644 --- a/Applications/TextMate/src/AppController Documents.mm +++ b/Applications/TextMate/src/AppController Documents.mm @@ -43,8 +43,14 @@ static NSString* const OakGlobalSessionInfo = @"OakGlobalSessionInfo"; openPanel.title = [NSString stringWithFormat:@"%@: Open", [[[NSBundle mainBundle] localizedInfoDictionary] valueForKey: @"CFBundleName"] ?: [[NSProcessInfo processInfo] processName]]; [openPanel setShowsHiddenFilesCheckBox:YES]; - if([openPanel runModalForTypes:nil] == NSOKButton) - OakOpenDocuments([openPanel filenames]); + if([openPanel runModal] == NSOKButton) + { + NSMutableArray* filenames = [NSMutableArray array]; + for(NSURL* url in [openPanel URLs]) + [filenames addObject:[[url filePathURL] path]]; + + OakOpenDocuments(filenames); + } } - (BOOL)application:(NSApplication*)theApplication openFile:(NSString*)aPath diff --git a/Frameworks/Find/src/FFWindowController.mm b/Frameworks/Find/src/FFWindowController.mm index 6d9f3ce9..6e5468ff 100644 --- a/Frameworks/Find/src/FFWindowController.mm +++ b/Frameworks/Find/src/FFWindowController.mm @@ -116,6 +116,7 @@ NSString* const FFSearchInOpenFiles = @"FFSearchInOpenFiles"; @interface FFWindowController () - (BOOL)outlineView:(NSOutlineView*)outlineView isGroupItem:(id)item; +- (void)openPanelDidEnd:(NSOpenPanel*)panel returnCode:(NSInteger)returnCode; @property (nonatomic, assign) BOOL canSetFileTypes; @property (nonatomic, assign) BOOL canSetWrapAround; @@ -445,14 +446,24 @@ struct operation_t - (IBAction)showFolderSelectionPanel:(id)sender { - NSOpenPanel* openPanel = [[NSOpenPanel openPanel] retain]; + NSOpenPanel* openPanel = [NSOpenPanel openPanel]; openPanel.title = @"Find in Folder"; openPanel.canChooseFiles = NO; openPanel.canChooseDirectories = YES; NSString* startPath = self.isSearchingFolders ? self.searchFolder : nil; + openPanel.directoryURL = [NSURL fileURLWithPath:startPath]; if([[self window] isVisible]) - [openPanel beginSheetForDirectory:startPath file:nil types:nil modalForWindow:[self window] modalDelegate:self didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) contextInfo:NULL]; - else [openPanel beginForDirectory:startPath file:nil types:nil modelessDelegate:self didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) contextInfo:NULL]; + { + [openPanel beginSheetModalForWindow:[self window] completionHandler:^(NSInteger result) { + [self openPanelDidEnd:openPanel returnCode:result]; + }]; + } + else + { + [openPanel beginWithCompletionHandler:^(NSInteger result) { + [self openPanelDidEnd:openPanel returnCode:result]; + }]; + } } /* @@ -1096,19 +1107,18 @@ Any other string: return res; } -- (void)openPanelDidEnd:(NSOpenPanel*)panel returnCode:(NSInteger)returnCode contextInfo:(void*)contextInfo +- (void)openPanelDidEnd:(NSOpenPanel*)panel returnCode:(NSInteger)returnCode { [self.window performSelector:@selector(makeKeyWindow) withObject:nil afterDelay:0.0]; if(returnCode == NSOKButton) { - self.searchIn = [[panel filenames] lastObject]; + self.searchIn = [[[[panel URLs] lastObject] filePathURL] path]; [self showWindow:self]; } else { self.searchIn = self.searchIn; // Restore previously selected menu item } - [panel release]; } - (IBAction)performFindAction:(id)sender diff --git a/Frameworks/HTMLOutput/src/browser/HOWebViewDelegateHelper.mm b/Frameworks/HTMLOutput/src/browser/HOWebViewDelegateHelper.mm index 411ce107..e95f3169 100644 --- a/Frameworks/HTMLOutput/src/browser/HOWebViewDelegateHelper.mm +++ b/Frameworks/HTMLOutput/src/browser/HOWebViewDelegateHelper.mm @@ -49,8 +49,9 @@ - (void)webView:(WebView*)sender runOpenPanelForFileButtonWithResultListener:(id )resultListener { NSOpenPanel* panel = [NSOpenPanel openPanel]; - if([panel runModalForDirectory:NSHomeDirectory() file:nil types:nil] == NSOKButton) - [resultListener chooseFilename:[[panel filenames] objectAtIndex:0]]; + [panel setDirectoryURL:[NSURL fileURLWithPath:NSHomeDirectory()]]; + if([panel runModal] == NSOKButton) + [resultListener chooseFilename:[[[[panel URLs] objectAtIndex:0] fileURL] path]]; } - (WebView*)webView:(WebView*)sender createWebViewWithRequest:(NSURLRequest*)request diff --git a/Frameworks/OakAppKit/src/OakSavePanel.mm b/Frameworks/OakAppKit/src/OakSavePanel.mm index 5663f22c..50897aad 100644 --- a/Frameworks/OakAppKit/src/OakSavePanel.mm +++ b/Frameworks/OakAppKit/src/OakSavePanel.mm @@ -13,7 +13,13 @@ NSSavePanel* savePanel = [NSSavePanel savePanel]; [savePanel setTreatsFilePackagesAsDirectories:YES]; - [savePanel beginSheetForDirectory:aDirectorySuggestion file:aPathSuggestion modalForWindow:aWindow modalDelegate:self didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:) contextInfo:NULL]; + [savePanel setDirectoryURL:[NSURL fileURLWithPath:aDirectorySuggestion]]; + [savePanel setNameFieldStringValue:[aPathSuggestion lastPathComponent]]; + [savePanel beginSheetModalForWindow:aWindow completionHandler:^(NSInteger result) { + NSString* path = result == NSOKButton ? [[savePanel.URL filePathURL] path] : nil; + [delegate savePanelDidEnd:self path:path contextInfo:contextInfo]; + [self release]; + }]; [savePanel deselectExtension]; } return self; @@ -24,10 +30,4 @@ [[OakSavePanel alloc] initWithPath:aPathSuggestion directory:aDirectorySuggestion fowWindow:aWindow delegate:aDelegate contextInfo:info]; } -- (void)savePanelDidEnd:(NSSavePanel*)sheet returnCode:(NSInteger)returnCode contextInfo:(void*)info -{ - NSString* path = returnCode == NSOKButton ? sheet.filename : nil; - [delegate savePanelDidEnd:self path:path contextInfo:contextInfo]; - [self release]; -} @end diff --git a/Frameworks/OakFileBrowser/src/OakFileBrowser.mm b/Frameworks/OakFileBrowser/src/OakFileBrowser.mm index 0686abab..1364995c 100644 --- a/Frameworks/OakFileBrowser/src/OakFileBrowser.mm +++ b/Frameworks/OakFileBrowser/src/OakFileBrowser.mm @@ -847,25 +847,17 @@ static struct data_source_options_map_t { NSString* const name; NSUInteger flag; [self pushURL:ParentForURL(url)]; } -- (void)goToSheetDidEnd:(NSOpenPanel*)panel returnCode:(NSInteger)returnCode contextInfo:(void*)contextInfo -{ - if(returnCode == NSOKButton) - [self showURL:[[panel URLs] lastObject]]; -} - - (IBAction)orderFrontGoToFolder:(id)sender { NSOpenPanel* panel = [NSOpenPanel openPanel]; [panel setCanChooseFiles:NO]; [panel setCanChooseDirectories:YES]; [panel setAllowsMultipleSelection:NO]; - [panel beginSheetForDirectory:self.location - file:nil - types:nil - modalForWindow:view.window - modalDelegate:self - didEndSelector:@selector(goToSheetDidEnd:returnCode:contextInfo:) - contextInfo:NULL]; + [panel setDirectoryURL:[NSURL fileURLWithPath:self.location]]; + [panel beginSheetModalForWindow:view.window completionHandler:^(NSInteger result) { + if(result == NSOKButton) + [self showURL:[[panel URLs] lastObject]]; + }]; } - (void)takeURLFrom:(id)sender