Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a Menubar Application with a NSPopover?

Tags:

I have seen a lot of applications with a Menubar Item or applications with only a Menubar interface.

There are some tutorials and stuff on the internet showing you how to accomplish that. But the thing is, those do only have clickable index rows in them.

I would want to have a NSPopover appear when you click the Menubar Icon / Item. Anybody who knows how to make this?

like image 794
Jacob Avatar asked Oct 20 '11 14:10

Jacob


People also ask

How to create a mobile responsive navigation menu bar?

A scrollable, vertical menu that adapts and scales based off of device size makes it more accessible than traditional horizontal bars as well! To create a mobile responsive navigation menu bar, you need to create an HTML file and CSS file in your code editor. Now, I will provide you the source code of HTML and CSS files for the menu bar.

How do I use menu item sub-sublists within options?

The menu item sub-sublists within options should contain pairs consisting of the text to display on the menu and the function to call when that option is selected. In this example, the text "File option 1" is displayed and the function file_function is called if this option is clicked on.

How to use the menubar on the grid?

The MenuBar is never displayed on a grid so there are no grid or alignment parameters. You can call the following methods on an MenuBar object. Schedules a single call to command after time milliseconds. (To repeatedly call the same command, use repeat ()) Gives focus to the widget (e.g. focusing a TextBox so that the user can type inside it)

How do I add a toggle button to The navbar bar?

The HTML code contains a logo at the left hand side, a list of navbar bar menu items with anchor tags, and a login button at the right side in the top bar. The code also includes a checkbox input element with a label tag to create a toggle button for mobile. Copy the following code and paste it inside the HTML file. ? <!-- Navbar logo --> <!--


1 Answers

I don't know if it can be done with a standard status bar item. Using a custom view for the menulet it's relatively easy.

Create a status bar item with a custom view:

item = [[NSStatusBar systemStatusBar] statusItemWithLength:thickness];
view = [[CustomView alloc] initWithFrame:(NSRect){.size={thickness, thickness}}];
[item setView:view];        

Your custom view needs to detect mouse clicks:

- (void)mouseDown:(NSEvent *)event {
   ...
}

And finally, at some point after detecting the mouse click, show/hide the popover.

if (/* menulet is active */) {
    [popover showRelativeToRect:/* menulet view frame */
                         ofView:/* menulet view */
                  preferredEdge:NSMinYEdge];
} else {
    [popover performClose:nil];
}

You need a bit of NSWindow swizzling to get text fields working inside the popover.

I've prepared a minimal Xcode project with these ideas and some glue: PopoverMenulet.

like image 153
djromero Avatar answered Nov 11 '22 18:11

djromero