5

Is there a way to have an NSMenu like object displayed as content of a NSPopover?

Essentially I'd like to reproduce what macOS Dock does when you right click on an app icon (I don't mind about the dark background here, I'm only interested in having the menu displayed in a popover-like window style with the arrow pointing to its target).

I have been looking into what NSPopUpButton does but I couldn't find a way to configure this component in such way; it has a arrowPosition but this is actually referred to the orientation of the arrow on the button itself. Also NSMenu is an NSObject and again I can't see a clean way to grab its view and add it to a popover, so I guess it's not possible but maybe you have any better idea?

Thanks for any suggestion!

enter image description here

ggould75
  • 880
  • 2
  • 14
  • 23

1 Answers1

-3

You could check the apple menu programming guide: https://developer.apple.com/library/archive/samplecode/MenuItemView/Introduction/Intro.html#//apple_ref/doc/uid/DTS10004136

In AppDelegate you could see:

// -------------------------------------------------------------------------------
//  applicationDockMenu:sender
// -------------------------------------------------------------------------------
// This NSApplication delegate method is called when the user clicks and holds on
// the application icon in the dock.
//
- (NSMenu *)applicationDockMenu:(NSApplication *)sender
{
    return self.appDockMenu;
}
user25917
  • 797
  • 7
  • 18