1. Welcome to the new forums. See our announcement and read our FAQ

A more recent tutorial for creating Menulets?

Discussion in 'Mac Programming' started by Jessica Lares, Jul 12, 2013.

  1. macrumors 604

    Jessica Lares

    #1
    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.
     
  2. macrumors 603

    ArtOfWarfare

    #2
    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.)
     
  3. macrumors 604

    Jessica Lares

    #3
    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.
     
  4. macrumors 603

    ArtOfWarfare

    #4
    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):

    Code:
    - (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.
     
  5. macrumors 604

    Jessica Lares

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

Share This Page