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[] =
33 "SetTextDimensionsMsgID",
34 "SetWindowTitleMsgID",
42 "RemoveMenuItemMsgID",
43 "EnableMenuItemMsgID",
47 "CreateScrollbarMsgID",
48 "DestroyScrollbarMsgID",
50 "SetScrollbarPositionMsgID",
51 "SetScrollbarThumbMsgID",
52 "ScrollbarEventMsgID",
55 "VimShouldCloseMsgID",
56 "SetDefaultColorsMsgID",
65 "AdjustLinespaceMsgID",
68 "EnterFullscreenMsgID",
69 "LeaveFullscreenMsgID",
70 "BuffersNotModifiedMsgID",
71 "BuffersModifiedMsgID",
73 "SetPreEditPositionMsgID",
77 "EnableAntialiasMsgID",
78 "DisableAntialiasMsgID",
80 "SetDocumentFilenameMsgID",
81 "OpenWithArgumentsMsgID",
84 "SetFullscreenColorMsgID",
85 "ShowFindReplaceDialogMsgID",
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";
105 // This loads all fonts from the Resources folder. The fonts are only
106 // available to the process which loaded them, so loading has to be done
107 // once for MacVim and an additional time for each Vim process. The
108 // returned container ref should be used to deactiave the font.
110 // (Code taken from cocoadev.com)
111 ATSFontContainerRef fontContainerRef = 0;
112 NSString *fontsFolder = [[NSBundle mainBundle] resourcePath];
114 NSURL *fontsURL = [NSURL fileURLWithPath:fontsFolder];
118 CFURLGetFSRef((CFURLRef)fontsURL, &fsRef);
120 if (FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &fsSpec,
122 ATSFontActivateFromFileSpecification(&fsSpec,
123 kATSFontContextLocal, kATSFontFormatUnspecified, NULL,
124 kATSOptionFlagsDefault, &fontContainerRef);
129 return fontContainerRef;
135 @implementation NSString (MMExtras)
137 - (NSString *)stringByEscapingSpecialFilenameCharacters
139 // NOTE: This code assumes that no characters already have been escaped.
140 NSMutableString *string = [self mutableCopy];
142 [string replaceOccurrencesOfString:@"\\"
144 options:NSLiteralSearch
145 range:NSMakeRange(0, [string length])];
146 [string replaceOccurrencesOfString:@" "
148 options:NSLiteralSearch
149 range:NSMakeRange(0, [string length])];
150 [string replaceOccurrencesOfString:@"\t"
152 options:NSLiteralSearch
153 range:NSMakeRange(0, [string length])];
154 [string replaceOccurrencesOfString:@"%"
156 options:NSLiteralSearch
157 range:NSMakeRange(0, [string length])];
158 [string replaceOccurrencesOfString:@"#"
160 options:NSLiteralSearch
161 range:NSMakeRange(0, [string length])];
162 [string replaceOccurrencesOfString:@"|"
164 options:NSLiteralSearch
165 range:NSMakeRange(0, [string length])];
166 [string replaceOccurrencesOfString:@"\""
168 options:NSLiteralSearch
169 range:NSMakeRange(0, [string length])];
171 return [string autorelease];
174 @end // NSString (MMExtras)
178 @implementation NSColor (MMExtras)
180 + (NSColor *)colorWithRgbInt:(unsigned)rgb
182 float r = ((rgb>>16) & 0xff)/255.0f;
183 float g = ((rgb>>8) & 0xff)/255.0f;
184 float b = (rgb & 0xff)/255.0f;
186 return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:1.0f];
189 + (NSColor *)colorWithArgbInt:(unsigned)argb
191 float a = ((argb>>24) & 0xff)/255.0f;
192 float r = ((argb>>16) & 0xff)/255.0f;
193 float g = ((argb>>8) & 0xff)/255.0f;
194 float b = (argb & 0xff)/255.0f;
196 return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:a];
199 @end // NSColor (MMExtras)
204 @implementation NSDictionary (MMExtras)
206 + (id)dictionaryWithData:(NSData *)data
208 id plist = [NSPropertyListSerialization
209 propertyListFromData:data
210 mutabilityOption:NSPropertyListImmutable
212 errorDescription:NULL];
214 return [plist isKindOfClass:[NSDictionary class]] ? plist : nil;
217 - (NSData *)dictionaryAsData
219 return [NSPropertyListSerialization dataFromPropertyList:self
220 format:NSPropertyListBinaryFormat_v1_0 errorDescription:NULL];
228 @implementation NSMutableDictionary (MMExtras)
230 + (id)dictionaryWithData:(NSData *)data
232 id plist = [NSPropertyListSerialization
233 propertyListFromData:data
234 mutabilityOption:NSPropertyListMutableContainers
236 errorDescription:NULL];
238 return [plist isKindOfClass:[NSMutableDictionary class]] ? plist : nil;