More code simplifications.

This commit is contained in:
fredkiefer 2019-12-11 23:46:44 +01:00
parent 3b48bd6277
commit 83963f9d2a

View file

@ -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];
@ -550,7 +547,6 @@ static NSArray *XmlConnectionRecordTags = nil;
} }
} }
} }
}
+ (NSInteger) coderVersion + (NSInteger) coderVersion
{ {
@ -565,8 +561,8 @@ 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]))
@ -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
@ -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
@ -845,14 +860,14 @@ didStartElement: (NSString*)elementName
namespaceURI: (NSString*)namespaceURI namespaceURI: (NSString*)namespaceURI
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]))
{ {
@ -3114,19 +3121,6 @@ didStartElement: (NSString*)elementName
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,6 +3438,7 @@ 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"]];
// FIXME: Shouldn't this be IBActionConnection5 ?
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"className == 'IBActionConnection'"]; NSPredicate *predicate = [NSPredicate predicateWithFormat: @"className == 'IBActionConnection'"];
NSArray *actions = [connections filteredArrayUsingPredicate: predicate]; NSArray *actions = [connections filteredArrayUsingPredicate: predicate];
hasValue = ([actions count] != 0); hasValue = ([actions count] != 0);