Revert "Modifier key sends Esc" related commits
[MacVim.git] / src / MacVim / MMApplication.m
blob10c69d9d626b01625118e21d648beba90c30e2ad
1 /* vi:set ts=8 sts=4 sw=4 ft=objc:
2  *
3  * VIM - Vi IMproved            by Bram Moolenaar
4  *                              MacVim GUI port by Bjorn Winckler
5  *
6  * Do ":help uganda"  in Vim to read copying and usage conditions.
7  * Do ":help credits" in Vim to see a list of people who contributed.
8  * See README.txt for an overview of the Vim source code.
9  */
11  * MMApplication
12  *
13  * Some default NSApplication key input behavior is overridden here.
14  */
16 #import "MMApplication.h"
18 // Ctrl-Tab is broken on pre 10.5, so we add a hack to make it work.
19 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
20 # import "MMTextView.h"
21 # define MM_CTRL_TAB_HACK 1
22 #endif
27 @implementation MMApplication
29 - (void)sendEvent:(NSEvent *)event
31     NSEventType type = [event type];
32     unsigned flags = [event modifierFlags];
34 #ifdef MM_CTRL_TAB_HACK
35     NSResponder *firstResponder = [[self keyWindow] firstResponder];
37     if (NSKeyDown == type && NSControlKeyMask & flags && 48 == [event keyCode]
38             && [firstResponder isKindOfClass:[MMTextView class]]) {
39         // HACK! This is a Ctrl-Tab key down event and the first responder is
40         // an MMTextView; send the event directly to the text view, else it
41         // will never receive it on pre 10.5 systems.
42         [firstResponder keyDown:event];
43         return;
44     }
45 #endif
47     // HACK! Intercept 'help' key presses and clear the 'help key flag', else
48     // Cocoa turns the mouse cursor into a question mark and goes into 'context
49     // help mode' (the keyDown: event itself never reaches the text view).  By
50     // clearing the 'help key flag' this event will be treated like a normal
51     // key event.
52     if ((NSKeyDown == type || NSKeyUp == type) && (flags & NSHelpKeyMask)) {
53         flags &= ~NSHelpKeyMask;
54         event = [NSEvent keyEventWithType:[event type]
55                                  location:[event locationInWindow]
56                             modifierFlags:flags
57                                 timestamp:[event timestamp]
58                              windowNumber:[event windowNumber]
59                                   context:[event context]
60                                characters:[event characters]
61               charactersIgnoringModifiers:[event charactersIgnoringModifiers]
62                                 isARepeat:[event isARepeat]
63                                   keyCode:[event keyCode]];
64     }
66     [super sendEvent:event];
70 - (void)orderFrontStandardAboutPanel:(id)sender
72     NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey:
73             @"CFBundleVersion"];
74     NSString *marketingVersion = [[NSBundle mainBundle]
75             objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
76     NSString *title = [NSString stringWithFormat:
77             @"Custom Version %@ (%@)", marketingVersion, version];
79     [self orderFrontStandardAboutPanelWithOptions:
80             [NSDictionary dictionaryWithObjectsAndKeys:
81                 @"",    @"Version",
82                 title,  @"ApplicationVersion",
83                 nil]];
86 @end