I have an NSPopupButton whose menu I need to change based on a model property. I'm observing selection.property of the relevant NSArrayController to be notified when the menu needs to change. I need to alternate between a provided menu and a content array provided by another array controller.

I have it working with the code below it just seems awfully long winded to accomplish something seemingly simple, I was hoping someone could take a look at it and point out where I could improve my implementation.

Thanks,
Keith

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([[keyPath lastKeyPathComponent] isEqualToString:KDAlarmTypeKey]) {
                NSString *alarmNameSubpath = nil;
                if ([[object valueForKeyPath:keyPath] integerValue] == ITUNES) {
                        alarmNameSubpath = KDAlarmNameKey;
                        
                        [advancedAlarmNameButton unbind:NSContentBinding];
                        [advancedAlarmNameButton unbind:NSContentValuesBinding];
                        
                        [advancedAlarmNameButton removeAllItems];
                        [advancedAlarmNameButton setMenu:[[sourceMenu copy] 
autorelease]];
                } else {
                        alarmNameSubpath = KDBackupAlarmNameKey;
                        
                        [advancedAlarmNameButton removeAllItems];
[advancedAlarmNameButton bind:NSContentBinding toObject:backupAlarmsController withKeyPath:@"arrangedObjects" options:nil]; [advancedAlarmNameButton bind:NSContentValuesBinding toObject:backupAlarmsController withKeyPath:@"arrangedObjects.key" options:nil];
                }
                
[advancedAlarmNameButton bind:NSSelectedValueBinding toObject:calendarController withKeyPath:[NSString keyPathForComponents:@"selection", alarmNameSubpath, nil] options:nil];
                
// This is a dirty hack, setting the menu/binding the selected value seems to disable the selected menu item!?
                [[advancedAlarmNameButton selectedItem] setEnabled:YES];
} else [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to