aboutsummaryrefslogtreecommitdiffstats
path: root/Source/TableContent.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-03-05 21:38:51 +0000
committerrowanbeentje <rowan@beent.je>2009-03-05 21:38:51 +0000
commit68dd0c0f1bd028725d697ed2fc1f2ce33bb9682f (patch)
treef3db7f49eabccd09f21b0479145bb8baa9f76134 /Source/TableContent.m
parent0ebdbeb0201580e5abcded23dd37b6b3516cbb84 (diff)
downloadsequelpro-68dd0c0f1bd028725d697ed2fc1f2ce33bb9682f.tar.gz
sequelpro-68dd0c0f1bd028725d697ed2fc1f2ce33bb9682f.tar.bz2
sequelpro-68dd0c0f1bd028725d697ed2fc1f2ce33bb9682f.zip
- Fix a number of edit sheet crashers regarding opening and saving files, image deletions, and image drag and dropping (fixes Issue #85 and google groups report)
- Improves compatbility of drag-and-drops onto the image well, including support for image drags from other applications - Attempt to automatically select the image or text tab in the edit sheet as appropriate - Fixes build-from-clean warnings caused by an unexposed function added in r375
Diffstat (limited to 'Source/TableContent.m')
-rw-r--r--Source/TableContent.m92
1 files changed, 72 insertions, 20 deletions
diff --git a/Source/TableContent.m b/Source/TableContent.m
index 9a85b84a..156ce5c8 100644
--- a/Source/TableContent.m
+++ b/Source/TableContent.m
@@ -746,52 +746,91 @@
// load new data/images
editData = [[NSData alloc] initWithContentsOfFile:fileName];
- NSImage *image = [[[NSImage alloc] initByReferencingFile:fileName] autorelease];
- NSString *contents = [[NSString stringWithContentsOfFile:fileName] autorelease];
+ NSImage *image = [[NSImage alloc] initWithData:editData];
+ NSString *contents = [NSString stringWithContentsOfFile:fileName];
// set the image preview, string contents and hex representation
[editImage setImage:image];
[editTextView setString:contents];
[hexTextView setString:[self dataToHex:editData]];
+
+ // If the image cell now contains a valid image, select the image tab
+ if (image) {
+ [editSheetTabView selectTabViewItemAtIndex:1];
+
+ // Otherwise deselect the image tab if it's selected but now not showing anything
+ } else {
+ if ([editSheetTabView indexOfTabViewItem:[editSheetTabView selectedTabViewItem]] == 1)
+ [editSheetTabView selectTabViewItemAtIndex:0];
+ }
+
+ [image release];
}
}
-- (IBAction)saveEditSheet:(id)sender
/*
- saves a file containing the content of the editSheet
+ * Saves a file containing the content of the editSheet
*/
+- (IBAction)saveEditSheet:(id)sender
{
NSSavePanel *panel = [NSSavePanel savePanel];
if ( [panel runModal] == NSOKButton ) {
NSString *fileName = [panel filename];
- NSString *data;
+ // Write binary field types directly to the file
if ( [editData isKindOfClass:[NSData class]] ) {
- data = editData;
+ [editData writeToFile:fileName atomically:YES];
+
+ // Write other field types' representations to the file via the current encoding
} else {
- data = [editData description];
+ [[editData description] writeToFile:fileName
+ atomically:YES
+ encoding:[CMMCPConnection encodingForMySQLEncoding:[[tableDocumentInstance connectionEncoding] UTF8String]]
+ error:NULL];
}
- [editData writeToFile:fileName atomically:YES encoding:[CMMCPConnection encodingForMySQLEncoding:[(NSString *)[tableDocumentInstance encoding] UTF8String]] error:NULL];
}
}
-- (IBAction)dropImage:(id)sender
/*
- invoked when user drag&drops image on imageView
+ * Invoked when the imageView in the connection sheet has the contents deleted
+ * or a file dragged and dropped onto it.
*/
+- (void)processUpdatedImageData:(NSData *)data
{
- // load new data/images
- if (nil != editData)
- {
- [editData release];
+ if (nil != editData) [editData release];
+
+ // If the image was not processed, set a blank string as the contents of the edit and hex views.
+ if ( data == nil ) {
+ editData = [[NSData alloc] init];
+ [editTextView setString:@""];
+ [hexTextView setString:@""];
+ return;
}
- editData = [[[NSData alloc] initWithContentsOfFile:[sender draggedFilePath]] retain];
- NSString *contents = [NSString stringWithContentsOfFile:[sender draggedFilePath]];
-
- // set the string contents and hex representation
+
+ // Process the provided image
+ editData = [[NSData alloc] initWithData:data];
+ NSString *contents = [[NSString alloc] initWithData:data encoding:[CMMCPConnection encodingForMySQLEncoding:[[tableDocumentInstance connectionEncoding] UTF8String]]];
+
+ // Set the string contents and hex representation
[editTextView setString:contents];
[hexTextView setString:[self dataToHex:editData]];
+
+ [contents release];
+}
+
+- (IBAction)dropImage:(id)sender
+{
+
+ // If the image was deleted, set a blank string as the contents of the edit and hex views.
+ // The actual dropped image processing is handled by processUpdatedImageData:.
+ if ( [editImage image] == nil ) {
+ if (nil != editData) [editData release];
+ editData = [[NSData alloc] init];
+ [editTextView setString:@""];
+ [hexTextView setString:@""];
+ return;
+ }
}
- (void)textDidChange:(NSNotification *)notification
@@ -1842,7 +1881,7 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn
editData = [theValue retain];
if ( [theValue isKindOfClass:[NSData class]] ) {
- image = [[NSImage alloc] initWithData:theValue];
+ image = [[[NSImage alloc] initWithData:theValue] autorelease];
[hexTextView setString:[self dataToHex:theValue]];
stringValue = [[NSString alloc] initWithData:theValue encoding:[mySQLConnection encoding]];
if (stringValue == nil)
@@ -1852,12 +1891,25 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn
stringValue = [[NSString alloc] initWithString:[theValue description]];
}
- [editImage setImage:image];
+ if (image) {
+ [editImage setImage:image];
+ } else {
+ [editImage setImage:nil];
+ }
if (stringValue) {
[editTextView setString:stringValue];
[editTextView setSelectedRange:NSMakeRange(0,[[editTextView string] length])];
[stringValue release];
}
+
+ // If the cell contains a valid image, select the image tab
+ if (image) {
+ [editSheetTabView selectTabViewItemAtIndex:1];
+
+ // Otherwise default to text tab
+ } else {
+ [editSheetTabView selectTabViewItemAtIndex:0];
+ }
[NSApp beginSheet:editSheet modalForWindow:tableWindow modalDelegate:self didEndSelector:nil contextInfo:nil];
code = [NSApp runModalForWindow:editSheet];