diff options
-rw-r--r-- | Interfaces/English.lproj/DBView.xib | 36 | ||||
-rw-r--r-- | Source/CMImageView.h | 13 | ||||
-rw-r--r-- | Source/CMImageView.m | 84 | ||||
-rw-r--r-- | Source/TableContent.h | 2 | ||||
-rw-r--r-- | Source/TableContent.m | 92 | ||||
-rw-r--r-- | Source/TableSource.h | 1 |
6 files changed, 185 insertions, 43 deletions
diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index 16d6dcc0..912d781b 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -8,7 +8,6 @@ <string key="IBDocument.HIToolboxVersion">353.00</string> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="725"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -5673,7 +5672,6 @@ </object> <string key="NSFrame">{{1, 1}, {574, 293}}</string> <reference key="NSSuperview" ref="1020679422"/> - <reference key="NSNextKeyView" ref="1011820278"/> <reference key="NSDocView" ref="1011820278"/> <reference key="NSBGColor" ref="449903125"/> <reference key="NSCursor" ref="32917531"/> @@ -5703,7 +5701,6 @@ </object> <string key="NSFrame">{{20, 20}, {587, 295}}</string> <reference key="NSSuperview" ref="375414526"/> - <reference key="NSNextKeyView" ref="134546146"/> <int key="NSsFlags">18</int> <reference key="NSVScroller" ref="435247014"/> <reference key="NSHScroller" ref="767953750"/> @@ -6974,7 +6971,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string> <string key="NSWindowContentMinSize">{213, 125}</string> <object class="NSView" key="NSWindowView" id="778680541"> - <reference key="NSNextResponder"/> + <nil key="NSNextResponder"/> <int key="NSvFlags">256</int> <object class="NSMutableArray" key="NSSubviews"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -7211,7 +7208,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> </object> </object> <string key="NSFrameSize">{418, 200}</string> - <reference key="NSSuperview"/> </object> <string key="NSScreenRect">{{0, 0}, {1440, 878}}</string> <string key="NSMinSize">{213, 147}</string> @@ -12379,6 +12375,22 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> </object> <int key="connectionID">4794</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">delegate</string> + <reference key="source" ref="976680482"/> + <reference key="destination" ref="427689665"/> + </object> + <int key="connectionID">4796</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">editSheetTabView</string> + <reference key="source" ref="392169872"/> + <reference key="destination" ref="473392579"/> + </object> + <int key="connectionID">4797</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -20703,7 +20715,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> </object> </object> <nil key="sourceID"/> - <int key="maxID">4795</int> + <int key="maxID">4800</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -20731,7 +20743,11 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> <object class="IBPartialClassDescription"> <string key="className">CMImageView</string> <string key="superclassName">NSImageView</string> - <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <object class="NSMutableDictionary" key="outlets"> + <string key="NS.key.0">delegate</string> + <string key="NS.object.0">id</string> + </object> + <object class="IBClassDescriptionSource" key="sourceIdentifier" id="520743177"> <string key="majorKey">IBProjectSource</string> <string key="minorKey">Source/CMImageView.h</string> </object> @@ -20882,6 +20898,10 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> </object> <object class="IBPartialClassDescription"> <string key="className">NSObject</string> + <reference key="sourceIdentifier" ref="520743177"/> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> <string key="minorKey">Source/CMMCPConnection.h</string> @@ -21012,6 +21032,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> <string>editData</string> <string>editImage</string> <string>editSheet</string> + <string>editSheetTabView</string> <string>editTextView</string> <string>fieldField</string> <string>filterButton</string> @@ -21050,6 +21071,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> <string>id</string> <string>id</string> <string>id</string> + <string>id</string> <string>CMCopyTable</string> <string>id</string> <string>id</string> diff --git a/Source/CMImageView.h b/Source/CMImageView.h index f52e8e5b..f4684cdc 100644 --- a/Source/CMImageView.h +++ b/Source/CMImageView.h @@ -24,13 +24,18 @@ #import <Cocoa/Cocoa.h> +@interface NSObject (CMImageViewDelegate) + +- (void)processUpdatedImageData:(NSData *)data; + +@end @interface CMImageView : NSImageView { - - NSString *draggedFilePath; - + + IBOutlet id delegate; + } -- (NSString *)draggedFilePath; +- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender; @end diff --git a/Source/CMImageView.m b/Source/CMImageView.m index 0eb4c250..de96fac5 100644 --- a/Source/CMImageView.m +++ b/Source/CMImageView.m @@ -27,22 +27,82 @@ @implementation CMImageView -- (NSString *)draggedFilePath + /* -returns the path of the dragged file -*/ + * On a drag and drop, read in dragged files and convert dragged images before passing + * them to the delegate for further processing + */ +- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender { - return [NSString stringWithString:draggedFilePath]; -} + id delegateForUse = nil; -- (void)concludeDragOperation:(id <NSDraggingInfo>)sender -{ - if ( draggedFilePath ) - [draggedFilePath release]; + // If the delegate or the delegate's content instance doesn't implement processUpdatedImageData:, + // return the super's implementation + if (delegate) { + if ([delegate respondsToSelector:@selector(processUpdatedImageData:)]) { + delegateForUse = delegate; + } else if ( [delegate valueForKey:@"tableContentInstance"] + && [[delegate valueForKey:@"tableContentInstance"] respondsToSelector:@selector(processUpdatedImageData:)] ) { + delegateForUse = [delegate valueForKey:@"tableContentInstance"]; + } + } + if (!delegateForUse) { + return [super performDragOperation:sender]; + } + + // If a filename is available, attempt to read it and pass it to the delegate + if ([[[sender draggingPasteboard] propertyListForType:@"NSFilenamesPboardType"] count]) { + [delegateForUse processUpdatedImageData:[NSData dataWithContentsOfFile:[[[sender draggingPasteboard] propertyListForType:@"NSFilenamesPboardType"] objectAtIndex:0]]]; + return [super performDragOperation:sender]; + } + + // Otherwise, see if a dragged image is available via file contents or TIFF and pass to delegate + if ([[sender draggingPasteboard] dataForType:@"NSFileContentsPboardType"]) { + [delegateForUse processUpdatedImageData:[[sender draggingPasteboard] dataForType:@"NSFileContentsPboardType"]]; + return [super performDragOperation:sender]; + } - draggedFilePath = [[NSString stringWithString:[[[sender draggingPasteboard] propertyListForType:@"NSFilenamesPboardType"] objectAtIndex:0]] retain]; + // For dragged image representations (in TIFF format), convert to PNG data for compatibility + if ([[sender draggingPasteboard] dataForType:@"NSTIFFPboardType"]) { + NSData *pngData = nil; + NSBitmapImageRep *draggedImage = [[NSBitmapImageRep alloc] initWithData:[[sender draggingPasteboard] dataForType:@"NSTIFFPboardType"]]; + if (draggedImage) { + pngData = [draggedImage representationUsingType:NSPNGFileType properties:nil]; + [draggedImage release]; + } + if (pngData) { + [delegateForUse processUpdatedImageData:pngData]; + return [super performDragOperation:sender]; + } + } + + // For dragged image representations (in PICT format), convert to PNG data for compatibility + if ([[sender draggingPasteboard] dataForType:@"NSPICTPboardType"]) { + NSData *pngData = nil; + NSPICTImageRep *draggedImage = [[NSPICTImageRep alloc] initWithData:[[sender draggingPasteboard] dataForType:@"NSPICTPboardType"]]; + if (draggedImage) { + NSImage *convertImage = [[NSImage alloc] initWithSize:[draggedImage size]]; + [convertImage lockFocus]; + [draggedImage drawInRect:[draggedImage boundingBox]]; + NSBitmapImageRep *bitmapImageRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[draggedImage boundingBox]]; + if (bitmapImageRep) { + pngData = [bitmapImageRep representationUsingType:NSPNGFileType properties:nil]; + [bitmapImageRep release]; + } + [convertImage unlockFocus]; + [convertImage release]; + [draggedImage release]; + } + if (pngData) { + [delegateForUse processUpdatedImageData:pngData]; + return [super performDragOperation:sender]; + } + } - [super concludeDragOperation:sender]; + // The image was not processed - return failure and clear image representation. + [delegateForUse processUpdatedImageData:nil]; + [self setImage:nil]; + return NO; } -@end +@end
\ No newline at end of file diff --git a/Source/TableContent.h b/Source/TableContent.h index 5847b868..e999e5e4 100644 --- a/Source/TableContent.h +++ b/Source/TableContent.h @@ -39,6 +39,7 @@ IBOutlet id tableWindow; IBOutlet CMCopyTable *tableContentView; IBOutlet id editSheet; + IBOutlet id editSheetTabView; IBOutlet id editImage; IBOutlet id editTextView; IBOutlet id hexTextView; @@ -86,6 +87,7 @@ - (IBAction)closeEditSheet:(id)sender; - (IBAction)openEditSheet:(id)sender; - (IBAction)saveEditSheet:(id)sender; +- (void)processUpdatedImageData:(NSData *)data; - (IBAction)dropImage:(id)sender; - (void)textDidChange:(NSNotification *)notification; - (NSString *)dataToHex:(NSData *)data; 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]; diff --git a/Source/TableSource.h b/Source/TableSource.h index 4b15bc6f..c66ec71f 100644 --- a/Source/TableSource.h +++ b/Source/TableSource.h @@ -88,6 +88,7 @@ //additional methods - (void)setConnection:(CMMCPConnection *)theConnection; - (NSArray *)fetchResultAsArray:(CMMCPResult *)theResult; +- (BOOL)saveRowOnDeselect; - (BOOL)addRowToDB; - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo; |