Cmd-. sends SIGINT
[MacVim.git] / src / MacVim / MacVim.m
blobc361be302eb632461819a89ce9633a5d6881fc43
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  * MacVim.m:  Code shared between Vim and MacVim.
12  */
14 #import "MacVim.h"
16 char *MessageStrings[] = 
18     "INVALID MESSAGE ID",
19     "OpenWindowMsgID",
20     "InsertTextMsgID",
21     "KeyDownMsgID",
22     "CmdKeyMsgID",
23     "BatchDrawMsgID",
24     "SelectTabMsgID",
25     "CloseTabMsgID",
26     "AddNewTabMsgID",
27     "DraggedTabMsgID",
28     "UpdateTabBarMsgID",
29     "ShowTabBarMsgID",
30     "HideTabBarMsgID",
31     "SetTextRowsMsgID",
32     "SetTextColumsMsgID",
33     "SetTextDimensionsMsgID",
34     "LiveResizeMsgID",
35     "SetTextDimensionsReplyMsgID",
36     "SetWindowTitleMsgID",
37     "ScrollWheelMsgID",
38     "MouseDownMsgID",
39     "MouseUpMsgID",
40     "MouseDraggedMsgID",
41     "FlushQueueMsgID",
42     "AddMenuMsgID",
43     "AddMenuItemMsgID",
44     "RemoveMenuItemMsgID",
45     "EnableMenuItemMsgID",
46     "ExecuteMenuMsgID",
47     "ShowToolbarMsgID",
48     "ToggleToolbarMsgID",
49     "CreateScrollbarMsgID",
50     "DestroyScrollbarMsgID",
51     "ShowScrollbarMsgID",
52     "SetScrollbarPositionMsgID",
53     "SetScrollbarThumbMsgID",
54     "ScrollbarEventMsgID",
55     "SetFontMsgID",
56     "SetWideFontMsgID",
57     "VimShouldCloseMsgID",
58     "SetDefaultColorsMsgID",
59     "ExecuteActionMsgID",
60     "DropFilesMsgID",
61     "DropStringMsgID",
62     "ShowPopupMenuMsgID",
63     "GotFocusMsgID",
64     "LostFocusMsgID",
65     "MouseMovedMsgID",
66     "SetMouseShapeMsgID",
67     "AdjustLinespaceMsgID",
68     "ActivateMsgID",
69     "SetServerNameMsgID",
70     "EnterFullscreenMsgID",
71     "LeaveFullscreenMsgID",
72     "BuffersNotModifiedMsgID",
73     "BuffersModifiedMsgID",
74     "AddInputMsgID",
75     "SetPreEditPositionMsgID",
76     "TerminateNowMsgID",
77     "XcodeModMsgID",
78     "EnableAntialiasMsgID",
79     "DisableAntialiasMsgID",
80     "SetVimStateMsgID",
81     "SetDocumentFilenameMsgID",
82     "OpenWithArgumentsMsgID",
83     "CloseWindowMsgID",
84     "SetFullscreenColorMsgID",
85     "ShowFindReplaceDialogMsgID",
86     "FindReplaceMsgID",
92 // Argument used to stop MacVim from opening an empty window on startup
93 // (techincally this is a user default but should not be used as such).
94 NSString *MMNoWindowKey = @"MMNoWindow";
96 // Vim pasteboard type (holds motion type + string)
97 NSString *VimPBoardType = @"VimPBoardType";
102 @implementation NSString (MMExtras)
104 - (NSString *)stringByEscapingSpecialFilenameCharacters
106     // NOTE: This code assumes that no characters already have been escaped.
107     NSMutableString *string = [self mutableCopy];
109     [string replaceOccurrencesOfString:@"\\"
110                             withString:@"\\\\"
111                                options:NSLiteralSearch
112                                  range:NSMakeRange(0, [string length])];
113     [string replaceOccurrencesOfString:@" "
114                             withString:@"\\ "
115                                options:NSLiteralSearch
116                                  range:NSMakeRange(0, [string length])];
117     [string replaceOccurrencesOfString:@"\t"
118                             withString:@"\\\t "
119                                options:NSLiteralSearch
120                                  range:NSMakeRange(0, [string length])];
121     [string replaceOccurrencesOfString:@"%"
122                             withString:@"\\%"
123                                options:NSLiteralSearch
124                                  range:NSMakeRange(0, [string length])];
125     [string replaceOccurrencesOfString:@"#"
126                             withString:@"\\#"
127                                options:NSLiteralSearch
128                                  range:NSMakeRange(0, [string length])];
129     [string replaceOccurrencesOfString:@"|"
130                             withString:@"\\|"
131                                options:NSLiteralSearch
132                                  range:NSMakeRange(0, [string length])];
133     [string replaceOccurrencesOfString:@"\""
134                             withString:@"\\\""
135                                options:NSLiteralSearch
136                                  range:NSMakeRange(0, [string length])];
138     return [string autorelease];
141 @end // NSString (MMExtras)
145 @implementation NSColor (MMExtras)
147 + (NSColor *)colorWithRgbInt:(unsigned)rgb
149     float r = ((rgb>>16) & 0xff)/255.0f;
150     float g = ((rgb>>8) & 0xff)/255.0f;
151     float b = (rgb & 0xff)/255.0f;
153     return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:1.0f];
156 + (NSColor *)colorWithArgbInt:(unsigned)argb
158     float a = ((argb>>24) & 0xff)/255.0f;
159     float r = ((argb>>16) & 0xff)/255.0f;
160     float g = ((argb>>8) & 0xff)/255.0f;
161     float b = (argb & 0xff)/255.0f;
163     return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:a];
166 @end // NSColor (MMExtras)
171 @implementation NSDictionary (MMExtras)
173 + (id)dictionaryWithData:(NSData *)data
175     id plist = [NSPropertyListSerialization
176             propertyListFromData:data
177                 mutabilityOption:NSPropertyListImmutable
178                           format:NULL
179                 errorDescription:NULL];
181     return [plist isKindOfClass:[NSDictionary class]] ? plist : nil;
184 - (NSData *)dictionaryAsData
186     return [NSPropertyListSerialization dataFromPropertyList:self
187             format:NSPropertyListBinaryFormat_v1_0 errorDescription:NULL];
190 @end
195 @implementation NSMutableDictionary (MMExtras)
197 + (id)dictionaryWithData:(NSData *)data
199     id plist = [NSPropertyListSerialization
200             propertyListFromData:data
201                 mutabilityOption:NSPropertyListMutableContainers
202                           format:NULL
203                 errorDescription:NULL];
205     return [plist isKindOfClass:[NSMutableDictionary class]] ? plist : nil;
208 @end