diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPFieldEditorController.m | 155 |
1 files changed, 87 insertions, 68 deletions
diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m index e62a2beb..9b0eda67 100644 --- a/Source/SPFieldEditorController.m +++ b/Source/SPFieldEditorController.m @@ -195,7 +195,6 @@ return ( code && isEditable ) ? [sheetEditData retain] : nil; } - - (IBAction)closeEditSheet:(id)sender { [NSApp stopModalWithCode:[sender tag]]; @@ -203,67 +202,11 @@ - (IBAction)openEditSheet:(id)sender { - NSOpenPanel *panel = [NSOpenPanel openPanel]; - - if ( [panel runModal] == NSOKButton ) { - NSString *fileName = [panel filename]; - NSString *contents = nil; - - editSheetWillBeInitialized = YES; - - [editSheetProgressBar startAnimation:self]; - - // free old data - if ( sheetEditData != nil ) { - [sheetEditData release]; - } - - // load new data/images - sheetEditData = [[NSData alloc] initWithContentsOfFile:fileName]; - - NSImage *image = [[NSImage alloc] initWithData:sheetEditData]; - contents = [[NSString alloc] initWithData:sheetEditData encoding:encoding]; - if (contents == nil) - contents = [[NSString alloc] initWithData:sheetEditData encoding:NSASCIIStringEncoding]; - - // set the image preview, string contents and hex representation - [editImage setImage:image]; - - - if(contents) - [editTextView setString:contents]; - else - [editTextView setString:@""]; - - // Load hex data only if user has already displayed them - if(![[hexTextView string] isEqualToString:@""]) - [hexTextView setString:[sheetEditData dataToFormattedHexString]]; - - // If the image cell now contains a valid image, select the image view - if (image) { - [editSheetSegmentControl setSelectedSegment:1]; - [hexTextView setHidden:YES]; - [hexTextScrollView setHidden:YES]; - [editImage setHidden:NO]; - [editTextView setHidden:YES]; - [editTextScrollView setHidden:YES]; - - // Otherwise deselect the image view - } else { - [editSheetSegmentControl setSelectedSegment:0]; - [hexTextView setHidden:YES]; - [hexTextScrollView setHidden:YES]; - [editImage setHidden:YES]; - [editTextView setHidden:NO]; - [editTextScrollView setHidden:NO]; - } - - [image release]; - if(contents) - [contents release]; - [editSheetProgressBar stopAnimation:self]; - editSheetWillBeInitialized = NO; - } + [[NSOpenPanel openPanel] beginSheetForDirectory:nil + file:@"" + modalForWindow:[self window] + modalDelegate:self didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) + contextInfo:NULL]; } /* @@ -312,10 +255,21 @@ * Saves a file containing the content of the editSheet */ - (IBAction)saveEditSheet:(id)sender +{ + [[NSSavePanel savePanel] beginSheetForDirectory:nil + file:@"" + modalForWindow:[self window] + modalDelegate:self + didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:) + contextInfo:NULL]; +} + +/** + * Save panel didEndSelector. Writes the current content to disk. + */ +- (void)savePanelDidEnd:(NSSavePanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo { - NSSavePanel *panel = [NSSavePanel savePanel]; - - if ( [panel runModal] == NSOKButton ) { + if (returnCode == NSOKButton) { [editSheetProgressBar startAnimation:self]; @@ -324,9 +278,10 @@ // Write binary field types directly to the file if ( [sheetEditData isKindOfClass:[NSData class]] ) { [sheetEditData writeToFile:fileName atomically:YES]; - + // Write other field types' representations to the file via the current encoding - } else { + } + else { [[sheetEditData description] writeToFile:fileName atomically:YES encoding:encoding @@ -334,10 +289,74 @@ } [editSheetProgressBar stopAnimation:self]; - } } +/** + * Open panel didEndSelector. Opens the selected file. + */ +- (void)openPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo +{ + if (returnCode == NSOKButton) { + NSString *fileName = [panel filename]; + NSString *contents = nil; + + editSheetWillBeInitialized = YES; + + [editSheetProgressBar startAnimation:self]; + + // free old data + if ( sheetEditData != nil ) { + [sheetEditData release]; + } + + // load new data/images + sheetEditData = [[NSData alloc] initWithContentsOfFile:fileName]; + + NSImage *image = [[NSImage alloc] initWithData:sheetEditData]; + contents = [[NSString alloc] initWithData:sheetEditData encoding:encoding]; + if (contents == nil) + contents = [[NSString alloc] initWithData:sheetEditData encoding:NSASCIIStringEncoding]; + + // set the image preview, string contents and hex representation + [editImage setImage:image]; + + + if(contents) + [editTextView setString:contents]; + else + [editTextView setString:@""]; + + // Load hex data only if user has already displayed them + if(![[hexTextView string] isEqualToString:@""]) + [hexTextView setString:[sheetEditData dataToFormattedHexString]]; + + // If the image cell now contains a valid image, select the image view + if (image) { + [editSheetSegmentControl setSelectedSegment:1]; + [hexTextView setHidden:YES]; + [hexTextScrollView setHidden:YES]; + [editImage setHidden:NO]; + [editTextView setHidden:YES]; + [editTextScrollView setHidden:YES]; + + // Otherwise deselect the image view + } else { + [editSheetSegmentControl setSelectedSegment:0]; + [hexTextView setHidden:YES]; + [hexTextScrollView setHidden:YES]; + [editImage setHidden:YES]; + [editTextView setHidden:NO]; + [editTextScrollView setHidden:NO]; + } + + [image release]; + if(contents) + [contents release]; + [editSheetProgressBar stopAnimation:self]; + editSheetWillBeInitialized = NO; + } +} #pragma mark - #pragma mark QuickLook |