mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:50:48 +00:00
More code simplifications.
This commit is contained in:
parent
3b48bd6277
commit
83963f9d2a
1 changed files with 148 additions and 153 deletions
|
@ -328,8 +328,6 @@ static NSArray *XmlConnectionRecordTags = nil;
|
||||||
+ (void) initialize
|
+ (void) initialize
|
||||||
{
|
{
|
||||||
if (self == [GSXib5KeyedUnarchiver class])
|
if (self == [GSXib5KeyedUnarchiver class])
|
||||||
{
|
|
||||||
@synchronized(self)
|
|
||||||
{
|
{
|
||||||
// Only check one since we're going to load all once...
|
// Only check one since we're going to load all once...
|
||||||
if (XmltagToObjectClassCrossReference == nil)
|
if (XmltagToObjectClassCrossReference == nil)
|
||||||
|
@ -415,7 +413,6 @@ static NSArray *XmlConnectionRecordTags = nil;
|
||||||
@"contentView", @"NSWindowView",
|
@"contentView", @"NSWindowView",
|
||||||
@"customClass", @"NSWindowClass",
|
@"customClass", @"NSWindowClass",
|
||||||
@"title", @"NSWindowTitle",
|
@"title", @"NSWindowTitle",
|
||||||
@"initialPositionMask", @"windowPositionMask",
|
|
||||||
@"contentRect", @"NSWindowRect",
|
@"contentRect", @"NSWindowRect",
|
||||||
@"insertionPointColor", @"NSInsertionColor",
|
@"insertionPointColor", @"NSInsertionColor",
|
||||||
@"vertical", @"NSIsVertical",
|
@"vertical", @"NSIsVertical",
|
||||||
|
@ -469,9 +466,9 @@ static NSArray *XmlConnectionRecordTags = nil;
|
||||||
// These define XML tags (i.e. '<autoresizingMask ...') to an associated decode method...
|
// These define XML tags (i.e. '<autoresizingMask ...') to an associated decode method...
|
||||||
XmlTagToDecoderSelectorMap = [NSDictionary dictionaryWithObjectsAndKeys:
|
XmlTagToDecoderSelectorMap = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
@"decodeTableColumnResizingMaskForElement:", @"tableColumnResizingMask",
|
@"decodeTableColumnResizingMaskForElement:", @"tableColumnResizingMask",
|
||||||
@"decodeAutoresizingMaskForElement:", @"autoresizingMask",
|
//@"decodeAutoresizingMaskForElement:", @"autoresizingMask",
|
||||||
@"decodeWindowStyleMaskForElement:", @"windowStyleMask",
|
@"decodeWindowStyleMaskForElement:", @"windowStyleMask",
|
||||||
@"decodeWindowPositionMaskForElement:", @"windowPositionMask",
|
//@"decodeWindowPositionMaskForElement:", @"windowPositionMask",
|
||||||
//@"decodeModifierMaskForElement:", @"modifierMask",
|
//@"decodeModifierMaskForElement:", @"modifierMask",
|
||||||
@"decodeTableViewGridLinesForElement:", @"tableViewGridLines",
|
@"decodeTableViewGridLinesForElement:", @"tableViewGridLines",
|
||||||
nil];
|
nil];
|
||||||
|
@ -549,7 +546,6 @@ static NSArray *XmlConnectionRecordTags = nil;
|
||||||
RETAIN(XmlKeyToDecoderSelectorMap);
|
RETAIN(XmlKeyToDecoderSelectorMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSInteger) coderVersion
|
+ (NSInteger) coderVersion
|
||||||
|
@ -565,13 +561,13 @@ static NSArray *XmlConnectionRecordTags = nil;
|
||||||
{
|
{
|
||||||
NSEnumerator *iter = [ClassNamePrefixes objectEnumerator];
|
NSEnumerator *iter = [ClassNamePrefixes objectEnumerator];
|
||||||
NSString *prefix = nil;
|
NSString *prefix = nil;
|
||||||
NSString *baseString = [[xibTag substringToIndex: 1] capitalizedString];
|
NSString *baseString = [[[xibTag substringToIndex: 1] capitalizedString]
|
||||||
baseString = [baseString stringByAppendingString: [xibTag substringFromIndex: 1]];
|
stringByAppendingString: [xibTag substringFromIndex: 1]];
|
||||||
|
|
||||||
// Try to generate a default name from tag...
|
// Try to generate a default name from tag...
|
||||||
while ((prefix = [iter nextObject]))
|
while ((prefix = [iter nextObject]))
|
||||||
{
|
{
|
||||||
NSString *theClassName = [NSString stringWithFormat:@"%@%@",prefix,baseString];
|
NSString *theClassName = [NSString stringWithFormat: @"%@%@", prefix, baseString];
|
||||||
|
|
||||||
if (NSClassFromString(theClassName))
|
if (NSClassFromString(theClassName))
|
||||||
{
|
{
|
||||||
|
@ -598,23 +594,46 @@ static NSArray *XmlConnectionRecordTags = nil;
|
||||||
stringByAppendingString: [name substringFromIndex: 3]];
|
stringByAppendingString: [name substringFromIndex: 3]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (GSXibElement*) connectionRecordForElement: (GSXibElement*)element
|
- (void) addConnection: (GSXibElement*)element
|
||||||
{
|
{
|
||||||
// Mimic the old IBConnectionRecord instance...
|
NSString *elementName = [element type];
|
||||||
if ([XmlConnectionRecordTags containsObject: [element type]])
|
|
||||||
|
if ([XmlConnectionRecordTags containsObject: elementName])
|
||||||
{
|
{
|
||||||
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
|
GSXibElement *connectionRecord;
|
||||||
@"IBConnectionRecord", @"class",
|
// Get the parent of the parent object...
|
||||||
[[NSUUID UUID] UUIDString], @"id",
|
// The current object at this point is the 'connections' array element.
|
||||||
nil];
|
// The parent of connections array element is the object ID we need...
|
||||||
GSXibElement *connectionRecord = [[GSXibElement alloc] initWithType: @"object"
|
GSXibElement *parent = [stack objectAtIndex: [stack count] - 1];
|
||||||
andAttributes: attributes];
|
NSString *parentId = [parent attributeForKey: @"id"];
|
||||||
//[element setAttribute: @"connection" forKey: @"key"];
|
NSString *objKey = (([@"action" isEqualToString: elementName]) ?
|
||||||
[connectionRecord setElement: element forKey: @"connection"];
|
@"destination" : @"source");
|
||||||
return AUTORELEASE(connectionRecord);
|
|
||||||
|
if (parentId == nil)
|
||||||
|
{
|
||||||
|
NSLog(@"Missing parent Id for connection on parent @%", parent);
|
||||||
|
// Fake an id for parent
|
||||||
|
parentId = [[NSUUID UUID] UUIDString];
|
||||||
|
[parent setAttribute: parentId forKey: @"id"];
|
||||||
|
[objects setObject: parent forKey: parentId];
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil;
|
// Store the ID reference of the parent object...
|
||||||
|
[element setAttribute: parentId forKey: objKey];
|
||||||
|
|
||||||
|
// Build a connection recort
|
||||||
|
connectionRecord = [[GSXibElement alloc] initWithType: @"object"
|
||||||
|
andAttributes:
|
||||||
|
[NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
|
@"IBConnectionRecord", @"class",
|
||||||
|
[[NSUUID UUID] UUIDString], @"id",
|
||||||
|
nil]];
|
||||||
|
[connectionRecord setElement: element forKey: @"connection"];
|
||||||
|
|
||||||
|
// Add the connection record element that includes this element...
|
||||||
|
[_connectionRecords addElement: connectionRecord];
|
||||||
|
RELEASE(connectionRecord);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (GSXibElement*) orderedObjectForElement: (GSXibElement*)element
|
- (GSXibElement*) orderedObjectForElement: (GSXibElement*)element
|
||||||
|
@ -654,7 +673,7 @@ static NSArray *XmlConnectionRecordTags = nil;
|
||||||
|
|
||||||
- (void) addRuntimeAttributesForElement: (GSXibElement*)element forID: (NSString*)idString
|
- (void) addRuntimeAttributesForElement: (GSXibElement*)element forID: (NSString*)idString
|
||||||
{
|
{
|
||||||
NSString *refID = [NSString stringWithFormat:@"%@.IBAttributePlaceholdersKey",idString];
|
NSString *refID = [NSString stringWithFormat: @"%@.IBAttributePlaceholdersKey", idString];
|
||||||
GSXibElement *objectRecord = (GSXibElement*)[_flattenedProperties elementForKey: refID];
|
GSXibElement *objectRecord = (GSXibElement*)[_flattenedProperties elementForKey: refID];
|
||||||
|
|
||||||
// Mimic the old IBAttributePlaceholders instance...
|
// Mimic the old IBAttributePlaceholders instance...
|
||||||
|
@ -822,10 +841,6 @@ static NSArray *XmlConnectionRecordTags = nil;
|
||||||
|
|
||||||
// objectRecords...
|
// objectRecords...
|
||||||
[_objectRecords setElement: _orderedObjects forKey: @"orderedObjects"];
|
[_objectRecords setElement: _orderedObjects forKey: @"orderedObjects"];
|
||||||
|
|
||||||
// flattenedProperties...
|
|
||||||
// NSString *runtimeAttributesKey = [NSString stringWithFormat: @"%@.IBAttributePlaceholdersKey", [[NSUUID UUID] UUIDString]];
|
|
||||||
// [_flattenedProperties setElement: _runtimeAttributes forKey: runtimeAttributesKey];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
|
@ -846,13 +861,13 @@ didStartElement: (NSString*)elementName
|
||||||
qualifiedName: (NSString*)qualifiedName
|
qualifiedName: (NSString*)qualifiedName
|
||||||
attributes: (NSDictionary*)attributeDict
|
attributes: (NSDictionary*)attributeDict
|
||||||
{
|
{
|
||||||
|
// Skip certain element names - for now...
|
||||||
|
if ([XmltagsToSkip containsObject: elementName] == NO)
|
||||||
|
{
|
||||||
NSMutableDictionary *attributes = AUTORELEASE([attributeDict mutableCopy]);
|
NSMutableDictionary *attributes = AUTORELEASE([attributeDict mutableCopy]);
|
||||||
NSString *className = nil;
|
NSString *className = nil;
|
||||||
NSString *elementType = elementName;
|
NSString *elementType = elementName;
|
||||||
|
|
||||||
// Skip certain element names - for now...
|
|
||||||
if ([XmltagsToSkip containsObject: elementName] == NO)
|
|
||||||
{
|
|
||||||
if (([@"window" isEqualToString: elementName] == NO) &&
|
if (([@"window" isEqualToString: elementName] == NO) &&
|
||||||
([@"customView" isEqualToString: elementName] == NO) &&
|
([@"customView" isEqualToString: elementName] == NO) &&
|
||||||
([@"customObject" isEqualToString: elementName] == NO))
|
([@"customObject" isEqualToString: elementName] == NO))
|
||||||
|
@ -892,26 +907,16 @@ didStartElement: (NSString*)elementName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (([attributes objectForKey: @"customClass"] == nil) ||
|
if ([[attributes objectForKey: @"userLabel"] isEqualToString: @"Application"] &&
|
||||||
([NSClassFromString([attributes objectForKey: @"customClass"]) isSubclassOfClass: [NSApplication class]] == NO))
|
(([attributes objectForKey: @"customClass"] == nil) ||
|
||||||
if ([[attributes objectForKey: @"userLabel"] isEqualToString: @"Application"])
|
([NSClassFromString([attributes objectForKey: @"customClass"]) isSubclassOfClass: [NSApplication class]] == NO)))
|
||||||
[attributes setObject:@"NSApplication" forKey:@"customClass"];
|
|
||||||
|
|
||||||
// If there is no ID assigned to this element we're going to arbritrarily
|
|
||||||
// add one since we need to cross-reference objects...
|
|
||||||
if ([attributes objectForKey: @"id"] == nil)
|
|
||||||
{
|
{
|
||||||
// FIXME NSLog(@"Add unique key for object %@ with attrs %@", elementName, attributes);
|
[attributes setObject: @"NSApplication" forKey: @"customClass"];
|
||||||
//[attributes setObject: [[NSUUID UUID] UUIDString] forKey: @"id"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FOR DEBUG...CAN BE REMOVED...
|
|
||||||
[attributes setObject: elementName forKey: @"key5"];
|
|
||||||
|
|
||||||
// Generate the XIB element object...
|
// Generate the XIB element object...
|
||||||
GSXibElement *element = [[GSXibElement alloc] initWithType: elementType
|
GSXibElement *element = [[GSXibElement alloc] initWithType: elementType
|
||||||
andAttributes: attributes];
|
andAttributes: attributes];
|
||||||
NSString *key = [attributes objectForKey: @"key"];
|
|
||||||
NSString *ref = [attributes objectForKey: @"id"];
|
NSString *ref = [attributes objectForKey: @"id"];
|
||||||
|
|
||||||
if ([@"array" isEqualToString: [currentElement type]])
|
if ([@"array" isEqualToString: [currentElement type]])
|
||||||
|
@ -920,24 +925,12 @@ didStartElement: (NSString*)elementName
|
||||||
[currentElement addElement: element];
|
[currentElement addElement: element];
|
||||||
|
|
||||||
// Need to store element for making the connections...
|
// Need to store element for making the connections...
|
||||||
if ([XmlConnectionRecordTags containsObject: elementName])
|
[self addConnection: element];
|
||||||
{
|
|
||||||
// Get the parent of the parent object...
|
|
||||||
// The current object at this point is the 'connections' array element.
|
|
||||||
// The parent of connections array element IS the object ID we need...
|
|
||||||
GSXibElement *parent = [stack objectAtIndex: [stack count]-1];
|
|
||||||
NSString *objKey = (([@"action" isEqualToString: elementName]) ?
|
|
||||||
@"destination" : @"source");
|
|
||||||
|
|
||||||
// Store the ID reference of the parent object...
|
|
||||||
[element setAttribute: [parent attributeForKey: @"id"] forKey: objKey];
|
|
||||||
|
|
||||||
// Add a connection record element that includes this element...
|
|
||||||
[_connectionRecords addElement: [self connectionRecordForElement: element]];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
NSString *key = [attributes objectForKey: @"key"];
|
||||||
|
|
||||||
// For elements...
|
// For elements...
|
||||||
[currentElement setElement: element forKey: key];
|
[currentElement setElement: element forKey: key];
|
||||||
|
|
||||||
|
@ -1062,6 +1055,7 @@ didStartElement: (NSString*)elementName
|
||||||
{
|
{
|
||||||
NSUInteger mask = 0;
|
NSUInteger mask = 0;
|
||||||
|
|
||||||
|
// FIXME
|
||||||
return [NSNumber numberWithUnsignedInteger: mask];
|
return [NSNumber numberWithUnsignedInteger: mask];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3001,7 +2995,7 @@ didStartElement: (NSString*)elementName
|
||||||
{
|
{
|
||||||
id object = [super decodeObjectForKey: key];
|
id object = [super decodeObjectForKey: key];
|
||||||
|
|
||||||
// If not object try some other cases before defaulting to remove 'NS' prefix if present...
|
// If no object is found, try some other cases before defaulting to remove 'NS' prefix if present...
|
||||||
if (object == nil)
|
if (object == nil)
|
||||||
{
|
{
|
||||||
// Try to reinterpret the request...
|
// Try to reinterpret the request...
|
||||||
|
@ -3009,11 +3003,24 @@ didStartElement: (NSString*)elementName
|
||||||
{
|
{
|
||||||
object = [self decodeObjectForKey: [XmlKeyMapTable objectForKey: key]];
|
object = [self decodeObjectForKey: [XmlKeyMapTable objectForKey: key]];
|
||||||
}
|
}
|
||||||
|
else if ([currentElement attributeForKey: key])
|
||||||
|
{
|
||||||
|
// New xib stores values as attributes...
|
||||||
|
object = [currentElement attributeForKey: key];
|
||||||
|
}
|
||||||
else if ([XmlKeyToDecoderSelectorMap objectForKey: key])
|
else if ([XmlKeyToDecoderSelectorMap objectForKey: key])
|
||||||
{
|
{
|
||||||
SEL selector = NSSelectorFromString([XmlKeyToDecoderSelectorMap objectForKey: key]);
|
SEL selector = NSSelectorFromString([XmlKeyToDecoderSelectorMap objectForKey: key]);
|
||||||
object = [self performSelector: selector withObject: currentElement];
|
object = [self performSelector: selector withObject: currentElement];
|
||||||
}
|
}
|
||||||
|
else if ([XmlReferenceAttributes containsObject: key])
|
||||||
|
{
|
||||||
|
// Elements not stored INSIDE current element potentially need to be cross
|
||||||
|
// referenced via attribute references...
|
||||||
|
NSString *idString = [currentElement attributeForKey: key];
|
||||||
|
GSXibElement *element = [objects objectForKey: idString];
|
||||||
|
object = [self objectForXib: element];
|
||||||
|
}
|
||||||
else if (([@"NSSearchButtonCell" isEqualToString: key]) ||
|
else if (([@"NSSearchButtonCell" isEqualToString: key]) ||
|
||||||
([@"NSCancelButtonCell" isEqualToString: key]))
|
([@"NSCancelButtonCell" isEqualToString: key]))
|
||||||
{
|
{
|
||||||
|
@ -3108,25 +3115,12 @@ didStartElement: (NSString*)elementName
|
||||||
// This would allow to do system dependent path separator decoding...
|
// This would allow to do system dependent path separator decoding...
|
||||||
object = @"/";
|
object = @"/";
|
||||||
}
|
}
|
||||||
else if ([key hasPrefix:@"NS"])
|
else if ([key hasPrefix: @"NS"])
|
||||||
{
|
{
|
||||||
// Try a key minus a (potential) NS prefix...
|
// Try a key minus a (potential) NS prefix...
|
||||||
NSString *newKey = [self alternateName: key];
|
NSString *newKey = [self alternateName: key];
|
||||||
object = [self decodeObjectForKey: newKey];
|
object = [self decodeObjectForKey: newKey];
|
||||||
}
|
}
|
||||||
else if ([XmlReferenceAttributes containsObject: key])
|
|
||||||
{
|
|
||||||
// Elements not stored INSIDE current element potentially need to be cross
|
|
||||||
// referenced via attribute references...
|
|
||||||
NSString *idString = [currentElement attributeForKey: key];
|
|
||||||
GSXibElement *element = [objects objectForKey:idString];
|
|
||||||
object = [self objectForXib: element];
|
|
||||||
}
|
|
||||||
else if ([currentElement attributeForKey: key])
|
|
||||||
{
|
|
||||||
// New xib stores values as attributes...
|
|
||||||
object = [currentElement attributeForKey: key];
|
|
||||||
}
|
|
||||||
#if 0 //defined(DEBUG)
|
#if 0 //defined(DEBUG)
|
||||||
else // DEBUG ONLY...
|
else // DEBUG ONLY...
|
||||||
{
|
{
|
||||||
|
@ -3444,7 +3438,8 @@ didStartElement: (NSString*)elementName
|
||||||
// Target is stored in the action XIB element - if present - which is
|
// Target is stored in the action XIB element - if present - which is
|
||||||
// stored under the connections array element...
|
// stored under the connections array element...
|
||||||
NSArray *connections = [self objectForXib: [currentElement elementForKey: @"connections"]];
|
NSArray *connections = [self objectForXib: [currentElement elementForKey: @"connections"]];
|
||||||
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"className == 'IBActionConnection'"];
|
// FIXME: Shouldn't this be IBActionConnection5 ?
|
||||||
|
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"className == 'IBActionConnection'"];
|
||||||
NSArray *actions = [connections filteredArrayUsingPredicate: predicate];
|
NSArray *actions = [connections filteredArrayUsingPredicate: predicate];
|
||||||
hasValue = ([actions count] != 0);
|
hasValue = ([actions count] != 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue