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",
35 "SetTextDimensionsReplyMsgID",
36 "SetWindowTitleMsgID",
44 "RemoveMenuItemMsgID",
45 "EnableMenuItemMsgID",
49 "CreateScrollbarMsgID",
50 "DestroyScrollbarMsgID",
52 "SetScrollbarPositionMsgID",
53 "SetScrollbarThumbMsgID",
54 "ScrollbarEventMsgID",
57 "VimShouldCloseMsgID",
58 "SetDefaultColorsMsgID",
67 "AdjustLinespaceMsgID",
70 "EnterFullscreenMsgID",
71 "LeaveFullscreenMsgID",
72 "BuffersNotModifiedMsgID",
73 "BuffersModifiedMsgID",
75 "SetPreEditPositionMsgID",
78 "EnableAntialiasMsgID",
79 "DisableAntialiasMsgID",
81 "SetDocumentFilenameMsgID",
82 "OpenWithArgumentsMsgID",
85 "SetFullscreenColorMsgID",
86 "ShowFindReplaceDialogMsgID",
93 // Argument used to stop MacVim from opening an empty window on startup
94 // (techincally this is a user default but should not be used as such).
95 NSString *MMNoWindowKey = @"MMNoWindow";
97 // Vim pasteboard type (holds motion type + string)
98 NSString *VimPBoardType = @"VimPBoardType";
106 // This loads all fonts from the Resources folder. The fonts are only
107 // available to the process which loaded them, so loading has to be done
108 // once for MacVim and an additional time for each Vim process. The
109 // returned container ref should be used to deactiave the font.
111 // (Code taken from cocoadev.com)
112 ATSFontContainerRef fontContainerRef = 0;
113 NSString *fontsFolder = [[NSBundle mainBundle] resourcePath];
115 NSURL *fontsURL = [NSURL fileURLWithPath:fontsFolder];
119 CFURLGetFSRef((CFURLRef)fontsURL, &fsRef);
121 if (FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &fsSpec,
123 ATSFontActivateFromFileSpecification(&fsSpec,
124 kATSFontContextLocal, kATSFontFormatUnspecified, NULL,
125 kATSOptionFlagsDefault, &fontContainerRef);
130 return fontContainerRef;
136 @implementation NSString (MMExtras)
138 - (NSString *)stringByEscapingSpecialFilenameCharacters
140 // NOTE: This code assumes that no characters already have been escaped.
141 NSMutableString *string = [self mutableCopy];
143 [string replaceOccurrencesOfString:@"\\"
145 options:NSLiteralSearch
146 range:NSMakeRange(0, [string length])];
147 [string replaceOccurrencesOfString:@" "
149 options:NSLiteralSearch
150 range:NSMakeRange(0, [string length])];
151 [string replaceOccurrencesOfString:@"\t"
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])];
167 [string replaceOccurrencesOfString:@"\""
169 options:NSLiteralSearch
170 range:NSMakeRange(0, [string length])];
172 return [string autorelease];
175 @end // NSString (MMExtras)
179 @implementation NSColor (MMExtras)
181 + (NSColor *)colorWithRgbInt:(unsigned)rgb
183 float r = ((rgb>>16) & 0xff)/255.0f;
184 float g = ((rgb>>8) & 0xff)/255.0f;
185 float b = (rgb & 0xff)/255.0f;
187 return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:1.0f];
190 + (NSColor *)colorWithArgbInt:(unsigned)argb
192 float a = ((argb>>24) & 0xff)/255.0f;
193 float r = ((argb>>16) & 0xff)/255.0f;
194 float g = ((argb>>8) & 0xff)/255.0f;
195 float b = (argb & 0xff)/255.0f;
197 return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:a];
200 @end // NSColor (MMExtras)
205 @implementation NSDictionary (MMExtras)
207 + (id)dictionaryWithData:(NSData *)data
209 id plist = [NSPropertyListSerialization
210 propertyListFromData:data
211 mutabilityOption:NSPropertyListImmutable
213 errorDescription:NULL];
215 return [plist isKindOfClass:[NSDictionary class]] ? plist : nil;
218 - (NSData *)dictionaryAsData
220 return [NSPropertyListSerialization dataFromPropertyList:self
221 format:NSPropertyListBinaryFormat_v1_0 errorDescription:NULL];
229 @implementation NSMutableDictionary (MMExtras)
231 + (id)dictionaryWithData:(NSData *)data
233 id plist = [NSPropertyListSerialization
234 propertyListFromData:data
235 mutabilityOption:NSPropertyListMutableContainers
237 errorDescription:NULL];
239 return [plist isKindOfClass:[NSMutableDictionary class]] ? plist : nil;