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",
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";
102 @implementation NSString (MMExtras)
104 - (NSString *)stringByEscapingSpecialFilenameCharacters
106 // NOTE: This code assumes that no characters already have been escaped.
107 NSMutableString *string = [self mutableCopy];
109 [string replaceOccurrencesOfString:@"\\"
111 options:NSLiteralSearch
112 range:NSMakeRange(0, [string length])];
113 [string replaceOccurrencesOfString:@" "
115 options:NSLiteralSearch
116 range:NSMakeRange(0, [string length])];
117 [string replaceOccurrencesOfString:@"\t"
119 options:NSLiteralSearch
120 range:NSMakeRange(0, [string length])];
121 [string replaceOccurrencesOfString:@"%"
123 options:NSLiteralSearch
124 range:NSMakeRange(0, [string length])];
125 [string replaceOccurrencesOfString:@"#"
127 options:NSLiteralSearch
128 range:NSMakeRange(0, [string length])];
129 [string replaceOccurrencesOfString:@"|"
131 options:NSLiteralSearch
132 range:NSMakeRange(0, [string length])];
133 [string replaceOccurrencesOfString:@"\""
135 options:NSLiteralSearch
136 range:NSMakeRange(0, [string length])];
138 return [string autorelease];
141 @end // NSString (MMExtras)
145 @implementation NSColor (MMExtras)
147 + (NSColor *)colorWithRgbInt:(unsigned)rgb
149 float r = ((rgb>>16) & 0xff)/255.0f;
150 float g = ((rgb>>8) & 0xff)/255.0f;
151 float b = (rgb & 0xff)/255.0f;
153 return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:1.0f];
156 + (NSColor *)colorWithArgbInt:(unsigned)argb
158 float a = ((argb>>24) & 0xff)/255.0f;
159 float r = ((argb>>16) & 0xff)/255.0f;
160 float g = ((argb>>8) & 0xff)/255.0f;
161 float b = (argb & 0xff)/255.0f;
163 return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:a];
166 @end // NSColor (MMExtras)
171 @implementation NSDictionary (MMExtras)
173 + (id)dictionaryWithData:(NSData *)data
175 id plist = [NSPropertyListSerialization
176 propertyListFromData:data
177 mutabilityOption:NSPropertyListImmutable
179 errorDescription:NULL];
181 return [plist isKindOfClass:[NSDictionary class]] ? plist : nil;
184 - (NSData *)dictionaryAsData
186 return [NSPropertyListSerialization dataFromPropertyList:self
187 format:NSPropertyListBinaryFormat_v1_0 errorDescription:NULL];
195 @implementation NSMutableDictionary (MMExtras)
197 + (id)dictionaryWithData:(NSData *)data
199 id plist = [NSPropertyListSerialization
200 propertyListFromData:data
201 mutabilityOption:NSPropertyListMutableContainers
203 errorDescription:NULL];
205 return [plist isKindOfClass:[NSMutableDictionary class]] ? plist : nil;