NSStatusItem how i can setAction and show menu ?

Discussion in 'Mac Programming' started by artbeat.easy, Aug 5, 2010.

  1. artbeat.easy macrumors newbie

    Joined:
    Jul 1, 2010
    #1
    Hello all )
    I have some problem
    if i set Action on NSStatusItem i can't show menu ((

    NSStatusItem*statusItem …

    [statusItem setMenu:…]
    [statusItem setAction:…]

    not work (( how i can handle click and show menu ?
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    You can't. You can do one or the other, not both.

    From the NSStatusItem reference doc for setMenu:
    When set, the receiver’s single click action behavior is not used.
     
  3. artbeat.easy thread starter macrumors newbie

    Joined:
    Jul 1, 2010
    #3
    ok ( how i can handle menu open ? or how i can show menu ? if i handle mouse click ( setAction ) i can show menu manual ?
     
  4. LinusR macrumors regular

    LinusR

    Joined:
    Jan 3, 2011
    #4
    Put in your method to call while clicking on the status item this code:
    Code:
    [theStatusItem popUpStatusItemMenu:theStatusMenu]
    So for example:
    Code:
    - (void) awakeFromNib{
        statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
    	
        [statusItem setAction:@selector(statusItemClicked)];
        [statusItem setTarget:self];
    }
    
    - (void)statusItemClicked {
        [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(showMenu) userInfo:nil repeats:NO];
        [NSApp activateIgnoringOtherApps:YES];
        
        [statusItem popUpStatusItemMenu:statusMenu];
    }
    
    Hope that helps.
     

Share This Page