comparison src/os_macosx.m @ 14091:616dc84228b7 v8.1.0063

patch 8.1.0063: Mac: NSStringPboardType is deprecated commit https://github.com/vim/vim/commit/d595a1910c5672808e44afa028e253e47f03651f Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 17 15:01:04 2018 +0200 patch 8.1.0063: Mac: NSStringPboardType is deprecated Problem: Mac: NSStringPboardType is deprecated. Solution: Use NSPasteboardTypeString. (Akshay Hegde, closes https://github.com/vim/vim/issues/3022)
author Christian Brabandt <cb@256bit.org>
date Sun, 17 Jun 2018 15:15:05 +0200
parents f80abb797a32
children 73162bc0b21f
comparison
equal deleted inserted replaced
14090:42f2385f014a 14091:616dc84228b7
61 clip_mch_request_selection(VimClipboard *cbd) 61 clip_mch_request_selection(VimClipboard *cbd)
62 { 62 {
63 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 63 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
64 64
65 NSPasteboard *pb = [NSPasteboard generalPasteboard]; 65 NSPasteboard *pb = [NSPasteboard generalPasteboard];
66 #ifdef AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
67 NSArray *supportedTypes = [NSArray arrayWithObjects:VimPboardType,
68 NSPasteboardTypeString, nil];
69 #else
66 NSArray *supportedTypes = [NSArray arrayWithObjects:VimPboardType, 70 NSArray *supportedTypes = [NSArray arrayWithObjects:VimPboardType,
67 NSStringPboardType, nil]; 71 NSStringPboardType, nil];
72 #endif
68 NSString *bestType = [pb availableTypeFromArray:supportedTypes]; 73 NSString *bestType = [pb availableTypeFromArray:supportedTypes];
69 if (!bestType) goto releasepool; 74 if (!bestType) goto releasepool;
70 75
71 int motion_type = MAUTO; 76 int motion_type = MAUTO;
72 NSString *string = nil; 77 NSString *string = nil;
74 if ([bestType isEqual:VimPboardType]) 79 if ([bestType isEqual:VimPboardType])
75 { 80 {
76 /* This type should consist of an array with two objects: 81 /* This type should consist of an array with two objects:
77 * 1. motion type (NSNumber) 82 * 1. motion type (NSNumber)
78 * 2. text (NSString) 83 * 2. text (NSString)
79 * If this is not the case we fall back on using NSStringPboardType. 84 * If this is not the case we fall back on using NSPasteboardTypeString.
80 */ 85 */
81 id plist = [pb propertyListForType:VimPboardType]; 86 id plist = [pb propertyListForType:VimPboardType];
82 if ([plist isKindOfClass:[NSArray class]] && [plist count] == 2) 87 if ([plist isKindOfClass:[NSArray class]] && [plist count] == 2)
83 { 88 {
84 id obj = [plist objectAtIndex:1]; 89 id obj = [plist objectAtIndex:1];
90 } 95 }
91 } 96 }
92 97
93 if (!string) 98 if (!string)
94 { 99 {
95 /* Use NSStringPboardType. The motion type is detected automatically. 100 /* Use NSPasteboardTypeString. The motion type is detected automatically.
96 */ 101 */
102 #ifdef AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
103 NSMutableString *mstring =
104 [[pb stringForType:NSPasteboardTypeString] mutableCopy];
105 #else
97 NSMutableString *mstring = 106 NSMutableString *mstring =
98 [[pb stringForType:NSStringPboardType] mutableCopy]; 107 [[pb stringForType:NSStringPboardType] mutableCopy];
108 #endif
99 if (!mstring) goto releasepool; 109 if (!mstring) goto releasepool;
100 110
101 /* Replace unrecognized end-of-line sequences with \x0a (line feed). */ 111 /* Replace unrecognized end-of-line sequences with \x0a (line feed). */
102 NSRange range = { 0, [mstring length] }; 112 NSRange range = { 0, [mstring length] };
103 unsigned n = [mstring replaceOccurrencesOfString:@"\x0d\x0a" 113 unsigned n = [mstring replaceOccurrencesOfString:@"\x0d\x0a"
176 NSString *string = [[NSString alloc] 186 NSString *string = [[NSString alloc]
177 initWithBytes:str length:len encoding:NSUTF8StringEncoding]; 187 initWithBytes:str length:len encoding:NSUTF8StringEncoding];
178 188
179 /* See clip_mch_request_selection() for info on pasteboard types. */ 189 /* See clip_mch_request_selection() for info on pasteboard types. */
180 NSPasteboard *pb = [NSPasteboard generalPasteboard]; 190 NSPasteboard *pb = [NSPasteboard generalPasteboard];
191 #ifdef AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
192 NSArray *supportedTypes = [NSArray arrayWithObjects:VimPboardType,
193 NSPasteboardTypeString, nil];
194 #else
181 NSArray *supportedTypes = [NSArray arrayWithObjects:VimPboardType, 195 NSArray *supportedTypes = [NSArray arrayWithObjects:VimPboardType,
182 NSStringPboardType, nil]; 196 NSStringPboardType, nil];
197 #endif
183 [pb declareTypes:supportedTypes owner:nil]; 198 [pb declareTypes:supportedTypes owner:nil];
184 199
185 NSNumber *motion = [NSNumber numberWithInt:motion_type]; 200 NSNumber *motion = [NSNumber numberWithInt:motion_type];
186 NSArray *plist = [NSArray arrayWithObjects:motion, string, nil]; 201 NSArray *plist = [NSArray arrayWithObjects:motion, string, nil];
187 [pb setPropertyList:plist forType:VimPboardType]; 202 [pb setPropertyList:plist forType:VimPboardType];
188 203
204 #ifdef AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
205 [pb setString:string forType:NSPasteboardTypeString];
206 #else
189 [pb setString:string forType:NSStringPboardType]; 207 [pb setString:string forType:NSStringPboardType];
208 #endif
190 209
191 [string release]; 210 [string release];
192 } 211 }
193 212
194 vim_free(str); 213 vim_free(str);