diff --git a/Cocoa/Classes/CreateResourceSheetController.h b/Cocoa/Classes/CreateResourceSheetController.h index a93db87..578fc68 100644 --- a/Cocoa/Classes/CreateResourceSheetController.h +++ b/Cocoa/Classes/CreateResourceSheetController.h @@ -1,4 +1,6 @@ #import +#import +#import "Resource.h" #import "ResourceDataSource.h" @interface CreateResourceSheetController : NSWindowController @@ -14,6 +16,8 @@ IBOutlet NSWindow *parent; } +- (void)controlTextDidChange:(NSNotification *)notification; + - (IBAction)showCreateResourceSheet:(id)sender; - (IBAction)hideCreateResourceSheet:(id)sender; - (IBAction)typePopupSelection:(id)sender; diff --git a/Cocoa/Classes/CreateResourceSheetController.m b/Cocoa/Classes/CreateResourceSheetController.m index fb03785..4fed724 100644 --- a/Cocoa/Classes/CreateResourceSheetController.m +++ b/Cocoa/Classes/CreateResourceSheetController.m @@ -1,8 +1,27 @@ #import "CreateResourceSheetController.h" -#import @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 = [[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]; +} + - (IBAction)showCreateResourceSheet:(id)sender { [NSApp beginSheet:[self window] modalForWindow:parent modalDelegate:self didEndSelector:NULL contextInfo:nil]; @@ -26,7 +45,8 @@ - (IBAction)typePopupSelection:(id)sender { - + [typeView setStringValue:[typePopup titleOfSelectedItem]]; + [typeView selectText:sender]; } @end diff --git a/Cocoa/Classes/ResourceDocument.h b/Cocoa/Classes/ResourceDocument.h index 27fdd1a..5fc8f0b 100644 --- a/Cocoa/Classes/ResourceDocument.h +++ b/Cocoa/Classes/ResourceDocument.h @@ -24,5 +24,6 @@ - (NSOutlineView *)outlineView; - (ResourceDataSource *)dataSource; +- (NSArray *)resources; // return the array as non-mutable @end \ No newline at end of file diff --git a/Cocoa/Classes/ResourceDocument.m b/Cocoa/Classes/ResourceDocument.m index 0ad8984..40c24b8 100644 --- a/Cocoa/Classes/ResourceDocument.m +++ b/Cocoa/Classes/ResourceDocument.m @@ -474,4 +474,9 @@ static NSString *RKShowInfoItemIdentifier = @"com.nickshanks.resknife.toolbar.sh return dataSource; } +- (NSArray *)resources +{ + return resources; +} + @end \ No newline at end of file diff --git a/Cocoa/English.lproj/InfoWindow.nib/objects.nib b/Cocoa/English.lproj/InfoWindow.nib/objects.nib index d628ff4..527d16a 100644 Binary files a/Cocoa/English.lproj/InfoWindow.nib/objects.nib and b/Cocoa/English.lproj/InfoWindow.nib/objects.nib differ diff --git a/Cocoa/English.lproj/ResourceDocument.nib/info.nib b/Cocoa/English.lproj/ResourceDocument.nib/info.nib index 3aa26e7..53173e0 100644 --- a/Cocoa/English.lproj/ResourceDocument.nib/info.nib +++ b/Cocoa/English.lproj/ResourceDocument.nib/info.nib @@ -6,10 +6,6 @@ 104 127 480 547 0 0 1024 746 IBFramework Version 248.0 - IBOpenObjects - - 5 - IBSystem Version 5P48 IBUserGuides diff --git a/Cocoa/English.lproj/ResourceDocument.nib/objects.nib b/Cocoa/English.lproj/ResourceDocument.nib/objects.nib index 143eb93..f54dda3 100644 Binary files a/Cocoa/English.lproj/ResourceDocument.nib/objects.nib and b/Cocoa/English.lproj/ResourceDocument.nib/objects.nib differ diff --git a/Cocoa/Plug-Ins/Hex Editor/English.lproj/HexWindow.nib/objects.nib b/Cocoa/Plug-Ins/Hex Editor/English.lproj/HexWindow.nib/objects.nib index a8948f0..c64bdc9 100644 Binary files a/Cocoa/Plug-Ins/Hex Editor/English.lproj/HexWindow.nib/objects.nib and b/Cocoa/Plug-Ins/Hex Editor/English.lproj/HexWindow.nib/objects.nib differ diff --git a/Cocoa/Plug-Ins/Hex Editor/HexEditorDelegate.m b/Cocoa/Plug-Ins/Hex Editor/HexEditorDelegate.m index 299b0d0..2fa78ac 100644 --- a/Cocoa/Plug-Ins/Hex Editor/HexEditorDelegate.m +++ b/Cocoa/Plug-Ins/Hex Editor/HexEditorDelegate.m @@ -182,6 +182,7 @@ - (NSRange)asciiRangeFromByteRange:(NSRange)byteRange; { +#warning There's a bug in this somewhere! // assumes 16 byte wide window NSRange asciiRange = NSMakeRange(0,0); @@ -191,47 +192,14 @@ return asciiRange; } -/* -- (void)textViewDidChangeSelection:(NSNotification *)notification; -{ -} - - (BOOL)textView:(NSTextView *)textView shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString; { if( textView == hex ) // we're editing in hexadecimal constrain to 0-9, A-F { + return YES; } else return YES; // we're editing in ASCII -}*/ - -/* -Raphael Sebbe's code -- (void)textViewDidChangeSelection:(NSNotification *)aNotification -{ - BOOL shouldUpdate = NO; - id textView = [aNotification object]; - if(textView == _hexText) - { - NSRange hexRange = [textView selectedRange]; - NSRange byteRange = [HVHexInterpreter byteRangeFromHexRange:hexRange]; - - _selectedByteRange = byteRange; shouldUpdate = YES; - } - else if(textView == _asciiText) - { - NSRange asciiRange = [textView selectedRange]; - NSRange byteRange = [HVHexInterpreter byteRangeFromAsciiRange:asciiRange]; - - _selectedByteRange = byteRange; shouldUpdate = YES; - } - if(shouldUpdate) - { - [self updateSelectionFeedback]; - [self updateSelectionOffsetTF]; - [self updateForms]; - } } -*/ - (NSTextView *)hex { diff --git a/Cocoa/Plug-Ins/Hex Editor/HexWindowController.h b/Cocoa/Plug-Ins/Hex Editor/HexWindowController.h index 2d10271..bc0165c 100644 --- a/Cocoa/Plug-Ins/Hex Editor/HexWindowController.h +++ b/Cocoa/Plug-Ins/Hex Editor/HexWindowController.h @@ -20,8 +20,8 @@ - (id)initWithResource:(id)newResource; // normal methods -- (void)resourceDidChange:(NSNotification *)notification; - (void)viewDidScroll:(NSNotification *)notification; +- (void)resourceDidChange:(NSNotification *)notification; - (void)refreshData:(NSData *)data; // accessors diff --git a/Cocoa/Plug-Ins/Hex Editor/HexWindowController.m b/Cocoa/Plug-Ins/Hex Editor/HexWindowController.m index b4f25b4..eb270fd 100644 --- a/Cocoa/Plug-Ins/Hex Editor/HexWindowController.m +++ b/Cocoa/Plug-Ins/Hex Editor/HexWindowController.m @@ -36,6 +36,9 @@ NSString *ResourceChangedNotification = @"ResourceChangedNotification"; { [super windowDidLoad]; + // swap text views to instances of my class instead + // An experianced NeXT programmer told me that poseAsClass would come back to bite me in the ass at some point, and that I should instead instanciate some HexTextViews and swap them in for now, and use IB do do things properly once IB is fixed. But, for now I think I'll not bother :-P + // we don't want this notification until we have a window! [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resourceDidChange:) name:ResourceChangedNotification object:nil]; @@ -51,13 +54,6 @@ NSString *ResourceChangedNotification = @"ResourceChangedNotification"; [self showWindow:self]; } -- (void)resourceDidChange:(NSNotification *)notification -{ - // see if it's our resource which got changed (we receive notifications for any resource being changed, allowing multi-resource editors) - if( [notification object] == resource ) - [self refreshData:[(id )resource data]]; -} - - (void)viewDidScroll:(NSNotification *)notification { // get object refs for increased speed @@ -97,6 +93,13 @@ NSString *ResourceChangedNotification = @"ResourceChangedNotification"; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidScroll:) name:NSViewBoundsDidChangeNotification object:asciiClip]; } +- (void)resourceDidChange:(NSNotification *)notification +{ + // see if it's our resource which got changed (we receive notifications for any resource being changed, allowing multi-resource editors) + if( [notification object] == resource ) + [self refreshData:[(id )resource data]]; +} + - (void)refreshData:(NSData *)data; { // clear delegates (see HexEditorDelegate class for explanation of why)