Fixed bug in NuTemplateEditor that messed up element values. -- it wasn't in copying the template elements, but rather the table got out of sync when an exception was thrown inNuTemplateElement::setStringValue:

This commit is contained in:
Uli Kusterer 2003-08-12 02:33:32 +02:00
parent 524c6532df
commit 4a2c00a0a2
9 changed files with 102 additions and 22 deletions

View File

@ -7,16 +7,16 @@
<key>IBEditorPositions</key>
<dict>
<key>246</key>
<string>12 513 340 222 0 0 1024 746 </string>
<string>344 386 340 222 0 0 1024 746 </string>
<key>29</key>
<string>28 222 347 44 0 0 1024 746 </string>
<string>33 294 347 44 0 0 1024 746 </string>
</dict>
<key>IBFramework Version</key>
<string>326.0</string>
<key>IBOpenObjects</key>
<array>
<integer>246</integer>
<integer>29</integer>
<integer>246</integer>
</array>
<key>IBSystem Version</key>
<string>7A202</string>

Binary file not shown.

View File

@ -39,7 +39,8 @@
-(id) copyWithZone: (NSZone*)zone
{
NuTemplateElement* el = [[[self class] allocWithZone: zone] initForType: type withLabel: label];
//NuTemplateElement* el = [[[self class] alloc] initForType:type withLabel:label];
[el setContaining: [self containing]];
return el;
}
@ -72,7 +73,7 @@
-(void) setContaining: (NSMutableArray*)arr
{
containing = arr; // It contains *us*, so it's unlikely it survives longer than we'd do, and we don't want to create a ring.
containing = arr; // It contains *us*, so it's unlikely we survive longer than it'd do, and we don't want to create a ring.
}
-(NSMutableArray*) containing
@ -123,5 +124,11 @@
}
-(void) setStringValue: (NSString*)str
{
// We need this method. Otherwise key/value coding throws an exception which screws up the table.
NSLog(@"This template item can't accept any values, especially not \"%@\".",str);
}
@end

View File

@ -10,11 +10,17 @@
#import "NuTemplateGroupElement.h"
@class NuTemplateLSTEElement;
@interface NuTemplateLSTBElement : NuTemplateGroupElement
{
NuTemplateLSTEElement* endElement; // Template to create our "list end" element from.
}
-(IBAction) showCreateResourceSheet: (id)sender;
-(void) setEndElement: (NuTemplateLSTEElement*)e;
-(NuTemplateLSTEElement*) endElement;
@end

View File

@ -12,6 +12,13 @@
@implementation NuTemplateLSTBElement
-(void) dealloc
{
[endElement release];
[super dealloc];
}
-(void) readSubElementsFrom: (NuTemplateStream*)stream
{
while( [stream bytesToGo] > 0 )
@ -19,7 +26,10 @@
NuTemplateElement* obj = [stream readOneElement];
if( [[obj type] isEqualToString: @"LSTE"] )
{
endElement = [obj retain];
break;
}
[subElements addObject: obj];
}
}
@ -45,17 +55,19 @@
{
while( [stream bytesToGo] > 0 )
{
nextItem = [self copy]; // Make another list item just like this one.
[containing addObject: nextItem]; // Add it below ourselves.
[nextItem readDataFrom:stream]; // Read it the same way we were.
nextItem = [[self copy] autorelease]; // Make another list item just like this one.
[nextItem setContaining: nil]; // Make sure it doesn't get into this "if" clause.
[containing addObject: nextItem]; // Add it below ourselves.
[nextItem readDataFrom:stream]; // Read it the same way we were.
[nextItem setContaining: containing]; // Set "containing" *after* readDataFrom so it doesn't pass the "containing == nil" check above.
}
// Now add a terminating 'LSTE' item:
NuTemplateLSTEElement* tlee;
tlee = [NuTemplateLSTEElement elementForType:@"LSTE" withLabel:label];
tlee = [[endElement copy] autorelease];
[containing addObject: tlee];
[tlee setContaining: containing];
[tlee setGroupElemTemplate: self];
if( bytesToGoAtStart == 0 ) // It's an empty list. Delete this LSTB again, so we only have the empty LSTE.
{
@ -63,7 +75,7 @@
[containing removeObject:self]; // Remove the LSTB.
}
else
[tlee setSubElements: [subElements copy]]; // Make a copy. So each has its own array.
[tlee setSubElements: [[subElements copy] autorelease]]; // Make a copy. So each has its own array.
}
}
@ -74,10 +86,34 @@
}
-(id) copyWithZone: (NSZone*)zone
{
NuTemplateLSTBElement* el = [super copyWithZone: zone];
[el setEndElement: [self endElement]];
return el;
}
-(void) setEndElement: (NuTemplateLSTEElement*)e
{
[e retain];
[endElement release];
endElement = e;
}
-(NuTemplateLSTEElement*) endElement
{
return endElement;
}
-(IBAction) showCreateResourceSheet: (id)sender
{
unsigned idx = [containing indexOfObject:self];
NuTemplateElement* te = [self copy];
unsigned idx = [containing indexOfObject:self];
NuTemplateGroupElement* te = [[self copy] autorelease];
[containing insertObject:te atIndex:idx+1];
[te setContaining:containing];
}
@ -85,8 +121,8 @@
-(IBAction) clear: (id)sender
{
[containing removeObject: self];
[self autorelease];
[[self retain] autorelease]; // Make sure we don't go away right now. That may surprise the one who called clear, or otherwise be bad.
[containing removeObject: self]; // Remove us from the array we're in. (this releases us once)
}

View File

@ -12,9 +12,12 @@
@interface NuTemplateLSTEElement : NuTemplateGroupElement
{
NuTemplateGroupElement* groupElemTemplate; // The item of which we're to create a copy.
}
-(IBAction) showCreateResourceSheet: (id)sender;
-(void) setGroupElemTemplate: (NuTemplateGroupElement*)e;
-(NuTemplateGroupElement*) groupElemTemplate;
@end

View File

@ -12,6 +12,25 @@
@implementation NuTemplateLSTEElement
-(void) dealloc
{
[groupElemTemplate release];
[super dealloc];
}
-(void) setGroupElemTemplate: (NuTemplateGroupElement*)e
{
[e retain];
[groupElemTemplate release];
groupElemTemplate = e;
}
-(NuTemplateGroupElement*) groupElemTemplate
{
return groupElemTemplate;
}
-(void) readSubElementsFrom: (NuTemplateStream*)stream
{
@ -55,12 +74,21 @@
}
-(id) copyWithZone: (NSZone*)zone
{
NuTemplateLSTEElement* el = [super copyWithZone: zone];
[el setGroupElemTemplate: [self groupElemTemplate]];
return el;
}
-(IBAction) showCreateResourceSheet: (id)sender
{
unsigned idx = [containing indexOfObject:self];
NuTemplateGroupElement* ge = [NuTemplateLSTBElement elementForType:@"LSTB" withLabel:[self label]];
NuTemplateGroupElement* ge = [[groupElemTemplate copy] autorelease];
[ge setSubElements: [subElements copy]];
[containing insertObject:ge atIndex:idx];
[ge setContaining: containing];
}

View File

@ -149,7 +149,7 @@
// Loop over template and read each field:
while( currElement = [enny nextObject] )
{
currElement = [currElement copy]; // Copy the template object.
currElement = [[currElement copy] autorelease]; // Copy the template object.
[resourceStructure addObject: currElement]; // Add it to our parsed resource data list. Do this right away so the element can append other items should it desire to.
[currElement setContaining: resourceStructure];
@ -319,7 +319,7 @@
return( [selElement validateMenuItem: item] );
else if( [item action] == @selector(clear:) )
return( selElement != nil && [selElement respondsToSelector: @selector(clear:)] );
else return [super validateMenuItem:item];
else return NO;
}

View File

@ -2654,11 +2654,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>Development version 0.5d1</string>
<string>Development version 0.5d2</string>
<key>CFBundleSignature</key>
<string>ResK</string>
<key>CFBundleVersion</key>
<string>0.5d1</string>
<string>0.5d2</string>
<key>NSMainNibFile</key>
<string>Application</string>
<key>NSPrincipalClass</key>