mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 13:10:59 +00:00
Merge branch 'master' into xib_gorm_integration
This commit is contained in:
commit
91fe895197
8 changed files with 169 additions and 22 deletions
24
ChangeLog
24
ChangeLog
|
@ -1,5 +1,4 @@
|
|||
<<<<<<< HEAD
|
||||
2021-04-25 Gregory John Casamento <greg.casamento@gmail.com>
|
||||
2021-05-01 Gregory John Casamento <greg.casamento@gmail.com>
|
||||
|
||||
* Headers/Additions/GNUstepGUI/GSXibLoading.h: Add declaration
|
||||
for customClassNames so that we can use that to collect the names
|
||||
|
@ -11,7 +10,25 @@
|
|||
* Source/GSXibLoading.m: Add in code in nibInstantiate which uses
|
||||
[NSClassSwapper isInInterfaceBuilder] to prevent connections
|
||||
from being established if the XIB is being loaded in IB/Gorm.
|
||||
=======
|
||||
|
||||
2021-04-30 Gregory John Casamento <greg.casamento@gmail.com>
|
||||
|
||||
* Headers/Additions/GNUstepGUI/GSModelLoaderFactory.h:
|
||||
Declaration of canReadData: in the GSModelLoader class and
|
||||
declaration of modelLoaderForData: in GSModelLoaderFactory.
|
||||
* Source/GSGModelLoader.m: Prototype method for canReadData:
|
||||
Implementation of modelLoaderForData:.
|
||||
* Source/GSGormLoader.m
|
||||
* Source/GSModelLoaderFactory.m
|
||||
* Source/GSNibLoader.m
|
||||
* Source/GSXibLoader.m: Implement -canReadData: method to
|
||||
determine for each loader if that loader can handle the data
|
||||
passed into it.
|
||||
* Source/NSNib.m: Use of [GSModelLoaderFactory modelLoaderForData:]
|
||||
to more generically implement methods that initialize an archive from
|
||||
archived data since we have no file extention to rely on to identify
|
||||
the archive contents.
|
||||
|
||||
2021-04-26 Ivan Vucica <ivan@vucica.net>
|
||||
|
||||
* ANNOUNCE:
|
||||
|
@ -21,7 +38,6 @@
|
|||
Updating documentation for the 0.29.0 release.
|
||||
* Version:
|
||||
Bumping requirement to gnustep-base 1.28.0.
|
||||
>>>>>>> cc6c371730d3f8835396041754713f8fbe0fbc2e
|
||||
|
||||
2021-04-23 Gregory John Casamento <greg.casamento@gmail.com>
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/** <title>NSBundleAdditions</title>
|
||||
/** <title>GSModelLoaderFactory</title>
|
||||
|
||||
<abstract>Implementation of NSBundle Additions</abstract>
|
||||
<abstract>Interface of GSModelLoader and GSModelLoaderFactory</abstract>
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
|
@ -39,6 +39,7 @@
|
|||
@class NSBundle;
|
||||
|
||||
@interface GSModelLoader : NSObject
|
||||
+ (BOOL) canReadData: (NSData *)theData;
|
||||
+ (NSString *) type;
|
||||
+ (float) priority;
|
||||
- (BOOL) loadModelData: (NSData *)data
|
||||
|
@ -57,6 +58,7 @@
|
|||
+ (NSString *) supportedModelFileAtPath: (NSString *)modelPath;
|
||||
+ (GSModelLoader *) modelLoaderForFileType: (NSString *)type;
|
||||
+ (GSModelLoader *) modelLoaderForFileName: (NSString *)modelPath;
|
||||
+ (GSModelLoader *) modelLoaderForData: (NSData *)theData;
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSBundle.h>
|
||||
#import <Foundation/NSDebug.h>
|
||||
#import <Foundation/NSData.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSEnumerator.h>
|
||||
#import <Foundation/NSException.h>
|
||||
|
@ -80,6 +81,33 @@ Class gmodel_class(void)
|
|||
// register for the gmodel type.
|
||||
}
|
||||
|
||||
+ (BOOL) canReadData: (NSData *)theData
|
||||
{
|
||||
char *header = calloc(1024, sizeof(char));
|
||||
|
||||
if (header != NULL)
|
||||
{
|
||||
NSUInteger len = [theData length];
|
||||
NSRange r = NSMakeRange(len - 1024, len - 1);
|
||||
NSString *hdr = nil;
|
||||
|
||||
[theData getBytes: header
|
||||
range: r];
|
||||
hdr = [[NSString alloc] initWithBytes: header
|
||||
length: 1024
|
||||
encoding: NSUTF8StringEncoding];
|
||||
AUTORELEASE(hdr);
|
||||
if ([hdr containsString: @"GMModel"])
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
free(header);
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (NSString *) type
|
||||
{
|
||||
return @"gmodel";
|
||||
|
@ -119,7 +147,7 @@ Class gmodel_class(void)
|
|||
if ([ext isEqualToString: @"gmodel"])
|
||||
{
|
||||
return [gmodel_class() loadIMFile: fileName
|
||||
owner: [context objectForKey: NSNibOwner]];
|
||||
owner: [context objectForKey: NSNibOwner]];
|
||||
}
|
||||
|
||||
return NO;
|
||||
|
|
|
@ -81,6 +81,26 @@
|
|||
}
|
||||
}
|
||||
|
||||
+ (BOOL) canReadData: (NSData *)theData
|
||||
{
|
||||
char *header = calloc(16, sizeof(char));
|
||||
|
||||
if (header != NULL)
|
||||
{
|
||||
[theData getBytes: header
|
||||
length: 16];
|
||||
|
||||
if (strncmp("GNUstep archive",header,15) == 0)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
free(header);
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (NSString *)type
|
||||
{
|
||||
return @"gorm";
|
||||
|
|
|
@ -38,6 +38,11 @@
|
|||
#import "GNUstepGUI/GSModelLoaderFactory.h"
|
||||
|
||||
@implementation GSModelLoader
|
||||
+ (BOOL) canReadData: (NSData *)theData
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (NSString *) type
|
||||
{
|
||||
return nil;
|
||||
|
@ -103,6 +108,7 @@
|
|||
static NSMutableDictionary *_modelMap = nil;
|
||||
|
||||
@implementation GSModelLoaderFactory
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
NSArray *classes = GSObjCAllSubclassesOfClass([GSModelLoader class]);
|
||||
|
@ -216,4 +222,23 @@ static NSMutableDictionary *_modelMap = nil;
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
+ (GSModelLoader *) modelLoaderForData: (NSData *)theData
|
||||
{
|
||||
NSEnumerator *oen = [_modelMap objectEnumerator];
|
||||
Class aClass = nil;
|
||||
GSModelLoader *result = nil;
|
||||
|
||||
while ((aClass = [oen nextObject]) != nil)
|
||||
{
|
||||
if ([aClass canReadData: theData])
|
||||
{
|
||||
result = AUTORELEASE([[aClass alloc] init]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -49,6 +49,39 @@
|
|||
// should do something...
|
||||
}
|
||||
|
||||
+ (BOOL) canReadData: (NSData *)theData
|
||||
{
|
||||
char *header = calloc(1024, sizeof(char));
|
||||
|
||||
if (header != NULL)
|
||||
{
|
||||
[theData getBytes: header
|
||||
length: 1024];
|
||||
|
||||
if (strncmp("bplist00",header,8) == 0)
|
||||
{
|
||||
free(header);
|
||||
return YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *hdr = [[NSString alloc] initWithBytes: header
|
||||
length: 1024
|
||||
encoding: NSUTF8StringEncoding];
|
||||
AUTORELEASE(hdr);
|
||||
if ([hdr containsString: @"NSKeyedArchiver"])
|
||||
{
|
||||
free(header);
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
free(header);
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (NSString *)type
|
||||
{
|
||||
return @"nib";
|
||||
|
|
|
@ -70,6 +70,31 @@
|
|||
|
||||
@implementation GSXibLoader
|
||||
|
||||
+ (BOOL) canReadData: (NSData *)theData
|
||||
{
|
||||
char *header = calloc(1024, sizeof(char));
|
||||
|
||||
if (header != NULL)
|
||||
{
|
||||
[theData getBytes: header
|
||||
length: 1024];
|
||||
|
||||
NSString *hdr = [[NSString alloc] initWithBytes: header
|
||||
length: 1024
|
||||
encoding: NSUTF8StringEncoding];
|
||||
AUTORELEASE(hdr);
|
||||
if ([hdr containsString: @"Cocoa.XIB"])
|
||||
{
|
||||
free(header);
|
||||
return YES;
|
||||
}
|
||||
|
||||
free(header);
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (NSString*) type
|
||||
{
|
||||
return @"xib";
|
||||
|
|
|
@ -150,8 +150,7 @@
|
|||
{
|
||||
ASSIGN(_bundle, bundle);
|
||||
ASSIGN(_nibData, nibData);
|
||||
// FIXME: Hardcode the most likely loader
|
||||
ASSIGN(_loader, [GSModelLoaderFactory modelLoaderForFileType: @"nib"]);
|
||||
ASSIGN(_loader, [GSModelLoaderFactory modelLoaderForData: nibData]);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -178,7 +177,7 @@
|
|||
- (BOOL) instantiateNibWithExternalNameTable: (NSDictionary *)externalNameTable
|
||||
{
|
||||
return [self instantiateNibWithExternalNameTable: externalNameTable
|
||||
withZone: NSDefaultMallocZone()];
|
||||
withZone: NSDefaultMallocZone()];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -198,7 +197,8 @@
|
|||
if (topLevelObjects != 0)
|
||||
{
|
||||
*topLevelObjects = [NSMutableArray array];
|
||||
[externalNameTable setObject: *topLevelObjects forKey: NSNibTopLevelObjects];
|
||||
[externalNameTable setObject: *topLevelObjects
|
||||
forKey: NSNibTopLevelObjects];
|
||||
}
|
||||
|
||||
return [self instantiateNibWithExternalNameTable: externalNameTable];
|
||||
|
@ -207,32 +207,30 @@
|
|||
- (BOOL) instantiateWithOwner: (id)owner
|
||||
topLevelObjects: (NSArray **)topLevelObjects
|
||||
{
|
||||
return [self instantiateNibWithOwner: owner topLevelObjects: topLevelObjects];
|
||||
return [self instantiateNibWithOwner: owner
|
||||
topLevelObjects: topLevelObjects];
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder *)coder
|
||||
{
|
||||
if ((self = [super init]) != nil)
|
||||
{
|
||||
//
|
||||
// NOTE: This is okay, since the only encodings which will ever be built into
|
||||
// the gui library are nib and gorm. GModel only supports certain
|
||||
// objects and is going to be deprecated in the future. There just so
|
||||
// happens to be a one to one correspondence here.
|
||||
//
|
||||
if ([coder allowsKeyedCoding])
|
||||
{
|
||||
// TODO_NIB: Need to verify this key...
|
||||
// TODO_NIB: Need to verify this key...
|
||||
ASSIGN(_nibData, [coder decodeObjectForKey: @"NSData"]);
|
||||
ASSIGN(_loader, [GSModelLoaderFactory modelLoaderForFileType: @"nib"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is sort of a kludge...
|
||||
[coder decodeValueOfObjCType: @encode(id)
|
||||
at: &_nibData];
|
||||
ASSIGN(_loader, [GSModelLoaderFactory modelLoaderForFileType: @"gorm"]);
|
||||
at: &_nibData];
|
||||
}
|
||||
|
||||
if (_nibData != nil)
|
||||
{
|
||||
ASSIGN(_loader, [GSModelLoaderFactory modelLoaderForData: _nibData]);
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue