Provide a default context menu for application icons when using

Macintosh or Windows 95 style menus. Inspired by OS X, the menu
contains items to hide or show the application, to terminate the
application, an item for each window present in the application's
window menu, and the items of the dock menu returned by the
application delegate.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@31892 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Wolfgang Lux 2011-01-15 14:36:38 +00:00
parent 9464856dfe
commit ba39755f4a
5 changed files with 542 additions and 350 deletions

View file

@ -380,6 +380,7 @@ struct _NSModalSession {
- (void) _windowWillClose: (NSNotification*) notification;
- (void) _workspaceNotification: (NSNotification*) notification;
- (NSArray *) _openFiles;
- (NSMenu *) _dockMenu;
@end
@interface NSWindow (ApplicationPrivate)
@ -457,6 +458,27 @@ NSApplication *NSApp = nil;
_windowLevel = NSDockWindowLevel;
}
- (void) rightMouseDown: (NSEvent *)theEvent
{
NSMenu *menu = nil;
NSInterfaceStyle style = NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil);
if (style == NSMacintoshInterfaceStyle || style == NSWindows95InterfaceStyle)
{
menu = [NSApp _dockMenu];
}
if (menu)
{
[NSMenu popUpContextMenu: menu
withEvent: theEvent
forView: [self contentView]];
}
else
{
[super rightMouseDown: theEvent];
}
}
@end
@implementation NSAppIconView
@ -4062,6 +4084,69 @@ struct _DelegateWrapper
return files;
}
- (NSMenu *) _dockMenu
{
NSUInteger i, j, n;
NSMenu *dockMenu, *windowsMenu;
// ask delegate for a dock menu, if none create a new one
dockMenu = nil;
if ([_delegate respondsToSelector: @selector(applicationDockMenu:)])
{
// NB we make a copy of the menu since we are going to modify it
dockMenu = [[_delegate applicationDockMenu: self] copy];
}
if (dockMenu == nil)
{
dockMenu = [[NSMenu alloc] initWithTitle:@""];
}
// copy window menu entries to the top of the menu
windowsMenu = [NSApp windowsMenu];
for (i = j = 0, n = [windowsMenu numberOfItems]; i < n; i++)
{
NSMenuItem *item = [windowsMenu itemAtIndex: i];
if ([[item target] isKindOfClass:[NSWindow class]] &&
sel_isEqual([item action], @selector(makeKeyAndOrderFront:)))
{
[[dockMenu insertItemWithTitle: [item title]
action: @selector(makeKeyAndOrderFront:)
keyEquivalent: @""
atIndex: j++]
setTarget: [item target]];
}
}
if (j > 0)
{
[dockMenu insertItem: [NSMenuItem separatorItem] atIndex: j++];
}
// insert standard entries to show or hide and to quit the application at
// the bottom
if (j < [dockMenu numberOfItems])
{
[dockMenu addItem: [NSMenuItem separatorItem]];
}
if ([self isHidden])
{
[dockMenu addItemWithTitle:_(@"Show")
action:@selector(unhide:)
keyEquivalent:@""];
}
else
{
[dockMenu addItemWithTitle:_(@"Hide")
action:@selector(hide:)
keyEquivalent:@""];
}
[dockMenu addItemWithTitle:_(@"Quit")
action:@selector(terminate:)
keyEquivalent:@""];
// return the menu
return dockMenu;
}
@end // NSApplication (Private)