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",
90 // Argument used to stop MacVim from opening an empty window on startup
91 // (techincally this is a user default but should not be used as such).
92 NSString *MMNoWindowKey = @"MMNoWindow";
94 // Vim pasteboard type (holds motion type + string)
95 NSString *VimPBoardType = @"VimPBoardType";
103 // This loads all fonts from the Resources folder. The fonts are only
104 // available to the process which loaded them, so loading has to be done
105 // once for MacVim and an additional time for each Vim process. The
106 // returned container ref should be used to deactiave the font.
108 // (Code taken from cocoadev.com)
109 ATSFontContainerRef fontContainerRef = 0;
110 NSString *fontsFolder = [[NSBundle mainBundle] resourcePath];
112 NSURL *fontsURL = [NSURL fileURLWithPath:fontsFolder];
116 CFURLGetFSRef((CFURLRef)fontsURL, &fsRef);
118 if (FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &fsSpec,
120 ATSFontActivateFromFileSpecification(&fsSpec,
121 kATSFontContextLocal, kATSFontFormatUnspecified, NULL,
122 kATSOptionFlagsDefault, &fontContainerRef);
127 return fontContainerRef;
133 @implementation NSString (MMExtras)
135 - (NSString *)stringByEscapingSpecialFilenameCharacters
137 // NOTE: This code assumes that no characters already have been escaped.
138 NSMutableString *string = [self mutableCopy];
140 [string replaceOccurrencesOfString:@"\\"
142 options:NSLiteralSearch
143 range:NSMakeRange(0, [string length])];
144 [string replaceOccurrencesOfString:@" "
146 options:NSLiteralSearch
147 range:NSMakeRange(0, [string length])];
148 [string replaceOccurrencesOfString:@"\t"
150 options:NSLiteralSearch
151 range:NSMakeRange(0, [string length])];
152 [string replaceOccurrencesOfString:@"%"
154 options:NSLiteralSearch
155 range:NSMakeRange(0, [string length])];
156 [string replaceOccurrencesOfString:@"#"
158 options:NSLiteralSearch
159 range:NSMakeRange(0, [string length])];
160 [string replaceOccurrencesOfString:@"|"
162 options:NSLiteralSearch
163 range:NSMakeRange(0, [string length])];
164 [string replaceOccurrencesOfString:@"\""
166 options:NSLiteralSearch
167 range:NSMakeRange(0, [string length])];
169 return [string autorelease];
172 @end // NSString (MMExtras)
176 @implementation NSColor (MMExtras)
178 + (NSColor *)colorWithRgbInt:(unsigned)rgb
180 float r = ((rgb>>16) & 0xff)/255.0f;
181 float g = ((rgb>>8) & 0xff)/255.0f;
182 float b = (rgb & 0xff)/255.0f;
184 return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:1.0f];
187 + (NSColor *)colorWithArgbInt:(unsigned)argb
189 float a = ((argb>>24) & 0xff)/255.0f;
190 float r = ((argb>>16) & 0xff)/255.0f;
191 float g = ((argb>>8) & 0xff)/255.0f;
192 float b = (argb & 0xff)/255.0f;
194 return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:a];
197 @end // NSColor (MMExtras)
202 @implementation NSDictionary (MMExtras)
204 + (id)dictionaryWithData:(NSData *)data
206 id plist = [NSPropertyListSerialization
207 propertyListFromData:data
208 mutabilityOption:NSPropertyListImmutable
210 errorDescription:NULL];
212 return [plist isKindOfClass:[NSDictionary class]] ? plist : nil;
215 - (NSData *)dictionaryAsData
217 return [NSPropertyListSerialization dataFromPropertyList:self
218 format:NSPropertyListBinaryFormat_v1_0 errorDescription:NULL];
226 @implementation NSMutableDictionary (MMExtras)
228 + (id)dictionaryWithData:(NSData *)data
230 id plist = [NSPropertyListSerialization
231 propertyListFromData:data
232 mutabilityOption:NSPropertyListMutableContainers
234 errorDescription:NULL];
236 return [plist isKindOfClass:[NSMutableDictionary class]] ? plist : nil;