From e8c270d59d0089f15c683c8a589fe1cc1ad055d9 Mon Sep 17 00:00:00 2001 From: Nicholas Shanks Date: Mon, 11 Feb 2002 01:22:17 +0000 Subject: [PATCH] Bugs fixed, optimizations made, etc. --- Cocoa/Classes/ApplicationDelegate.m | 7 ++++- Cocoa/Classes/InfoWindowController.m | 12 +++---- Cocoa/Classes/PrefsWindowController.h | 1 + Cocoa/Classes/PrefsWindowController.m | 17 +++++++++- Cocoa/Classes/ResourceDocument.m | 31 ++++++++++--------- Cocoa/Plug-Ins/Hex Editor/HexEditorDelegate.m | 20 ++++++------ Cocoa/Plug-Ins/Hex Editor/HexTextView.h | 6 +++- Cocoa/Plug-Ins/Hex Editor/HexTextView.m | 13 ++++---- Cocoa/Plug-Ins/Hex Editor/HexWindow.h | 7 ----- Cocoa/Plug-Ins/Hex Editor/HexWindow.m | 5 --- .../Plug-Ins/Hex Editor/HexWindowController.h | 3 +- .../Plug-Ins/Hex Editor/HexWindowController.m | 3 -- Cocoa/Resources/defaults.plist | 2 ++ Hex Editor/Classes/HexWindow.cpp | 6 ++-- ResKnife.pbproj/project.pbxproj | 14 --------- 15 files changed, 74 insertions(+), 73 deletions(-) delete mode 100644 Cocoa/Plug-Ins/Hex Editor/HexWindow.h delete mode 100644 Cocoa/Plug-Ins/Hex Editor/HexWindow.m diff --git a/Cocoa/Classes/ApplicationDelegate.m b/Cocoa/Classes/ApplicationDelegate.m index aa19250..87efa85 100644 --- a/Cocoa/Classes/ApplicationDelegate.m +++ b/Cocoa/Classes/ApplicationDelegate.m @@ -12,7 +12,7 @@ - (id)init { self = [super init]; - [NSApp registerServicesMenuSendTypes:[NSArray arrayWithObject:@"NSString"] returnTypes:[NSArray arrayWithObject:@"NSString"]]; + [NSApp registerServicesMenuSendTypes:[NSArray arrayWithObject:NSStringPboardType] returnTypes:[NSArray arrayWithObject:NSStringPboardType]]; return self; } @@ -25,6 +25,11 @@ [self initUserDefaults]; } +- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender +{ + return [[NSUserDefaults standardUserDefaults] boolForKey:@"OpenUntitledFileOnLaunch"]; +} + - (IBAction)showAbout:(id)sender { [NSApp orderFrontStandardAboutPanel:sender]; diff --git a/Cocoa/Classes/InfoWindowController.m b/Cocoa/Classes/InfoWindowController.m index b7011ed..bb6ed46 100644 --- a/Cocoa/Classes/InfoWindowController.m +++ b/Cocoa/Classes/InfoWindowController.m @@ -12,6 +12,12 @@ return self; } +- (void)dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [super dealloc]; +} + - (void)windowDidLoad { [super windowDidLoad]; @@ -29,12 +35,6 @@ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectedResourceChanged:) name:NSOutlineViewSelectionDidChangeNotification object:nil]; } -- (void)dealloc -{ - [[NSNotificationCenter defaultCenter] removeObserver:self]; - [super dealloc]; -} - - (void)updateInfoWindow { if( selectedResource ) diff --git a/Cocoa/Classes/PrefsWindowController.h b/Cocoa/Classes/PrefsWindowController.h index f601cdc..0dff3bf 100644 --- a/Cocoa/Classes/PrefsWindowController.h +++ b/Cocoa/Classes/PrefsWindowController.h @@ -13,6 +13,7 @@ enum DataProtection IBOutlet NSMatrix *dataProtectionMatrix; } +- (void)updatePrefs:(NSNotification *)notification; - (IBAction)acceptPrefs:(id)sender; - (IBAction)cancelPrefs:(id)sender; - (IBAction)resetToDefault:(id)sender; diff --git a/Cocoa/Classes/PrefsWindowController.m b/Cocoa/Classes/PrefsWindowController.m index b355b19..ad308c3 100644 --- a/Cocoa/Classes/PrefsWindowController.m +++ b/Cocoa/Classes/PrefsWindowController.m @@ -9,7 +9,22 @@ return self; } +- (void)dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [super dealloc]; +} + - (void)awakeFromNib +{ + // represent current prefs in window state + [self updatePrefs:nil]; + + // listen out for pref changes from elsewhere + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updatePrefs:) name:NSUserDefaultsDidChangeNotification object:nil]; +} + +- (void)updatePrefs:(NSNotification *)notification { // load preferencesÉ NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; @@ -23,7 +38,7 @@ [[dataProtectionMatrix cellAtRow:autosaveBox column:0] setState:autosave]; [autosaveIntervalField setStringValue:[NSString stringWithFormat:@"%d", autosaveInterval]]; [[dataProtectionMatrix cellAtRow:deleteResourceWarningBox column:0] setState:deleteResourceWarning]; -} +} - (IBAction)acceptPrefs:(id)sender { diff --git a/Cocoa/Classes/ResourceDocument.m b/Cocoa/Classes/ResourceDocument.m index 14d136d..0ad8984 100644 --- a/Cocoa/Classes/ResourceDocument.m +++ b/Cocoa/Classes/ResourceDocument.m @@ -44,6 +44,7 @@ [[outlineView tableColumnWithIdentifier:@"name"] setDataCell:resourceNameCell]; } +// [[controller window] setResizeIncrements:NSMakeSize(1,18)]; // [controller setDocumet:self]; [dataSource setResources:resources]; } @@ -57,7 +58,7 @@ { NSString *file = [[[sender representedFilename] lastPathComponent] stringByDeletingPathExtension]; if( [file isEqualToString:@""] ) file = @"this document"; - NSBeginAlertSheet( @"Save Document?", @"Save", @"Cancel", @"DonŐt Save", sender, self, @selector(didEndShouldCloseSheet:returnCode:contextInfo:), NULL, sender, @"Do you wish to save %@?", file ); + NSBeginAlertSheet( @"Save Document?", @"Save", @"DonŐt Save", @"Cancel", sender, self, @selector(didEndShouldCloseSheet:returnCode:contextInfo:), NULL, sender, @"Do you wish to save %@?", file ); return NO; } @@ -68,7 +69,7 @@ [self saveDocument:contextInfo]; [(NSWindow *)contextInfo close]; } - else if( returnCode == NSAlertOtherReturn ) // don't save, just close + else if( returnCode == NSAlertAlternateReturn ) // don't save, just close { [(NSWindow *)contextInfo close]; } @@ -76,19 +77,19 @@ { NSLog( @"didEndShouldCloseSheet received NSAlertErrorReturn return code" ); } - // else returnCode == NSAlertAlternateReturn, cancel + // else returnCode == NSAlertOtherReturn, cancel } /* TOOLBAR MANAGMENT */ #pragma mark - -static NSString *RKToolbarIdentifier = @"com.nickshanks.resknife.toolbar"; -static NSString *RKCreateItemIdentifier = @"com.nickshanks.resknife.toolbar.create"; -static NSString *RKDeleteItemIdentifier = @"com.nickshanks.resknife.toolbar.delete"; -static NSString *RKEditItemIdentifier = @"com.nickshanks.resknife.toolbar.edit"; -static NSString *RKEditHexItemIdentifier = @"com.nickshanks.resknife.toolbar.edithex"; -static NSString *RKSaveItemIdentifier = @"com.nickshanks.resknife.toolbar.save"; -static NSString *RKShowInfoItemIdentifier = @"com.nickshanks.resknife.toolbar.showinfo"; +static NSString *RKToolbarIdentifier = @"com.nickshanks.resknife.toolbar"; +static NSString *RKCreateItemIdentifier = @"com.nickshanks.resknife.toolbar.create"; +static NSString *RKDeleteItemIdentifier = @"com.nickshanks.resknife.toolbar.delete"; +static NSString *RKEditItemIdentifier = @"com.nickshanks.resknife.toolbar.edit"; +static NSString *RKEditHexItemIdentifier = @"com.nickshanks.resknife.toolbar.edithex"; +static NSString *RKSaveItemIdentifier = @"com.nickshanks.resknife.toolbar.save"; +static NSString *RKShowInfoItemIdentifier = @"com.nickshanks.resknife.toolbar.showinfo"; - (void)setupToolbar:(NSWindowController *)controller { @@ -269,25 +270,25 @@ static NSString *RKShowInfoItemIdentifier = @"com.nickshanks.resknife.toolbar.sh { [[dataSource createResourceSheetController] showCreateResourceSheet:self]; } -/* + - (IBAction)openResource:(id)sender { if( NO ); else [self openResourceAsHex:sender]; } -*/ + - (IBAction)openResourceAsHex:(id)sender { NSBundle *hexEditor = [NSBundle bundleWithPath:[[[NSBundle mainBundle] builtInPlugInsPath] stringByAppendingPathComponent:@"Hexadecimal Editor.plugin"]]; Resource *resource = [outlineView itemAtRow:[outlineView selectedRow]]; - // bug: I alloc a plug instance here, but have no idea where I should dealloc it, perhaps the plug ought to call [self dealloc] when it's last window is closed? + // bug: I alloc a plug instance here, but have no idea where I should dealloc it, perhaps the plug ought to call [self autorelease] when it's last window is closed? [(id )[[hexEditor principalClass] alloc] initWithResource:resource]; } -/* + - (IBAction)playSound:(id)sender { } -*/ + /* FILE HANDLING */ #pragma mark - diff --git a/Cocoa/Plug-Ins/Hex Editor/HexEditorDelegate.m b/Cocoa/Plug-Ins/Hex Editor/HexEditorDelegate.m index b41dac3..299b0d0 100644 --- a/Cocoa/Plug-Ins/Hex Editor/HexEditorDelegate.m +++ b/Cocoa/Plug-Ins/Hex Editor/HexEditorDelegate.m @@ -8,6 +8,7 @@ - (NSString *)offsetRepresentation:(NSData *)data; { +#warning The hex editor window is currently limited to 16 bytes per row int row, dataLength = [data length]; int rows = (dataLength / 16) + ((dataLength % 16)? 1:0); NSMutableString *representation = [NSMutableString string]; @@ -24,9 +25,11 @@ - (NSString *)hexRepresentation:(NSData *)data; { +#warning The hex editor window is currently limited to 16 bytes per row int row, addr, currentByte = 0, dataLength = [data length]; int rows = (dataLength / 16) + ((dataLength % 16)? 1:0); - char buffer[16*3], byte, hex1, hex2; + char buffer[16*3], hex1, hex2; + char *bytes = (char *) [data bytes]; NSMutableString *representation = [NSMutableString string]; // draw bytes @@ -36,9 +39,8 @@ { if( currentByte < dataLength ) { - [data getBytes:&byte range:NSMakeRange(currentByte, 1)]; - hex1 = byte; - hex2 = byte; + hex1 = bytes[currentByte]; + hex2 = bytes[currentByte]; hex1 >>= 4; hex1 &= 0x0F; hex2 &= 0x0F; @@ -73,9 +75,11 @@ - (NSString *)asciiRepresentation:(NSData *)data; { +#warning The hex editor window is currently limited to 16 bytes per row int row, addr, currentByte = 0, dataLength = [data length]; int rows = (dataLength / 16) + ((dataLength % 16)? 1:0); - char buffer[17], byte = 0x00; + char buffer[17]; + char *bytes = (char *) [data bytes]; NSMutableString *representation = [NSMutableString string]; // draw bytes @@ -85,9 +89,8 @@ { if( currentByte < dataLength ) { - [data getBytes:&byte range:NSMakeRange(currentByte, 1)]; - if( byte >= 0x20 && byte < 0x7F ) - buffer[addr] = byte; + if( bytes[currentByte] >= 0x20 && bytes[currentByte] < 0x7F ) + buffer[addr] = bytes[currentByte]; else buffer[addr] = 0x2E; // full stop // advance current byte @@ -135,7 +138,6 @@ hexRange = [self hexRangeFromByteRange:byteRange]; [hex setSelectedRange:hexRange]; } - else NSLog( @"What the hell are you selecting?" ); // put the new selection into the message bar [message setStringValue:[NSString stringWithFormat:@"Current selection: %@", NSStringFromRange(byteRange)]]; diff --git a/Cocoa/Plug-Ins/Hex Editor/HexTextView.h b/Cocoa/Plug-Ins/Hex Editor/HexTextView.h index 01d8094..e56e64c 100644 --- a/Cocoa/Plug-Ins/Hex Editor/HexTextView.h +++ b/Cocoa/Plug-Ins/Hex Editor/HexTextView.h @@ -1,4 +1,8 @@ -#import +#import +#import "HexEditorDelegate.h" +#import "HexWindowController.h" + +#import "ResKnifeResourceProtocol.h" @interface HexTextView : NSTextView { diff --git a/Cocoa/Plug-Ins/Hex Editor/HexTextView.m b/Cocoa/Plug-Ins/Hex Editor/HexTextView.m index c23ced1..bb04109 100644 --- a/Cocoa/Plug-Ins/Hex Editor/HexTextView.m +++ b/Cocoa/Plug-Ins/Hex Editor/HexTextView.m @@ -1,13 +1,16 @@ #import "HexTextView.h" -#import "ResKnifeResourceProtocol.h" @implementation HexTextView - (void)insertText:(id)insertString { - // bug: Every time a character is typed or string pasted, the entire resource is duplicated, operated on and disposed of! Perhaps I could do this in a better way? +#warning Every time a character is typed or string pasted, the entire resource is duplicated, operated on and disposed of! Perhaps I could do this in a better way? NSMutableData *newData = [NSMutableData dataWithData:[[[self window] windowController] data]]; NSRange selection = [self selectedRange]; + if( self == (id) [[self delegate] hex] ) + selection = [[self delegate] byteRangeFromHexRange:selection]; + else if( self == (id) [[self delegate] ascii] ) + selection = [[self delegate] byteRangeFromAsciiRange:selection]; NSLog( insertString ); // modify resource data @@ -23,8 +26,6 @@ // select whole bytes at a time (only if selecting in hex!) if( self == (id) [[self delegate] hex] ) { -// NSLog( NSStringFromRange(newRange) ); - // move selection offset to beginning of byte newRange.location -= (charRange.location % 3); newRange.length += (charRange.location % 3); @@ -37,10 +38,8 @@ // move insertion point to next byte if needs be if( newRange.location == charRange.location -1 && newRange.length == 0 ) newRange.location += 3; - -// NSLog( NSStringFromRange(newRange) ); -// NSLog( @"===========" ); } + // select return character if selecting ascii else if( self == (id) [[self delegate] ascii] ) { diff --git a/Cocoa/Plug-Ins/Hex Editor/HexWindow.h b/Cocoa/Plug-Ins/Hex Editor/HexWindow.h deleted file mode 100644 index df5fe64..0000000 --- a/Cocoa/Plug-Ins/Hex Editor/HexWindow.h +++ /dev/null @@ -1,7 +0,0 @@ -#import - -@interface HexWindow : NSObject -{ -} - -@end diff --git a/Cocoa/Plug-Ins/Hex Editor/HexWindow.m b/Cocoa/Plug-Ins/Hex Editor/HexWindow.m deleted file mode 100644 index 79fd468..0000000 --- a/Cocoa/Plug-Ins/Hex Editor/HexWindow.m +++ /dev/null @@ -1,5 +0,0 @@ -#import "HexWindow.h" - -@implementation HexWindow - -@end diff --git a/Cocoa/Plug-Ins/Hex Editor/HexWindowController.h b/Cocoa/Plug-Ins/Hex Editor/HexWindowController.h index 73516a2..2e17def 100644 --- a/Cocoa/Plug-Ins/Hex Editor/HexWindowController.h +++ b/Cocoa/Plug-Ins/Hex Editor/HexWindowController.h @@ -1,5 +1,6 @@ -#import +#import #import "HexEditorDelegate.h" +#import "HexTextView.h" #import "ResKnifePluginProtocol.h" #import "ResKnifeResourceProtocol.h" diff --git a/Cocoa/Plug-Ins/Hex Editor/HexWindowController.m b/Cocoa/Plug-Ins/Hex Editor/HexWindowController.m index cc97471..cc95064 100644 --- a/Cocoa/Plug-Ins/Hex Editor/HexWindowController.m +++ b/Cocoa/Plug-Ins/Hex Editor/HexWindowController.m @@ -1,7 +1,4 @@ #import "HexWindowController.h" -#import "HexTextView.h" - -#import "ResKnifeResourceProtocol.h" @implementation HexWindowController diff --git a/Cocoa/Resources/defaults.plist b/Cocoa/Resources/defaults.plist index cd275c8..2eb02a9 100644 --- a/Cocoa/Resources/defaults.plist +++ b/Cocoa/Resources/defaults.plist @@ -3,4 +3,6 @@ Autosave = YES; AutosaveInterval = 5; DeleteResourceWarning = YES; + + OpenUntitledFileOnLaunch = YES; } \ No newline at end of file diff --git a/Hex Editor/Classes/HexWindow.cpp b/Hex Editor/Classes/HexWindow.cpp index dfc835e..8788e2b 100644 --- a/Hex Editor/Classes/HexWindow.cpp +++ b/Hex Editor/Classes/HexWindow.cpp @@ -302,9 +302,9 @@ OSStatus HexWindow::DrawContent( EventRef event ) { if( currentByte < length ) { - BlockMoveData( *data + currentByte, &ascii, 1 ); - hex1 = ascii; - hex2 = ascii; + // BlockMoveData( *data + currentByte, &ascii, 1 ); + hex1 = *(*data + currentByte); + hex2 = *(*data + currentByte); hex1 >>= 4; hex1 &= 0x0F; hex2 &= 0x0F; diff --git a/ResKnife.pbproj/project.pbxproj b/ResKnife.pbproj/project.pbxproj index d4de1bd..378060b 100644 --- a/ResKnife.pbproj/project.pbxproj +++ b/ResKnife.pbproj/project.pbxproj @@ -237,7 +237,6 @@ F5CDEBAE01FC90AD01A80001, F5EF83AA020C08E601A80001, F5EF83AB020C08E601A80001, - F5EF83AC020C08E601A80001, F5EF83AD020C08E601A80001, ); isa = PBXHeadersBuildPhase; @@ -257,7 +256,6 @@ files = ( F5EF83B0020C08E601A80001, F5EF83B1020C08E601A80001, - F5EF83B2020C08E601A80001, F5EF83B3020C08E601A80001, ); isa = PBXSourcesBuildPhase; @@ -2480,12 +2478,6 @@ settings = { }; }; - F5EF83AC020C08E601A80001 = { - fileRef = F5EF83A4020C08E601A80001; - isa = PBXBuildFile; - settings = { - }; - }; F5EF83AD020C08E601A80001 = { fileRef = F5EF83A7020C08E601A80001; isa = PBXBuildFile; @@ -2510,12 +2502,6 @@ settings = { }; }; - F5EF83B2020C08E601A80001 = { - fileRef = F5EF83A5020C08E601A80001; - isa = PBXBuildFile; - settings = { - }; - }; F5EF83B3020C08E601A80001 = { fileRef = F5EF83A8020C08E601A80001; isa = PBXBuildFile;