Looks like I've found a workaround:

- (IBAction)formatForTextExportChanged:(id)sender
{    
    self.textExportFormat = [sender indexOfSelectedItem];
        
    NSString *path = 
self.currentSavePanel.nameFieldStringValue.stringByDeletingPathExtension;
    
    switch (self.textExportFormat) {
        case 0:
            path = [path stringByAppendingPathExtension:@"txt"];
            self.currentSavePanel.allowedFileTypes = @[@"txt"];
            break;
        case 1:
            path = [path stringByAppendingPathExtension:@"rtf"];
            self.currentSavePanel.allowedFileTypes = @[@"rtf"];
            break;
    }
    
    self.currentSavePanel.nameFieldStringValue = path;

    [[NSUserDefaults standardUserDefaults] setValue:[NSNumber 
numberWithInteger:self.textExportFormat]
                                                                                
         forKey:ANTextExportFormatKey];
}

By setting the desired file type as the only allowable, the save panel now also 
returns the correct file extension, even if the user chose to hide the 
extension. If there is a better solution, please tell.

-António

On 10 Jul, 2013, at 10:47 , Antonio Nunes <devli...@sintraworks.com> wrote:

> 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 (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/devlists%40sintraworks.com
> 
> This email sent to devli...@sintraworks.com

-----------------------------------------
Perfume is the forgiveness
that the trampled flower casts
upon the heel that crushes it.
-----------------------------------------




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to