Merge pull request #103 from gnustep/xib_gorm_integration

XIB/Gorm integration
This commit is contained in:
Gregory Casamento 2021-05-06 23:08:16 -04:00 committed by GitHub
commit a354fb0f7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 96 additions and 88 deletions

View file

@ -1,3 +1,16 @@
2021-05-01 Gregory John Casamento <greg.casamento@gmail.com>
* Headers/Additions/GNUstepGUI/GSXibLoading.h: Add declaration
for customClassNames so that we can use that to collect the names
of all of the custom classes and their associations.
* Source/GNUmakefile: Remove classes which are not used.
* Source/GSXib5KeyedUnarchiver.m: In parserDidStartElement...
call isInInterfaceBuilder to determine if we should allocate
custom classes.
* Source/GSXibLoading.m: Add in code in nibInstantiate which uses
[NSClassSwapper isInInterfaceBuilder] to prevent connections
from being established if the XIB is being loaded in IB/Gorm.
2021-04-30 Gregory John Casamento <greg.casamento@gmail.com>
* Headers/Additions/GNUstepGUI/GSModelLoaderFactory.h:

View file

@ -53,4 +53,6 @@
- (id) _decodeArrayOfObjectsForElement: (GSXibElement*)element;
- (id) _decodeDictionaryOfObjectsForElement: (GSXibElement*)element;
- (id) objectForXib: (GSXibElement*)element;
- (NSDictionary *) decoded;
@end

View file

@ -159,6 +159,7 @@
- (id) nibInstantiate;
- (NSEnumerator *) connectionRecordEnumerator;
- (NSEnumerator *) objectRecordEnumerator;
- (NSDictionary *) customClassNames;
@end
@interface IBUserDefinedRuntimeAttributesPlaceholder : NSObject <NSCoding>

View file

@ -1,43 +0,0 @@
/* <title>GSXibObjectContainer</title>
<abstract>Xib v5 (Cocoa XML) container</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_GSXibObjectContainer
#define _GNUstep_H_GSXibObjectContainer
#import <Foundation/NSObject.h>
@class NSMutableArray;
@interface GSXibObjectContainer : NSObject
{
NSMutableArray *objects;
NSMutableArray *connections;
}
@end
#endif

View file

@ -350,7 +350,6 @@ GSXibLoader.m \
GSXibLoading.m \
GSXibKeyedUnarchiver.m \
GSXib5KeyedUnarchiver.m \
GSXibObjectContainer.m \
GSHelpAttachment.m
# Turn off NSMenuItem warning that NSMenuItem conforms to <NSObject>,
@ -658,7 +657,6 @@ GSWindowDecorationView.h \
GSXibElement.h \
GSXibLoading.h \
GSXibKeyedUnarchiver.h \
GSXibObjectContainer.h \
GSHelpAttachment.h
libgnustep-gui_HEADER_FILES = ${GUI_HEADERS}

View file

@ -41,7 +41,9 @@
GSXibElement *_runtimeAttributes;
NSMutableDictionary *_orderedObjectsDict;
NSArray *_resources;
NSMutableArray *_customClasses;
}
- (NSRange) decodeRangeForKey: (NSString*)key;
- (NSMutableArray *) customClasses;
@end

View file

@ -8,6 +8,10 @@
Date: 12/28/16
Modifications: Fred Kiefer <fredkiefer@gmx.de>
Date: December 2019
Modifications: Gregory John Casamento <greg.casamento@gmail.com>
Integration with Gorm so that XIB files can be loaded and support
for other classes/attributes.
Date: April 2021
This file is part of the GNUstep GUI Library.
@ -732,6 +736,9 @@ static NSArray *XmlBoolDefaultYes = nil;
[_IBObjectContainer setElement: _connectionRecords forKey: @"connectionRecords"];
[_IBObjectContainer setElement: _objectRecords forKey: @"objectRecords"];
[_IBObjectContainer setElement: _flattenedProperties forKey: @"flattenedProperties"];
// Hold the dictionary which contains custom class information for Gorm/IB.
_customClasses = [[NSMutableArray alloc] initWithCapacity: 10];
}
- (void)dealloc
@ -744,9 +751,30 @@ static NSArray *XmlBoolDefaultYes = nil;
RELEASE(_orderedObjects);
RELEASE(_orderedObjectsDict);
RELEASE(_resources);
RELEASE(_customClasses);
[super dealloc];
}
- (NSMutableArray *) customClasses
{
return _customClasses;
}
- (void) createCustomClassRecordForId: (NSString *)theId
withParentClass: (NSString *)parentClassName
forCustomClass: (NSString *)customClassName
{
if (theId == nil || customClassName == nil)
return;
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
theId, @"id",
parentClassName, @"parentClassName",
customClassName, @"customClassName",nil];
[_customClasses addObject: dict];
// NSLog(@"theId = %@, parentClassName = %@, customClassName = %@", theId, parentClassName, customClassName);
}
- (void) parser: (NSXMLParser*)parser
didStartElement: (NSString*)elementName
namespaceURI: (NSString*)namespaceURI
@ -759,12 +787,22 @@ didStartElement: (NSString*)elementName
NSMutableDictionary *attributes = AUTORELEASE([attributeDict mutableCopy]);
NSString *className = nil;
NSString *elementType = elementName;
NSString *customClassName = nil;
if (([@"window" isEqualToString: elementName] == NO) &&
([@"customView" isEqualToString: elementName] == NO) &&
([@"customObject" isEqualToString: elementName] == NO))
// If we are in IB we don't want to handle custom classes since they are
// not linked into the application.
if ([NSClassSwapper isInInterfaceBuilder] == NO)
{
className = [attributes objectForKey: @"customClass"];
if (([@"window" isEqualToString: elementName] == NO) &&
([@"customView" isEqualToString: elementName] == NO) &&
([@"customObject" isEqualToString: elementName] == NO))
{
className = [attributes objectForKey: @"customClass"];
}
}
else
{
customClassName = [attributes objectForKey: @"customClass"];
}
if (nil == className)
@ -787,6 +825,16 @@ didStartElement: (NSString*)elementName
[attributes setObject: className forKey: @"class"];
}
// If we are in IB/Gorm, record the id, custom class name, and parent class name so that
// they can be edited.
if ([NSClassSwapper isInInterfaceBuilder] == YES)
{
NSString *ref = [attributeDict objectForKey: @"id"];
[self createCustomClassRecordForId: ref
withParentClass: className
forCustomClass: customClassName];
}
if ([attributes objectForKey: @"key"] == nil)
{
// Special cases to allow current initWithCoder methods to obtain objects..._IBObjectContainer

View file

@ -202,8 +202,15 @@
if([classNodes count] > 0)
{
id classAttr = nil;
Class cls = NSClassFromString(className);
Class cls = nil;
// If we are in the interface builder app, do not replace
// the existing classes with their custom subclasses.
if ([NSClassSwapper isInInterfaceBuilder] == NO)
{
cls = NSClassFromString(className);
}
classNode = [classNodes objectAtIndex:0];
classAttr = [classNode attributeForName:@"class"];
[classAttr setStringValue:className];
@ -257,13 +264,7 @@
NSXMLParser *theParser;
NSData *theData = data;
// If we are in the interface builder app, do not replace
// the existing classes with their custom subclasses.
if ([NSClassSwapper isInInterfaceBuilder] == NO)
{
theData = [self _preProcessXib: data];
}
theData = [self _preProcessXib: data];
if (theData == nil)
{
return nil;
@ -1028,4 +1029,8 @@ didStartElement: (NSString*)elementName
return 0;
}
- (NSDictionary *) decoded
{
return decoded;
}
@end

View file

@ -695,6 +695,13 @@
[connection establishConnection];
}
- (NSString *) description
{
return [NSString stringWithFormat: @"<%@ - %d, %@>", [super description],
connectionID,
connection];
}
@end
@implementation IBToolTipAttribute
@ -1039,6 +1046,12 @@
NSEnumerator *en;
id obj;
// If we are currently in IB, then don't do anything.
if ([NSClassSwapper isInInterfaceBuilder])
{
return self;
}
// iterate over connections, instantiate, and then establish them.
en = [connectionRecords objectEnumerator];
while ((obj = [en nextObject]) != nil)

View file

@ -1,31 +0,0 @@
/* <title>GSXibObjectContainer</title>
<abstract>Xib v5 (Cocoa XML) container</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 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; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02110 USA.
*/
#import "GNUstepGUI/GSXibObjectContainer.h"
@implementation GSXibObjectContainer
@end