systemStatusBar notification for mouse click

  • Hello,

    Is there a way to be notified when someone clicks on my systemStatusBar
    Item  OR when the pop up menu becomes visible?

    This is how the system status bar is created:

        {
            ...
            statusBar = [[NSStatusBar systemStatusBar] retain];
            statusItem = [[statusBar statusItemWithLength:50] retain]

            [statusItem setLength: NSVariableStatusItemLength];
            [statusItem setHighlightMode:YES];

            [statusItem setMenu:theDockMenu];
            [statusItem setImage: img ];
            [statusItem setEnabled:YES];

            [statusItem setLength:NSVariableStatusItemLength];

    I tried calling:

            [statusItem setTarget:self];
            [statusItem setAction:@selector(onStatusMenu:)];
        }

        - (void)onStatusMenu:(id)none
        {
            NSLog(@"onStatusMenu");
        }

    However the action is never called and after investigating online it
    looks like setTarget/setAction dont work for image status items.

    Thank you,
    -Vance
  • Never mind, I found it could be done by creating a custom view and
    setting it ([statusItem setView: myView])

    Vance wrote:
    > Hello,
    >
    > Is there a way to be notified when someone clicks on my
    > systemStatusBar Item  OR when the pop up menu becomes visible?
    >
    > This is how the system status bar is created:
    >
    > {
    > ...
    > statusBar = [[NSStatusBar systemStatusBar] retain];
    > statusItem = [[statusBar statusItemWithLength:50] retain]
    >
    > [statusItem setLength: NSVariableStatusItemLength];
    > [statusItem setHighlightMode:YES];
    > [statusItem setMenu:theDockMenu];
    > [statusItem setImage: img ];
    > [statusItem setEnabled:YES];
    >
    > [statusItem setLength:NSVariableStatusItemLength];
    >
    > I tried calling:
    >
    > [statusItem setTarget:self];
    > [statusItem setAction:@selector(onStatusMenu:)];
    > }
    >
    > - (void)onStatusMenu:(id)none
    > {
    > NSLog(@"onStatusMenu");
    > }
    >
    > However the action is never called and after investigating online it
    > looks like setTarget/setAction dont work for image status items.
    >
    > Thank you,
    > -Vance
  • The documentation for setAction: says "If the receiver has a menu set, action is not sent to the target when receiver is clicked". Not related to status items with images.

    If you just need to know that you menu is going to be shown then you could set a delegate for the menu and implement menuWillOpen:.

    If you need to know that the item itself was clicked then you could instead not set the menu but do set the action of statusItem. Then, in the action do whatever processing you need before calling [statusItem popUpStatusItemMenu:theDockMenu];
    -Andy

    -----Original Message-----
    Sent: Thursday, January 31, 2008 6:51 PM
    To: <Cocoa-dev...>
    Subject: systemStatusBar notification for mouse click

    Hello,

    Is there a way to be notified when someone clicks on my systemStatusBar
    Item  OR when the pop up menu becomes visible?

    This is how the system status bar is created:

        {
            ...
            statusBar = [[NSStatusBar systemStatusBar] retain];
            statusItem = [[statusBar statusItemWithLength:50] retain]

            [statusItem setLength: NSVariableStatusItemLength];
            [statusItem setHighlightMode:YES];

            [statusItem setMenu:theDockMenu];
            [statusItem setImage: img ];
            [statusItem setEnabled:YES];

            [statusItem setLength:NSVariableStatusItemLength];

    I tried calling:

            [statusItem setTarget:self];
            [statusItem setAction:@selector(onStatusMenu:)];
        }

        - (void)onStatusMenu:(id)none
        {
            NSLog(@"onStatusMenu");
        }

    However the action is never called and after investigating online it
    looks like setTarget/setAction dont work for image status items.

    Thank you,
    -Vance
previous month february 2008 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29    
Go to today