Add eval & add input methods to MacVim, apply to file open
[MacVim.git] / src / MacVim / MacVim.m
blob23e903259bb19ee2824ce38a74d7ec2f293aa983
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 #import "MacVim.h"
13 char *MessageStrings[] = 
15     "INVALID MESSAGE ID",
16     "OpenVimWindowMsgID",
17     "InsertTextMsgID",
18     "KeyDownMsgID",
19     "CmdKeyMsgID",
20     "BatchDrawMsgID",
21     "SelectTabMsgID",
22     "CloseTabMsgID",
23     "AddNewTabMsgID",
24     "DraggedTabMsgID",
25     "UpdateTabBarMsgID",
26     "ShowTabBarMsgID",
27     "HideTabBarMsgID",
28     "SetTextDimensionsMsgID",
29     "SetWindowTitleMsgID",
30     "ScrollWheelMsgID",
31     "MouseDownMsgID",
32     "MouseUpMsgID",
33     "MouseDraggedMsgID",
34     "FlushQueueMsgID",
35     "AddMenuMsgID",
36     "AddMenuItemMsgID",
37     "RemoveMenuItemMsgID",
38     "EnableMenuItemMsgID",
39     "ExecuteMenuMsgID",
40     "ShowToolbarMsgID",
41     "ToggleToolbarMsgID",
42     "CreateScrollbarMsgID",
43     "DestroyScrollbarMsgID",
44     "ShowScrollbarMsgID",
45     "SetScrollbarPositionMsgID",
46     "SetScrollbarThumbMsgID",
47     "ScrollbarEventMsgID",
48     "SetFontMsgID",
49     "VimShouldCloseMsgID",
50     "SetDefaultColorsMsgID",
51     "ExecuteActionMsgID",
52     "DropFilesMsgID",
53     "DropStringMsgID",
54     "ShowPopupMenuMsgID",
55     "GotFocusMsgID",
56     "LostFocusMsgID",
57     "MouseMovedMsgID",
58     "SetMouseShapeMsgID",
59     "AdjustLinespaceMsgID",
60     "ActivateMsgID",
61     "SetServerNameMsgID",
62     "EnterFullscreenMsgID",
63     "LeaveFullscreenMsgID",
64     "BuffersNotModifiedMsgID",
65     "BuffersModifiedMsgID",
66     "AddInputMsgID",
72 // NSUserDefaults keys
73 NSString *MMNoWindowKey                 = @"MMNoWindow";
74 NSString *MMTabMinWidthKey              = @"MMTabMinWidth";
75 NSString *MMTabMaxWidthKey              = @"MMTabMaxWidth";
76 NSString *MMTabOptimumWidthKey          = @"MMTabOptimumWidth";
77 NSString *MMTextInsetLeftKey            = @"MMTextInsetLeft";
78 NSString *MMTextInsetRightKey           = @"MMTextInsetRight";
79 NSString *MMTextInsetTopKey             = @"MMTextInsetTop";
80 NSString *MMTextInsetBottomKey          = @"MMTextInsetBottom";
81 NSString *MMTerminateAfterLastWindowClosedKey
82                                         = @"MMTerminateAfterLastWindowClosed";
83 NSString *MMTypesetterKey               = @"MMTypesetter";
84 NSString *MMCellWidthMultiplierKey      = @"MMCellWidthMultiplier";
85 NSString *MMBaselineOffsetKey           = @"MMBaselineOffset";
86 NSString *MMTranslateCtrlClickKey       = @"MMTranslateCtrlClick";
87 NSString *MMTopLeftPointKey             = @"MMTopLeftPoint";
88 NSString *MMOpenFilesInTabsKey          = @"MMOpenFilesInTabs";
93     ATSFontContainerRef
94 loadFonts()
96     // This loads all fonts from the Resources folder.  The fonts are only
97     // available to the process which loaded them, so loading has to be done
98     // once for MacVim and an additional time for each Vim process.  The
99     // returned container ref should be used to deactiave the font.
100     //
101     // (Code taken from cocoadev.com)
102     ATSFontContainerRef fontContainerRef = 0;
103     NSString *fontsFolder = [[NSBundle mainBundle] resourcePath];    
104     if (fontsFolder) {
105         NSURL *fontsURL = [NSURL fileURLWithPath:fontsFolder];
106         if (fontsURL) {
107             FSRef fsRef;
108             FSSpec fsSpec;
109             CFURLGetFSRef((CFURLRef)fontsURL, &fsRef);
111             if (FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &fsSpec,
112                         NULL) == noErr) {
113                 ATSFontActivateFromFileSpecification(&fsSpec,
114                         kATSFontContextLocal, kATSFontFormatUnspecified, NULL,
115                         kATSOptionFlagsDefault, &fontContainerRef);
116             }
117         }
118     }
120     return fontContainerRef;
126 @implementation NSString (MMExtras)
128 - (NSString *)stringByEscapingSpecialFilenameCharacters
130     // NOTE: This code assumes that no characters already have been escaped.
131     NSMutableString *string = [self mutableCopy];
133     [string replaceOccurrencesOfString:@"\\"
134                             withString:@"\\\\"
135                                options:NSLiteralSearch
136                                  range:NSMakeRange(0, [string length])];
137     [string replaceOccurrencesOfString:@" "
138                             withString:@"\\ "
139                                options:NSLiteralSearch
140                                  range:NSMakeRange(0, [string length])];
141     [string replaceOccurrencesOfString:@"\t"
142                             withString:@"\\\t "
143                                options:NSLiteralSearch
144                                  range:NSMakeRange(0, [string length])];
145     [string replaceOccurrencesOfString:@"%"
146                             withString:@"\\%"
147                                options:NSLiteralSearch
148                                  range:NSMakeRange(0, [string length])];
149     [string replaceOccurrencesOfString:@"#"
150                             withString:@"\\#"
151                                options:NSLiteralSearch
152                                  range:NSMakeRange(0, [string length])];
153     [string replaceOccurrencesOfString:@"|"
154                             withString:@"\\|"
155                                options:NSLiteralSearch
156                                  range:NSMakeRange(0, [string length])];
157     [string replaceOccurrencesOfString:@"\""
158                             withString:@"\\\""
159                                options:NSLiteralSearch
160                                  range:NSMakeRange(0, [string length])];
162     return [string autorelease];
166 @end // NSString (MMExtras)