Author: mlytwyn Date: Thu Dec 22 21:56:31 2016 New Revision: 40278 URL: http://svn.gna.org/viewcvs/gnustep?rev=40278&view=rev Log: Cleanup NSCursor/NSImage subtitution code for hardcoded Xcode images in XIBs
Modified: libs/gui/branches/gnustep_testplant_branch/Source/NSCursor.m libs/gui/branches/gnustep_testplant_branch/Source/NSImage.m Modified: libs/gui/branches/gnustep_testplant_branch/Source/NSCursor.m URL: http://svn.gna.org/viewcvs/gnustep/libs/gui/branches/gnustep_testplant_branch/Source/NSCursor.m?rev=40278&r1=40277&r2=40278&view=diff ============================================================================== --- libs/gui/branches/gnustep_testplant_branch/Source/NSCursor.m (original) +++ libs/gui/branches/gnustep_testplant_branch/Source/NSCursor.m Thu Dec 22 21:56:31 2016 @@ -40,6 +40,11 @@ #import "AppKit/NSBitmapImageRep.h" #import "GNUstepGUI/GSDisplayServer.h" + +@interface NSImage (Private) ++ (NSDictionary *)_XcodeImageMappings; ++ (NSArray *)_XcodeImagePaths; +@end // Class variables static NSMutableArray *gnustep_gui_cursor_stack; @@ -608,7 +613,7 @@ DESTROY(self); if ([aDecoder containsValueForKey: @"NSCursorType"]) { - int type = [aDecoder decodeIntForKey: @"NSCursorType"]; + int type = [aDecoder decodeIntForKey: @"NSCursorType"]; switch (type) { @@ -666,7 +671,7 @@ break; } RETAIN(self); - } + } else { NSPoint hotSpot = NSMakePoint(0, 0); @@ -682,20 +687,31 @@ } // Testplant-MAL-2015-06-26: Keeping testplant fixes... - if ([[image name] isEqualToString:@"file://localhost/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Resources/DVTIbeamCursor.tiff"]) - { - NSDebugLog(@"An NSCursor object was encoded with the image " - @"file://localhost/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Resources/DVTIbeamCursor.tiff. " - @"This cursor was automatically substituted with [NSCursor IBeamCursor]."); - - [image setName:nil]; - self = RETAIN([NSCursor IBeamCursor]); - } - else - { - self = [[NSCursor alloc] initWithImage: image - hotSpot: hotSpot]; - } + if ([[NSImage _XcodeImagePaths] containsObject:[image name]]) + { + NSString *selectorName = [[NSImage _XcodeImageMappings] objectForKey:[image name]]; + SEL selector = NSSelectorFromString(selectorName); + + if (selector == NULL) + { + NSDebugLog(@"An NSCursor object was encoded with the image %@ which was not automatically substituted with NSCursor substitute due to missing selector: %@.", [image name], selectorName); + } + else + { + NSDebugLog(@"An NSCursor object was encoded with the image %@. This cursor was automatically substituted with NSCursor substitute (%@).", [image name], selectorName); + + self = RETAIN([NSCursor performSelector:selector]); + [image setName:nil]; + } + } + else if (image == nil) + { + NSLog(@"%s:NSCursor object was encoded with image which was not found", __PRETTY_FUNCTION__); + } + else + { + self = [[NSCursor alloc] initWithImage: image hotSpot: hotSpot]; + } } } else Modified: libs/gui/branches/gnustep_testplant_branch/Source/NSImage.m URL: http://svn.gna.org/viewcvs/gnustep/libs/gui/branches/gnustep_testplant_branch/Source/NSImage.m?rev=40278&r1=40277&r2=40278&view=diff ============================================================================== --- libs/gui/branches/gnustep_testplant_branch/Source/NSImage.m (original) +++ libs/gui/branches/gnustep_testplant_branch/Source/NSImage.m Thu Dec 22 21:56:31 2016 @@ -394,6 +394,8 @@ static NSArray *iterate_reps_for_types(NSArray *imageReps, SEL method); +static NSDictionary *_XcodeImageMappings = nil; + /* Find the GSRepData object holding a representation */ static GSRepData* repd_for_rep(NSArray *_reps, NSImageRep *rep) @@ -418,6 +420,8 @@ @interface NSImage (Private) + (void) _clearFileTypeCaches: (NSNotification*)notif; + (void) _reloadCachedImages; ++ (NSArray*) _XcodeImagePaths; ++ (NSDictionary*) _XcodeImageMappings; - (BOOL) _useFromFile: (NSString *)fileName; - (BOOL) _loadFromData: (NSData *)data; - (BOOL) _loadFromFile: (NSString *)fileName; @@ -439,7 +443,18 @@ // Initial version [self setVersion: 1]; - + + { + if (_XcodeImageMappings == nil) + { + @synchronized([self class]) + { + _XcodeImageMappings = @{ @"file://localhost/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Resources/DVTIbeamCursor.tiff" : @"IBeamCursor" }; + RETAIN(_XcodeImageMappings); + } + } + } + // initialize the class variables nameDict = [[NSMutableDictionary alloc] initWithCapacity: 10]; path = [NSBundle pathForLibraryResource: @"nsmapping" @@ -2025,26 +2040,33 @@ if (rep == nil) { // Testplant-MAL-10042016: keeping branch code... - NSString *fileName = [[tmp absoluteString] lastPathComponent]; - NSString *path = [[NSBundle mainBundle] pathForImageResource: fileName]; - rep = [NSImageRep imageRepWithContentsOfFile: path]; - - // This hack is a workaround on the issue where Xcode is including its cursor image - // on NSTextView's scroll view: We set the name of the image so we can catch it - // in the NSCursor's initWithCoder: - if ([[tmp absoluteString] isEqualToString:@"file://localhost/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Resources/DVTIbeamCursor.tiff"]) - { - [self setName:[tmp absoluteString]]; - } - else if ([[tmp absoluteString] rangeOfString:@"/Xcode.app/"].length > 0 - || [[tmp absoluteString] rangeOfString:@"/DVTKit.framework/"].length > 0) - { - NSDebugLog (@"WARNING: Decoding image with absolute path %@." - @" Xcode may have inserted this in your XIB and the" - @" image may not be available in the app's resources" - , [tmp absoluteString]); - } - + // This hack is a workaround on the issue where Xcode is including its cursor image + // on NSTextView's scroll view: We set the name of the image so we can catch it + // in the NSCursor's initWithCoder: + NSString *filePath = [tmp absoluteString]; + NSString *fileName = [filePath lastPathComponent]; + NSString *path = [[NSBundle mainBundle] pathForImageResource: fileName]; + + // Check Xcode known hard-encoded image references... + if (path == nil) + { + if ([[[self class] _XcodeImagePaths] containsObject:filePath]) + { + [self setName:[tmp absoluteString]]; + } + else if (([filePath rangeOfString:@"/Xcode.app/"].length > 0) || + ([filePath rangeOfString:@"/DVTKit.framework/"].length > 0)) + { + NSDebugLog (@"WARNING: Decoding image with absolute path %@." + @" Xcode may have inserted this in your XIB and the" + @" image may not be available in the app's resources" + , [tmp absoluteString]); + } + } + else + { + rep = [NSImageRep imageRepWithContentsOfFile: path]; + } } // If the representation was found, add it... @@ -2300,6 +2322,16 @@ [self addRepresentation: image]; } return ok; +} + ++ (NSArray *)_XcodeImagePaths +{ + return [_XcodeImageMappings allKeys]; +} + ++ (NSDictionary *)_XcodeImageMappings +{ + return _XcodeImageMappings; } - (BOOL) _loadFromFile: (NSString *)fileName _______________________________________________ Gnustep-cvs mailing list Gnustep-cvs@gna.org https://mail.gna.org/listinfo/gnustep-cvs