aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPFieldEditorController.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2009-08-03 02:20:12 +0000
committerstuconnolly <stuart02@gmail.com>2009-08-03 02:20:12 +0000
commit63323b1d133fe3c7ed6c6c9d37d1a28608014938 (patch)
tree6d110ac5c6ee1c23a4235d3ae5be11d37861e94d /Source/SPFieldEditorController.m
parentef575afcc1cd8575773176d366da34f39975c118 (diff)
downloadsequelpro-63323b1d133fe3c7ed6c6c9d37d1a28608014938.tar.gz
sequelpro-63323b1d133fe3c7ed6c6c9d37d1a28608014938.tar.bz2
sequelpro-63323b1d133fe3c7ed6c6c9d37d1a28608014938.zip
In the field editor sheet:
- Make some of the QuickLook format menuitem name's uppercase. - Run both the save and open panels as sheets to prevent blocking the entire app.
Diffstat (limited to 'Source/SPFieldEditorController.m')
-rw-r--r--Source/SPFieldEditorController.m155
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