Color menu

Tags ( )

What would be the best example in the Mori source code for how to utilize your color menu? Also, is the menu itself stored in a particular nib file?

My purpose is to add a pop-up menu to the mGTD prefs so that users can choose what label color should be associated with different action types (overdue, etc).

Thanks
Jeff

The +colorLabelMenu is

The +colorLabelMenu is declared in MIUserInterfaceProtocols.h. That will return a NSMenu that contains menu items for the different color choices. This menu isn't really tied to any particular behavior in Mori, so you can use it anyway that you want. A copy of the menu is given to you so you can do anything that you want with that copy including add/remove items, rename items, change actions, change targets...

So basically (once you include MIUserInterfaceProtocols.h you can use the color menu like this:

NSMenu *myColorMenu = [NSObject colorLabelMenu];
// and then do whatever you want with the menu, such as use it in a popup menu.

So for a pref pane, do think

So for a pref pane, do think it would be easiest to call the menu on the prefs awakeFromNib, and then attach it to a ComboBox for the user to choose from? Are there other objects that could display such a menu inside a view?

I think I'm using it as

I think I'm using it as suggested:

IBOutlet NSPopUpButton *urgentButton;

[urgentButton setMenu:[NSObject colorLabelMenu]];

The menu pops up under the button, but all of the items are disabled.
Any ideas for what I'm missing?

Thanks,
Jeff

By default each menu item in

By default each menu item in the colorLabelMenu has the action @selector(changeColorLabel:). I think those actions might override any action that you have set in the NSPopUpButton. So you'll need to:

1. Maybe set all the colorLabelMenu items actions to NULL, and that might give your NSPopUpButton action precedence.
2. Or set the target of each colorLabel menu item to one of your own objects, and make that object implement - changeColorLabel:(id)sender.

Thanks for the help. #1

Thanks for the help.

#1 didn't seem to work, but #2 did.

However, when I try to set the binding programmically it never propagates to the prefererence file:

[urgentButton bind:@"selectedValue"
toObject:[NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:@"values.MGurgentColor"
options:nil];

I've tried @selectedValue, @selectedTag, @selectedIndex, @selectedObject (all with nil options.)

the pref will bind if I set it from IB using the "item1" "item2" popup cells.

Thanks

I think this is an oddity

I think this is an oddity with bindings, and not directly related to the color menu. I just tried to get this working and had the same problems that you did. But then I look inspected the existing menu items (that do work OK) in the debugger and found the problem. It seems that NSPopUpButton bindings only work if all menu items in it's popup menu are targeted to the NSPopUpButton cell and have the action _popUpItemAction:. At least that's what it seems like, and after I retargeted the color menu items it seems to work OK. Here's the code that I used to turn a NSPopUpButton into a color menu whose selectedTag is bound to the defaults key MGurgentColor.

- (void)awakeFromNib {
NSMenu *colorMenu = [NSObject colorLabelMenu];
NSEnumerator *enumerator = [[[[colorMenu itemArray] copy] autorelease] objectEnumerator];
NSMenuItem *each;

while (each = [enumerator nextObject]) {
[each setTarget:[popUpButton cell]];
[each setAction:@selector(_popUpItemAction:)];
}

[popUpButton setMenu:colorMenu];
[popUpButton bind:@"selectedTag" toObject:[NSUserDefaultsController sharedUserDefaultsController] withKeyPath:@"values.MGurgentColor" options:nil];
[popUpButton setTarget:self];
[popUpButton setAction:@selector(doIt:)];
}

- (IBAction)doIt:(id)sender {
NSBeep();
}

Thanks, I don't think I ever

Thanks, I don't think I ever would have tracked that down on my own. But it's working now.
People can choose their own labels for mGTD!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.