NSOpenPanel and Accessory Views
NSOpenPanel and Accessory Views
- Subject: NSOpenPanel and Accessory Views
- From: Timothy Ritchey <email@hidden>
- Date: Fri, 5 Apr 2002 12:19:31 -0500
In reading the documentation for the NSSavePanel and NSOpenPanel
classes. It appears that it should be possible to change the accessory
view on-the-fly:
"The NSSavePanel automatically resizes itself to accommodate aView. You
can invoke this method repeatedly to change the accessory view as
needed. If aView is nil, the NSSavePanel removes the current accessory
view."
Apparently, this is not quite the case. I have subclassed NSOpenPanel,
an re-implemented the following borowser delegate function:
RRImportPanel.m:
- (void)browser:(NSBrowser *)sender willDisplayCell:(id)cell
atRow:(int)row column:(int)column
{
[accessoryViewDelegate importPanel:self didSelectPath:[_browser
path]];
[super browser:sender willDisplayCell:cell atRow:row column:column];
}
This allows me to send a message to my import controller whenever the
user selects a file, and add an accessory view based on what kind of
file they have selected (i.e. text, csv, binary, etc). I am having two
problems. 1) when I change the accessory view, the panel resizes, but is
not longer attached to the title bar - it "jumps" up higher than its
normal position to account for the increased size instead of dropping
down lower. 2) if you set the accessory view to nil after having set it
to a view, you get an array out of bounds exception from some code in
the panel library. Anyone know if these are bugs, am I just misreading
the docs, or implementing this incorrectly?
RRImportController.m:
- (void)importPanel:(RRImportPanel*)importPanel
didSelectPath:(NSString*)path
{
NSDictionary *fileAttributes;
NSFileManager *manager = [NSFileManager defaultManager];
// eject immediately if nothing has changed
if([currentPath isEqualTo:path])
return;
[currentPath autorelease];
currentPath = [realPath copy];
fileAttributes = [manager fileAttributesAtPath:currentPath
traverseLink:YES];
if(NSFileTypeDirectory == [fileAttributes objectForKey:NSFileType]) {
// we have a dictionary, so don't do anything
[panel setAccessoryView:importDirectoryView]; // a nil here
causes an out-of-bounds exception
} else {
[panel setAccessoryView:importTextView];
}
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.