Re: Enabling/Disabling Control view hiearchies
Re: Enabling/Disabling Control view hiearchies
- Subject: Re: Enabling/Disabling Control view hiearchies
- From: Shaun Wexler <email@hidden>
- Date: Fri, 18 Jun 2004 15:40:56 -0700
Followup:
I just tested this, and it works fine; in fact, I added it to my base
framework. However, you'll need to change the -superviewIsEnabled
method as shown:
- (BOOL)superviewIsEnabled
{
NSView *superview;
if ((superview = [self superview])) {
return [superview isEnabled];
}
return YES;
}
I'd written it correctly at first, and it apparently got fuxored during
an undo/redo while editing in Mail.app.
Good luck!
--
Shaun Wexler
MacFOH
http://www.macfoh.com
On Jun 18, 2004, at 3:00 PM, Shaun Wexler wrote:
>
On Jun 18, 2004, at 2:15 PM, Scott Thompson wrote:
>
>
> I'm trying to set up a scheme whereby I can enable and disable a group
>
> of related controls all at once. Given the elegance of the rest of
>
> the framework, I can only think that I must have misunderstood
>
> something. Can anyone help me out by describing the expected strategy
>
> for enabling/disabling controls, or by pointing me to the appropriate
>
> documentation?
>
>
If all controls and cells follow convention and manage state using
>
accessor methods, you can add a category to NSView, and poseAs
>
NSControl (and subclasses, as necessary) to enforce its use. Example
>
(untested, written in Mail.app):
>
>
@interface NSView (EnabledState)
>
- (BOOL)superviewIsEnabled;
>
- (BOOL)isEnabled;
>
- (void)setEnabled:(BOOL)enabled;
>
- (BOOL)enabled;
>
@end
>
>
@implementation NSView (EnabledState)
>
>
- (BOOL)superviewIsEnabled
>
{
>
return [[self superview] isEnabled];
>
}
>
>
- (BOOL)isEnabled
>
{
>
return YES; // Override in subclasses.
>
}
>
>
- (void)setEnabled:(BOOL)enabled
>
{
>
// NOP. Override in subclasses, to set ivar.
>
}
>
>
- (BOOL)enabled // KVC/bindings support
>
{
>
return [self isEnabled];
>
}
>
>
@end
>
>
@interface PosedNSControl : NSControl {}
>
@end
>
>
@implementation PosedNSControl
>
>
+ (void)load
>
{
>
[self poseAsClass:[NSControl class]];
>
}
>
>
- (BOOL)isEnabled
>
{
>
return [super isEnabled] && [self superviewIsEnabled];
>
}
>
>
@end
>
--
>
Shaun Wexler
>
MacFOH
>
http://www.macfoh.com
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.