mirror of
https://github.com/nickshanks/ResKnife.git
synced 2024-12-22 17:30:15 +00:00
64 lines
2.4 KiB
Objective-C
64 lines
2.4 KiB
Objective-C
#import "CreateResourceSheetController.h"
|
||
#import "ResourceDataSource.h"
|
||
#import "ResourceDocument.h"
|
||
#import "Resource.h"
|
||
|
||
@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;
|
||
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];
|
||
}
|
||
|
||
- (void)showCreateResourceSheet:(ResourceDocument *)sheetDoc
|
||
{
|
||
#warning didEndSelector could be better employed than using the button's targets from interface builder
|
||
document = sheetDoc;
|
||
[NSApp beginSheet:[self window] modalForWindow:[document mainWindow] modalDelegate:self didEndSelector:NULL contextInfo:nil];
|
||
}
|
||
|
||
- (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];
|
||
[[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];
|
||
}
|
||
[[self window] orderOut:nil];
|
||
[NSApp endSheet:[self window]];
|
||
}
|
||
|
||
- (IBAction)typePopupSelection:(id)sender
|
||
{
|
||
[typeView setStringValue:[typePopup titleOfSelectedItem]];
|
||
[typeView selectText:sender];
|
||
}
|
||
|
||
@end
|