mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 15:11:37 +00:00
Corrections to xib loading.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@35510 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
11a17a5165
commit
7da4d487ca
2 changed files with 131 additions and 47 deletions
|
@ -1,3 +1,11 @@
|
|||
2012-09-03 21:37-EDT Gregory John Casamento <greg.casamento@gmail.com>
|
||||
|
||||
* Source/GSXibLoader.m: Changes by Marcian Lyttwyn to correct
|
||||
issue with when a xib contains an array instead of a dictionary in
|
||||
flattenedProperties. Changes by myself to implement custom class
|
||||
cell support so that the cell class changes along with the
|
||||
control class when unarchiving.
|
||||
|
||||
2012-09-03 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||
|
||||
* Source/NSWindow.m (_screenForFrame:): Fix bug where this method
|
||||
|
@ -9,6 +17,7 @@
|
|||
* Source/GSToolTips.m (_timedOut:): Don't display the tooltip
|
||||
window (GSTTPanel) if the tooltip is nil or is an empty string.
|
||||
|
||||
>>>>>>> .r35509
|
||||
2012-09-02 13:56-EDT Gregory John Casamento <greg.casamento@gmail.com>
|
||||
|
||||
* Source/GSXibLoader.m: Correct issue with reuse of enumerator.
|
||||
|
|
|
@ -1035,61 +1035,136 @@
|
|||
NSXMLDocument *document = [[NSXMLDocument alloc] initWithData:data
|
||||
options:0
|
||||
error:NULL];
|
||||
if(document != nil)
|
||||
if(document == nil)
|
||||
{
|
||||
NSLog(@"%s:DOCUMENT IS NIL: %@\n", __PRETTY_FUNCTION__, document);
|
||||
}
|
||||
else
|
||||
{
|
||||
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;
|
||||
NSMutableDictionary *customClassDict = [NSMutableDictionary dictionary];
|
||||
if (customClassNodes)
|
||||
{
|
||||
NSDebugLLog(@"PREXIB", @"%s:customClassNodes: %@\n", __PRETTY_FUNCTION__, customClassNodes);
|
||||
|
||||
while((node = [en nextObject]) != nil)
|
||||
{
|
||||
NSXMLNode *keyNode = [node attributeForName:@"key"];
|
||||
NSString *keyValue = [[keyNode stringValue] stringByReplacingOccurrencesOfString:@".CustomClassName"
|
||||
withString:@""];
|
||||
NSString *className = [node stringValue];
|
||||
NSString *objectRecordXpath = nil;
|
||||
// Replace the NSXMLNodes with a dictionary...
|
||||
NSInteger index = 0;
|
||||
for (index = 0; index < [customClassNodes count]; ++index)
|
||||
{
|
||||
id node = [customClassNodes objectAtIndex:index];
|
||||
if ([node isMemberOfClass:[NSXMLElement class]])
|
||||
{
|
||||
NSString *key = [[node attributeForName:@"key"] stringValue];
|
||||
if ([key rangeOfString:@"CustomClassName"].location != NSNotFound)
|
||||
[customClassDict setObject:[node stringValue] forKey:key];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NSArray *flatProps = [document nodesForXPath:@"//object[@key=\"flattenedProperties\"]" error:NULL];
|
||||
if ([flatProps count] == 1)
|
||||
{
|
||||
NSInteger index = 0;
|
||||
NSArray *xmlKeys = [[flatProps objectAtIndex:0] nodesForXPath:@"//object[@key=\"flattenedProperties\"]/object[@key=\"dict.sortedKeys\"]/*" error:NULL];
|
||||
NSArray *xmlObjs = [[flatProps objectAtIndex:0] nodesForXPath:@"//object[@key=\"flattenedProperties\"]/object[@key=\"dict.values\"]/*" error:NULL];
|
||||
if ([xmlKeys count] != [xmlObjs count])
|
||||
{
|
||||
NSLog(@"%s:keys to objs count mismatch - keys: %d objs: %d\n", __PRETTY_FUNCTION__,
|
||||
[xmlKeys count], [xmlObjs count]);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (index = 0; index < [xmlKeys count]; ++index)
|
||||
{
|
||||
id key = [[xmlKeys objectAtIndex:index] stringValue];
|
||||
if ([key rangeOfString:@"CustomClassName"].location != NSNotFound)
|
||||
{
|
||||
NSString *obj = [[xmlObjs objectAtIndex:index] stringValue];
|
||||
if ([obj isEqualToString:@"NSSecureTextField"] == NO) // SKIP FOR NOW!!!
|
||||
[customClassDict setObject:[[xmlObjs objectAtIndex:index] stringValue] forKey:key];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NSDebugLLog(@"PREXIB", @"%s:customClassDict: %@\n", __PRETTY_FUNCTION__, customClassDict);
|
||||
|
||||
if([customClassDict count] > 0)
|
||||
{
|
||||
NSArray *objectRecords = nil;
|
||||
NSEnumerator *en = [[customClassDict allKeys] objectEnumerator];
|
||||
NSString *key = nil;
|
||||
|
||||
objectRecordXpath = [NSString stringWithFormat:@"//object[@class=\"IBObjectRecord\"]/"
|
||||
@"int[@key=\"objectID\"][text()=\"%@\"]/../reference",
|
||||
keyValue];
|
||||
while((key = [en nextObject]) != nil)
|
||||
{
|
||||
NSString *keyValue = [key stringByReplacingOccurrencesOfString:@".CustomClassName" withString:@""];
|
||||
NSString *className = [customClassDict objectForKey:key];
|
||||
NSString *objectRecordXpath = nil;
|
||||
|
||||
objectRecords = [document nodesForXPath:objectRecordXpath
|
||||
error:NULL];
|
||||
NSString *refId = nil;
|
||||
if([objectRecords count] > 0)
|
||||
{
|
||||
id record = nil;
|
||||
NSEnumerator *oen = [objectRecords objectEnumerator];
|
||||
while((record = [oen nextObject]) != nil)
|
||||
{
|
||||
if([[[record attributeForName:@"key"] stringValue] isEqualToString:@"object"])
|
||||
{
|
||||
NSArray *classNodes = nil;
|
||||
id classNode = nil;
|
||||
NSString *refXpath = nil;
|
||||
objectRecordXpath = [NSString stringWithFormat:@"//object[@class=\"IBObjectRecord\"]/"
|
||||
@"int[@key=\"objectID\"][text()=\"%@\"]/../reference",
|
||||
keyValue];
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
objectRecords = [document nodesForXPath:objectRecordXpath error:NULL];
|
||||
NSString *refId = nil;
|
||||
if([objectRecords count] > 0)
|
||||
{
|
||||
id record = nil;
|
||||
NSEnumerator *oen = [objectRecords objectEnumerator];
|
||||
while((record = [oen nextObject]) != nil)
|
||||
{
|
||||
if ([record isMemberOfClass:[NSXMLElement class]])
|
||||
{
|
||||
if([[[record attributeForName:@"key"] stringValue] isEqualToString:@"object"])
|
||||
{
|
||||
NSArray *classNodes = nil;
|
||||
id classNode = nil;
|
||||
NSString *refXpath = nil;
|
||||
|
||||
refId = [[record attributeForName:@"ref"] stringValue];
|
||||
refXpath = [NSString stringWithFormat:@"//object[@id=\"%@\"]",refId];
|
||||
classNodes = [document nodesForXPath:refXpath
|
||||
error:NULL];
|
||||
if([classNodes count] > 0)
|
||||
{
|
||||
id classAttr = nil;
|
||||
Class cls = NSClassFromString(className);
|
||||
|
||||
classNode = [classNodes objectAtIndex:0];
|
||||
classAttr = [classNode attributeForName:@"class"];
|
||||
[classAttr setStringValue:className];
|
||||
|
||||
if(cls != nil)
|
||||
{
|
||||
if([cls respondsToSelector:@selector(cellClass)])
|
||||
{
|
||||
NSArray *cellNodes = nil;
|
||||
id cellNode = nil;
|
||||
id cellClass = [cls cellClass];
|
||||
NSString *cellXpath = [NSString stringWithFormat:@"//object[@id=\"%@\"]/object[@key=\"NSCell\"]",refId];
|
||||
cellNodes = [document nodesForXPath:cellXpath
|
||||
error:NULL];
|
||||
if([cellNodes count] > 0)
|
||||
{
|
||||
NSString *cellClassString = NSStringFromClass(cellClass);
|
||||
id cellAttr = nil;
|
||||
cellNode = [cellNodes objectAtIndex:0];
|
||||
cellAttr = [cellNode attributeForName:@"class"];
|
||||
[cellAttr setStringValue:cellClassString];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result = [document XMLData];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue