• 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: NSOpenPanel won't enable "Ok" button second time around
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSOpenPanel won't enable "Ok" button second time around


  • Subject: Re: NSOpenPanel won't enable "Ok" button second time around
  • From: Matt Neuburg <email@hidden>
  • Date: Thu, 04 Jan 2007 21:59:31 -0800
  • Thread-topic: NSOpenPanel won't enable "Ok" button second time around

On Fri, 5 Jan 2007 00:30:52 +0000, "Matt Mower" <email@hidden> said:
>Hi.
>
>I am using an NSOpenPanel in one of my applications in order to select
>a folder. When the user selects "Ok" I save the folder into a user
>default for the next time. However when the panel is opened a second
>time, although the right folder is selected, the "Ok" button is not
>enabled.
>
>The requires the user to navigate up or down one level and back again
>in order to get "Ok" to be re-enabled so that they can pick the
>directory (in the likely case they want the same one).
>
>I'd be grateful if anyone can help me work around this problem.
>
>My code looks like this:
>
>01 NSOpenPanel* browser = [NSOpenPanel openPanel];
>02 NSString* directory = [[NSUserDefaults standardUserDefaults]
>                                      objectForKey:lastUsedPathKey];
>03 if( directory != nil ) {
>04   [browser setDirectory:directory];
>05 }
>06 [browser setCanChooseFiles:NO];
>07 [browser setCanChooseDirectories:YES];
>08 [browser setAllowsMultipleSelection:NO];
>09 if( [browser runModal] != NSCancelButton ) {
>10   NSString* choosenDirectory = [[browser filenames] objectAtIndex:0];
>11   [[NSUserDefaults standardUserDefaults] setObject:choosenDirectory
>
>forKey:lastUsedPathKey];
>12 }

I tested your code and I see what you mean. Perhaps you've found a Cocoa bug
(so you might like to report it). If you delete the setDirectory: call,
though, the problem goes away. It isn't needed anyway: Cocoa is already
implementing the logic you want (the second time, the panel opens to the
correct directory). m.

--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>



_______________________________________________

Cocoa-dev mailing list (email@hidden)

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

  • Prev by Date: Re: Observing bounds of an NSBezierPath
  • Next by Date: Re: regarding transparent NSWindow.
  • Previous by thread: NSOpenPanel won't enable "Ok" button second time around
  • Next by thread: Getting a list of files/folders in a folder/drive
  • Index(es):
    • Date
    • Thread