PDA

View Full Version : A more recent tutorial for creating Menulets?




Jessica Lares
Jul 12, 2013, 02:01 AM
Can anyone recommend a tutorial for making a Menulet? There are loads all over Google, however, many of them are from years back and while they're all sorta similar, I'm running into problems because some code has been deprecated since then.



ArtOfWarfare
Jul 12, 2013, 05:13 AM
I have written menulets so I may be able to help. What specific code are you having issues with?

(Don't message it to me. Post it here. Just saying this premptively because when someone hears "I can help" online, they often try personal communication.)

Jessica Lares
Jul 12, 2013, 06:38 AM
Of course...

Well in this case I'm actually having more trouble with interface builder. I can't connect the delegate to the menu. I can do the Window though.

ArtOfWarfare
Jul 12, 2013, 06:58 AM
Of course...

Well in this case I'm actually having more trouble with interface builder. I can't connect the delegate to the menu. I can do the Window though.

Hm. Personally, I just make the entire menu / menu UI in code. Making menus with icons, text, actions, and submenus in code is pretty trivial.

For Battery Status, I had a category on NSMenu that made adding that kind of stuff even more trivial. Here's some of the methods from it that I'll probably reuse in future projects (Battery Status supports pretty old Macs, thus why I have calls to release in here instead of just relying on ARC):

- (void)addSeparatorItem
{
[self addItem:[NSMenuItem separatorItem]];
}

- (void)addItemWithTitle:(NSString *)title
{
NSMenuItem *item;
item = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:title
action:NULL
keyEquivalent:@""];
[self addItem:item];
[item release];
}

- (void)addItemWithTitle:(NSString *)title selector:(SEL)selector
{
NSMenuItem *item;
item = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:title
action:selector
keyEquivalent:@""];
[self addItem:item];
[item release];
}

- (void)addItemWithTitle:(NSString *)title image:(NSImage *)image
{
NSMenuItem *item;
item = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:title
action:NULL
keyEquivalent:@""];
item.image = image;
[self addItem:item];
[item release];
}

- (void)addItemWithTitle:(NSString *)title indentationLevel:(NSInteger)indentationLevel
{
NSMenuItem *item;
item = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:title
action:NULL
keyEquivalent:@""];
item.indentationLevel = indentationLevel;
[self addItem:item];
[item release];
}

I hope those help.

Jessica Lares
Jul 12, 2013, 07:08 AM
Hm. Personally, I just make the entire menu / menu UI in code. Making menus with icons, text, actions, and submenus in code is pretty trivial.

For Battery Status, I had a category on NSMenu that made adding that kind of stuff even more trivial. Here's some of the methods from it that I'll probably reuse in future projects (Battery Status supports pretty old Macs, thus why I have calls to release in here instead of just relying on ARC):

snip

I hope those help.

Thanks, that does help somewhat. I'll look into it later today.