* Source/GSXibLoader.m: Add _preProcessXib: method to perform

custom class substitutions when loading a XIB file.
	* Source/GSXibLoading.m: Add stub classes for IBNSLayoutConstraint
	and IBNSLayoutConstant so that these can now be loaded.



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@35482 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2012-08-31 16:27:06 +00:00
parent 09915b2bb3
commit 58c33f3dce
3 changed files with 122 additions and 3 deletions

View file

@ -1,3 +1,10 @@
2012-08-31 12:09-EDT Gregory John Casamento <greg.casamento@gmail.com>
* Source/GSXibLoader.m: Add _preProcessXib: method to perform
custom class substitutions when loading a XIB file.
* Source/GSXibLoading.m: Add stub classes for IBNSLayoutConstraint
and IBNSLayoutConstant so that these can now be loaded.
2012-08-27 11:44-EDT Gregory John Casamento <greg.casamento@gmail.com>
* Headers/AppKit/NSTabViewItem.h: Add _toolTip ivar.

View file

@ -35,6 +35,8 @@
#import <Foundation/NSString.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSXMLParser.h>
#import <Foundation/NSXMLDocument.h>
#import <Foundation/NSXMLElement.h>
#import <GNUstepBase/GSMime.h>
#import "AppKit/NSApplication.h"
@ -571,6 +573,15 @@
return objectID;
}
- (NSString *) description
{
return [NSString stringWithFormat: @"<%@, %@, %@, %d>",
[self className],
object,
parent,
objectID];
}
@end
@implementation IBMutableOrderedSet
@ -1018,15 +1029,84 @@
@implementation GSXibKeyedUnarchiver
- (NSData *) _preProcessXib: (NSData *)data
{
NSData *result = nil;
NSXMLDocument *document = [[NSXMLDocument alloc] initWithData:data
options:0
error:NULL];
if(document != nil)
{
NSArray *customClassNodes = [document nodesForXPath:@"//dictionary[@key=\"flattenedProperties\"]/"
@"string[contains(@key,\"CustomClassName\")]"
error:NULL];
if([customClassNodes count] > 0)
{
NSArray *objectRecords = nil;
NSEnumerator *en = [customClassNodes objectEnumerator];
id node = nil;
while((node = [en nextObject]) != nil)
{
NSXMLNode *keyNode = [node attributeForName:@"key"];
NSString *keyValue = [[keyNode stringValue] stringByReplacingOccurrencesOfString:@".CustomClassName"
withString:@""];
NSString *className = [node stringValue];
NSString *objectRecordXpath = nil;
objectRecordXpath = [NSString stringWithFormat:@"//object[@class=\"IBObjectRecord\"]/"
@"int[@key=\"objectID\"][text()=\"%@\"]/../reference",
keyValue];
objectRecords = [document nodesForXPath:objectRecordXpath
error:NULL];
NSString *refId = nil;
if([objectRecords count] > 0)
{
id record = nil;
en = [objectRecords objectEnumerator];
while((record = [en nextObject]) != nil)
{
if([[[record attributeForName:@"key"] stringValue] isEqualToString:@"object"])
{
NSArray *classNodes = nil;
id classNode = nil;
NSString *refXpath = nil;
refId = [[record attributeForName:@"ref"] stringValue];
// NSLog(@"Reference Id = %@",refId);
refXpath = [NSString stringWithFormat:@"//object[@id=\"%@\"]",refId];
classNodes = [document nodesForXPath:refXpath
error:NULL];
if([classNodes count] > 0)
{
classNode = [classNodes objectAtIndex:0];
// NSLog(@"%@",classNode);
[[classNode attributeForName:@"class"] setStringValue:className];
// NSLog(@"Changed %@",classNode);
result = [document XMLData];
}
}
}
}
}
}
}
return result;
}
- (id) initForReadingWithData: (NSData*)data
{
NSXMLParser *theParser;
NSData *theData = [self _preProcessXib: data];
objects = [[NSMutableDictionary alloc] init];
stack = [[NSMutableArray alloc] init];
decoded = [[NSMutableDictionary alloc] init];
theParser = [[NSXMLParser alloc] initWithData: data];
theParser = [[NSXMLParser alloc] initWithData: theData];
[theParser setDelegate: self];
NS_DURING
@ -1051,7 +1131,7 @@
DESTROY(objects);
DESTROY(stack);
DESTROY(decoded);
[super dealloc];
}
@ -1116,9 +1196,11 @@ didStartElement: (NSString*)elementName
- (id) allocObjectForClassName: (NSString*)classname
{
Class c = [self classForClassName: classname];
Class c = nil;
id delegate = [self delegate];
c = [self classForClassName: classname];
if (c == nil)
{
c = [[self class] classForClassName: classname];

View file

@ -22,6 +22,12 @@
@interface IBAccessibilityAttribute : NSObject <NSCoding>
@end
@interface IBNSLayoutConstraint : NSObject <NSCoding>
@end
@interface IBLayoutConstant : NSObject <NSCoding>
@end
@implementation IBUserDefinedRuntimeAttributesPlaceholder
- (void) encodeWithCoder: (NSCoder *)coder
@ -92,3 +98,27 @@
}
@end
@implementation IBNSLayoutConstraint
- (void) encodeWithCoder: (NSCoder *)coder
{
// Do nothing...
}
- (id) initWithCoder: (NSCoder *)coder
{
return self;
}
@end
@implementation IBLayoutConstant
- (void) encodeWithCoder: (NSCoder *)coder
{
// Do nothing...
}
- (id) initWithCoder: (NSCoder *)coder
{
return self;
}
@end