Skip to content

Commit

Permalink
Fix open/save panel related compilation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
b4winckler committed Jul 21, 2011
1 parent 1c1b721 commit 672bf1f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 5 deletions.
36 changes: 33 additions & 3 deletions src/MacVim/MMAppController.m
Expand Up @@ -1070,10 +1070,40 @@ - (IBAction)fileOpen:(id)sender
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setAllowsMultipleSelection:YES];
[panel setAccessoryView:showHiddenFilesView()];
#if (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6)
// NOTE: -[NSOpenPanel runModalForDirectory:file:types:] is deprecated on
// 10.7 but -[NSOpenPanel setDirectoryURL:] requires 10.6 so jump through
// the following hoops on 10.6+.
dir = [dir stringByExpandingTildeInPath];
if (dir) {
NSURL *dirURL = [NSURL fileURLWithPath:dir isDirectory:YES];
if (dirURL)
[panel setDirectoryURL:dirURL];
}

NSInteger result = [panel runModal];
#else
NSInteger result = [panel runModalForDirectory:dir file:nil types:nil];
#endif
if (NSOKButton == result) {
// NOTE: -[NSOpenPanel filenames] is deprecated on 10.7 so use
// -[NSOpenPanel URLs] instead. The downside is that we have to check
// that each URL is really a path first.
NSMutableArray *filenames = [NSMutableArray array];
NSArray *urls = [panel URLs];
NSUInteger i, count = [urls count];
for (i = 0; i < count; ++i) {
NSURL *url = [urls objectAtIndex:i];
if ([url isFileURL]) {
NSString *path = [url path];
if (path)
[filenames addObject:path];
}
}

int result = [panel runModalForDirectory:dir file:nil types:nil];
if (NSOKButton == result)
[self application:NSApp openFiles:[panel filenames]];
if ([filenames count] > 0)
[self application:NSApp openFiles:filenames];
}
}

- (IBAction)selectNextWindow:(id)sender
Expand Down
40 changes: 38 additions & 2 deletions src/MacVim/MMVimController.m
Expand Up @@ -894,7 +894,12 @@ - (void)handleMessage:(int)msgid data:(NSData *)data
- (void)savePanelDidEnd:(NSSavePanel *)panel code:(int)code
context:(void *)context
{
NSString *path = (code == NSOKButton) ? [panel filename] : nil;
NSString *path = nil;
if (code == NSOKButton) {
NSURL *url = [panel URL];
if ([url isFileURL])
path = [url path];
}
ASLogDebug(@"Open/save panel path=%@", path);

// NOTE! This causes the sheet animation to run its course BEFORE the rest
Expand Down Expand Up @@ -1386,6 +1391,12 @@ - (void)handleBrowseForFile:(NSDictionary *)attr
dir = [vimState objectForKey:@"pwd"];
}

#if (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6)
// 10.6+ APIs uses URLs instead of paths
dir = [dir stringByExpandingTildeInPath];
NSURL *dirURL = dir ? [NSURL fileURLWithPath:dir isDirectory:YES] : nil;
#endif

if (saving) {
NSSavePanel *panel = [NSSavePanel savePanel];

Expand All @@ -1395,22 +1406,47 @@ - (void)handleBrowseForFile:(NSDictionary *)attr
[panel setDelegate:self];
if ([panel isExpanded])
[panel setAccessoryView:showHiddenFilesView()];

#if (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6)
// NOTE: -[NSSavePanel beginSheetForDirectory::::::] is deprecated on
// 10.6 but -[NSSavePanel setDirectoryURL:] requires 10.6 so jump
// through the following hoops on 10.6+.
if (dirURL)
[panel setDirectoryURL:dirURL];

[panel beginSheetModalForWindow:[windowController window]
completionHandler:^(NSInteger result) {
[self savePanelDidEnd:panel code:result context:nil];
}];
#else
[panel beginSheetForDirectory:dir file:nil
modalForWindow:[windowController window]
modalDelegate:self
didEndSelector:@selector(savePanelDidEnd:code:context:)
contextInfo:NULL];
#endif
} else {
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setAllowsMultipleSelection:NO];
[panel setAccessoryView:showHiddenFilesView()];

#if (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6)
// NOTE: -[NSOpenPanel beginSheetForDirectory:::::::] is deprecated on
// 10.6 but -[NSOpenPanel setDirectoryURL:] requires 10.6 so jump
// through the following hoops on 10.6+.
if (dirURL)
[panel setDirectoryURL:dirURL];

[panel beginSheetModalForWindow:[windowController window]
completionHandler:^(NSInteger result) {
[self savePanelDidEnd:panel code:result context:nil];
}];
#else
[panel beginSheetForDirectory:dir file:nil types:nil
modalForWindow:[windowController window]
modalDelegate:self
didEndSelector:@selector(savePanelDidEnd:code:context:)
contextInfo:NULL];
#endif
}
}

Expand Down

0 comments on commit 672bf1f

Please sign in to comment.