A more recent tutorial for creating Menulets?

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

  1. macrumors G3

    Jessica Lares

    Joined:
    Oct 31, 2009
    Location:
    Near Dallas, Texas, USA
    #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 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #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. thread starter macrumors G3

    Jessica Lares

    Joined:
    Oct 31, 2009
    Location:
    Near Dallas, Texas, USA
    #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 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #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. thread starter macrumors G3

    Jessica Lares

    Joined:
    Oct 31, 2009
    Location:
    Near Dallas, Texas, USA
    #5
    Thanks, that does help somewhat. I'll look into it later today.
     

Share This Page