How can I stop or fix Wakanda menu highlighting? - wakanda

Wakanda's Menu Bar widget seems to not have a sense of hierarchy; that is, clicking an item will highlight it and will not un-highlight a clicked item of a different menu item group. Example below:
"Home" was clicked, and then the submenu item "View Requests" was clicked. "Home" remains highlighted, but it really should have un-highlighted.
It looks sloppy. Do you have any advice for making it nicer?
event.preventDefault() on the onClick event did not prevent the coloring change for the down state.
Edit: This is all one complex menu bar widget. It has menu bar widgets as submenu items. That's what I mean by a lack of sense of heirarchy. Wakanda fails to see the tree of menu bar widgets as ONE menu bar.

In the properties tab of the Menu Bar widget, change the value of "Show submenus" from 'On Mouse Over' (default) to 'On Mouse Click'.
Regards.

Related

Drop-down menu in NSToolbar like Mail.app

I'd like a toolbar button with an attached dropdown menu, like the "Flag" button in the toolbar in Mail.app:
I'd hoped that making a normal NSMenuItem and adding a menu as the menuFormRepresentation would do the trick, but that menu only appears when the button goes into overflow mode.
I had also hoped that adding an NSPopupButton as a custom view would work, but that makes the whole view a menu, whereas I want the left part of the component to behave like a normal button, and the right dropdown part bring up the menu.
Is there some trick to making the NSToolbarItem show a component like this, or is this two custom views stuck together?
There's nothing magical about NSToolbar here. That's just one of the ways you can set up NSSegmentedControl, regardless of whether it appears as a toolbar item's custom view or on its own.
You can't set this up in Interface Builder (storyboard), but NSSegmentedControl has APIs for assigning menus to segments:
segmentControl.setMenu(myMenu, forSegment: 1)
segmentControl.setShowsMenuIndicator(true, forSegment: 1) // for the little arrow
You probably want to set the tracking mode to momentary, since your segment control is acting as a set of visually-connected buttons, not a choose-one-of-N selector.
When the user clicks either segment, your action method will need to use the selectedSegment to decide whether to perform the action associated with the "button" side or ignore the click (letting the menu show for the other side).

How do I prevent the menu bar from moving down when my popover is open?

I have an app with a popover that appears on a status bar item. The thing is, when you click on the icon while you're in a full screen app, then move the mouse away from the menu bar to click on something in the popup, the menu bar moves up, and so does the popup. It's annoying.
Anyone know of any way to solve this? I've tried attaching an invisible menu to the popup, but I can't get the menu to be invisible.
Screenshot for clarity, the annoying part is where I wave my mouse around:
The popover window is moving because its parent window is the status item window, and when the parent window moves, the child moves with it. (Before I investigated this, I didn't even know Cocoa had parent and child windows.) I solved the problem with this code immediately after showing the popover:
NSWindow *popoverWindow = self.popup.contentViewController.view.window;
[popoverWindow.parentWindow removeChildWindow:popoverWindow];
Now, the menu bar still moves up, but at least the popup stays in the same place.
Either use Carbon events or watch for things happening to the menu bar (window of type NSStatusBarWindow):
Notifications of type
NSWindowDidChangeOcclusionStateNotification
NSWindowDidMoveNotification
NSWindowWillCloseNotification
NSWindowDidCloseNotification
with an object of class NSStatusBarWindow should give you enough information about the menu bar showing or hiding to add proper handling.
Super-hacky approach:
Custom window with some super-high window level to make it appear over the menu bar, then add a transparent custom view to the new window that catches and handles/blocks mouse clicks according to your needs.
Or:
Get the window instance the popover is using to display and track/handle NSWindowWillMoveNotification / NSWindowDidMoveNotification.
I converted #tbodt's answer to Swift 4 and confirmed that is resolves this issue:
let popoverWindow = popup.contentViewController.view.window as? NSWindow
popoverWindow?.parent?.removeChildWindow(popoverWindow!)

How to embed an NSMenu inside a borderless window to create a fake menu bar

I am trying to create a fake menu bar in a cocoa application. I have been able to acomplish 95% of what I need, only the menu bar does not match mainMenu. See screen grab below of what I have so far.
I am using a "Pop Up Button" object in a xib to try to emulate the system menu bar. The problem is that it is a popup menu and does not look exactly like the mainMenu. Additionally, the title menu item does not hilite, and the popup menu has rounded corners that overlap the menu title. So, it's close, but no cigar.
Is it possible to create a fake menu bar inside a borderless window that matches the default system menu bar? If so, how?
I also tried using an NSStatusItem, which by default matches the system menu bar more closely than what I have been able to accomplish with a button, but I was unable to embed NSStatusItem into a window.
Ideally, if there is a way to embed an NSMenu directly in a windows view, that would be the best solution.
You'll need to create a custom button or view that looks and acts like the top-level item, then assign an NSMenu to your view's menu outlet.
You can then either implement menuForEvent: in your view and return your menu when the mouse is down, or alternatively call the NSMenu class method +popUpContextMenu:withEvent:forView: when the mouse is clicked.
This seems to be a slightly odd idea, by the way. Why do you want to do it?

How to require explicit dismissal of a yui popup menu?

I have a page with a couple of widgets on it, each of which, when clicked, brings up a yui popup menu: If I click on widget 1, its menu comes up. If I now click on widget 2, widget 1's menu gets a hide event, and widget 2's menu gets a show event and comes up. I'd like to change this so that, when widget 1's menu is up, it must be explicitly dismissed by a click on the page background (and/or, perhaps, another click on the widget or the escape key) before the menu attached to widget 2 is allowed to appear.
I've set up some beforeShowEvent and beforeHideEvent handlers on the menus, hoping to be able to use some method (a global variable? ick) of keeping track of when a menu is present and showing or hiding accordingly, but it's not working -- these handlers can't tell the difference between a click on the page background and a click on widget 2 (at least, not as I've done it so far). Is there any way to do what I'm trying to do? Thanks!
I think that a combination of clicktohide: false
Boolean indicating if the Menu will automatically be hidden if the user clicks outside of it. This property is only applied when the "position" configuration property is set to dynamic and is automatically applied to all submenus.
and keepopen: true
Boolean indicating if the menu should remain open when clicked.
will take care of this.
http://developer.yahoo.com/yui/menu/#configref

Confusion with popUpMenuPositioningItem:atLocation:inView:

The documentation for this method says: "Pops up the menu at the specified location." but the pamameters seem to describe a different situations:
item
The menu item to be positioned at the specified location in the view.
location
The location in the view coordinate system to display the menu item.
view
The view to display the menu item over.
The parameters seem to imply that you will only be popping up a MenuItem. What does this method actually do?
I don't know how you get that it might just pop up a menu item — there isn't even such a thing as a pop-up menu item. Nowhere in the parameter descriptions does it say it won't show a pop-up menu. The parameter descriptions all mention the item because they all relate to its positioning. It works as documented.
For convenience, you can set the coordinates of a single menu item. Your menu will be positioned accordingly around that single menu item.
You'll notice that this is how NSPopUpButton behaves: the selected menu item is always positioned directly overtop the button.
If you don't want your menu to behave like that, just pass in your top-most menu item.
You're forgetting something: This is a message you send to the menu object.
In English, the message is:
“Hey menu! Pop up yourself, positioning this item at this location relative to this view.”
The parameters describe where the whole pop-up menu should appear, in terms of positioning a specific item from the menu at a specific location. The whole menu appears as the pop-up, not just the positioning item. Popping up only a single item would be quite useless.
One other thing: This convenient method was introduced in Snow Leopard, so if you're targeting Leopard or earlier, you can't depend on it. You'll have to use another solution, such as the NSPopUpButtonCell I suggested in an answer on one of your earlier questions.

Resources