Handle ⌥⌘⇠ / ⌥⌘⇢ in main menu subclass

This means they work (as alternatives for ⌘[ / ⌘]) in all windows with tabs.

We now also trigger menu-flashing for when pressing the keys.
This commit is contained in:
Allan Odgaard
2013-02-18 15:34:30 +01:00
parent f0523c3b43
commit 63beedc6f4
2 changed files with 20 additions and 11 deletions

View File

@@ -52,6 +52,21 @@ static CGPoint MenuPosition ()
@end
@implementation OakMainMenu
- (BOOL)performWindowMenuAction:(SEL)anAction
{
NSMenu* windowMenu = [[self itemWithTitle:@"Window"] submenu];
NSInteger index = [windowMenu indexOfItemWithTarget:nil andAction:anAction];
if(!windowMenu || index == -1)
return [NSApp sendAction:anAction to:nil from:self];
[windowMenu update];
if(![[windowMenu itemAtIndex:index] isEnabled])
return NO;
[windowMenu performActionForItemAtIndex:index];
return YES;
}
- (BOOL)performKeyEquivalent:(NSEvent*)anEvent
{
std::string const keyString = to_s(anEvent);
@@ -75,6 +90,11 @@ static CGPoint MenuPosition ()
}
}
if(keyString == "~@\uF702") // ⌥⌘⇠
return [self performWindowMenuAction:@selector(selectPreviousTab:)];
else if(keyString == "~@\uF703") // ⌥⌘⇢
return [self performWindowMenuAction:@selector(selectNextTab:)];
return [super performKeyEquivalent:anEvent];
}
@end

View File

@@ -509,17 +509,6 @@ static id SafeObjectAtIndex (NSArray* array, NSUInteger index)
}
@synthesize delegate, dataSource, slideAroundAnimationTimer, layoutNeedsUpdate;
- (BOOL)performKeyEquivalent:(NSEvent*)anEvent
{
// this should be in the window controller, but there we need subclassing mojo to get key events
std::string const keyStr = to_s(anEvent);
if(keyStr == "~@\uF702") // ⌥⌘⇠
return [NSApp sendAction:@selector(selectPreviousTab:) to:nil from:self];
else if(keyStr == "~@\uF703") // ⌥⌘⇢
return [NSApp sendAction:@selector(selectNextTab:) to:nil from:self];
return NO;
}
- (id)initWithFrame:(NSRect)aRect
{
if(self = [super initWithFrame:aRect])