Re: Single selection and bindings
Re: Single selection and bindings
- Subject: Re: Single selection and bindings
- From: Matt Neuburg <email@hidden>
- Date: Fri, 30 Jun 2006 10:13:58 -0700
- Thread-topic: Single selection and bindings
On Fri, 30 Jun 2006 15:19:39 +0100, Jonathan Guy <email@hidden> said:
> This would seem an easy thing to do but can't figure it out. I want to bind
> the "Enabled" part of a button to the selection of a tree controller BUT I
> only want the button to be enable when there is a single item selected in the
> outline view (NOT a zero or multiple selection).
Another solution (besides the value transformer approach from my earlier
message) would be a controller subclass. In the case of NSArrayController,
we could bind the button's Enabled to an ivar (because that's an
observable). The ivar is set by code that takes advantage of the fact that
selectedObjects, too, is an observable:
@implementation MyNSArrayController
- (void) awakeFromNib {
[self addObserver:self forKeyPath:@"selectedObjects"
options:0 context:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object change:(NSDictionary *)change
context:(void *)context {
[self setValue:
[NSNumber numberWithBool:
[[self selectedObjects] count] == 1]
forKey: @"selectionIsOne"];
}
@end
So we bind the button's Enabled to the controller's "selectionIsOne" and
presto, we're there.
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>
_______________________________________________
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