Moved MacVim project to src/MacVim and removed runtime folder
[MacVim/jjgod.git] / src / MacVim / MacVim.m
blob5ad21d863add588c4d65702a15a4b3e021b61aa4
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",
71 // NSUserDefaults keys
72 NSString *MMNoWindowKey                 = @"MMNoWindow";
73 NSString *MMTabMinWidthKey              = @"MMTabMinWidth";
74 NSString *MMTabMaxWidthKey              = @"MMTabMaxWidth";
75 NSString *MMTabOptimumWidthKey          = @"MMTabOptimumWidth";
76 NSString *MMTextInsetLeftKey            = @"MMTextInsetLeft";
77 NSString *MMTextInsetRightKey           = @"MMTextInsetRight";
78 NSString *MMTextInsetTopKey             = @"MMTextInsetTop";
79 NSString *MMTextInsetBottomKey          = @"MMTextInsetBottom";
80 NSString *MMTerminateAfterLastWindowClosedKey
81                                         = @"MMTerminateAfterLastWindowClosed";
82 NSString *MMTypesetterKey               = @"MMTypesetter";
83 NSString *MMCellWidthMultiplierKey      = @"MMCellWidthMultiplier";
84 NSString *MMBaselineOffsetKey           = @"MMBaselineOffset";
85 NSString *MMTranslateCtrlClickKey       = @"MMTranslateCtrlClick";
86 NSString *MMTopLeftPointKey             = @"MMTopLeftPoint";
87 NSString *MMOpenFilesInTabsKey          = @"MMOpenFilesInTabs";
92     ATSFontContainerRef
93 loadFonts()
95     // This loads all fonts from the Resources folder.  The fonts are only
96     // available to the process which loaded them, so loading has to be done
97     // once for MacVim and an additional time for each Vim process.  The
98     // returned container ref should be used to deactiave the font.
99     //
100     // (Code taken from cocoadev.com)
101     ATSFontContainerRef fontContainerRef = 0;
102     NSString *fontsFolder = [[NSBundle mainBundle] resourcePath];    
103     if (fontsFolder) {
104         NSURL *fontsURL = [NSURL fileURLWithPath:fontsFolder];
105         if (fontsURL) {
106             FSRef fsRef;
107             FSSpec fsSpec;
108             CFURLGetFSRef((CFURLRef)fontsURL, &fsRef);
110             if (FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &fsSpec,
111                         NULL) == noErr) {
112                 ATSFontActivateFromFileSpecification(&fsSpec,
113                         kATSFontContextLocal, kATSFontFormatUnspecified, NULL,
114                         kATSOptionFlagsDefault, &fontContainerRef);
115             }
116         }
117     }
119     return fontContainerRef;
125 @implementation NSString (MMExtras)
127 - (NSString *)stringByEscapingSpecialFilenameCharacters
129     // NOTE: This code assumes that no characters already have been escaped.
130     NSMutableString *string = [self mutableCopy];
132     [string replaceOccurrencesOfString:@"\\"
133                             withString:@"\\\\"
134                                options:NSLiteralSearch
135                                  range:NSMakeRange(0, [string length])];
136     [string replaceOccurrencesOfString:@" "
137                             withString:@"\\ "
138                                options:NSLiteralSearch
139                                  range:NSMakeRange(0, [string length])];
140     [string replaceOccurrencesOfString:@"\t"
141                             withString:@"\\\t "
142                                options:NSLiteralSearch
143                                  range:NSMakeRange(0, [string length])];
144     [string replaceOccurrencesOfString:@"%"
145                             withString:@"\\%"
146                                options:NSLiteralSearch
147                                  range:NSMakeRange(0, [string length])];
148     [string replaceOccurrencesOfString:@"#"
149                             withString:@"\\#"
150                                options:NSLiteralSearch
151                                  range:NSMakeRange(0, [string length])];
152     [string replaceOccurrencesOfString:@"|"
153                             withString:@"\\|"
154                                options:NSLiteralSearch
155                                  range:NSMakeRange(0, [string length])];
156     [string replaceOccurrencesOfString:@"\""
157                             withString:@"\\\""
158                                options:NSLiteralSearch
159                                  range:NSMakeRange(0, [string length])];
161     return [string autorelease];
165 @end // NSString (MMExtras)