1 /* vi:set ts=8 sts=4 sw=4 ft=objc:
3 * VIM - Vi IMproved by Bram Moolenaar
4 * MacVim GUI port by Bjorn Winckler
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.
11 * MacVim.m: Code shared between Vim and MacVim.
16 char *MessageStrings[] =
31 "SetTextDimensionsMsgID",
32 "SetWindowTitleMsgID",
40 "RemoveMenuItemMsgID",
41 "EnableMenuItemMsgID",
45 "CreateScrollbarMsgID",
46 "DestroyScrollbarMsgID",
48 "SetScrollbarPositionMsgID",
49 "SetScrollbarThumbMsgID",
50 "ScrollbarEventMsgID",
53 "VimShouldCloseMsgID",
54 "SetDefaultColorsMsgID",
63 "AdjustLinespaceMsgID",
66 "EnterFullscreenMsgID",
67 "LeaveFullscreenMsgID",
68 "BuffersNotModifiedMsgID",
69 "BuffersModifiedMsgID",
71 "SetPreEditPositionMsgID",
76 "EnableAntialiasMsgID",
77 "DisableAntialiasMsgID",
84 // NSUserDefaults keys
85 NSString *MMNoWindowKey = @"MMNoWindow";
86 NSString *MMTabMinWidthKey = @"MMTabMinWidth";
87 NSString *MMTabMaxWidthKey = @"MMTabMaxWidth";
88 NSString *MMTabOptimumWidthKey = @"MMTabOptimumWidth";
89 NSString *MMTextInsetLeftKey = @"MMTextInsetLeft";
90 NSString *MMTextInsetRightKey = @"MMTextInsetRight";
91 NSString *MMTextInsetTopKey = @"MMTextInsetTop";
92 NSString *MMTextInsetBottomKey = @"MMTextInsetBottom";
93 NSString *MMTerminateAfterLastWindowClosedKey
94 = @"MMTerminateAfterLastWindowClosed";
95 NSString *MMTypesetterKey = @"MMTypesetter";
96 NSString *MMCellWidthMultiplierKey = @"MMCellWidthMultiplier";
97 NSString *MMBaselineOffsetKey = @"MMBaselineOffset";
98 NSString *MMTranslateCtrlClickKey = @"MMTranslateCtrlClick";
99 NSString *MMTopLeftPointKey = @"MMTopLeftPoint";
100 NSString *MMOpenFilesInTabsKey = @"MMOpenFilesInTabs";
101 NSString *MMNoFontSubstitutionKey = @"MMNoFontSubstitution";
102 NSString *MMLoginShellKey = @"MMLoginShell";
103 NSString *MMAtsuiRendererKey = @"MMAtsuiRenderer";
104 NSString *MMUntitledWindowKey = @"MMUntitledWindow";
105 NSString *MMTexturedWindowKey = @"MMTexturedWindow";
106 NSString *MMZoomBothKey = @"MMZoomBoth";
107 NSString *MMCurrentPreferencePaneKey = @"MMCurrentPreferencePane";
108 NSString *MMLoginShellCommandKey = @"MMLoginShellCommand";
109 NSString *MMLoginShellArgumentKey = @"MMLoginShellArgument";
117 // This loads all fonts from the Resources folder. The fonts are only
118 // available to the process which loaded them, so loading has to be done
119 // once for MacVim and an additional time for each Vim process. The
120 // returned container ref should be used to deactiave the font.
122 // (Code taken from cocoadev.com)
123 ATSFontContainerRef fontContainerRef = 0;
124 NSString *fontsFolder = [[NSBundle mainBundle] resourcePath];
126 NSURL *fontsURL = [NSURL fileURLWithPath:fontsFolder];
130 CFURLGetFSRef((CFURLRef)fontsURL, &fsRef);
132 if (FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &fsSpec,
134 ATSFontActivateFromFileSpecification(&fsSpec,
135 kATSFontContextLocal, kATSFontFormatUnspecified, NULL,
136 kATSOptionFlagsDefault, &fontContainerRef);
141 return fontContainerRef;
148 buildTabDropCommand(NSArray *filenames)
150 // Create a command line string that will open the specified files in tabs.
152 if (!filenames || [filenames count] == 0)
153 return [NSString string];
155 NSMutableString *cmd = [NSMutableString stringWithString:
156 @"<C-\\><C-N>:tab drop"];
158 NSEnumerator *e = [filenames objectEnumerator];
160 while ((o = [e nextObject])) {
161 NSString *file = [o stringByEscapingSpecialFilenameCharacters];
162 [cmd appendString:@" "];
163 [cmd appendString:file];
166 [cmd appendString:@"|redr|f<CR>"];
172 buildSelectRangeCommand(NSRange range)
174 // Build a command line string that will select the given range of lines.
175 // If range.length == 0, then position the cursor on the given line but do
178 if (range.location == NSNotFound)
179 return [NSString string];
182 if (range.length > 0) {
183 cmd = [NSString stringWithFormat:@"<C-\\><C-N>%dGV%dGz.0",
184 NSMaxRange(range), range.location];
186 cmd = [NSString stringWithFormat:@"<C-\\><C-N>%dGz.0", range.location];
193 buildSearchTextCommand(NSString *searchText)
195 // TODO: Searching is an exclusive motion, so if the pattern would match on
196 // row 0 column 0 then this pattern will miss that match.
197 return [NSString stringWithFormat:@"<C-\\><C-N>gg/\\c%@<CR>", searchText];
203 @implementation NSString (MMExtras)
205 - (NSString *)stringByEscapingSpecialFilenameCharacters
207 // NOTE: This code assumes that no characters already have been escaped.
208 NSMutableString *string = [self mutableCopy];
210 [string replaceOccurrencesOfString:@"\\"
212 options:NSLiteralSearch
213 range:NSMakeRange(0, [string length])];
214 [string replaceOccurrencesOfString:@" "
216 options:NSLiteralSearch
217 range:NSMakeRange(0, [string length])];
218 [string replaceOccurrencesOfString:@"\t"
220 options:NSLiteralSearch
221 range:NSMakeRange(0, [string length])];
222 [string replaceOccurrencesOfString:@"%"
224 options:NSLiteralSearch
225 range:NSMakeRange(0, [string length])];
226 [string replaceOccurrencesOfString:@"#"
228 options:NSLiteralSearch
229 range:NSMakeRange(0, [string length])];
230 [string replaceOccurrencesOfString:@"|"
232 options:NSLiteralSearch
233 range:NSMakeRange(0, [string length])];
234 [string replaceOccurrencesOfString:@"\""
236 options:NSLiteralSearch
237 range:NSMakeRange(0, [string length])];
239 return [string autorelease];
242 @end // NSString (MMExtras)
246 @implementation NSIndexSet (MMExtras)
248 + (id)indexSetWithVimList:(NSString *)list
250 NSMutableIndexSet *idxSet = [NSMutableIndexSet indexSet];
251 NSArray *array = [list componentsSeparatedByString:@"\n"];
252 unsigned i, count = [array count];
254 for (i = 0; i < count; ++i) {
255 NSString *entry = [array objectAtIndex:i];
256 if ([entry intValue] > 0)
263 @end // NSIndexSet (MMExtras)
268 @implementation NSColor (MMExtras)
270 + (NSColor *)colorWithRgbInt:(unsigned)rgb
272 float r = ((rgb>>16) & 0xff)/255.0f;
273 float g = ((rgb>>8) & 0xff)/255.0f;
274 float b = (rgb & 0xff)/255.0f;
276 return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:1.0f];
279 + (NSColor *)colorWithArgbInt:(unsigned)argb
281 float a = ((argb>>24) & 0xff)/255.0f;
282 float r = ((argb>>16) & 0xff)/255.0f;
283 float g = ((argb>>8) & 0xff)/255.0f;
284 float b = (argb & 0xff)/255.0f;
286 return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:a];
289 @end // NSColor (MMExtras)