mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 16:00:37 +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
|
||||
{
|
||||
if (self == [GSXib5KeyedUnarchiver class])
|
||||
{
|
||||
@synchronized(self)
|
||||
{
|
||||
// Only check one since we're going to load all once...
|
||||
if (XmltagToObjectClassCrossReference == nil)
|
||||
|
@ -415,7 +413,6 @@ static NSArray *XmlConnectionRecordTags = nil;
|
|||
@"contentView", @"NSWindowView",
|
||||
@"customClass", @"NSWindowClass",
|
||||
@"title", @"NSWindowTitle",
|
||||
@"initialPositionMask", @"windowPositionMask",
|
||||
@"contentRect", @"NSWindowRect",
|
||||
@"insertionPointColor", @"NSInsertionColor",
|
||||
@"vertical", @"NSIsVertical",
|
||||
|
@ -469,9 +466,9 @@ static NSArray *XmlConnectionRecordTags = nil;
|
|||
// These define XML tags (i.e. '<autoresizingMask ...') to an associated decode method...
|
||||
XmlTagToDecoderSelectorMap = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"decodeTableColumnResizingMaskForElement:", @"tableColumnResizingMask",
|
||||
@"decodeAutoresizingMaskForElement:", @"autoresizingMask",
|
||||
//@"decodeAutoresizingMaskForElement:", @"autoresizingMask",
|
||||
@"decodeWindowStyleMaskForElement:", @"windowStyleMask",
|
||||
@"decodeWindowPositionMaskForElement:", @"windowPositionMask",
|
||||
//@"decodeWindowPositionMaskForElement:", @"windowPositionMask",
|
||||
//@"decodeModifierMaskForElement:", @"modifierMask",
|
||||
@"decodeTableViewGridLinesForElement:", @"tableViewGridLines",
|
||||
nil];
|
||||
|
@ -550,7 +547,6 @@ static NSArray *XmlConnectionRecordTags = nil;
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+ (NSInteger) coderVersion
|
||||
{
|
||||
|
@ -565,8 +561,8 @@ static NSArray *XmlConnectionRecordTags = nil;
|
|||
{
|
||||
NSEnumerator *iter = [ClassNamePrefixes objectEnumerator];
|
||||
NSString *prefix = nil;
|
||||
NSString *baseString = [[xibTag substringToIndex: 1] capitalizedString];
|
||||
baseString = [baseString stringByAppendingString: [xibTag substringFromIndex: 1]];
|
||||
NSString *baseString = [[[xibTag substringToIndex: 1] capitalizedString]
|
||||
stringByAppendingString: [xibTag substringFromIndex: 1]];
|
||||
|
||||
// Try to generate a default name from tag...
|
||||
while ((prefix = [iter nextObject]))
|
||||
|
@ -598,23 +594,46 @@ static NSArray *XmlConnectionRecordTags = nil;
|
|||
stringByAppendingString: [name substringFromIndex: 3]];
|
||||
}
|
||||
|
||||
- (GSXibElement*) connectionRecordForElement: (GSXibElement*)element
|
||||
- (void) addConnection: (GSXibElement*)element
|
||||
{
|
||||
// Mimic the old IBConnectionRecord instance...
|
||||
if ([XmlConnectionRecordTags containsObject: [element type]])
|
||||
NSString *elementName = [element type];
|
||||
|
||||
if ([XmlConnectionRecordTags containsObject: elementName])
|
||||
{
|
||||
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"IBConnectionRecord", @"class",
|
||||
[[NSUUID UUID] UUIDString], @"id",
|
||||
nil];
|
||||
GSXibElement *connectionRecord = [[GSXibElement alloc] initWithType: @"object"
|
||||
andAttributes: attributes];
|
||||
//[element setAttribute: @"connection" forKey: @"key"];
|
||||
[connectionRecord setElement: element forKey: @"connection"];
|
||||
return AUTORELEASE(connectionRecord);
|
||||
GSXibElement *connectionRecord;
|
||||
// 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 *parentId = [parent attributeForKey: @"id"];
|
||||
NSString *objKey = (([@"action" isEqualToString: elementName]) ?
|
||||
@"destination" : @"source");
|
||||
|
||||
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
|
||||
|
@ -822,10 +841,6 @@ static NSArray *XmlConnectionRecordTags = nil;
|
|||
|
||||
// objectRecords...
|
||||
[_objectRecords setElement: _orderedObjects forKey: @"orderedObjects"];
|
||||
|
||||
// flattenedProperties...
|
||||
// NSString *runtimeAttributesKey = [NSString stringWithFormat: @"%@.IBAttributePlaceholdersKey", [[NSUUID UUID] UUIDString]];
|
||||
// [_flattenedProperties setElement: _runtimeAttributes forKey: runtimeAttributesKey];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
|
@ -845,14 +860,14 @@ didStartElement: (NSString*)elementName
|
|||
namespaceURI: (NSString*)namespaceURI
|
||||
qualifiedName: (NSString*)qualifiedName
|
||||
attributes: (NSDictionary*)attributeDict
|
||||
{
|
||||
// Skip certain element names - for now...
|
||||
if ([XmltagsToSkip containsObject: elementName] == NO)
|
||||
{
|
||||
NSMutableDictionary *attributes = AUTORELEASE([attributeDict mutableCopy]);
|
||||
NSString *className = nil;
|
||||
NSString *elementType = elementName;
|
||||
|
||||
// Skip certain element names - for now...
|
||||
if ([XmltagsToSkip containsObject: elementName] == NO)
|
||||
{
|
||||
if (([@"window" isEqualToString: elementName] == NO) &&
|
||||
([@"customView" isEqualToString: elementName] == NO) &&
|
||||
([@"customObject" isEqualToString: elementName] == NO))
|
||||
|
@ -892,26 +907,16 @@ didStartElement: (NSString*)elementName
|
|||
}
|
||||
}
|
||||
|
||||
if (([attributes objectForKey: @"customClass"] == nil) ||
|
||||
([NSClassFromString([attributes objectForKey: @"customClass"]) isSubclassOfClass: [NSApplication class]] == NO))
|
||||
if ([[attributes objectForKey: @"userLabel"] isEqualToString: @"Application"])
|
||||
[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)
|
||||
if ([[attributes objectForKey: @"userLabel"] isEqualToString: @"Application"] &&
|
||||
(([attributes objectForKey: @"customClass"] == nil) ||
|
||||
([NSClassFromString([attributes objectForKey: @"customClass"]) isSubclassOfClass: [NSApplication class]] == NO)))
|
||||
{
|
||||
// FIXME NSLog(@"Add unique key for object %@ with attrs %@", elementName, attributes);
|
||||
//[attributes setObject: [[NSUUID UUID] UUIDString] forKey: @"id"];
|
||||
[attributes setObject: @"NSApplication" forKey: @"customClass"];
|
||||
}
|
||||
|
||||
// FOR DEBUG...CAN BE REMOVED...
|
||||
[attributes setObject: elementName forKey: @"key5"];
|
||||
|
||||
// Generate the XIB element object...
|
||||
GSXibElement *element = [[GSXibElement alloc] initWithType: elementType
|
||||
andAttributes: attributes];
|
||||
NSString *key = [attributes objectForKey: @"key"];
|
||||
NSString *ref = [attributes objectForKey: @"id"];
|
||||
|
||||
if ([@"array" isEqualToString: [currentElement type]])
|
||||
|
@ -920,24 +925,12 @@ didStartElement: (NSString*)elementName
|
|||
[currentElement addElement: element];
|
||||
|
||||
// Need to store element for making the connections...
|
||||
if ([XmlConnectionRecordTags containsObject: elementName])
|
||||
{
|
||||
// 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]];
|
||||
}
|
||||
[self addConnection: element];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *key = [attributes objectForKey: @"key"];
|
||||
|
||||
// For elements...
|
||||
[currentElement setElement: element forKey: key];
|
||||
|
||||
|
@ -1062,6 +1055,7 @@ didStartElement: (NSString*)elementName
|
|||
{
|
||||
NSUInteger mask = 0;
|
||||
|
||||
// FIXME
|
||||
return [NSNumber numberWithUnsignedInteger: mask];
|
||||
}
|
||||
|
||||
|
@ -3001,7 +2995,7 @@ didStartElement: (NSString*)elementName
|
|||
{
|
||||
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)
|
||||
{
|
||||
// Try to reinterpret the request...
|
||||
|
@ -3009,11 +3003,24 @@ didStartElement: (NSString*)elementName
|
|||
{
|
||||
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])
|
||||
{
|
||||
SEL selector = NSSelectorFromString([XmlKeyToDecoderSelectorMap objectForKey: key]);
|
||||
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]) ||
|
||||
([@"NSCancelButtonCell" isEqualToString: key]))
|
||||
{
|
||||
|
@ -3114,19 +3121,6 @@ didStartElement: (NSString*)elementName
|
|||
NSString *newKey = [self alternateName: key];
|
||||
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)
|
||||
else // DEBUG ONLY...
|
||||
{
|
||||
|
@ -3444,6 +3438,7 @@ didStartElement: (NSString*)elementName
|
|||
// Target is stored in the action XIB element - if present - which is
|
||||
// stored under the connections array element...
|
||||
NSArray *connections = [self objectForXib: [currentElement elementForKey: @"connections"]];
|
||||
// FIXME: Shouldn't this be IBActionConnection5 ?
|
||||
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"className == 'IBActionConnection'"];
|
||||
NSArray *actions = [connections filteredArrayUsingPredicate: predicate];
|
||||
hasValue = ([actions count] != 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue