Add IB defined runtime attribute processing for XIB

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@38878 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Marcian Lytwyn 2015-08-13 16:33:48 +00:00
parent 3f3bb2771a
commit faf6349ffd
3 changed files with 103 additions and 28 deletions

View file

@ -37,6 +37,7 @@
@class NSString, NSDictionary, NSArray, NSMutableDictionary, NSMutableArray;
@class NSNibBindingConnector;
@class GSXibElement;
@class NSNibConnector;
// Hack: This allows the class name FirstResponder in NSCustomObject and
// correctly returns nil as the corresponding object.
@ -158,6 +159,38 @@
- (NSEnumerator *) objectRecordEnumerator;
@end
@interface IBUserDefinedRuntimeAttributesPlaceholder : NSObject <NSCoding>
{
NSArray *runtimeAttributes;
NSString *name;
}
- (void) setName: (NSString *)name;
- (NSString *) name;
- (void) setRuntimeAttributes: (NSString *)attributes;
- (NSString *) runtimeAttributes;
@end
@interface IBUserDefinedRuntimeAttribute : NSObject <NSCoding>
{
NSString *typeIdentifier;
NSString *keyPath;
id value;
}
- (void) setTypeIdentifier: (NSString *)type;
- (NSString *) typeIdentifier;
- (void) setKeyPath: (NSString *)keyPath;
- (NSString *) keyPath;
- (void) setValue: (id)value;
- (id) value;
@end
@interface GSXibKeyedUnarchiver: NSKeyedUnarchiver
{
NSMutableDictionary *objects;

View file

@ -856,12 +856,30 @@
value = [properties objectForKey: @"IBAttributePlaceholdersKey"];
if (value != nil)
{
IBToolTipAttribute *tta = [(NSDictionary*)value objectForKey: @"ToolTip"];
NSDictionary *infodict = (NSDictionary*)value;
// Process tooltips...
IBToolTipAttribute *tooltip = [infodict objectForKey: @"ToolTip"];
if ([realObj respondsToSelector: @selector(setToolTip:)])
if (tooltip && [realObj respondsToSelector: @selector(setToolTip:)])
{
[realObj setToolTip: [tta toolTip]];
[realObj setToolTip: [tooltip toolTip]];
}
// Process XIB runtime attributes...
if ([infodict objectForKey:@"IBUserDefinedRuntimeAttributesPlaceholderName"])
{
IBUserDefinedRuntimeAttributesPlaceholder *placeholder =
[infodict objectForKey:@"IBUserDefinedRuntimeAttributesPlaceholderName"];
NSArray *attributes = [placeholder runtimeAttributes];
NSEnumerator *objectiter = [attributes objectEnumerator];
IBUserDefinedRuntimeAttribute *attribute = nil;
while (attribute = [objectiter nextObject])
{
[realObj setValue:[attribute value] forKeyPath:[attribute keyPath]];
}
}
}
if ([realObj respondsToSelector: @selector(awakeFromNib)])

View file

@ -1,24 +1,8 @@
#import <Foundation/NSObject.h>
#import <AppKit/NSNibConnector.h>
#import <Foundation/NSKeyedArchiver.h>
#import "GNUstepGUI/GSXibElement.h"
@interface IBUserDefinedRuntimeAttributesPlaceholder : NSObject <NSCoding>
{
NSString *typeIdentifier;
NSString *keyPath;
id value;
}
- (void) setTypeIdentifier: (NSString *)type;
- (NSString *) typeIdentifier;
- (void) setKeyPath: (NSString *)keyPath;
- (NSString *) keyPath;
- (void) setValue: (id)value;
- (id) value;
@end
#import "GNUstepGUI/GSXibLoading.h"
@interface IBAccessibilityAttribute : NSObject <NSCoding>
@end
@ -29,18 +13,15 @@
@interface IBLayoutConstant : NSObject <NSCoding>
@end
@implementation IBUserDefinedRuntimeAttributesPlaceholder
@implementation IBUserDefinedRuntimeAttribute
- (void) encodeWithCoder: (NSCoder *)coder
{
if([coder allowsKeyedCoding])
{
[coder encodeObject: typeIdentifier
forKey: @"typeIdentifier"];
[coder encodeObject: keyPath
forKey: @"keyPath"];
[coder encodeObject: value
forKey: @"value"];
[coder encodeObject: typeIdentifier forKey: @"typeIdentifier"];
[coder encodeObject: keyPath forKey: @"keyPath"];
[coder encodeObject: value forKey: @"value"];
}
}
@ -87,6 +68,49 @@
@end
@implementation IBUserDefinedRuntimeAttributesPlaceholder
- (void) encodeWithCoder: (NSCoder *)coder
{
if([coder allowsKeyedCoding])
{
[coder encodeObject: name forKey: @"IBUserDefinedRuntimeAttributesPlaceholderName"];
[coder encodeObject: runtimeAttributes forKey: @"userDefinedRuntimeAttributes"];
}
}
- (id) initWithCoder: (NSCoder *)coder
{
if([coder allowsKeyedCoding])
{
[self setName: [coder decodeObjectForKey: @"IBUserDefinedRuntimeAttributesPlaceholderName"]];
[self setRuntimeAttributes: [coder decodeObjectForKey: @"userDefinedRuntimeAttributes"]];
}
return self;
}
- (void) setName: (NSString *)value
{
ASSIGN(name, value);
}
- (NSString *) name
{
return name;
}
- (void) setRuntimeAttributes: (NSString *)attrbutes
{
ASSIGN(runtimeAttributes, attrbutes);
}
- (NSString *) runtimeAttributes
{
return runtimeAttributes;
}
@end
@implementation IBAccessibilityAttribute
- (void) encodeWithCoder: (NSCoder *)coder