diff --git a/Carbon/Classes/Files.cpp b/Carbon/Classes/Files.cpp index a9ef20c..ba2037f 100644 --- a/Carbon/Classes/Files.cpp +++ b/Carbon/Classes/Files.cpp @@ -347,6 +347,11 @@ pascal void NavEventFilter( NavEventCallbackMessage callBackSelector, NavCBRecPt break; } break; + +/* // Don't open file if it gets double-clicked (e.g. to add to an 'open' list instead) + case kNavCBOpenSelection: + NavCustomControl( callBackParms->context, (long) kNavCtlSetActionState, (void *) kNavDontOpenState ); + break; */ } } diff --git a/Cocoa/Classes/ApplicationDelegate.m b/Cocoa/Classes/ApplicationDelegate.m index f6c1f3e..c03a382 100644 --- a/Cocoa/Classes/ApplicationDelegate.m +++ b/Cocoa/Classes/ApplicationDelegate.m @@ -27,6 +27,7 @@ - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender { +#pragma unused( sender ) NSString *launchAction = [[NSUserDefaults standardUserDefaults] stringForKey:@"LaunchAction"]; if( [launchAction isEqualToString:@"OpenUntitledFile"] ) return YES; @@ -38,6 +39,12 @@ else return NO; // should be @"None", but we shall return NO for any other value } +- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag +{ +#pragma unused( sender ) + return !flag; +} + - (IBAction)showAbout:(id)sender { [NSApp orderFrontStandardAboutPanel:sender]; diff --git a/Cocoa/Classes/InfoWindowController.m b/Cocoa/Classes/InfoWindowController.m index 612aff7..6448615 100644 --- a/Cocoa/Classes/InfoWindowController.m +++ b/Cocoa/Classes/InfoWindowController.m @@ -25,6 +25,8 @@ // set window to only accept key when editing text boxes [(NSPanel *)[self window] setBecomesKeyOnlyIfNeeded:YES]; + [[self window] setBackgroundColor:[NSColor clearColor]]; + [[self window] setOpaque:NO]; // retain views for swapping in and out [documentView retain]; diff --git a/Cocoa/Classes/PrefsWindowController.h b/Cocoa/Classes/PrefsWindowController.h index a3c9d37..e116df8 100644 --- a/Cocoa/Classes/PrefsWindowController.h +++ b/Cocoa/Classes/PrefsWindowController.h @@ -14,6 +14,8 @@ enum LaunchAction displayOpenPanelBox }; +#define prefs [NSUserDefaults standardUserDefaults] + @interface PrefsWindowController : NSWindowController { IBOutlet NSTextField *autosaveIntervalField; @@ -28,4 +30,11 @@ enum LaunchAction + (id)sharedPrefsWindowController; +@end + +@interface NSString (BooleanSupport) + +- (BOOL)boolValue; ++ (NSString *)stringWithBool:(BOOL)boolean; + @end \ No newline at end of file diff --git a/Cocoa/Classes/PrefsWindowController.m b/Cocoa/Classes/PrefsWindowController.m index bdfaac6..c749013 100644 --- a/Cocoa/Classes/PrefsWindowController.m +++ b/Cocoa/Classes/PrefsWindowController.m @@ -110,3 +110,17 @@ } @end + +@implementation NSString (BooleanSupport) + +- (BOOL)boolValue +{ + return [self isEqualToString:@"YES"]; +} + ++ (NSString *)stringWithBool:(BOOL)boolean +{ + return boolean? @"YES" : @"NO"; +} + +@end diff --git a/Cocoa/Classes/ResourceDocument.h b/Cocoa/Classes/ResourceDocument.h index c87e2a2..13e35d2 100644 --- a/Cocoa/Classes/ResourceDocument.h +++ b/Cocoa/Classes/ResourceDocument.h @@ -10,8 +10,7 @@ IBOutlet NSOutlineView *outlineView; NSMutableArray *resources; - BOOL saveToDataFork; - HFSUniStr255 *otherFork; // name of fork to save to if not using data fork (usually 'RESOURCE_FORK' as returned from FSGetResourceForkName() -- ignored if saveToDataFork is YES ) + HFSUniStr255 *fork; // name of fork to save to, usually empty string (data fork) or 'RESOURCE_FORK' as returned from FSGetResourceForkName() } - (void)setupToolbar:(NSWindowController *)windowController; diff --git a/Cocoa/Classes/ResourceDocument.m b/Cocoa/Classes/ResourceDocument.m index 48b0e32..81fe6b5 100644 --- a/Cocoa/Classes/ResourceDocument.m +++ b/Cocoa/Classes/ResourceDocument.m @@ -13,15 +13,14 @@ { self = [super init]; resources = [[NSMutableArray alloc] init]; - otherFork = nil; + fork = nil; return self; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; - if( otherFork ) - DisposePtr( (Ptr) otherFork ); + if( fork ) DisposePtr( (Ptr) fork ); [resources release]; [super dealloc]; } @@ -179,7 +178,7 @@ static NSString *RKShowInfoItemIdentifier = @"com.nickshanks.resknife.toolbar.sh { [item setLabel:NSLocalizedString(@"Save", nil)]; [item setPaletteLabel:NSLocalizedString(@"Save", nil)]; - [item setToolTip:[NSString stringWithFormat:NSLocalizedString(@"Save To %@ Fork", nil), !otherFork? NSLocalizedString(@"Data", nil) : NSLocalizedString(@"Resource", nil)]]; + [item setToolTip:[NSString stringWithFormat:NSLocalizedString(@"Save To %@ Fork", nil), !fork? NSLocalizedString(@"Data", nil) : NSLocalizedString(@"Resource", nil)]]; [item setImage:[NSImage imageNamed:@"Save"]]; [item setTarget:self]; [item setAction:@selector(saveDocument:)]; @@ -244,7 +243,6 @@ static NSString *RKShowInfoItemIdentifier = @"com.nickshanks.resknife.toolbar.sh { // opens the resource in it's default template Resource *resource = [outlineView itemAtRow:[outlineView selectedRow]]; - NSLog( [resource type] ); [self openResourceUsingTemplate:[resource type]]; } @@ -256,22 +254,14 @@ static NSString *RKShowInfoItemIdentifier = @"com.nickshanks.resknife.toolbar.sh Resource *resource = [outlineView itemAtRow:[outlineView selectedRow]]; Resource *tmpl = [dataSource resourceNamed:[resource type] ofType:@"TMPL"]; - NSLog( @"attempting to open %@ using template %@", [resource name], templateName ); - // open the resource, passing in the template to use if( tmpl /*&& [[templateEditor principalClass] respondsToSelector:@selector(initWithResources:)]*/ ) { - NSLog( @"opening using %@ template", templateName ); // 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 )[[templateEditor principalClass] alloc] initWithResources:resource, tmpl, nil]; } // if no template exists, or template editor is broken, open as hex - else - { - if( !tmpl ) NSLog( @"no %@ template present, opening as hex", templateName ); - else NSLog( @"template editor does not respond to -initWithResources:, opening as hex" ); - [self openResourceAsHex:self]; - } + else [self openResourceAsHex:self]; } - (IBAction)openResourceAsHex:(id)sender @@ -402,19 +392,23 @@ static NSString *RKShowInfoItemIdentifier = @"com.nickshanks.resknife.toolbar.sh NSLog( @"Opening Resource fork failed, trying data fork..." ); error = FSOpenResourceFile( fileRef, 0, nil, fsRdPerm, &fileRefNum); } - else otherFork = resourceForkName; + else fork = resourceForkName; SetResLoad( true ); // restore resource loading as soon as is possible // read the resources (without spawning thousands of undos for resource creation) [[self undoManager] disableUndoRegistration]; if( fileRefNum && !error ) succeeded = [self readResourceMap:fileRefNum]; - else if( !fileRefNum ) NSLog( @"Opening data fork failed too! (fileRef)" ); + else if( !fileRefNum ) + { + // supposed to read data fork as byte stream here + NSLog( @"Opening data fork failed too! (fileRef)" ); + } else NSLog( @"Opening data fork failed too! (error)" ); [[self undoManager] enableUndoRegistration]; // tidy up loose ends - if( !otherFork ) DisposePtr( (Ptr) resourceForkName ); // only delete if we're not saving it + if( !fork ) DisposePtr( (Ptr) resourceForkName ); // only delete if we're not saving it if( fileRefNum ) FSClose( fileRefNum ); DisposePtr( (Ptr) fileRef ); return succeeded; @@ -427,8 +421,6 @@ static NSString *RKShowInfoItemIdentifier = @"com.nickshanks.resknife.toolbar.sh SInt16 oldResFile = CurResFile(); UseResFile( fileRefNum ); - NSLog( @"Reading resource map..." ); - for( i = 1; i <= Count1Types(); i++ ) { ResType resType; @@ -472,8 +464,6 @@ static NSString *RKShowInfoItemIdentifier = @"com.nickshanks.resknife.toolbar.sh } } - NSLog( @"Resource map read" ); - // save resource map and clean up UseResFile( oldResFile ); return YES; @@ -490,13 +480,13 @@ static NSString *RKShowInfoItemIdentifier = @"com.nickshanks.resknife.toolbar.sh // create and open file for writing error = FSPathMakeRef( [[fileName stringByDeletingLastPathComponent] cString], parentRef, nil ); - if( otherFork ) + if( fork ) { unichar *uniname = (unichar *) NewPtrClear( sizeof(unichar) *256 ); [[fileName lastPathComponent] getCharacters:uniname]; - error = FSCreateResourceFile( parentRef, [[fileName lastPathComponent] length], (UniChar *) uniname, kFSCatInfoNone, nil, otherFork->length, (UniChar *) &otherFork->unicode, fileRef, fileSpec ); + error = FSCreateResourceFile( parentRef, [[fileName lastPathComponent] length], (UniChar *) uniname, kFSCatInfoNone, nil, fork->length, (UniChar *) &fork->unicode, fileRef, fileSpec ); if( !error ) - error = FSOpenResourceFile( fileRef, otherFork->length, (UniChar *) &otherFork->unicode, fsWrPerm, &fileRefNum); + error = FSOpenResourceFile( fileRef, fork->length, (UniChar *) &fork->unicode, fsWrPerm, &fileRefNum); } else { diff --git a/Cocoa/Classes/ResourceNameCell.m b/Cocoa/Classes/ResourceNameCell.m index 704dbf1..233ad25 100644 --- a/Cocoa/Classes/ResourceNameCell.m +++ b/Cocoa/Classes/ResourceNameCell.m @@ -18,7 +18,7 @@ - (void)setImage:(NSImage *)newImage { // save image and set to 16x16 pixels - [image autorelease]; // would this be better autoreleased instead? + [image autorelease]; image = [newImage retain]; [image setScalesWhenResized:YES]; [image setSize:NSMakeSize(16,16)]; diff --git a/Cocoa/Plug-Ins/Hex Editor/English.lproj/HexWindow.nib/info.nib b/Cocoa/Plug-Ins/Hex Editor/English.lproj/HexWindow.nib/info.nib index c5f5489..e779796 100644 --- a/Cocoa/Plug-Ins/Hex Editor/English.lproj/HexWindow.nib/info.nib +++ b/Cocoa/Plug-Ins/Hex Editor/English.lproj/HexWindow.nib/info.nib @@ -3,7 +3,7 @@ IBDocumentLocation - 460 737 356 240 0 0 1280 1002 + 248 107 356 240 0 0 1024 746 IBFramework Version 248.0 IBOpenObjects @@ -11,6 +11,6 @@ 6 IBSystem Version - 5P48 + 5Q45 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 9d578f0..2729f6d 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/FindSheetController.h b/Cocoa/Plug-Ins/Hex Editor/FindSheetController.h index 70b35b0..b56b54a 100644 --- a/Cocoa/Plug-Ins/Hex Editor/FindSheetController.h +++ b/Cocoa/Plug-Ins/Hex Editor/FindSheetController.h @@ -7,10 +7,19 @@ IBOutlet NSForm *form; IBOutlet NSButton *replaceAllButton; IBOutlet NSButton *replaceFindNextButton; + + NSString *findString; + NSString *replaceString; } +- (void)updateStrings; + +- (IBAction)showFindSheet:(id)sender; +- (IBAction)hideFindSheet:(id)sender; + - (IBAction)findNext:(id)sender; -- (IBAction)hideWindow:(id)sender; +- (IBAction)findPrevious:(id)sender; +- (IBAction)findWithSelection:(id)sender; - (IBAction)replaceAll:(id)sender; - (IBAction)replaceFindNext:(id)sender; diff --git a/Cocoa/Plug-Ins/Hex Editor/FindSheetController.m b/Cocoa/Plug-Ins/Hex Editor/FindSheetController.m index a24b28f..a592e40 100644 --- a/Cocoa/Plug-Ins/Hex Editor/FindSheetController.m +++ b/Cocoa/Plug-Ins/Hex Editor/FindSheetController.m @@ -1,21 +1,70 @@ #import "FindSheetController.h" +#import "HexWindowController.h" @implementation FindSheetController -- (IBAction)findNext:(id)sender +/* FORM DELEGATION METHOD */ + +- (void)controlTextDidEndEditing:(NSNotification *)aNotification { + [self updateStrings]; } -- (IBAction)hideWindow:(id)sender +- (void)updateStrings { + [findString autorelease]; + [replaceString autorelease]; + + findString = [[[form cellAtIndex:0] stringValue] copy]; + replaceString = [[[form cellAtIndex:1] stringValue] copy]; +} + +/* HIDE AND SHOW SHEET */ + +- (IBAction)showFindSheet:(id)sender +{ + [NSApp beginSheet:[self window] modalForWindow:[sender window] modalDelegate:self didEndSelector:NULL contextInfo:nil]; +} + +- (IBAction)hideFindSheet:(id)sender +{ + [[self window] orderOut:nil]; + [NSApp endSheet:[self window]]; +} + +- (IBAction)findNext:(id)sender +{ + [self updateStrings]; + [self hideFindSheet:self]; + NSLog( @"Finding next \"%@\"", findString ); +} + +- (IBAction)findPrevious:(id)sender +{ + [self updateStrings]; + [self hideFindSheet:self]; + NSLog( @"Finding previous \"%@\"", findString ); +} + +- (IBAction)findWithSelection:(id)sender +{ + [findString autorelease]; + findString = [[NSString string] retain]; + NSLog( @"Finding \"%@\"", findString ); } - (IBAction)replaceAll:(id)sender { + [self updateStrings]; + [self hideFindSheet:self]; + NSLog( @"Replacing all \"%@\" with \"%@\"", findString, replaceString ); } - (IBAction)replaceFindNext:(id)sender { + [self updateStrings]; + [self hideFindSheet:self]; + NSLog( @"Replacing \"%@\" with \"%@\" and finding next", findString, replaceString ); } @end diff --git a/Cocoa/Plug-Ins/Hex Editor/HexEditorDelegate.m b/Cocoa/Plug-Ins/Hex Editor/HexEditorDelegate.m index df49352..edb8845 100644 --- a/Cocoa/Plug-Ins/Hex Editor/HexEditorDelegate.m +++ b/Cocoa/Plug-Ins/Hex Editor/HexEditorDelegate.m @@ -9,34 +9,28 @@ - (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); + int row, dataLength = [data length], bytesPerRow = [controller bytesPerRow]; + int rows = (dataLength / bytesPerRow) + ((dataLength % bytesPerRow)? 1:0); NSMutableString *representation = [NSMutableString string]; for( row = 0; row < rows; row++ ) - [representation appendFormat:@"%08lX:\n", row * 16]; - - // remove last character (the return on the end) - if( dataLength % 16 != 0 ) - [representation deleteCharactersInRange:NSMakeRange([representation length] -1, 1)]; + [representation appendFormat:@"%08lX:", row * bytesPerRow]; return representation; } - (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], hex1, hex2; + int row, addr, currentByte = 0, dataLength = [data length], bytesPerRow = [controller bytesPerRow]; + int rows = (dataLength / bytesPerRow) + ((dataLength % bytesPerRow)? 1:0); + char buffer[bytesPerRow*3 +1], hex1, hex2; char *bytes = (char *) [data bytes]; NSMutableString *representation = [NSMutableString string]; // draw bytes for( row = 0; row < rows; row++ ) { - for( addr = 0; addr < 16; addr++ ) + for( addr = 0; addr < bytesPerRow; addr++ ) { if( currentByte < dataLength ) { @@ -63,12 +57,10 @@ } // clear last byte on line - buffer[16*3 -1] = 0x00; + buffer[bytesPerRow*3] = 0x00; // append buffer to representation [representation appendString:[NSString stringWithCString:buffer]]; - if( currentByte != dataLength || dataLength % 16 == 0 ) - [representation appendString:@"\n"]; } return representation; @@ -76,17 +68,16 @@ - (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]; + int row, addr, currentByte = 0, dataLength = [data length], bytesPerRow = [controller bytesPerRow]; + int rows = (dataLength / bytesPerRow) + ((dataLength % bytesPerRow)? 1:0); + char buffer[bytesPerRow +1]; char *bytes = (char *) [data bytes]; NSMutableString *representation = [NSMutableString string]; // draw bytes for( row = 0; row < rows; row++ ) { - for( addr = 0; addr < 16; addr++ ) + for( addr = 0; addr < bytesPerRow; addr++ ) { if( currentByte < dataLength ) { @@ -105,12 +96,10 @@ } // clear last byte on line - buffer[16] = 0x00; + buffer[bytesPerRow] = 0x00; // append buffer to representation [representation appendString:[NSString stringWithCString:buffer]]; - if( currentByte != dataLength || dataLength % 16 == 0 ) - [representation appendString:@"\n"]; } return representation; @@ -118,7 +107,9 @@ /* delegation methods */ -- (BOOL)textView:(NSTextView *)textView shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString; +// I'm going to try a lower level approach overriding NSResponder methods in the HexTextView class. + +/*- (BOOL)textView:(NSTextView *)textView shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString; { #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 *data = [NSMutableData dataWithData:[controller data]]; @@ -137,7 +128,7 @@ // update resource data - this causes a notification to be sent out, which the plug receives and acts upon to update the text views [[controller resource] setData:data]; return NO; -} +}*/ - (NSRange)textView:(NSTextView *)textView willChangeSelectionFromCharacterRange:(NSRange)oldSelectedCharRange toCharacterRange:(NSRange)newSelectedCharRange { @@ -176,44 +167,30 @@ { // valid for all window widths NSRange byteRange = NSMakeRange(0,0); - byteRange.location = (hexRange.location / 3); byteRange.length = (hexRange.length / 3) + ((hexRange.length % 3)? 1:0); - return byteRange; } - (NSRange)hexRangeFromByteRange:(NSRange)byteRange; { + // valid for all window widths NSRange hexRange = NSMakeRange(0,0); - hexRange.location = (byteRange.location * 3); hexRange.length = (byteRange.length * 3); - return hexRange; } - (NSRange)byteRangeFromAsciiRange:(NSRange)asciiRange; { - // assumes 16 byte wide window - NSRange byteRange; - - byteRange.location = asciiRange.location - (asciiRange.location / 17); - byteRange.length = asciiRange.length - ((asciiRange.location + asciiRange.length) / 17) + (asciiRange.location / 17); - - return byteRange; + // one-to-one mapping + return asciiRange; } - (NSRange)asciiRangeFromByteRange:(NSRange)byteRange; { -#warning There's a bug in this somewhere! - // assumes 16 byte wide window - NSRange asciiRange = NSMakeRange(0,0); - - asciiRange.location = byteRange.location + (byteRange.location / 17); - asciiRange.length = byteRange.length + ((byteRange.location + byteRange.length) / 17) - (byteRange.location / 17); - - return asciiRange; + // one-to-one mapping + return byteRange; } - (NSTextView *)hex diff --git a/Cocoa/Plug-Ins/Hex Editor/HexTextView.m b/Cocoa/Plug-Ins/Hex Editor/HexTextView.m index eb162fb..819e642 100644 --- a/Cocoa/Plug-Ins/Hex Editor/HexTextView.m +++ b/Cocoa/Plug-Ins/Hex Editor/HexTextView.m @@ -2,6 +2,13 @@ @implementation HexTextView +- (id)init +{ + self = [super init]; + [[[NSCursor alloc] initWithImage:[NSImage imageNamed:@"Show Info"] hotSpot:NSMakePoint(0,0)] set]; + return self; +} + - (void)setSelectedRange:(NSRange)charRange affinity:(NSSelectionAffinity)affinity stillSelecting:(BOOL)flag { NSRange newRange = charRange; diff --git a/Cocoa/Plug-Ins/Hex Editor/HexWindowController.h b/Cocoa/Plug-Ins/Hex Editor/HexWindowController.h index 8177333..e55ff9f 100644 --- a/Cocoa/Plug-Ins/Hex Editor/HexWindowController.h +++ b/Cocoa/Plug-Ins/Hex Editor/HexWindowController.h @@ -14,11 +14,15 @@ IBOutlet NSTextField *message; id resource; + int bytesPerRow; } // conform to the ResKnifePluginProtocol with the inclusion of these methods - (id)initWithResource:(id)newResource; +// show find sheet +- (IBAction)showFind:(id)sender; + // normal methods - (void)viewDidScroll:(NSNotification *)notification; - (void)resourceDataDidChange:(NSNotification *)notification; @@ -27,5 +31,6 @@ // accessors - (id)resource; - (NSData *)data; +- (int)bytesPerRow; @end diff --git a/Cocoa/Plug-Ins/Hex Editor/HexWindowController.m b/Cocoa/Plug-Ins/Hex Editor/HexWindowController.m index 2f1f61e..57faf2d 100644 --- a/Cocoa/Plug-Ins/Hex Editor/HexWindowController.m +++ b/Cocoa/Plug-Ins/Hex Editor/HexWindowController.m @@ -1,5 +1,6 @@ #import "HexWindowController.h" #import "HexTextView.h" +#import "FindSheetController.h" @implementation HexWindowController @@ -24,6 +25,7 @@ NSString *ResourceDidChangeNotification = @"ResourceDidChangeNotification"; // one instance of your principal class will be created for every resource the user wants to edit (similar to Windows apps) resource = [newResource retain]; + bytesPerRow = 16; // load the window from the nib file and set it's title [self window]; // implicitly loads nib @@ -32,6 +34,11 @@ NSString *ResourceDidChangeNotification = @"ResourceDidChangeNotification"; return self; } +- (id)initWithResources:(id)newResource, ... +{ + return nil; +} + - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; @@ -71,6 +78,13 @@ NSString *ResourceDidChangeNotification = @"ResourceDidChangeNotification"; [self showWindow:self]; } +- (IBAction)showFind:(id)sender +{ + // bug: HexWindowController allocs a sheet controller, but it's never disposed of + FindSheetController *sheetController = [[FindSheetController alloc] initWithWindowNibName:@"FindSheet"]; + [sheetController showFindSheet:self]; +} + - (void)viewDidScroll:(NSNotification *)notification { // get object refs for increased speed @@ -119,6 +133,9 @@ NSString *ResourceDidChangeNotification = @"ResourceDidChangeNotification"; - (void)refreshData:(NSData *)data; { + NSDictionary *dictionary; + NSMutableParagraphStyle *paragraph = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; + // save selections NSRange hexSelection = [hex selectedRange]; NSRange asciiSelection = [ascii selectedRange]; @@ -128,11 +145,20 @@ NSString *ResourceDidChangeNotification = @"ResourceDidChangeNotification"; [hex setDelegate:nil]; [ascii setDelegate:nil]; + // prepare attributes dictionary + [paragraph setLineBreakMode:NSLineBreakByCharWrapping]; + dictionary = [NSDictionary dictionaryWithObject:paragraph forKey:NSParagraphStyleAttributeName]; + // do stuff with data [offset setString:[hexDelegate offsetRepresentation:data]]; [hex setString:[hexDelegate hexRepresentation:data]]; [ascii setString:[hexDelegate asciiRepresentation:data]]; + // apply attributes + [[offset textStorage] addAttributes:dictionary range:NSMakeRange(0, [[offset textStorage] length])]; + [[hex textStorage] addAttributes:dictionary range:NSMakeRange(0, [[hex textStorage] length])]; + [[ascii textStorage] addAttributes:dictionary range:NSMakeRange(0, [[ascii textStorage] length])]; + // restore selections (this is the dumbest way to do it, but it'll do for now) [hex setSelectedRange:hexSelection]; [ascii setSelectedRange:asciiSelection]; @@ -152,4 +178,9 @@ NSString *ResourceDidChangeNotification = @"ResourceDidChangeNotification"; return [resource data]; } +- (int)bytesPerRow +{ + return bytesPerRow; +} + @end diff --git a/ResKnife.pbproj/project.pbxproj b/ResKnife.pbproj/project.pbxproj index 3b0843f..3bc2064 100644 --- a/ResKnife.pbproj/project.pbxproj +++ b/ResKnife.pbproj/project.pbxproj @@ -5,6 +5,214 @@ }; objectVersion = 34; objects = { + F535442F0225D46C01A80001 = { + fileRef = F5B588920156D6D901000001; + isa = PBXBuildFile; + settings = { + }; + }; + F53544320226550001A80001 = { + fileRef = F5B588920156D6D901000001; + isa = PBXBuildFile; + settings = { + }; + }; + F5354435022673C101A80001 = { + children = ( + F535444D0226B5F501A80001, + F535444E0226B5F501A80001, + F535443E0226752901A80001, + F535443F0226752901A80001, + F5D0CBD302278F8B01A80001, + F535443D0226752901A80001, + ); + isa = PBXGroup; + path = "Template Editor"; + refType = 4; + }; + F5354436022674B301A80001 = { + isa = PBXBundleReference; + path = "Template Editor.plugin"; + refType = 3; + }; + F5354437022674B401A80001 = { + buildPhases = ( + F5354438022674B401A80001, + F5354439022674B401A80001, + F535443A022674B401A80001, + F535443B022674B401A80001, + F535443C022674B401A80001, + ); + buildSettings = { + OTHER_CFLAGS = ""; + OTHER_LDFLAGS = ""; + OTHER_REZFLAGS = ""; + PRODUCT_NAME = "Template Editor"; + SECTORDER_FLAGS = ""; + WARNING_CFLAGS = "-Wmost -Wno-four-char-constants -Wno-unknown-pragmas"; + WRAPPER_EXTENSION = plugin; + }; + dependencies = ( + ); + isa = PBXBundleTarget; + name = "Template Editor Cocoa"; + productInstallPath = "$(USER_LIBRARY_DIR)/Bundles"; + productName = "Template Editor Cocoa"; + productReference = F5354436022674B301A80001; + productSettingsXML = " + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + Template Editor + CFBundleGetInfoString + © Nicholas Shanks 2002 + CFBundleIconFile + + CFBundleIdentifier + com.nickshanks.resknife.template + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ResKnife Template Editor + CFBundlePackageType + BNDL + CFBundleShortVersionString + + CFBundleSignature + ResK + CFBundleVersion + 0.0.1d1 + NSMainNibFile + TemplateWindow + NSPrincipalClass + TemplateWindowController + + +"; + shouldUseHeadermap = 0; + }; + F5354438022674B401A80001 = { + buildActionMask = 2147483647; + files = ( + F53544400226752901A80001, + F535444F0226B5F501A80001, + ); + isa = PBXHeadersBuildPhase; + name = Headers; + }; + F5354439022674B401A80001 = { + buildActionMask = 2147483647; + files = ( + F53544410226752901A80001, + F5D0CBD402278F8B01A80001, + ); + isa = PBXResourcesBuildPhase; + name = "Bundle Resources"; + }; + F535443A022674B401A80001 = { + buildActionMask = 2147483647; + files = ( + F53544420226752901A80001, + F53544500226B5F501A80001, + ); + isa = PBXSourcesBuildPhase; + name = Sources; + }; + F535443B022674B401A80001 = { + buildActionMask = 2147483647; + files = ( + F53544460226907801A80001, + ); + isa = PBXFrameworksBuildPhase; + name = "Frameworks & Libraries"; + }; + F535443C022674B401A80001 = { + buildActionMask = 2147483647; + files = ( + ); + isa = PBXRezBuildPhase; + name = "ResourceManager Resources"; + }; + F535443D0226752901A80001 = { + isa = PBXFileReference; + path = SupportedTypes.plist; + refType = 4; + }; + F535443E0226752901A80001 = { + isa = PBXFileReference; + path = TemplateWindowController.h; + refType = 4; + }; + F535443F0226752901A80001 = { + isa = PBXFileReference; + path = TemplateWindowController.m; + refType = 4; + }; + F53544400226752901A80001 = { + fileRef = F535443E0226752901A80001; + isa = PBXBuildFile; + settings = { + }; + }; + F53544410226752901A80001 = { + fileRef = F535443D0226752901A80001; + isa = PBXBuildFile; + settings = { + }; + }; + F53544420226752901A80001 = { + fileRef = F535443F0226752901A80001; + isa = PBXBuildFile; + settings = { + }; + }; + F53544430226778D01A80001 = { + isa = PBXFileReference; + name = TemplateWindow.nib; + path = English.lproj/TemplateWindow.nib; + refType = 4; + }; + F535444502268F9501A80001 = { + isa = PBXTargetDependency; + target = F5354437022674B401A80001; + }; + F53544460226907801A80001 = { + fileRef = F5B5884B0156D40B01000001; + isa = PBXBuildFile; + settings = { + }; + }; + F53544470226912301A80001 = { + fileRef = F5354436022674B301A80001; + isa = PBXBuildFile; + settings = { + }; + }; + F535444D0226B5F501A80001 = { + isa = PBXFileReference; + path = Element.h; + refType = 4; + }; + F535444E0226B5F501A80001 = { + isa = PBXFileReference; + path = Element.m; + refType = 4; + }; + F535444F0226B5F501A80001 = { + fileRef = F535444D0226B5F501A80001; + isa = PBXBuildFile; + settings = { + }; + }; + F53544500226B5F501A80001 = { + fileRef = F535444E0226B5F501A80001; + isa = PBXBuildFile; + settings = { + }; + }; F53B5F3001C97EFB01A8010C = { fileRef = F5B588210156D40B01000001; isa = PBXBuildFile; @@ -66,6 +274,27 @@ settings = { }; }; + F54E622B021D192201A80001 = { + children = ( + F54E622C021D192201A80001, + ); + isa = PBXVariantGroup; + name = CreateResourceSheet.nib; + path = ""; + refType = 4; + }; + F54E622C021D192201A80001 = { + isa = PBXFileReference; + name = English; + path = Cocoa/English.lproj/CreateResourceSheet.nib; + refType = 2; + }; + F54E622D021D192201A80001 = { + fileRef = F54E622B021D192201A80001; + isa = PBXBuildFile; + settings = { + }; + }; F5502C3301C5586301C57124 = { fileRef = F5B5884B0156D40B01000001; isa = PBXBuildFile; @@ -74,8 +303,7 @@ }; F5502C4001C579FF01C57124 = { isa = PBXFileReference; - name = ResKnifePluginProtocol.h; - path = "Plug-Ins/ResKnifePluginProtocol.h"; + path = ResKnifePluginProtocol.h; refType = 4; }; F5502C4101C579FF01C57124 = { @@ -84,6 +312,15 @@ settings = { }; }; + F5594EE9021F3E2301A80001 = { + children = ( + F5D0CBCF022744C701A80001, + F5D0CBD0022744C701A80001, + ); + isa = PBXGroup; + path = Catagories; + refType = 4; + }; F5730B930159528A01000001 = { isa = PBXFileReference; path = defaults.plist; @@ -195,6 +432,7 @@ dstSubfolderSpec = 13; files = ( F577A9060212B69C01A80001, + F53544470226912301A80001, ); isa = PBXCopyFilesBuildPhase; name = "Copy Files"; @@ -204,10 +442,10 @@ F5502C4001C579FF01C57124, F5CDEBAB01FC893201A80001, F5EF839F020C08E601A80001, + F5354435022673C101A80001, ); isa = PBXGroup; - name = "Plug-Ins"; - path = ""; + path = "Plug-Ins"; refType = 4; }; F57CEE0D0189C95101A8010B = { @@ -333,9 +571,10 @@ projectDirPath = ""; targets = ( F5B588130156D30301000001, + F57CEE0E0189C95101A8010B, + F5354437022674B401A80001, F5B588750156D5CB01000001, F5B588D20156D78201000001, - F57CEE0E0189C95101A8010B, F5B588EE0156DAF301000001, F5B5890B0156DC2201000001, ); @@ -358,10 +597,11 @@ children = ( F5B588120156D30301000001, F5B588740156D5CB01000001, + F57CEE0D0189C95101A8010B, + F5354436022674B301A80001, F5B588D10156D78201000001, F5B588ED0156DAF301000001, F5B589030156DC2201000001, - F57CEE0D0189C95101A8010B, ); isa = PBXGroup; name = Products; @@ -385,6 +625,7 @@ OTHER_CFLAGS = ""; OTHER_LDFLAGS = ""; OTHER_REZFLAGS = ""; + PREBINDING = NO; PRODUCT_NAME = "ResKnife Cocoa"; SECTORDER_FLAGS = ""; WARNING_CFLAGS = "-Wmost -Wno-four-char-constants -Wno-unknown-pragmas"; @@ -392,6 +633,7 @@ }; dependencies = ( F5CDEBAF01FCA71501A80001, + F535444502268F9501A80001, ); isa = PBXApplicationTarget; name = "ResKnife Cocoa"; @@ -406,6 +648,22 @@ English CFBundleDocumentTypes + + CFBundleTypeExtensions + + * + + CFBundleTypeName + Any file + CFBundleTypeOSTypes + + **** + + CFBundleTypeRole + Editor + NSDocumentClass + ResourceDocument + CFBundleTypeExtensions @@ -443,22 +701,6 @@ NSDocumentClass ResourceDocument - - CFBundleTypeExtensions - - * - - CFBundleTypeName - NSFilenamesPboardType - CFBundleTypeOSTypes - - **** - - CFBundleTypeRole - Editor - NSDocumentClass - ResourceDocument - CFBundleExecutable ResKnife Cocoa @@ -492,7 +734,11 @@ F5B588140156D30301000001 = { buildActionMask = 2147483647; files = ( + F5CDEBAC01FC893201A80001, + F5502C4101C579FF01C57124, + F53B5F3101C97EFB01A8010C, F5B5884F0156D40B01000001, + F53B5F3001C97EFB01A8010C, F5B588520156D40B01000001, F5B588530156D40B01000001, F5B588540156D40B01000001, @@ -500,12 +746,9 @@ F5B588560156D40B01000001, F5B588570156D40B01000001, F5B588580156D40B01000001, - F5B588590156D40B01000001, - F5502C4101C579FF01C57124, - F53B5F3001C97EFB01A8010C, - F53B5F3101C97EFB01A8010C, - F5CDEBAC01FC893201A80001, F577A902021215C901A80001, + F5B588590156D40B01000001, + F5D0CBD1022744C701A80001, ); isa = PBXHeadersBuildPhase; name = Headers; @@ -518,18 +761,19 @@ F5B5885C0156D40B01000001, F5B5885E0156D40B01000001, F5B5885F0156D40B01000001, + F54E622D021D192201A80001, F5B588600156D40B01000001, F5B588610156D40B01000001, + F5730B940159528A01000001, F5B588620156D40B01000001, F5B588630156D40B01000001, F5B588640156D40B01000001, - F5730B940159528A01000001, - F577A8F50211D05E01A80001, - F577A8F90211DC1E01A80001, F577A8FD0211E4D401A80001, + F577A905021220D601A80001, F577A8FE0211E4D401A80001, F577A8FF0211E4D401A80001, - F577A905021220D601A80001, + F577A8F50211D05E01A80001, + F577A8F90211DC1E01A80001, ); isa = PBXResourcesBuildPhase; name = "Bundle Resources"; @@ -548,8 +792,9 @@ F5B5886E0156D40B01000001, F5B5886F0156D40B01000001, F5B588700156D40B01000001, - F5B588710156D40B01000001, F577A903021215C901A80001, + F5B588710156D40B01000001, + F5D0CBD2022744C701A80001, ); isa = PBXSourcesBuildPhase; name = Sources; @@ -574,6 +819,7 @@ children = ( F5B5881B0156D40B01000001, F5B5881C0156D40B01000001, + F5594EE9021F3E2301A80001, F5B588350156D40B01000001, F57CEE0B0189C95101A8010B, ); @@ -594,8 +840,6 @@ F5B588200156D40B01000001, F5B588210156D40B01000001, F5B588220156D40B01000001, - F5B588230156D40B01000001, - F5B588240156D40B01000001, F5B588250156D40B01000001, F5B588260156D40B01000001, F5B588270156D40B01000001, @@ -649,16 +893,6 @@ path = CreateResourceSheetController.m; refType = 4; }; - F5B588230156D40B01000001 = { - isa = PBXFileReference; - path = InfoWindow.h; - refType = 4; - }; - F5B588240156D40B01000001 = { - isa = PBXFileReference; - path = InfoWindow.m; - refType = 4; - }; F5B588250156D40B01000001 = { isa = PBXFileReference; path = InfoWindowController.h; @@ -743,6 +977,7 @@ children = ( F5B588360156D40B01000001, F5B588380156D40B01000001, + F54E622B021D192201A80001, F5B5883A0156D40B01000001, F5B5883E0156D40B01000001, F5B588400156D40B01000001, @@ -1272,7 +1507,6 @@ buildActionMask = 2147483647; files = ( F53B5F3201C984F301A8010C, - F5D0BAFC0202558901A80001, ); isa = PBXFrameworksBuildPhase; name = "Frameworks & Libraries"; @@ -1312,7 +1546,6 @@ F5B588800156D6D901000001, F5B588830156D6D901000001, F5B588A20156D6D901000001, - F5B588A70156D6D901000001, ); isa = PBXGroup; path = Carbon; @@ -1551,12 +1784,6 @@ path = ResKnife.nib; refType = 4; }; - F5B588A70156D6D901000001 = { - isa = PBXFileReference; - name = ResKnife.lib; - path = Carbon/ResKnife.lib; - refType = 2; - }; F5B588A80156D6D901000001 = { fileRef = F5B588840156D6D901000001; isa = PBXBuildFile; @@ -1787,6 +2014,7 @@ F5B588D70156D78201000001, ); buildSettings = { + LIBRARY_SEARCH_PATHS = /Volumes/DeskStar/nicholas/Projects/ResKnife/Carbon; OTHER_LDFLAGS = "-bundle -bundle_loader \"$HOME/Projects/ResKnife/build/ResKnife Cocoa.app/Contents/MacOS/ResKnife Cocoa\" -undefined error"; OTHER_REZFLAGS = ""; PRODUCT_NAME = "Hex Editor"; @@ -1797,7 +2025,7 @@ dependencies = ( ); isa = PBXBundleTarget; - name = "Hex Editor"; + name = "Hex Editor Carbon"; productName = "Hex Editor"; productReference = F5B588D10156D78201000001; productSettingsXML = " @@ -1839,6 +2067,7 @@ F5B588E40156D9D401000001, F5B588E50156D9D401000001, F5B588E60156D9D401000001, + F535442F0225D46C01A80001, ); isa = PBXHeadersBuildPhase; name = Headers; @@ -2019,8 +2248,8 @@ F5B588F30156DAF301000001, ); buildSettings = { - OTHER_CFLAGS = ""; - OTHER_LDFLAGS = "-bundle -undefined suppress"; + LIBRARY_SEARCH_PATHS = /Volumes/DeskStar/nicholas/Projects/ResKnife/Carbon; + OTHER_LDFLAGS = "-bundle -undefined error"; OTHER_REZFLAGS = ""; PRODUCT_NAME = "Template Editor"; SECTORDER_FLAGS = ""; @@ -2030,7 +2259,7 @@ dependencies = ( ); isa = PBXBundleTarget; - name = "Template Editor"; + name = "Template Editor Carbon"; productInstallPath = "$(USER_LIBRARY_DIR)/Bundles"; productName = "Template Editor"; productReference = F5B588ED0156DAF301000001; @@ -2071,6 +2300,7 @@ F5B589040156DC2201000001, F5B589050156DC2201000001, F5B589060156DC2201000001, + F53544320226550001A80001, ); isa = PBXHeadersBuildPhase; name = Headers; @@ -2384,8 +2614,7 @@ }; F5CDEBAB01FC893201A80001 = { isa = PBXFileReference; - name = ResKnifeResourceProtocol.h; - path = "Plug-Ins/ResKnifeResourceProtocol.h"; + path = ResKnifeResourceProtocol.h; refType = 4; }; F5CDEBAC01FC893201A80001 = { @@ -2410,8 +2639,38 @@ isa = PBXTargetDependency; target = F57CEE0E0189C95101A8010B; }; - F5D0BAFC0202558901A80001 = { - fileRef = F5B588A70156D6D901000001; + F5D0CBCF022744C701A80001 = { + isa = PBXFileReference; + path = "NSOutlineView-SelectedItems.h"; + refType = 4; + }; + F5D0CBD0022744C701A80001 = { + isa = PBXFileReference; + path = "NSOutlineView-SelectedItems.m"; + refType = 4; + }; + F5D0CBD1022744C701A80001 = { + fileRef = F5D0CBCF022744C701A80001; + isa = PBXBuildFile; + settings = { + }; + }; + F5D0CBD2022744C701A80001 = { + fileRef = F5D0CBD0022744C701A80001; + isa = PBXBuildFile; + settings = { + }; + }; + F5D0CBD302278F8B01A80001 = { + children = ( + F53544430226778D01A80001, + ); + isa = PBXVariantGroup; + name = TemplateWindow.nib; + refType = 4; + }; + F5D0CBD402278F8B01A80001 = { + fileRef = F5D0CBD302278F8B01A80001; isa = PBXBuildFile; settings = { }; @@ -2450,8 +2709,7 @@ F5EF83A9020C08E601A80001, ); isa = PBXGroup; - name = "Hex Editor"; - path = "Plug-Ins/Hex Editor"; + path = "Hex Editor"; refType = 4; }; F5EF83A0020C08E601A80001 = {