Added support for adding LSTBs by selecting LSTB/LSTE fields and choosing "Create New Resource...".

This commit is contained in:
Uli Kusterer 2003-08-10 00:53:58 +02:00
parent c2987b5297
commit c3dfaeef25
11 changed files with 86 additions and 13 deletions

View File

@ -30,7 +30,7 @@
}
-(void) readDataFrom: (NuTemplateStream*)stream containingArray: (NSMutableArray*)containing
-(void) readDataFrom: (NuTemplateStream*)stream
{
[stream readAmount:2 toBuffer: &shortValue];
}

View File

@ -22,8 +22,9 @@
@interface NuTemplateElement : NSObject <NSCopying>
{
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;

View File

@ -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.

View File

@ -6,6 +6,7 @@
// Copyright (c) 2003 M. Uli Kusterer. All rights reserved.
//
#import <AppKit/AppKit.h>
#import "NuTemplateGroupElement.h"
@ -14,4 +15,6 @@
}
-(IBAction) showCreateResourceSheet: (id)sender;
@end

View File

@ -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

View File

@ -6,6 +6,7 @@
// Copyright (c) 2003 M. Uli Kusterer. All rights reserved.
//
#import <AppKit/AppKit.h>
#import "NuTemplateGroupElement.h"
@ -14,4 +15,6 @@
}
-(IBAction) showCreateResourceSheet: (id)sender;
@end

View File

@ -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

View File

@ -37,7 +37,7 @@
}
-(void) readDataFrom: (NuTemplateStream*)stream containingArray: (NSMutableArray*)containing
-(void) readDataFrom: (NuTemplateStream*)stream
{
char buf[256] = { 0 };

View File

@ -37,7 +37,7 @@
}
-(void) readDataFrom: (NuTemplateStream*)stream containingArray: (NSMutableArray*)containing
-(void) readDataFrom: (NuTemplateStream*)stream
{
char buf[4] = { ' ', ' ', ' ', ' ' };

View File

@ -47,5 +47,7 @@
-(void) resourceDataDidChange: (NSNotification*)notification;
-(void) writeResData;
-(IBAction) showCreateResourceSheet: (id)sender;
@end

View File

@ -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.
{