mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 02:04:20 +00:00
Addition of XIBObject base class for handling objects parsed out of the XIB file.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@37799 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
22d1969783
commit
1e9799efeb
5 changed files with 112 additions and 0 deletions
|
@ -1,3 +1,11 @@
|
|||
2014-04-16 17:28-EDT Gregory John Casamento <greg.casamento@gmail.com>
|
||||
|
||||
* Headers/Additions/GNUstepGUI/GSXibElement.h
|
||||
* Headers/Additions/GNUstepGUI/GSXibObjectContainer.h
|
||||
* Source/GSXibElement.m
|
||||
* Source/GSXibParser.m: More XIB changes. Addition of XIBObject
|
||||
class.
|
||||
|
||||
2014-04-03 00:55-EDT Gregory John Casamento <greg.casamento@gmail.com>
|
||||
|
||||
* Source/GSXibParser.m: Add code to parse XML into a tree
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
- (void) setValue: (NSString*)text;
|
||||
- (NSString*) attributeForKey: (NSString*)key;
|
||||
- (GSXibElement*) elementForKey: (NSString*)key;
|
||||
- (NSDictionary *) attributes;
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,7 +29,13 @@
|
|||
|
||||
#import <Foundation/NSObject.h>
|
||||
|
||||
@class NSMutableArray;
|
||||
|
||||
@interface GSXibObjectContainer : NSObject
|
||||
{
|
||||
NSMutableArray *objects;
|
||||
NSMutableArray *connections;
|
||||
}
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
|
|
@ -100,6 +100,11 @@
|
|||
return [elements objectForKey: key];
|
||||
}
|
||||
|
||||
- (NSDictionary *)attributes
|
||||
{
|
||||
return attributes;
|
||||
}
|
||||
|
||||
- (NSString*) description
|
||||
{
|
||||
return [NSString stringWithFormat:
|
||||
|
|
|
@ -34,6 +34,65 @@
|
|||
#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
|
||||
|
@ -66,6 +125,34 @@
|
|||
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
|
||||
{
|
||||
|
@ -92,6 +179,7 @@ didStartElement: (NSString*)elementName
|
|||
{
|
||||
if (key != nil)
|
||||
{
|
||||
// id obj = [self instantiateObjectForElement: element];
|
||||
[currentElement setElement: element forKey: key];
|
||||
}
|
||||
else
|
||||
|
@ -115,5 +203,9 @@ didStartElement: (NSString*)elementName
|
|||
currentElement = [stack lastObject];
|
||||
[stack removeLastObject];
|
||||
}
|
||||
else
|
||||
{
|
||||
objects = [self instantiateObjects];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue