Re: sandboxing and filename extensions
Re: sandboxing and filename extensions
- Subject: Re: sandboxing and filename extensions
- From: Quincey Morris <email@hidden>
- Date: Wed, 15 May 2013 10:39:36 -0700
On May 15, 2013, at 08:31 , Scott Ribe <email@hidden> wrote:
> I guess about the only thing I can do here in order to get the file named in a usable manner […] is to use a delegate, implement panel:validateURL:error:, and force the user to type ".pdf".
I don't believe this. If true, it would suggest that sandboxed Save panels are so broken that no one could save anything without typing the correct extension.
In fact, I'm not seeing the behavior you describe. In an existing sandboxed app of mine, there's an Export function that does the right thing. The code is like this:
> NSSavePanel* savePanel = [NSSavePanel savePanel];
>
> savePanel.title = …
> savePanel.prompt = …
> savePanel.nameFieldLabel = …
> savePanel.canCreateDirectories = YES;
> savePanel.canSelectHiddenExtension = YES;
> savePanel.allowedFileTypes = [NSArray arrayWithObject: @"abc"];
>
> NSString* exportDirectory = …
> if (exportDirectory)
> savePanel.directoryURL = [NSURL fileURLWithPath: exportDirectory];
>
> NSString* exportFileName = [[self.document displayName] stringByDeletingPathExtension];
> exportFileName = [exportFileName stringByAppendingString: @" Export"];
> exportFileName = [exportFileName stringByAppendingPathExtension: @"abc"]; // <-- this
> savePanel.nameFieldStringValue = exportFileName;
>
> [savePanel beginSheetModalForWindow: [self.document windowForSheet] completionHandler: ^(NSInteger result)
> {
> … savePanel.URL …
> }];
(The line labeled "<-- this" is, IIRC, the change I referred to earlier. Originally, there was no need to supply the extension explicitly there, but somewhere around 10.7, it became necessary.)
Because of "canSelectHiddenExtension", my Save dialog has a "Hide Extension" checkbox. If it's unchecked, and I retype the file name text box without an extension, the checkbox turns itself on automatically. If I type the correct extension, the checkbox turns itself off automatically. (If I type an incorrect extension, the checkbox turns on. I assume I'd get something like "filename.def.abc" in that case.)
No matter whether the extension is shown in the text field, the Save panel returns a URL with the correct extension. I have no idea why you might be seeing different behavior. Except …
On May 14, 2013, at 21:16 , Scott Ribe <email@hidden> wrote:
> [pnl beginSheetForDirectory: ...];
When comparing your code with mine, I realized that -[NSSavePanel beginSheetForDirectory: …] was deprecated in 10.6. Try using one of the non-deprecated methods. It *does* matter, with powerbox.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden