diff options
author | stuconnolly <stuart02@gmail.com> | 2011-01-27 20:38:23 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2011-01-27 20:38:23 +0000 |
commit | 8db2f78294982e89fce5a162d92b2be6d9291aa1 (patch) | |
tree | b8dc7736f4af896aa3ed3fa9a96d1f3c4bfd0e59 /Source/SPWindow.m | |
parent | fa7cff57548edc51420693e6909fe2adb3c18951 (diff) | |
parent | 7cc062247ff23496dd0390cf07b5d45d6bc49777 (diff) | |
download | sequelpro-8db2f78294982e89fce5a162d92b2be6d9291aa1.tar.gz sequelpro-8db2f78294982e89fce5a162d92b2be6d9291aa1.tar.bz2 sequelpro-8db2f78294982e89fce5a162d92b2be6d9291aa1.zip |
Bring outline view branch up to date with trunk (r3056:r3162).
Diffstat (limited to 'Source/SPWindow.m')
-rw-r--r-- | Source/SPWindow.m | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/Source/SPWindow.m b/Source/SPWindow.m new file mode 100644 index 00000000..58f38d0b --- /dev/null +++ b/Source/SPWindow.m @@ -0,0 +1,112 @@ +// +// $Id$ +// +// SPWindow.m +// sequel-pro +// +// Created by Rowan Beentje on January 23, 2011 +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at <http://code.google.com/p/sequel-pro/> + +#import "SPWindow.h" + + +@implementation SPWindow + +#pragma mark - +#pragma mark Keyboard shortcut additions + +/** + * While keyboard shortcuts are an easy way to apply code app-wide, alternate menu + * items only collapse if the unmodified key matches; this method allows keyboard + * shortcuts without menu equivalents for a window, or the use of different base shortcuts. + */ +- (void) sendEvent:(NSEvent *)theEvent +{ + + if ([theEvent type] == NSKeyDown && [[theEvent characters] length]) { + + unichar theCharacter = [[theEvent charactersIgnoringModifiers] characterAtIndex:0]; + + // ⌃⎋ sends a right-click to order front the context menu under the first responder's visible Rect + if ([theEvent keyCode] == 53 && (([theEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask) == (NSAlternateKeyMask))) { + + id firstResponder = [[NSApp keyWindow] firstResponder]; + + if(firstResponder && [firstResponder respondsToSelector:@selector(menuForEvent:)]) { + + NSRect theRect = [firstResponder visibleRect]; + NSPoint loc = theRect.origin; + loc.y += theRect.size.height+5; + loc = [firstResponder convertPoint:loc toView:nil]; + NSEvent *anEvent = [NSEvent + mouseEventWithType:NSRightMouseDown + location:loc + modifierFlags:0 + timestamp:1 + windowNumber:[self windowNumber] + context:[NSGraphicsContext currentContext] + eventNumber:0 + clickCount:1 + pressure:0.0]; + + [NSMenu popUpContextMenu:[firstResponder menuForEvent:theEvent] withEvent:anEvent forView:firstResponder]; + + return; + + } + + } + + switch (theCharacter) { + + // Alternate keys for switching tabs - ⇧⌘[ and ⇧⌘]. These seem to be standards on some apps, + // including Apple applications under some circumstances + case '}': + if (([theEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask) == (NSCommandKeyMask | NSShiftKeyMask)) + { + return [[self windowController] selectNextDocumentTab:self]; + } + break; + case '{': + if (([theEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask) == (NSCommandKeyMask | NSShiftKeyMask)) + { + return [[self windowController] selectPreviousDocumentTab:self]; + } + break; + + // Also support ⌥⌘← and ⌥⌘→, used in other applications, for maximum compatibility + case NSRightArrowFunctionKey: + if (([theEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask) == (NSCommandKeyMask | NSAlternateKeyMask | NSNumericPadKeyMask | NSFunctionKeyMask)) + { + return [[self windowController] selectNextDocumentTab:self]; + } + break; + case NSLeftArrowFunctionKey: + if (([theEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask) == (NSCommandKeyMask | NSAlternateKeyMask | NSNumericPadKeyMask | NSFunctionKeyMask)) + { + return [[self windowController] selectPreviousDocumentTab:self]; + } + break; + } + } + + [super sendEvent:theEvent]; +} + + +@end |