aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPFieldEditor.h17
-rw-r--r--Source/SPFieldEditor.m161
2 files changed, 172 insertions, 6 deletions
diff --git a/Source/SPFieldEditor.h b/Source/SPFieldEditor.h
index 8b057f80..ff7cd5c6 100644
--- a/Source/SPFieldEditor.h
+++ b/Source/SPFieldEditor.h
@@ -22,9 +22,14 @@
IBOutlet id hexTextScrollView;
id editData;
+
+ NSString *stringValue;
+
BOOL editSheetWillBeInitialized;
+ BOOL isBlob;
int quickLookCloseMarker;
NSStringEncoding encoding;
+
}
@@ -34,15 +39,21 @@
- (IBAction)dropImage:(id)sender;
- (IBAction)segmentControllerChanged:(id)sender;
- (IBAction)quickLookFormatButton:(id)sender;
+- (IBAction)dropImage:(id)sender;
-- (void)setEditData:(id)data;
-
-- (void)setMySQLConnectionEncoding:(NSStringEncoding)anEncoding;
+- (void)initWithObject:(id)data usingEncoding:(NSStringEncoding)anEncoding isObjectBlob:(BOOL)isFieldBlob;
- (void)processPasteImageData;
- (void)processUpdatedImageData:(NSData *)data;
+- (id)editData;
+
- (void)invokeQuickLookOfType:(NSString *)type treatAsText:(BOOL)isText;
- (void)removeQuickLooksTempFile:(NSString*)aPath;
+- (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector;
+- (void)textViewDidChangeSelection:(NSNotification *)notification;
+
+- (void)clean;
+
@end
diff --git a/Source/SPFieldEditor.m b/Source/SPFieldEditor.m
index 9d0bb75e..3a389f6e 100644
--- a/Source/SPFieldEditor.m
+++ b/Source/SPFieldEditor.m
@@ -17,14 +17,126 @@
@implementation SPFieldEditor
-- (void)setEditData:(id)data
+- (void)initWithObject:(id)data usingEncoding:(NSStringEncoding)anEncoding isObjectBlob:(BOOL)isFieldBlob
{
+
+ // hide all views in editSheet
+ [hexTextView setHidden:YES];
+ [hexTextScrollView setHidden:YES];
+ [editImage setHidden:YES];
+ [editTextView setHidden:YES];
+ [editTextScrollView setHidden:YES];
+
+ editSheetWillBeInitialized = YES;
+
+ encoding = anEncoding;
+
+ isBlob = isFieldBlob;
+
editData = [data retain];
+
+ // hide all views in editSheet
+ [hexTextView setHidden:YES];
+ [hexTextScrollView setHidden:YES];
+ [editImage setHidden:YES];
+ [editTextView setHidden:YES];
+ [editTextScrollView setHidden:YES];
+
+ // Hide QuickLook button and text/iamge/hex control for text data
+ [editSheetQuickLookButton setHidden:(!isBlob)];
+ [editSheetSegmentControl setHidden:(!isBlob)];
+
+ [editSheetProgressBar startAnimation:self];
+ NSImage *image = nil;
+ if ( [editData isKindOfClass:[NSData class]] ) {
+ image = [[[NSImage alloc] initWithData:editData] autorelease];
+
+ // Set hex view to "" - load on demand only
+ [hexTextView setString:@""];
+
+ stringValue = [[NSString alloc] initWithData:editData encoding:encoding];
+ if (stringValue == nil)
+ stringValue = [[NSString alloc] initWithData:editData encoding:NSASCIIStringEncoding];
+
+ [hexTextView setHidden:NO];
+ [hexTextScrollView setHidden:NO];
+ [editImage setHidden:YES];
+ [editTextView setHidden:YES];
+ [editTextScrollView setHidden:YES];
+ [editSheetSegmentControl setSelectedSegment:2];
+ } else {
+ stringValue = [editData retain];
+
+ [hexTextView setString:@""];
+
+ [hexTextView setHidden:YES];
+ [hexTextScrollView setHidden:YES];
+ [editImage setHidden:YES];
+ [editTextView setHidden:NO];
+ [editTextScrollView setHidden:NO];
+ [editSheetSegmentControl setSelectedSegment:0];
+ }
+
+ if (image) {
+ [editImage setImage:image];
+
+ [hexTextView setHidden:YES];
+ [hexTextScrollView setHidden:YES];
+ [editImage setHidden:NO];
+ [editTextView setHidden:YES];
+ [editTextScrollView setHidden:YES];
+ [editSheetSegmentControl setSelectedSegment:1];
+ } else {
+ [editImage setImage:nil];
+ }
+ if (stringValue) {
+ [editTextView setString:stringValue];
+
+ if(image == nil) {
+ [hexTextView setHidden:YES];
+ [hexTextScrollView setHidden:YES];
+ [editImage setHidden:YES];
+ [editTextView setHidden:NO];
+ [editTextScrollView setHidden:NO];
+ [editSheetSegmentControl setSelectedSegment:0];
+ }
+
+ // Locate the caret in editTextView
+ // (to select all takes a bit time for large data)
+ [editTextView setSelectedRange:NSMakeRange(0,0)];
+
+ // Set focus
+ if(image == nil)
+ [self makeFirstResponder:editTextView];
+ else
+ [self makeFirstResponder:editImage];
+
+ [stringValue release];
+ }
+
+
+
+ editSheetWillBeInitialized = NO;
+
+ [editSheetProgressBar stopAnimation:self];
+
+
}
-- (void)setMySQLConnectionEncoding:(NSStringEncoding)anEncoding;
+- (void)clean
{
- encoding = anEncoding;
+ [hexTextView setString:@""];
+ [editTextView setString:@""];
+ [editImage setImage:nil];
+ if ( editData ) {
+ [editData release];
+ }
+
+}
+
+- (id)editData
+{
+ return editData;
}
@@ -366,6 +478,49 @@
}
}
+- (void)textViewDidChangeSelection:(NSNotification *)notification
+/*
+ invoked when the user changes the string in the editSheet
+ */
+{
+
+ // Do nothing if user really didn't changed text (e.g. for font size changing return)
+ if(editSheetWillBeInitialized || ([[[notification object] textStorage] changeInLength]==0))
+ return;
+
+ // clear the image and hex (since i doubt someone can "type" a gif)
+ [editImage setImage:nil];
+ [hexTextView setString:@""];
+
+ // free old data
+ if ( editData != nil ) {
+ [editData release];
+ }
+
+ // set edit data to text
+ editData = [[editTextView string] retain];
+
+}
+
+// TextView delegate methods
+
+/**
+ * Traps enter and return key and closes editSheet instead of inserting a linebreak when user hits return.
+ */
+- (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector
+{
+ if ( aTextView == editTextView ) {
+ if ( [aTextView methodForSelector:aSelector] == [aTextView methodForSelector:@selector(insertNewline:)] &&
+ [[[NSApp currentEvent] characters] isEqualToString:@"\003"] )
+ {
+ [NSApp stopModalWithCode:1];
+ return YES;
+ }
+ else
+ return NO;
+ }
+ return NO;
+}
@end