aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-06-25 21:14:07 +0000
committerBibiko <bibiko@eva.mpg.de>2009-06-25 21:14:07 +0000
commit4f7a6885813b7e8bd2e09c00567fd88a20c66af7 (patch)
tree43e84982fa737f2e9eea9f1f1f0a3b2444f8b5f2 /Source
parent838e5a6c3db933cf0d8453db6620e0c6f2ff365d (diff)
downloadsequelpro-4f7a6885813b7e8bd2e09c00567fd88a20c66af7.tar.gz
sequelpro-4f7a6885813b7e8bd2e09c00567fd88a20c66af7.tar.bz2
sequelpro-4f7a6885813b7e8bd2e09c00567fd88a20c66af7.zip
• some work on SPFieldEditor
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