diff --git a/NuTemplateEditor/NuTemplateDWRDElement.m b/NuTemplateEditor/NuTemplateDWRDElement.m index ed4f041..1d45414 100644 --- a/NuTemplateEditor/NuTemplateDWRDElement.m +++ b/NuTemplateEditor/NuTemplateDWRDElement.m @@ -30,7 +30,7 @@ } --(void) readDataFrom: (NuTemplateStream*)stream containingArray: (NSMutableArray*)containing +-(void) readDataFrom: (NuTemplateStream*)stream { [stream readAmount:2 toBuffer: &shortValue]; } diff --git a/NuTemplateEditor/NuTemplateElement.h b/NuTemplateEditor/NuTemplateElement.h index ad3e3ae..85f313d 100644 --- a/NuTemplateEditor/NuTemplateElement.h +++ b/NuTemplateEditor/NuTemplateElement.h @@ -22,8 +22,9 @@ @interface NuTemplateElement : NSObject { - NSString* type; - NSString* label; + NSString* type; // Type code of this item (4 chars if from TMPL resource, but we may support longer types later). + NSString* label; // Label ("name") of this field. + NSMutableArray* containing; // The NSMutableArray* of the template field containing us, or the template window's list. } +(id) elementForType: (NSString*)type withLabel: (NSString*)label; @@ -37,6 +38,9 @@ -(void) setLabel:(NSString*)l; -(NSString*) label; +-(void) setContaining: (NSMutableArray*)arr; +-(NSMutableArray*) containing; + -(NSString*) stringValue; // Used to display your data in the list. // Items that have sub-items (like LSTB, LSTZ, LSTC and other lists) should implement these: @@ -45,7 +49,7 @@ -(void) readSubElementsFrom: (NuTemplateStream*)stream; // This is called on an item of your class when displaying resource data using a template that uses your field: --(void) readDataFrom: (NuTemplateStream*)stream containingArray: (NSMutableArray*)containing; +-(void) readDataFrom: (NuTemplateStream*)stream; // This is used to instantiate copies of the item from the template for storing data of the resource. A copy created with this is then sent readDataFrom:. -(id) copyWithZone: (NSZone*)zone; diff --git a/NuTemplateEditor/NuTemplateElement.m b/NuTemplateEditor/NuTemplateElement.m index ddaa099..a4de1e0 100644 --- a/NuTemplateEditor/NuTemplateElement.m +++ b/NuTemplateEditor/NuTemplateElement.m @@ -22,6 +22,7 @@ { label = [l retain]; type = [t retain]; + containing = nil; } return self; @@ -69,6 +70,16 @@ return label; } +-(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. +} + +-(NSMutableArray*) containing +{ + return containing; +} + -(int) subElementCount { @@ -86,7 +97,7 @@ } --(void) readDataFrom: (NuTemplateStream*)stream containingArray: (NSMutableArray*)containing +-(void) readDataFrom: (NuTemplateStream*)stream { // You should read whatever kind of data your template field stands for from "stream" // and store it in an instance variable. diff --git a/NuTemplateEditor/NuTemplateLSTBElement.h b/NuTemplateEditor/NuTemplateLSTBElement.h index 0320e4b..c195f57 100644 --- a/NuTemplateEditor/NuTemplateLSTBElement.h +++ b/NuTemplateEditor/NuTemplateLSTBElement.h @@ -6,6 +6,7 @@ // Copyright (c) 2003 M. Uli Kusterer. All rights reserved. // +#import #import "NuTemplateGroupElement.h" @@ -14,4 +15,6 @@ } +-(IBAction) showCreateResourceSheet: (id)sender; + @end diff --git a/NuTemplateEditor/NuTemplateLSTBElement.m b/NuTemplateEditor/NuTemplateLSTBElement.m index 0c67f8b..ddb4591 100644 --- a/NuTemplateEditor/NuTemplateLSTBElement.m +++ b/NuTemplateEditor/NuTemplateLSTBElement.m @@ -25,7 +25,7 @@ } --(void) readDataFrom: (NuTemplateStream*)stream containingArray: (NSMutableArray*)containing +-(void) readDataFrom: (NuTemplateStream*)stream { NSEnumerator *enny = [subElements objectEnumerator]; NuTemplateElement *el, *nextItem; @@ -36,7 +36,7 @@ fill themselves with default values. */ while( el = [enny nextObject] ) { - [el readDataFrom: stream containingArray: subElements]; + [el readDataFrom: stream]; } /* Read additional elements until we have enough items, @@ -47,13 +47,15 @@ { nextItem = [self copy]; // Make another list item just like this one. [containing addObject: nextItem]; // Add it below ourselves. - [nextItem readDataFrom:stream containingArray:nil]; // Read it the same way we were. + [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]; [containing addObject: tlee]; + [tlee setContaining: containing]; if( bytesToGoAtStart == 0 ) // It's an empty list. Delete this LSTB again, so we only have the empty LSTE. { @@ -72,5 +74,14 @@ } +-(IBAction) showCreateResourceSheet: (id)sender +{ + unsigned idx = [containing indexOfObject:self]; + NuTemplateElement* te = [self copy]; + [containing insertObject:te atIndex:idx+1]; + [te setContaining:containing]; +} + + @end diff --git a/NuTemplateEditor/NuTemplateLSTEElement.h b/NuTemplateEditor/NuTemplateLSTEElement.h index dfc82cf..280e854 100644 --- a/NuTemplateEditor/NuTemplateLSTEElement.h +++ b/NuTemplateEditor/NuTemplateLSTEElement.h @@ -6,6 +6,7 @@ // Copyright (c) 2003 M. Uli Kusterer. All rights reserved. // +#import #import "NuTemplateGroupElement.h" @@ -14,4 +15,6 @@ } +-(IBAction) showCreateResourceSheet: (id)sender; + @end diff --git a/NuTemplateEditor/NuTemplateLSTEElement.m b/NuTemplateEditor/NuTemplateLSTEElement.m index c356d7a..f81b439 100644 --- a/NuTemplateEditor/NuTemplateLSTEElement.m +++ b/NuTemplateEditor/NuTemplateLSTEElement.m @@ -7,6 +7,7 @@ // #import "NuTemplateLSTEElement.h" +#import "NuTemplateLSTBElement.h" @implementation NuTemplateLSTEElement @@ -18,14 +19,14 @@ } --(void) readDataFrom: (NuTemplateStream*)stream containingArray: (NSMutableArray*)containing +-(void) readDataFrom: (NuTemplateStream*)stream { NSEnumerator* enny = [subElements objectEnumerator]; NuTemplateElement* el; while( el = [enny nextObject] ) { - [el readDataFrom: stream containingArray: subElements]; + [el readDataFrom: stream]; } } @@ -54,5 +55,17 @@ } +-(IBAction) showCreateResourceSheet: (id)sender +{ + unsigned idx = [containing indexOfObject:self]; + NuTemplateGroupElement* ge = [NuTemplateLSTBElement elementForType:@"LSTB" withLabel:[self label]]; + + [ge setSubElements: [subElements copy]]; + [containing insertObject:ge atIndex:idx]; + [ge setContaining: containing]; +} + + + @end diff --git a/NuTemplateEditor/NuTemplatePSTRElement.m b/NuTemplateEditor/NuTemplatePSTRElement.m index b4916b9..080323d 100644 --- a/NuTemplateEditor/NuTemplatePSTRElement.m +++ b/NuTemplateEditor/NuTemplatePSTRElement.m @@ -37,7 +37,7 @@ } --(void) readDataFrom: (NuTemplateStream*)stream containingArray: (NSMutableArray*)containing +-(void) readDataFrom: (NuTemplateStream*)stream { char buf[256] = { 0 }; diff --git a/NuTemplateEditor/NuTemplateTNAMElement.m b/NuTemplateEditor/NuTemplateTNAMElement.m index 5d2d009..352dc86 100644 --- a/NuTemplateEditor/NuTemplateTNAMElement.m +++ b/NuTemplateEditor/NuTemplateTNAMElement.m @@ -37,7 +37,7 @@ } --(void) readDataFrom: (NuTemplateStream*)stream containingArray: (NSMutableArray*)containing +-(void) readDataFrom: (NuTemplateStream*)stream { char buf[4] = { ' ', ' ', ' ', ' ' }; diff --git a/NuTemplateEditor/NuTemplateWindowController.h b/NuTemplateEditor/NuTemplateWindowController.h index 51a2efb..063bf83 100644 --- a/NuTemplateEditor/NuTemplateWindowController.h +++ b/NuTemplateEditor/NuTemplateWindowController.h @@ -47,5 +47,7 @@ -(void) resourceDataDidChange: (NSNotification*)notification; -(void) writeResData; +-(IBAction) showCreateResourceSheet: (id)sender; + @end diff --git a/NuTemplateEditor/NuTemplateWindowController.m b/NuTemplateEditor/NuTemplateWindowController.m index e621c77..83495b8 100644 --- a/NuTemplateEditor/NuTemplateWindowController.m +++ b/NuTemplateEditor/NuTemplateWindowController.m @@ -32,6 +32,8 @@ #import "NuTemplateDWRDElement.h" #import "NuTemplateStream.h" +#import "NSOutlineView-SelectedItems.h" + @implementation NuTemplateWindowController @@ -149,7 +151,8 @@ currElement = [currElement copy]; // 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 readDataFrom: stream containingArray: resourceStructure]; // Fill it with resource data. + [currElement setContaining: resourceStructure]; + [currElement readDataFrom: stream]; // Fill it with resource data. } [dataList reloadData]; // Make sure our outline view displays the new data. @@ -245,6 +248,29 @@ } +/* showCreateResourceSheet: we mis-use this menu item for creating new template fields. + This works by selecting an item that serves as a template (another LSTB), or knows + how to create an item (LSTE) and passing the message on to it. */ + +-(IBAction) showCreateResourceSheet: (id)sender; +{ + NuTemplateElement *selItem = (NuTemplateElement*) [dataList selectedItem]; + + [selItem showCreateResourceSheet: sender]; // Let selected item do its magic. + + [dataList reloadData]; // Update our display. +} + + +-(BOOL) validateMenuItem: (NSMenuItem*)item +{ + NuTemplateElement *selItem = (NuTemplateElement*) [dataList selectedItem]; + + if( [item action] == @selector(showCreateResourceSheet:) ) + return( selItem != nil && [selItem respondsToSelector: @selector(showCreateResourceSheet:)] ); + else return [super validateMenuItem:item]; +} + -(BOOL) windowShouldClose: (id)sender // Window delegate. {