mirror of
https://github.com/nickshanks/ResKnife.git
synced 2024-07-05 15:29:12 +00:00
Restrictions applied to resource creation sheet to prevent type/ID clashes occuring.
This commit is contained in:
parent
25ffdd2023
commit
40c8861964
@ -1,4 +1,6 @@
|
|||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#import <Carbon/Carbon.h>
|
||||||
|
#import "Resource.h"
|
||||||
#import "ResourceDataSource.h"
|
#import "ResourceDataSource.h"
|
||||||
|
|
||||||
@interface CreateResourceSheetController : NSWindowController
|
@interface CreateResourceSheetController : NSWindowController
|
||||||
@ -14,6 +16,8 @@
|
|||||||
IBOutlet NSWindow *parent;
|
IBOutlet NSWindow *parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)controlTextDidChange:(NSNotification *)notification;
|
||||||
|
|
||||||
- (IBAction)showCreateResourceSheet:(id)sender;
|
- (IBAction)showCreateResourceSheet:(id)sender;
|
||||||
- (IBAction)hideCreateResourceSheet:(id)sender;
|
- (IBAction)hideCreateResourceSheet:(id)sender;
|
||||||
- (IBAction)typePopupSelection:(id)sender;
|
- (IBAction)typePopupSelection:(id)sender;
|
||||||
|
@ -1,8 +1,27 @@
|
|||||||
#import "CreateResourceSheetController.h"
|
#import "CreateResourceSheetController.h"
|
||||||
#import <Carbon/Carbon.h>
|
|
||||||
|
|
||||||
@implementation CreateResourceSheetController
|
@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
|
- (IBAction)showCreateResourceSheet:(id)sender
|
||||||
{
|
{
|
||||||
[NSApp beginSheet:[self window] modalForWindow:parent modalDelegate:self didEndSelector:NULL contextInfo:nil];
|
[NSApp beginSheet:[self window] modalForWindow:parent modalDelegate:self didEndSelector:NULL contextInfo:nil];
|
||||||
@ -26,7 +45,8 @@
|
|||||||
|
|
||||||
- (IBAction)typePopupSelection:(id)sender
|
- (IBAction)typePopupSelection:(id)sender
|
||||||
{
|
{
|
||||||
|
[typeView setStringValue:[typePopup titleOfSelectedItem]];
|
||||||
|
[typeView selectText:sender];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -24,5 +24,6 @@
|
|||||||
|
|
||||||
- (NSOutlineView *)outlineView;
|
- (NSOutlineView *)outlineView;
|
||||||
- (ResourceDataSource *)dataSource;
|
- (ResourceDataSource *)dataSource;
|
||||||
|
- (NSArray *)resources; // return the array as non-mutable
|
||||||
|
|
||||||
@end
|
@end
|
@ -474,4 +474,9 @@ static NSString *RKShowInfoItemIdentifier = @"com.nickshanks.resknife.toolbar.sh
|
|||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSArray *)resources
|
||||||
|
{
|
||||||
|
return resources;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
BIN
Cocoa/English.lproj/InfoWindow.nib/objects.nib
generated
BIN
Cocoa/English.lproj/InfoWindow.nib/objects.nib
generated
Binary file not shown.
@ -6,10 +6,6 @@
|
|||||||
<string>104 127 480 547 0 0 1024 746 </string>
|
<string>104 127 480 547 0 0 1024 746 </string>
|
||||||
<key>IBFramework Version</key>
|
<key>IBFramework Version</key>
|
||||||
<string>248.0</string>
|
<string>248.0</string>
|
||||||
<key>IBOpenObjects</key>
|
|
||||||
<array>
|
|
||||||
<integer>5</integer>
|
|
||||||
</array>
|
|
||||||
<key>IBSystem Version</key>
|
<key>IBSystem Version</key>
|
||||||
<string>5P48</string>
|
<string>5P48</string>
|
||||||
<key>IBUserGuides</key>
|
<key>IBUserGuides</key>
|
||||||
|
BIN
Cocoa/English.lproj/ResourceDocument.nib/objects.nib
generated
BIN
Cocoa/English.lproj/ResourceDocument.nib/objects.nib
generated
Binary file not shown.
Binary file not shown.
@ -182,6 +182,7 @@
|
|||||||
|
|
||||||
- (NSRange)asciiRangeFromByteRange:(NSRange)byteRange;
|
- (NSRange)asciiRangeFromByteRange:(NSRange)byteRange;
|
||||||
{
|
{
|
||||||
|
#warning There's a bug in this somewhere!
|
||||||
// assumes 16 byte wide window
|
// assumes 16 byte wide window
|
||||||
NSRange asciiRange = NSMakeRange(0,0);
|
NSRange asciiRange = NSMakeRange(0,0);
|
||||||
|
|
||||||
@ -191,47 +192,14 @@
|
|||||||
return asciiRange;
|
return asciiRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
- (void)textViewDidChangeSelection:(NSNotification *)notification;
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL)textView:(NSTextView *)textView shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString;
|
- (BOOL)textView:(NSTextView *)textView shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString;
|
||||||
{
|
{
|
||||||
if( textView == hex ) // we're editing in hexadecimal constrain to 0-9, A-F
|
if( textView == hex ) // we're editing in hexadecimal constrain to 0-9, A-F
|
||||||
{
|
{
|
||||||
|
return YES;
|
||||||
}
|
}
|
||||||
else return YES; // we're editing in ASCII
|
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
|
- (NSTextView *)hex
|
||||||
{
|
{
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
- (id)initWithResource:(id)newResource;
|
- (id)initWithResource:(id)newResource;
|
||||||
|
|
||||||
// normal methods
|
// normal methods
|
||||||
- (void)resourceDidChange:(NSNotification *)notification;
|
|
||||||
- (void)viewDidScroll:(NSNotification *)notification;
|
- (void)viewDidScroll:(NSNotification *)notification;
|
||||||
|
- (void)resourceDidChange:(NSNotification *)notification;
|
||||||
- (void)refreshData:(NSData *)data;
|
- (void)refreshData:(NSData *)data;
|
||||||
|
|
||||||
// accessors
|
// accessors
|
||||||
|
@ -36,6 +36,9 @@ NSString *ResourceChangedNotification = @"ResourceChangedNotification";
|
|||||||
{
|
{
|
||||||
[super windowDidLoad];
|
[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!
|
// we don't want this notification until we have a window!
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resourceDidChange:) name:ResourceChangedNotification object:nil];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resourceDidChange:) name:ResourceChangedNotification object:nil];
|
||||||
|
|
||||||
@ -51,13 +54,6 @@ NSString *ResourceChangedNotification = @"ResourceChangedNotification";
|
|||||||
[self showWindow:self];
|
[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 <ResKnifeResourceProtocol>)resource data]];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)viewDidScroll:(NSNotification *)notification
|
- (void)viewDidScroll:(NSNotification *)notification
|
||||||
{
|
{
|
||||||
// get object refs for increased speed
|
// get object refs for increased speed
|
||||||
@ -97,6 +93,13 @@ NSString *ResourceChangedNotification = @"ResourceChangedNotification";
|
|||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidScroll:) name:NSViewBoundsDidChangeNotification object:asciiClip];
|
[[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 <ResKnifeResourceProtocol>)resource data]];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)refreshData:(NSData *)data;
|
- (void)refreshData:(NSData *)data;
|
||||||
{
|
{
|
||||||
// clear delegates (see HexEditorDelegate class for explanation of why)
|
// clear delegates (see HexEditorDelegate class for explanation of why)
|
||||||
|
Loading…
Reference in New Issue
Block a user