• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Dynamically change file name extension in NSSavePanel when extension is hidden
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dynamically change file name extension in NSSavePanel when extension is hidden


  • Subject: Re: Dynamically change file name extension in NSSavePanel when extension is hidden
  • From: Antonio Nunes <email@hidden>
  • Date: Wed, 10 Jul 2013 12:50:37 +0100

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 <email@hidden> 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 (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

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




_______________________________________________

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


References: 
 >Dynamically change file name extension in NSSavePanel when extension is hidden (From: Antonio Nunes <email@hidden>)

  • Prev by Date: Bundle Identifiers - and application support directory
  • Next by Date: How to prevent UITableView from scrolling when inserting in CoreData?
  • Previous by thread: Dynamically change file name extension in NSSavePanel when extension is hidden
  • Next by thread: Bundle Identifiers - and application support directory
  • Index(es):
    • Date
    • Thread