* Headers/Additions/GNUstepGUI/GSModelLoaderFactory.h,

* Source/GSModelLoaderFactory.m: Add new method +supportedTypes.
* Source/NSBundleAdditions.m: Use this new method to implement
  NIB resource detection on top of the base methods instead of doing
  it here.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@37421 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2013-12-01 12:26:12 +00:00
parent 46d7887140
commit 3ad5c33813
4 changed files with 61 additions and 45 deletions

View file

@ -1,3 +1,10 @@
2013-12-01 Fred Kiefer <FredKiefer@gmx.de>
* Headers/Additions/GNUstepGUI/GSModelLoaderFactory.h,
* Source/GSModelLoaderFactory.m: Add new method +supportedTypes.
* Source/NSBundleAdditions.m: Use this new method to implement NIB
resource detection on top of the base methods instead of doing it here.
2013-11-24 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSGradient.m: Rearrange code to avoid duplicate

View file

@ -32,6 +32,7 @@
#import <Foundation/NSObject.h>
#import <Foundation/NSZone.h>
@class NSArray;
@class NSData;
@class NSDictionary;
@class NSString;
@ -51,10 +52,11 @@
@interface GSModelLoaderFactory : NSObject
+ (void) registerModelLoaderClass: (Class)aClass;
+ (Class)classForType: (NSString *)type;
+ (Class) classForType: (NSString *)type;
+ (NSArray *) supportedTypes;
+ (NSString *) supportedModelFileAtPath: (NSString *)modelPath;
+ (GSModelLoader *)modelLoaderForFileType: (NSString *)type;
+ (GSModelLoader *)modelLoaderForFileName: (NSString *)modelPath;
+ (GSModelLoader *) modelLoaderForFileType: (NSString *)type;
+ (GSModelLoader *) modelLoaderForFileName: (NSString *)modelPath;
@end
#endif

View file

@ -130,6 +130,23 @@ static NSMutableDictionary *_modelMap = nil;
return [_modelMap objectForKey: type];
}
+ (NSArray *) supportedTypes
{
NSArray *objectArray = [_modelMap allValues];
NSArray *sortedArray = [objectArray sortedArrayUsingSelector:
@selector(_comparePriority:)];
NSEnumerator *oen = [sortedArray objectEnumerator];
Class cls = nil;
NSMutableArray *types = [[NSMutableArray alloc] init];
while ((cls = [oen nextObject]) != nil)
{
[types addObject: [cls type]];
}
return AUTORELEASE(types);
}
+ (NSString *) supportedModelFileAtPath: (NSString *)modelPath
{
NSString *result = nil;
@ -168,7 +185,7 @@ static NSMutableDictionary *_modelMap = nil;
return result;
}
+ (GSModelLoader *)modelLoaderForFileType: (NSString *)type
+ (GSModelLoader *) modelLoaderForFileType: (NSString *)type
{
Class aClass = [GSModelLoaderFactory classForType: type];
GSModelLoader *loader = nil;
@ -186,7 +203,7 @@ static NSMutableDictionary *_modelMap = nil;
return loader;
}
+ (GSModelLoader *)modelLoaderForFileName: (NSString *)modelPath
+ (GSModelLoader *) modelLoaderForFileName: (NSString *)modelPath
{
NSString *path = [GSModelLoaderFactory supportedModelFileAtPath: modelPath];
GSModelLoader *result = nil;

View file

@ -34,6 +34,7 @@
#import <Foundation/NSArray.h>
#import <Foundation/NSBundle.h>
#import <Foundation/NSCoder.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSException.h>
@ -281,53 +282,42 @@
- (NSString *) pathForNibResource: (NSString *)fileName
{
NSMutableArray *array = [NSMutableArray arrayWithCapacity: 8];
NSArray *languages;
NSString *rootPath = [self bundlePath];
NSString *primary;
NSString *language;
NSEnumerator *enumerator;
NSEnumerator *enumerator;
NSArray *types = [GSModelLoaderFactory supportedTypes];
NSString *ext = [fileName pathExtension];
languages = [[NSUserDefaults standardUserDefaults]
stringArrayForKey: @"NSLanguages"];
/*
* Build an array of resource paths that differs from the normal order -
* we want a localized file in preference to a generic one.
*/
primary = [rootPath stringByAppendingPathComponent: @"Resources"];
enumerator = [languages objectEnumerator];
while ((language = [enumerator nextObject]))
NSDebugLLog(@"NIB", @"Path for NIB file %@", fileName);
if ((ext == nil) || [ext isEqualToString:@""])
{
NSString *langDir;
NSString *type;
langDir = [NSString stringWithFormat: @"%@.lproj", language];
[array addObject: [primary stringByAppendingPathComponent: langDir]];
enumerator = [types objectEnumerator];
while ((type = [enumerator nextObject]))
{
NSDebugLLog(@"NIB", @"Checking type %@", fileName);
NSString *path = [self pathForResource: fileName
ofType: type];
if (path != nil)
{
return path;
}
}
}
[array addObject: primary];
primary = rootPath;
enumerator = [languages objectEnumerator];
while ((language = [enumerator nextObject]))
else
{
NSString *langDir;
langDir = [NSString stringWithFormat: @"%@.lproj", language];
[array addObject: [primary stringByAppendingPathComponent: langDir]];
}
[array addObject: primary];
enumerator = [array objectEnumerator];
while ((rootPath = [enumerator nextObject]) != nil)
{
NSString *modelPath = [rootPath stringByAppendingPathComponent: fileName];
NSString *path = [GSModelLoaderFactory supportedModelFileAtPath: modelPath];
if (path != nil)
{
return path;
}
if ([types containsObject: ext])
{
NSString *path = [self pathForResource:
[fileName stringByDeletingPathExtension]
ofType: ext];
if (path != nil)
{
return path;
}
}
}
NSDebugLLog(@"NIB", @"Did not find NIB resource %@", fileName);
return nil;
}