2001-10-19 19:41:13 +00:00
|
|
|
|
#import "CreateResourceSheetController.h"
|
2002-02-14 23:24:53 +00:00
|
|
|
|
#import "ResourceDataSource.h"
|
|
|
|
|
#import "ResourceDocument.h"
|
|
|
|
|
#import "Resource.h"
|
2001-10-19 19:41:13 +00:00
|
|
|
|
|
|
|
|
|
@implementation CreateResourceSheetController
|
|
|
|
|
|
2003-08-01 22:23:50 +00:00
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
|
controlTextDidChange:
|
|
|
|
|
Someone changed the control ID edit field. Check whether this is
|
|
|
|
|
a unique ID and appropriately enable the "create" button.
|
|
|
|
|
|
|
|
|
|
Check "notification" against being nil, which is how we call it when
|
|
|
|
|
we need to explicitly update the enabled state of the "create" button.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
REVISIONS:
|
|
|
|
|
2003-08-01 UK Commented, changed to use data source's resourceOfType
|
|
|
|
|
instead of directly messing with the resource list's
|
|
|
|
|
enumerator Removed ID > 0 check -- negative IDs are
|
|
|
|
|
allowed as well.
|
|
|
|
|
-------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
-(void) controlTextDidChange: (NSNotification*)notification
|
2002-02-12 01:24:53 +00:00
|
|
|
|
{
|
2003-08-01 22:23:50 +00:00
|
|
|
|
BOOL enableButton = NO;
|
|
|
|
|
NSString *type = [typeView stringValue];
|
|
|
|
|
NSNumber *resID = [NSNumber numberWithInt:[resIDView intValue]];
|
2002-02-12 01:24:53 +00:00
|
|
|
|
|
2003-08-01 22:23:50 +00:00
|
|
|
|
if( [type length] == 4 )
|
2002-02-12 01:24:53 +00:00
|
|
|
|
{
|
2002-05-31 00:17:53 +00:00
|
|
|
|
// I could use +[Resource getResourceOfType:andID:inDocument:] != nil, but that would be much slower
|
2003-08-01 22:23:50 +00:00
|
|
|
|
Resource *resource = [[document dataSource] resourceOfType:type andID:resID];
|
|
|
|
|
if( resource == nil ) // No resource with that type and ID yet?
|
|
|
|
|
enableButton = YES;
|
2002-02-12 01:24:53 +00:00
|
|
|
|
}
|
|
|
|
|
[createButton setEnabled:enableButton];
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-01 22:23:50 +00:00
|
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
|
showCreateResourceSheet:
|
|
|
|
|
Show our sheet and set it up before that.
|
|
|
|
|
|
|
|
|
|
REVISIONS:
|
|
|
|
|
2003-08-01 UK Commented, made it "fake" a popup selection so
|
|
|
|
|
type field and popup match. Made it suggest an unused
|
|
|
|
|
resource ID.
|
|
|
|
|
-------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
-(void) showCreateResourceSheet: (ResourceDocument*)sheetDoc
|
2001-10-19 19:41:13 +00:00
|
|
|
|
{
|
2002-03-31 12:00:02 +00:00
|
|
|
|
// bug: didEndSelector could be better employed than using the button's targets from interface builder
|
2002-02-23 03:40:24 +00:00
|
|
|
|
document = sheetDoc;
|
|
|
|
|
[NSApp beginSheet:[self window] modalForWindow:[document mainWindow] modalDelegate:self didEndSelector:NULL contextInfo:nil];
|
2003-08-01 22:23:50 +00:00
|
|
|
|
[resIDView setObjectValue: [[document dataSource] uniqueIDForType: [typeView stringValue]]];
|
|
|
|
|
[self typePopupSelection: typePopup]; // Puts current popup value in text field and updates state of "create" button.
|
2001-10-19 19:41:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (IBAction)hideCreateResourceSheet:(id)sender
|
|
|
|
|
{
|
|
|
|
|
if( sender == createButton )
|
|
|
|
|
{
|
|
|
|
|
unsigned short attributes = 0;
|
|
|
|
|
attributes ^= [[attributesMatrix cellAtRow:0 column:0] intValue]? resPreload:0;
|
|
|
|
|
attributes ^= [[attributesMatrix cellAtRow:1 column:0] intValue]? resPurgeable:0;
|
|
|
|
|
attributes ^= [[attributesMatrix cellAtRow:2 column:0] intValue]? resLocked:0;
|
|
|
|
|
attributes ^= [[attributesMatrix cellAtRow:0 column:1] intValue]? resSysHeap:0;
|
|
|
|
|
attributes ^= [[attributesMatrix cellAtRow:1 column:1] intValue]? resProtected:0;
|
2002-02-14 23:24:53 +00:00
|
|
|
|
|
|
|
|
|
[[document undoManager] beginUndoGrouping];
|
2002-02-23 03:40:24 +00:00
|
|
|
|
[[document dataSource] addResource:[Resource resourceOfType:[typeView stringValue] andID:[NSNumber numberWithShort:(short) [resIDView intValue]] withName:[nameView stringValue] andAttributes:[NSNumber numberWithUnsignedShort:attributes]]];
|
2002-02-14 23:24:53 +00:00
|
|
|
|
if( [[nameView stringValue] length] == 0 )
|
|
|
|
|
[[document undoManager] setActionName:NSLocalizedString(@"Create Resource", nil)];
|
|
|
|
|
else [[document undoManager] setActionName:[NSString stringWithFormat:NSLocalizedString(@"Create Resource <20>%@<40>", nil), [nameView stringValue]]];
|
|
|
|
|
[[document undoManager] endUndoGrouping];
|
2001-10-19 19:41:13 +00:00
|
|
|
|
}
|
|
|
|
|
[[self window] orderOut:nil];
|
|
|
|
|
[NSApp endSheet:[self window]];
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-01 22:23:50 +00:00
|
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
|
typePopupSelection:
|
|
|
|
|
Someone chose an item from our "res type" popup menu. Update our
|
|
|
|
|
edit field to show that.
|
|
|
|
|
|
|
|
|
|
REVISIONS:
|
|
|
|
|
2003-08-01 UK Commented, made it update state of "create" button..
|
|
|
|
|
-------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
-(IBAction) typePopupSelection:(id)sender
|
2001-10-19 19:41:13 +00:00
|
|
|
|
{
|
2002-02-12 01:24:53 +00:00
|
|
|
|
[typeView setStringValue:[typePopup titleOfSelectedItem]];
|
|
|
|
|
[typeView selectText:sender];
|
2003-08-01 22:23:50 +00:00
|
|
|
|
[self controlTextDidChange: nil]; // Make sure "create" button is updated.
|
2001-10-19 19:41:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|