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",
89 // Argument used to stop MacVim from opening an empty window on startup
90 // (techincally this is a user default but should not be used as such).
91 NSString *MMNoWindowKey = @"MMNoWindow";
93 // Vim pasteboard type (holds motion type + string)
94 NSString *VimPBoardType = @"VimPBoardType";
102 // This loads all fonts from the Resources folder. The fonts are only
103 // available to the process which loaded them, so loading has to be done
104 // once for MacVim and an additional time for each Vim process. The
105 // returned container ref should be used to deactiave the font.
107 // (Code taken from cocoadev.com)
108 ATSFontContainerRef fontContainerRef = 0;
109 NSString *fontsFolder = [[NSBundle mainBundle] resourcePath];
111 NSURL *fontsURL = [NSURL fileURLWithPath:fontsFolder];
115 CFURLGetFSRef((CFURLRef)fontsURL, &fsRef);
117 if (FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &fsSpec,
119 ATSFontActivateFromFileSpecification(&fsSpec,
120 kATSFontContextLocal, kATSFontFormatUnspecified, NULL,
121 kATSOptionFlagsDefault, &fontContainerRef);
126 return fontContainerRef;
132 @implementation NSString (MMExtras)
134 - (NSString *)stringByEscapingSpecialFilenameCharacters
136 // NOTE: This code assumes that no characters already have been escaped.
137 NSMutableString *string = [self mutableCopy];
139 [string replaceOccurrencesOfString:@"\\"
141 options:NSLiteralSearch
142 range:NSMakeRange(0, [string length])];
143 [string replaceOccurrencesOfString:@" "
145 options:NSLiteralSearch
146 range:NSMakeRange(0, [string length])];
147 [string replaceOccurrencesOfString:@"\t"
149 options:NSLiteralSearch
150 range:NSMakeRange(0, [string length])];
151 [string replaceOccurrencesOfString:@"%"
153 options:NSLiteralSearch
154 range:NSMakeRange(0, [string length])];
155 [string replaceOccurrencesOfString:@"#"
157 options:NSLiteralSearch
158 range:NSMakeRange(0, [string length])];
159 [string replaceOccurrencesOfString:@"|"
161 options:NSLiteralSearch
162 range:NSMakeRange(0, [string length])];
163 [string replaceOccurrencesOfString:@"\""
165 options:NSLiteralSearch
166 range:NSMakeRange(0, [string length])];
168 return [string autorelease];
171 @end // NSString (MMExtras)
175 @implementation NSColor (MMExtras)
177 + (NSColor *)colorWithRgbInt:(unsigned)rgb
179 float r = ((rgb>>16) & 0xff)/255.0f;
180 float g = ((rgb>>8) & 0xff)/255.0f;
181 float b = (rgb & 0xff)/255.0f;
183 return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:1.0f];
186 + (NSColor *)colorWithArgbInt:(unsigned)argb
188 float a = ((argb>>24) & 0xff)/255.0f;
189 float r = ((argb>>16) & 0xff)/255.0f;
190 float g = ((argb>>8) & 0xff)/255.0f;
191 float b = (argb & 0xff)/255.0f;
193 return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:a];
196 @end // NSColor (MMExtras)
201 @implementation NSDictionary (MMExtras)
203 + (id)dictionaryWithData:(NSData *)data
205 id plist = [NSPropertyListSerialization
206 propertyListFromData:data
207 mutabilityOption:NSPropertyListImmutable
209 errorDescription:NULL];
211 return [plist isKindOfClass:[NSDictionary class]] ? plist : nil;
214 - (NSData *)dictionaryAsData
216 return [NSPropertyListSerialization dataFromPropertyList:self
217 format:NSPropertyListBinaryFormat_v1_0 errorDescription:NULL];
225 @implementation NSMutableDictionary (MMExtras)
227 + (id)dictionaryWithData:(NSData *)data
229 id plist = [NSPropertyListSerialization
230 propertyListFromData:data
231 mutabilityOption:NSPropertyListMutableContainers
233 errorDescription:NULL];
235 return [plist isKindOfClass:[NSMutableDictionary class]] ? plist : nil;