Re: [SOLVED] NSOpenPanel -setAllowedFileTypes
Re: [SOLVED] NSOpenPanel -setAllowedFileTypes
- Subject: Re: [SOLVED] NSOpenPanel -setAllowedFileTypes
- From: email@hidden
- Date: Thu, 26 Aug 2010 19:37:24 -0600
For those interested in my solution.
@interface FSAccessoryView : NSView {
@public
NSOpenPanel *m_NSOpenPanel;
NSMutableArray *m_fileTypes;
NSInteger m_idx;
IBOutlet NSTextField *m_stitches, *m_colors, *m_inches, *m_millimeters;
IBOutlet NSComboBox *m_filterDescriptions;
}
@end
FSAccessoryView is added to the open panel. It contains a NSComboBox,
set non-editable and some other controls that do not bear on this
discussion.
-selectFileTypes is wired to the combo box. The -setNeedsDisplay call
causes my preview to be drawn.
m_fileTypes is an Array of Arrays containing file extensions.
m_filterDescriptions populates the combo box.
@implementation FSAccessoryView
- (IBAction)selectFileTypes:(id)sender {
NSInteger idx = [sender indexOfSelectedItem];
if(idx > -1)
{
m_idx = idx;
[m_NSOpenPanel validateVisibleColumns];
}
}
- (void)panelSelectionDidChange:(id)sender { [self
setNeedsDisplay:YES]; }
- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename {
BOOL dir;
[[NSFileManager defaultManager] fileExistsAtPath:filename
isDirectory:&dir];
if(dir) return YES;
else
{
NSString *ext = [filename pathExtension];
NSString *lcext = [ext lowercaseString];
NSString *ucext = [ext uppercaseString];
if([[m_fileTypes objectAtIndex:m_idx] containsObject:lcext] ||
[[m_fileTypes objectAtIndex:m_idx] containsObject:ucext]) return YES;
}
return NO;
}
- (BOOL)isFlipped { return YES;}
- (void)drawRect:(NSRect)rect {
code to draw a preview
}
@end
On Aug 26, 2010, at 6:42 PM, Quincey Morris wrote:
On Aug 26, 2010, at 10:41, email@hidden wrote:
I have an accessory view in an NSOpenPanel which contains a
NSComboBox. The combo box is a list of file extensions. When the
user selects an entry the action method calls --
setAllowedFileTypes. All these mechanics work properly. The issue:
The open panel does not respond to the new allowed file types.
What I am trying to accomplish is a dynamic filter as we see in a
Windows open file dialog.
You should probably post your code at this point, since several
people (myself included) aren't sure exactly what you've done, or
what you're expecting to happen.
However, I will point out that NSComboBox is a strange choice for a
control to filter file types. As I keep having to say on this list,
a NSComboBox is a kind of text field, not a kind of menu. While it
doesn't seem impossible to use a combo box in this situation, it's
going to take support code to behave like a menu choice. Perhaps
that's where the problem lies.
You'll get better help on this list if you ask more technically
accurate questions. Ambiguous language, like "does not respond" or
"dynamic filter as we see in ... Windows", forces us to guess what
you're expecting, so we can't respond helpfully.
_______________________________________________
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
_______________________________________________
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