On 19/06/2006, andrewbogott@gmail.com wrote in message
<1150726519.766830.218680@g10g2000cwb.googlegroups.com>:
> I'm trying to create an open panel that changes the allowed file types
> dynamically. The panel includes an accessory view which, when
> appropriate, calls setAllowedFileTypes on the panel.
>
> I'm getting nowhere. Calling setAllowedFileTypes after an NSOpenPanel
> is visible seems to have no effect.
Sorry, but that method is not suitable when the user can already see the
panel: the list you supply is only consulted when the panel is created.
Instead, implement your own filter that looks at each file and decides
whether it should be allowed or not -- in your case, by simply examining the filetype.
Look in the definition for NSSavePanel for the delegate method
- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename
You have to set up a delegate to make it work, but it's not too hard to do and does exactly what you want done. Although it's documented in NSSavePanel, NSOpenPanel inherits from that, so it works in both.
I've never used it so I'm not sure how to make it rescan the files already showing if the user changes the current file format selection. I suspect it's something easy, like sending a refresh message to the panel.
Simon.

Signature
http://www.hearsay.demon.co.uk
Andrew - 23 Jun 2006 19:30 GMT
Thanks, Simon. That turns out to work just fine. And, indeed, it's
enough to just call [window update] to refresh the state of each file.
- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename
{
NSString* ext = [filename pathExtension];
NSEnumerator* tagEnumerator = [[(NSOpenPanel *) [BottleSelection
window] allowedFileTypes] objectEnumerator];
NSString* allowedExt;
while ((allowedExt = [tagEnumerator nextObject]))
{
if ([ext caseInsensitiveCompare:allowedExt] == NSOrderedSame)
{
return TRUE;
}
}
return FALSE;
}
(I'm cheating, and using the 'allowedFileTypes' member to store my
types list anyway. That allows me to pretend, elsewhere, that setting
it actually works.)
So, that answers the 'what should I do?' question. It leaves
unanswered the 'why did apple implement these functions when they can
never be usefully called?' question. But I put in a bug report to
apple about that, so now I feel free to ignore that question as long as
they do.
Thanks again!
-Andrew
> On 19/06/2006, andrewbogott@gmail.com wrote in message
> <1150726519.766830.218680@g10g2000cwb.googlegroups.com>:
[quoted text clipped - 20 lines]
>
> Simon.
Simon Slavin - 26 Jun 2006 23:02 GMT
On 23/06/2006, Andrew wrote in message
<1151087427.246146.159470@r2g2000cwb.googlegroups.com>:
> So, that answers the 'what should I do?' question.
Glad you got it working.
> It leaves
> unanswered the 'why did apple implement these functions when they can
> never be usefully called?' question.
I think that those functions are there for another model of working.
Almost all applications don't have such flexible ways of opening files:
the application can only open certain kinds of file, and there's nothing
within the 'open' dialog that can change those kinds. Under those
circumstances, the functions are fine: you set them once before you open
the panel and they tell the panel what to do. Your program is more
sophisticated in that you want to change which kinds of file the panel
wants to work with when the panel has already been opened.
I agree that either the functions could be changed to work the way you
want, or that the documentation for them should state that those are the
ones to use before the panel is open and that they don't work after that.
Happy to see that you solved your problem.
Simon.

Signature
http://www.hearsay.demon.co.uk