QCocoaMenuBar: set the app's 'Window' menu
To enable a list of windows the app has open in the Dock's menu. Not to surprise existing applications with a 'Window' menu where they did not have it before, make the item hidden. Fixes: QTBUG-59433 Change-Id: I1ac3d3de69f4313f39c4631dc4b68bf6e096532a Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>bb10
parent
e01c25e859
commit
3fcdb6cb6e
|
|
@ -75,6 +75,7 @@
|
|||
|
||||
#include "qcocoaapplicationdelegate.h"
|
||||
#include "qcocoaintegration.h"
|
||||
#include "qcocoamenubar.h"
|
||||
#include "qcocoamenu.h"
|
||||
#include "qcocoamenuloader.h"
|
||||
#include "qcocoamenuitem.h"
|
||||
|
|
@ -230,6 +231,8 @@ QT_USE_NAMESPACE
|
|||
// (See the activateIgnoringOtherApps docs.)
|
||||
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
|
||||
}
|
||||
|
||||
QCocoaMenuBar::insertWindowMenu();
|
||||
}
|
||||
|
||||
- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ public:
|
|||
NSMenu *nsMenu() const override { return m_nativeMenu; }
|
||||
|
||||
static void updateMenuBarImmediately();
|
||||
static void insertWindowMenu();
|
||||
|
||||
QList<QCocoaMenuItem*> merged() const;
|
||||
NSMenuItem *itemForRole(QPlatformMenuItem::MenuRole role);
|
||||
|
|
|
|||
|
|
@ -333,9 +333,36 @@ void QCocoaMenuBar::updateMenuBarImmediately()
|
|||
|
||||
[mergedItems release];
|
||||
[NSApp setMainMenu:mb->nsMenu()];
|
||||
insertWindowMenu();
|
||||
[loader qtTranslateApplicationMenu];
|
||||
}
|
||||
|
||||
void QCocoaMenuBar::insertWindowMenu()
|
||||
{
|
||||
// For such an item/menu we get for 'free' an additional feature -
|
||||
// a list of windows the application has created in the Dock's menu.
|
||||
|
||||
NSApplication *app = NSApplication.sharedApplication;
|
||||
if (app.windowsMenu)
|
||||
return;
|
||||
|
||||
NSMenu *mainMenu = app.mainMenu;
|
||||
NSMenuItem *winMenuItem = [[[NSMenuItem alloc] initWithTitle:@"QtWindowMenu"
|
||||
action:nil keyEquivalent:@""] autorelease];
|
||||
// We don't want to show this menu, nobody asked us to do so:
|
||||
winMenuItem.hidden = YES;
|
||||
|
||||
winMenuItem.submenu = [[[NSMenu alloc] initWithTitle:@"QtWindowMenu"] autorelease];
|
||||
[mainMenu insertItem:winMenuItem atIndex:mainMenu.itemArray.count];
|
||||
app.windowsMenu = winMenuItem.submenu;
|
||||
|
||||
// Windows, created and 'ordered front' before, will not be in this menu:
|
||||
for (NSWindow *win in app.windows) {
|
||||
if (win.title && ![win.title isEqualToString:@""])
|
||||
[app addWindowsItem:win title:win.title filename:NO];
|
||||
}
|
||||
}
|
||||
|
||||
QList<QCocoaMenuItem*> QCocoaMenuBar::merged() const
|
||||
{
|
||||
QList<QCocoaMenuItem*> r;
|
||||
|
|
|
|||
Loading…
Reference in New Issue