Re: complicated (I think) Binding
Re: complicated (I think) Binding
- Subject: Re: complicated (I think) Binding
- From: John Pannell <email@hidden>
- Date: Sat, 11 Mar 2006 16:45:23 -0700
Hi Mike-
I can get you part of the way there...
Basically, I have in my document window, an NSPopupButton. I would
ideally like to:
* Have a central object in my app keep a list of the files in a
particular folder
This is how I get a list of the system sounds:
NSArray *soundList = [[[NSFileManager defaultManager]
directoryContentsAtPath:@"/System/Library/Sounds"] retain];
* The popup button displays a list of the names of these files,
minus their extension
Set up an array controller whose content is the array of loaded file
names. Bind the popup's "content" and "contentValues" to this array
controller. Use a value transformer to strip the extension off the
values. Here is the implementation I wrote:
@implementation NoPathExtensionValueTransformer
+ (Class)transformedValueClass
{
return [NSArray class];
}
+ (BOOL)allowsReverseTransformation
{
return NO;
}
- (id)transformedValue:(id)aValue
{
NSMutableArray *returnArray = [[NSMutableArray alloc] init];
NSEnumerator *e = [aValue objectEnumerator];
NSString *aSound;
while(aSound = [e nextObject]){
aSound = [aSound stringByDeletingPathExtension];
[returnArray addObject:aSound];
}
return returnArray;
}
@end
You will need to create and register the value transformer to use
it... do this in your application delegate's +initialize method...
NSValueTransformer *transformer = [[NoPathExtensionValueTransformer
alloc] init];
[NSValueTransformer setValueTransformer:transformer
forName:@"NoPathExtensionValueTransformer"];
* The selected item of the popup button is kept in the document's
data store, but it is stored with the extension
Well, if you bind selectedValue to something (I bind it to a
NSUserDefaults controller) it will be without the extension. You
could certainly drop the binding for this purpose and set the popup's
target and action to a method that records the selected file name for
you.
HTH! Email me off list if you want the files for the value
transformer...
John
John Pannell
Positive Spin Media
http://www.positivespinmedia.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden