Remove now obsolete GSXibParser.

Move over more Eggplant changes.
Add basic decoding for bindings.
This commit is contained in:
fredkiefer 2019-12-09 14:22:33 +01:00
parent 9032de5842
commit 244e7a48d7
8 changed files with 76 additions and 303 deletions

View file

@ -1,53 +0,0 @@
/* <title>GSXibParser</title>
<abstract>Xib v5 (Cocoa XML) parser</abstract>
Copyright (C) 2014 Free Software Foundation, Inc.
Written by: Gregory Casamento <greg.casamento@gmail.com>
Created: March 2014
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef _GNUstep_H_GSXibParser
#define _GNUstep_H_GSXibParser
#import <Foundation/NSObject.h>
@class NSData;
@class NSXMLParser;
@class NSMutableDictionary;
@class GSXibElement;
@class NSMutableArray;
@interface GSXibParser : NSObject
{
NSMutableDictionary *objects;
GSXibElement *currentElement;
NSMutableArray *stack;
NSXMLParser *theParser;
}
- (id) initWithData: (NSData *)data;
- (NSDictionary *) parse;
@end
#endif

View file

@ -310,7 +310,6 @@ GSXibLoading.m \
GSXibKeyedUnarchiver.m \
GSXib5KeyedUnarchiver.m \
GSXibObjectContainer.m \
GSXibParser.m \
GSHelpAttachment.m
# Turn off NSMenuItem warning that NSMenuItem conforms to <NSObject>,
@ -566,7 +565,6 @@ GSXibElement.h \
GSXibLoading.h \
GSXibKeyedUnarchiver.h \
GSXibObjectContainer.h \
GSXibParser.h \
GSHelpAttachment.h
libgnustep-gui_HEADER_FILES = ${GUI_HEADERS}

View file

@ -52,6 +52,7 @@
#import "GNUstepGUI/GSNibLoading.h"
#import "AppKit/NSApplication.h"
#import "AppKit/NSFontManager.h"
#import "AppKit/NSImage.h"
#import "AppKit/NSMenuItem.h"
#import "AppKit/NSMenuView.h"
@ -326,10 +327,12 @@ static BOOL _isInInterfaceBuilder = NO;
_flags.isDeferred = deferred;
_flags.isOneShot = oneShot;
_flags.isVisible = visible;
_flags.isNotShadowed = ![window hasShadow];
_flags.wantsToBeColor = wantsToBeColor;
_flags.dynamicDepthLimit = [window hasDynamicDepthLimit];
_flags.autoPositionMask = autoPositionMask;
_flags.savePosition = YES; // not yet implemented.
_flags.autorecalculatesKeyViewLoop = [window autorecalculatesKeyViewLoop];
}
}
return self;
@ -343,14 +346,26 @@ static BOOL _isInInterfaceBuilder = NO;
{
ASSIGN(_viewClass, [coder decodeObjectForKey: @"NSViewClass"]);
}
else
{
ASSIGN(_viewClass, @"NSView");
}
if ([coder containsValueForKey: @"NSWindowClass"])
{
ASSIGN(_windowClass, [coder decodeObjectForKey: @"NSWindowClass"]);
}
else
{
ASSIGN(_windowClass, @"NSWindow");
}
if ([coder containsValueForKey: @"NSWindowStyleMask"])
{
_windowStyle = [coder decodeIntForKey: @"NSWindowStyleMask"];
}
else
{
_windowStyle = 0;
}
if ([coder containsValueForKey: @"NSWindowBacking"])
{
_backingStoreType = [coder decodeIntForKey: @"NSWindowBacking"];
@ -485,6 +500,8 @@ static BOOL _isInInterfaceBuilder = NO;
// [_realObject setAutoPosition: _flags.autoPosition];
[_realObject setDynamicDepthLimit: _flags.dynamicDepthLimit];
// [_realObject setFrameAutosaveName: _autosaveName]; // done after setting the min/max sizes
[_realObject setHasShadow: !_flags.isNotShadowed];
[_realObject setAutorecalculatesKeyViewLoop: _flags.autorecalculatesKeyViewLoop];
// reset attributes...
[_realObject setContentView: _view];
@ -1004,6 +1021,11 @@ static BOOL _isInInterfaceBuilder = NO;
{
_object = RETAIN([aClass sharedApplication]);
}
else if ((GSObjCIsKindOf(aClass, [NSFontManager class])) ||
([_className isEqual: @"NSFontManager"]))
{
_object = RETAIN([aClass sharedFontManager]);
}
else
{
_object = [[aClass allocWithZone: NSDefaultMallocZone()] init];

View file

@ -101,7 +101,7 @@ static NSString *ApplicationClass = nil;
if (self)
{
_userLabel = [coder decodeObjectForKey:@"userLabel"];
_userLabel = [coder decodeObjectForKey: @"userLabel"];
if (_className)
{
@ -317,7 +317,7 @@ static NSString *ApplicationClass = nil;
if (self)
{
if([coder allowsKeyedCoding])
if ([coder allowsKeyedCoding])
{
[self setTypeIdentifier: [coder decodeObjectForKey: @"type"]];
@ -408,7 +408,7 @@ static NSArray *XmlConnectionRecordTags = nil;
XmlReferenceAttributes = [NSArray arrayWithObjects: @"headerView", @"initialItem", nil];
RETAIN(XmlReferenceAttributes);
XmlConnectionRecordTags = [NSArray arrayWithObjects: @"action", @"outlet", nil];
XmlConnectionRecordTags = [NSArray arrayWithObjects: @"action", @"outlet", @"binding", nil];
RETAIN(XmlConnectionRecordTags);
// These cross-reference from the OLD key to the NEW key that can be referenced and it's value
@ -463,6 +463,7 @@ static NSArray *XmlConnectionRecordTags = nil;
@"maxNumberOfRows", @"NSMaxNumberOfGridRows",
@"maxNumberOfColumns", @"NSMaxNumberOfGridColumns",
@"sortKey", @"NSKey",
@"name", @"NSBinding",
nil];
RETAIN(XmlKeyMapTable);
@ -500,12 +501,12 @@ static NSArray *XmlConnectionRecordTags = nil;
// These define XML tags (i.e. '<autoresizingMask ...') to an associated decode method...
XmlTagToDecoderSelectorMap = [NSDictionary dictionaryWithObjectsAndKeys:
@"decodeTableColumnResizingMaskForElement", @"tableColumnResizingMask:",
@"decodeAutoresizingMaskForElement", @"autoresizingMask:",
@"decodeWindowStyleMaskForElement", @"windowStyleMask:",
@"decodeWindowPositionMaskForElement", @"windowPositionMask:",
//@"decodeModifierMaskForElement", @"modifierMask:",
@"decodeTableViewGridLinesForElement", @"tableViewGridLines:",
@"decodeTableColumnResizingMaskForElement:", @"tableColumnResizingMask",
@"decodeAutoresizingMaskForElement:", @"autoresizingMask",
@"decodeWindowStyleMaskForElement:", @"windowStyleMask",
@"decodeWindowPositionMaskForElement:", @"windowPositionMask",
//@"decodeModifierMaskForElement:", @"modifierMask",
@"decodeTableViewGridLinesForElement:", @"tableViewGridLines",
nil];
RETAIN(XmlTagToDecoderSelectorMap);
@ -591,7 +592,7 @@ static NSArray *XmlConnectionRecordTags = nil;
+ (NSString*) classNameForXibTag: (NSString*)xibTag
{
NSString *className = [XmltagToObjectClassCrossReference objectForKey:xibTag];
NSString *className = [XmltagToObjectClassCrossReference objectForKey: xibTag];
if (nil == className)
{
@ -618,7 +619,7 @@ static NSArray *XmlConnectionRecordTags = nil;
+ (Class) classForXibTag: (NSString*)xibTag
{
return NSClassFromString([self classNameForXibTag:xibTag]);
return NSClassFromString([self classNameForXibTag: xibTag]);
}
- (GSXibElement*) connectionRecordForElement: (GSXibElement*)element
@ -735,6 +736,7 @@ static NSArray *XmlConnectionRecordTags = nil;
NSXMLParser *theParser = nil;
NSData *theData = data;
NSLog(@"Starting to load XIB 5 data");
// Check data...
if (theData == nil)
{
@ -872,23 +874,30 @@ didStartElement: (NSString*)elementName
if (([@"window" isEqualToString: elementName] == NO) &&
([@"customView" isEqualToString: elementName] == NO) &&
([@"customObject" isEqualToString: elementName] == NO))
className = [attributes objectForKey: @"customClass"];
if (nil == className)
className = [[self class] classNameForXibTag:elementName];
{
className = [attributes objectForKey: @"customClass"];
}
if (nil == className)
{
className = [[self class] classNameForXibTag: elementName];
}
if (nil != className)
{
if ([NSClassFromString(className) isSubclassOfClass:[NSArray class]])
if ([NSClassFromString(className) isSubclassOfClass: [NSArray class]])
elementType = @"array";
else if ([@"string" isEqualToString: elementName] == NO)
elementType = @"object";
}
// Add the necessary attribute(s)...
if (className)
[attributes setObject: className forKey: @"class"];
{
[attributes setObject: className forKey: @"class"];
}
if ([attributes objectForKey:@"key"] == nil)
if ([attributes objectForKey: @"key"] == nil)
{
// Special cases to allow current initWithCoder methods to obtain objects..._IBObjectContainer
if ([@"objects" isEqualToString: elementName])
@ -2888,7 +2897,8 @@ didStartElement: (NSString*)elementName
NSString *elementName = [element type];
if (([@"outlet" isEqualToString: elementName]) ||
([@"action" isEqualToString: elementName]))
([@"action" isEqualToString: elementName]) ||
([@"binding" isEqualToString: elementName]))
{
NSString *classname = nil;
NSString *targID = [element attributeForKey: @"target"];
@ -2903,8 +2913,10 @@ didStartElement: (NSString*)elementName
if ([@"outlet" isEqualToString: elementName])
classname = @"IBOutletConnection5";
else
else if ([@"action" isEqualToString: elementName])
classname = @"IBActionConnection5";
else
classname = @"NSNibBindingConnector";
// Decode the object...
object = [self decodeObjectForXib: element forClassName: classname withID: [element attributeForKey: @"id"]];
@ -3392,9 +3404,9 @@ didStartElement: (NSString*)elementName
return range;
}
- (BOOL)containsValueForKey:(NSString *)key
- (BOOL) containsValueForKey: (NSString *)key
{
BOOL hasValue = [super containsValueForKey:key];
BOOL hasValue = [super containsValueForKey: key];
// Check attributes (for XIB 5 and above) for additional values...
if (hasValue == NO)
@ -3433,12 +3445,12 @@ didStartElement: (NSString*)elementName
// These are arbitrarily defined through hard-coding...
hasValue = YES;
}
else if ([key hasPrefix:@"NS"])
else if ([key hasPrefix: @"NS"])
{
// Try a key minus a (potential) NS prefix...
NSString *newKey = [key stringByDeletingPrefix:@"NS"];
newKey = [[[newKey substringToIndex:1] lowercaseString] stringByAppendingString:[newKey substringFromIndex:1]];
hasValue = [self containsValueForKey:newKey];
NSString *newKey = [key stringByDeletingPrefix: @"NS"];
newKey = [[[newKey substringToIndex: 1] lowercaseString] stringByAppendingString: [newKey substringFromIndex:1]];
hasValue = [self containsValueForKey: newKey];
}
else
{

View file

@ -732,7 +732,7 @@ didStartElement: (NSString*)elementName
}
else
{
NSLog(@"Unknown element type %@", elementName);
//NSLog(@"Unknown element type %@", elementName);
}
return nil;
@ -970,7 +970,8 @@ didStartElement: (NSString*)elementName
if (o != nil)
{
if ([o isKindOfClass: [NSNumber class]] == YES)
if (([o isKindOfClass: [NSNumber class]] == YES) ||
([o isKindOfClass: [NSString class]] == YES))
{
long long l = [o longLongValue];

View file

@ -45,7 +45,6 @@
#import "GNUstepGUI/GSModelLoaderFactory.h"
#import "GNUstepGUI/GSNibLoading.h"
#import "GNUstepGUI/GSXibLoading.h"
#import "GNUstepGUI/GSXibParser.h"
#import "GNUstepGUI/GSXibObjectContainer.h"
#import "GNUstepGUI/GSXibElement.h"
#import "GNUstepGUI/GSXibKeyedUnarchiver.h"
@ -353,11 +352,11 @@
{
object_setIvar(source, ivar, destination);
}
#if defined(DEBUG)
else
{
NSWarnMLog(@"class '%@' has no instance var named: %@", NSStringFromClass(class), label);
}
#if defined(DEBUG)
else
{
NSWarnMLog(@"class '%@' has no instance var named: %@", NSStringFromClass(class), label);
}
#endif
}
}

View file

@ -1,211 +0,0 @@
/* <title>GSXibParser</title>
<abstract>Xib v5 (Cocoa XML) parser</abstract>
Copyright (C) 2014 Free Software Foundation, Inc.
Written by: Gregory Casamento <greg.casamento@gmail.com>
Created: March 2014
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#import <Foundation/NSData.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSXMLParser.h>
#import <Foundation/NSString.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSException.h>
#import "GNUstepGUI/GSXibParser.h"
#import "GNUstepGUI/GSXibElement.h"
// XIB Object...
@interface XIBObject : NSObject
{
NSMutableArray *connections;
}
- (id) initWithXibElement: (GSXibElement *)element;
- (id) instantiateObject;
@end
@implementation XIBObject
- (id) initWithXibElement: (GSXibElement *)element
{
if ((self = [super init]) != nil)
{
connections = [[NSMutableArray alloc] initWithCapacity: 10];
}
return self;
}
- (void) dealloc
{
[connections release];
[super dealloc];
}
- (id) instantiateObject
{
return nil;
}
- (NSArray *) connections
{
return connections;
}
@end
@interface XIBAction : XIBObject
- (void) setSelector: (NSString *)selectorName;
- (NSString *) selector;
- (void) setTarget: (NSString *)targetId;
- (NSString *) target;
@end
@interface XIBOutlet : XIBObject
- (void) setProperty: (NSString *)propertyName;
- (NSString *) property;
- (void) setDestination: (NSString *)destinationId;
- (NSString *) destination;
@end
@interface XIBCustomObject
- (void) setUserLabel: (NSString *)label;
- (NSString *) userLabel;
- (void) setCustomClass: (NSString *)className;
- (NSString *) customClass;
@end
@implementation GSXibParser
- (id) initWithData: (NSData *)data
{
if ((self = [super init]) != nil)
{
theParser = [[NSXMLParser alloc] initWithData: data];
[theParser setDelegate: self];
objects = [[NSMutableDictionary alloc] initWithCapacity: 100];
stack = [[NSMutableArray alloc] initWithCapacity: 100];
currentElement = nil;
}
return self;
}
- (NSDictionary *) parse
{
NS_DURING
{
[theParser parse];
}
NS_HANDLER
{
NSLog(@"%@",[localException reason]);
}
NS_ENDHANDLER;
return objects;
}
- (NSMutableDictionary *) instantiateObjects
{
return nil;
}
- (NSString *)classNameFromType: (NSString *)typeName
{
NSString *className = [@"XIB" stringByAppendingString: [typeName capitalizedString]];
return className;
}
- (id) instantiateObjectForElement: (GSXibElement *)element
{
NSString *className = [self classNameFromType: [element type]];
id obj = nil;
if (className != nil)
{
Class cls = NSClassFromString(className);
if (cls != nil)
{
obj = [[cls alloc] initWithXibElement:element];
}
}
return obj;
}
- (void) parser: (NSXMLParser*)parser
foundCharacters: (NSString*)string
{
[currentElement setValue: string];
}
- (void) parser: (NSXMLParser*)parser
didStartElement: (NSString*)elementName
namespaceURI: (NSString*)namespaceURI
qualifiedName: (NSString*)qualifiedName
attributes: (NSDictionary*)attributeDict
{
GSXibElement *element = [[GSXibElement alloc] initWithType: elementName
andAttributes: attributeDict];
NSString *key = [attributeDict objectForKey: @"id"];
// FIXME: We should use proper memory management here
AUTORELEASE(element);
if ([@"document" isEqualToString: elementName])
{
currentElement = element;
}
else
{
if (key != nil)
{
// id obj = [self instantiateObjectForElement: element];
[currentElement setElement: element forKey: key];
}
else
{
// For Arrays
[currentElement addElement: element];
}
currentElement = element;
}
[stack addObject: currentElement];
}
- (void) parser: (NSXMLParser*)parser
didEndElement: (NSString*)elementName
namespaceURI: (NSString*)namespaceURI
qualifiedName: (NSString*)qName
{
if (![@"document" isEqualToString: elementName])
{
currentElement = [stack lastObject];
[stack removeLastObject];
}
else
{
objects = [self instantiateObjects];
}
}
@end

View file

@ -145,10 +145,15 @@
if ([aDecoder allowsKeyedCoding])
{
if ([aDecoder decodeIntForKey: @"NSNibBindingConnectorVersion"] != 2)
if ([aDecoder containsValueForKey: @"NSNibBindingConnectorVersion"])
{
RELEASE(self);
return nil;
int version = [aDecoder decodeIntForKey: @"NSNibBindingConnectorVersion"];
if (version != 2)
{
NSLog(@"Unexpected NSNibBindingConnectorVersion %d", version);
RELEASE(self);
return nil;
}
}
if ([aDecoder containsValueForKey: @"NSBinding"])
{