ResKnife/Cocoa/Classes/CreateResourceSheetController.m

64 lines
2.4 KiB
Mathematica
Raw Normal View History

2001-10-19 19:41:13 +00:00
#import "CreateResourceSheetController.h"
#import "ResourceDataSource.h"
#import "ResourceDocument.h"
#import "Resource.h"
2001-10-19 19:41:13 +00:00
@implementation CreateResourceSheetController
- (void)controlTextDidChange:(NSNotification *)notification
{
BOOL enableButton = NO, clash = NO;
NSString *type = [typeView stringValue];
NSNumber *resID = [NSNumber numberWithInt:[resIDView intValue]];
if( [type length] == 4 && [[resIDView stringValue] length] > 0 )
{
Resource *resource;
2002-02-23 03:40:24 +00:00
NSEnumerator *enumerator = [[[document dataSource] resources] objectEnumerator];
while( resource = [enumerator nextObject] )
{
if( [type isEqualToString:[resource type]] && [resID isEqualToNumber:[resource resID]] )
clash = YES;
}
if( !clash ) enableButton = YES;
}
[createButton setEnabled:enableButton];
}
2002-02-23 03:40:24 +00:00
- (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];
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;
[[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]]];
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]];
}
- (IBAction)typePopupSelection:(id)sender
{
[typeView setStringValue:[typePopup titleOfSelectedItem]];
[typeView selectText:sender];
2001-10-19 19:41:13 +00:00
}
@end