mirror of
https://github.com/nickshanks/ResKnife.git
synced 2024-12-21 11:29:31 +00:00
Bugs fixed, optimizations made, etc.
This commit is contained in:
parent
298ab346f2
commit
e8c270d59d
@ -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];
|
||||
|
@ -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 )
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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 <ResKnifePluginProtocol>)[[hexEditor principalClass] alloc] initWithResource:resource];
|
||||
}
|
||||
/*
|
||||
|
||||
- (IBAction)playSound:(id)sender
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
/* FILE HANDLING */
|
||||
#pragma mark -
|
||||
|
||||
|
@ -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)]];
|
||||
|
@ -1,4 +1,8 @@
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "HexEditorDelegate.h"
|
||||
#import "HexWindowController.h"
|
||||
|
||||
#import "ResKnifeResourceProtocol.h"
|
||||
|
||||
@interface HexTextView : NSTextView
|
||||
{
|
||||
|
@ -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] )
|
||||
{
|
||||
|
@ -1,7 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface HexWindow : NSObject
|
||||
{
|
||||
}
|
||||
|
||||
@end
|
@ -1,5 +0,0 @@
|
||||
#import "HexWindow.h"
|
||||
|
||||
@implementation HexWindow
|
||||
|
||||
@end
|
@ -1,5 +1,6 @@
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "HexEditorDelegate.h"
|
||||
#import "HexTextView.h"
|
||||
|
||||
#import "ResKnifePluginProtocol.h"
|
||||
#import "ResKnifeResourceProtocol.h"
|
||||
|
@ -1,7 +1,4 @@
|
||||
#import "HexWindowController.h"
|
||||
#import "HexTextView.h"
|
||||
|
||||
#import "ResKnifeResourceProtocol.h"
|
||||
|
||||
@implementation HexWindowController
|
||||
|
||||
|
@ -3,4 +3,6 @@
|
||||
Autosave = YES;
|
||||
AutosaveInterval = 5;
|
||||
DeleteResourceWarning = YES;
|
||||
|
||||
OpenUntitledFileOnLaunch = YES;
|
||||
}
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user