Dynamically change file name extension in NSSavePanel when extension is hidden
Dynamically change file name extension in NSSavePanel when extension is hidden
- Subject: Dynamically change file name extension in NSSavePanel when extension is hidden
- From: Antonio Nunes <email@hidden>
- Date: Wed, 10 Jul 2013 10:47:01 +0100
Hi,
I show an NSSavePanel that offers the option to hide the file extension. It also offers the user to switch between saving .txt and .rtf formats.
When the user changes the format, the following code is run:
- (IBAction)formatForTextExportChanged:(id)sender
{
self.textExportFormat = [sender indexOfSelectedItem];
NSString *path = self.currentSavePanel.nameFieldStringValue.stringByDeletingPathExtension;
switch (self.textExportFormat) {
case 0:
path = [path stringByAppendingPathExtension:@"txt"];
break;
case 1:
path = [path stringByAppendingPathExtension:@"rtf"];
break;
}
self.currentSavePanel.nameFieldStringValue = path;
[[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithInteger:self.textExportFormat]
forKey:ANTextExportFormatKey];
}
This works fine when the extension is being shown. However, when the extension is not shown, although the code appears to work while in the panel, when the panel is dismissed, the URL returned has the extension of the original format. How do I ensure the URL returned b the save panel ends on the user selected choice, even when the extension is hidden? I can't directly set the save panel's URL since it is read only. SInce the app is snadboxed, I need the save panel to return the correct URL, otherwise we later don't have permission to write to the URL, if I change it afterwards.
-António
----------------------------------------------------
There is a world of difference between
searching for happiness and choosing
to be happy.
----------------------------------------------------
_______________________________________________
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