From a343ff6aa7e5789cd0d35a28caace8e39959e777 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Sat, 13 Jun 2009 13:25:59 +0000 Subject: =?UTF-8?q?=E2=80=A2=20moved=20code=20for=20de/increasing=20font?= =?UTF-8?q?=20and=20drag&drop=20feature=20(content=20or=20while=20holding?= =?UTF-8?q?=20=E2=8C=98=20path)=20to=20SPTextViewAddition=20-=20two=20fing?= =?UTF-8?q?er=20zooming=20gesture=20is=20disabled=20for=20NSTableView=20ce?= =?UTF-8?q?lls=20-=20i.e.=20all=20NSTextViews=20including=20NSTableView=20?= =?UTF-8?q?cells=20inherit=20these=20feature=20=E2=80=A2=20simplified=20Qu?= =?UTF-8?q?ickLookFormat=20IBActions=20-=20added=20bin/text=20storing=20ty?= =?UTF-8?q?pe=20to=20each=20action=20=E2=80=A2=20QuickLook=20animation=20s?= =?UTF-8?q?et=20to=20SP's=20window=20middle=20point=20=E2=80=A2=20fixed=20?= =?UTF-8?q?issue=20that=20while=20having=20an=20image=20in=20editSheet=20a?= =?UTF-8?q?n=20attribute=20change=20(font/size)=20in=20the=20editTextView?= =?UTF-8?q?=20destroyed=20the=20image=20data=20=E2=80=A2=20fix=20to=20allo?= =?UTF-8?q?w=20again=20drag&drop=20an=20image=20to=20editSheet=20=E2=80=A2?= =?UTF-8?q?=20hide=20text/image/hex=20segment=20controll=20and=20QuickLook?= =?UTF-8?q?=20pull=20down=20button=20if=20user=20chose=20multipleLineEditi?= =?UTF-8?q?ngButton=20for=20non-blob=20fields=20=20=E2=80=A2=20disabled=20?= =?UTF-8?q?NSLog=20of=20print=20result=20in=20TableDocument?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/TableContent.m | 109 +++++++++++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 45 deletions(-) (limited to 'Source/TableContent.m') diff --git a/Source/TableContent.m b/Source/TableContent.m index f75cef3e..eb36e9ba 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -37,6 +37,7 @@ #import "SPQueryConsole.h" #import "SPStringAdditions.h" #import "SPArrayAdditions.h" +#import "SPTextViewAdditions.h" @implementation TableContent @@ -951,6 +952,7 @@ NSString *fileName = [panel filename]; // Write binary field types directly to the file + //// || [editSheetBinaryButton state] == NSOnState if ( [editData isKindOfClass:[NSData class]] ) { [editData writeToFile:fileName atomically:YES]; @@ -970,47 +972,25 @@ #pragma mark - #pragma mark QuickLook -- (IBAction)quickLookAsWordDoc:(id)sender +- (IBAction)quickLookFormatButton:(id)sender { - [self invokeQuickLookOfType:@"doc"]; -} -- (IBAction)quickLookAsRTF:(id)sender -{ - [self invokeQuickLookOfType:@"rtf"]; -} -- (IBAction)quickLookAsMovie:(id)sender -{ - [self invokeQuickLookOfType:@"mov"]; -} -- (IBAction)quickLookAsSoundM4A:(id)sender -{ - [self invokeQuickLookOfType:@"m4a"]; -} -- (IBAction)quickLookAsSoundMP3:(id)sender -{ - [self invokeQuickLookOfType:@"mp3"]; -} -- (IBAction)quickLookAsSoundLinear:(id)sender -{ - [self invokeQuickLookOfType:@"wav"]; -} -- (IBAction)quickLookAsImage:(id)sender -{ - [self invokeQuickLookOfType:@"pict"]; -} -- (IBAction)quickLookAsPDF:(id)sender -{ - [self invokeQuickLookOfType:@"pdf"]; -} -- (IBAction)quickLookAsHTML:(id)sender -{ - [self invokeQuickLookOfType:@"html"]; + switch([sender tag]) { + case 0: [self invokeQuickLookOfType:@"pict" treatAsText:NO]; break; + case 1: [self invokeQuickLookOfType:@"m4a" treatAsText:NO]; break; + case 2: [self invokeQuickLookOfType:@"mp3" treatAsText:NO]; break; + case 3: [self invokeQuickLookOfType:@"wav" treatAsText:NO]; break; + case 4: [self invokeQuickLookOfType:@"mov" treatAsText:NO]; break; + case 5: [self invokeQuickLookOfType:@"pdf" treatAsText:NO]; break; + case 6: [self invokeQuickLookOfType:@"html" treatAsText:YES]; break; + case 7: [self invokeQuickLookOfType:@"doc" treatAsText:NO]; break; + case 8: [self invokeQuickLookOfType:@"rtf" treatAsText:YES]; break; + } } /* * Opens QuickLook for current data if QuickLook is available */ -- (void)invokeQuickLookOfType:(NSString *)type +- (void)invokeQuickLookOfType:(NSString *)type treatAsText:(BOOL)isText { // Load private framework @@ -1023,7 +1003,7 @@ NSString *tmpFileName = [NSString stringWithFormat:@"/tmp/SequelProQuickLook.%@", type]; // if data are binary - if ( [editData isKindOfClass:[NSData class]] ) { + if ( [editData isKindOfClass:[NSData class]] || !isText) { [editData writeToFile:tmpFileName atomically:YES]; // write other field types' representations to the file via the current encoding @@ -1083,11 +1063,13 @@ // if user closes the QuickLook view quickLookCloseMarker = 1; - // TODO get QuickLook's pulldown button's frame to zoom out/in from/into it - NSRect r = [editSheetQuickLookButton convertRectToBase:[editSheetQuickLookButton frame]]; - // tentative setting - r.origin.y=400; - return r; + // Return the App's middle point + NSRect mwf = [[NSApp mainWindow] frame]; + return NSMakeRect( + mwf.origin.x+mwf.size.width/2, + mwf.origin.y+mwf.size.height/2, + 5, 5); + } @@ -1112,7 +1094,8 @@ NSString *contents = [[NSString alloc] initWithData:data encoding:[CMMCPConnection encodingForMySQLEncoding:[[tableDocumentInstance connectionEncoding] UTF8String]]]; // Set the string contents and hex representation - [editTextView setString:contents]; + if(contents) + [editTextView setString:contents]; [hexTextView setString:[self dataToHex:editData]]; [contents release]; @@ -1132,11 +1115,16 @@ } } -- (void)textDidChange:(NSNotification *)notification +- (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:@""]; @@ -1148,6 +1136,7 @@ // set edit data to text editData = [[editTextView string] retain]; + } - (NSString *)dataToHex:(NSData *)data @@ -2232,8 +2221,11 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn } } + BOOL isBlob = [tableDataInstance columnIsBlobOrText:[aTableColumn identifier]]; // Open the sheet if the multipleLineEditingButton is enabled or the column was a blob or a text. - if ( [multipleLineEditingButton state] == NSOnState || [tableDataInstance columnIsBlobOrText:[aTableColumn identifier]] ) { + if ( [multipleLineEditingButton state] == NSOnState || isBlob ) { + + editSheetWillBeInitialized = YES; theValue = [[filteredResult objectAtIndex:rowIndex] objectForKey:[aTableColumn identifier]]; NSImage *image = nil; @@ -2246,6 +2238,9 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn [editTextView setHidden:YES]; [editTextScrollView setHidden:YES]; + [editSheetQuickLookButton setHidden:(!isBlob)]; + [editSheetSegmentControl setHidden:(!isBlob)]; + // order out editSheet to inform the user that // SP is working [NSApp beginSheet:editSheet modalForWindow:tableWindow modalDelegate:self didEndSelector:nil contextInfo:nil]; @@ -2299,6 +2294,8 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn [editSheetProgressBar stopAnimation:self]; + editSheetWillBeInitialized = NO; + // wait for editSheet code = [NSApp runModalForWindow:editSheet]; @@ -2430,6 +2427,7 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn /** * Traps enter and return key and closes editSheet instead of inserting a linebreak when user hits return. + * Catch ⌘+ and ⌘- to de/increase font size of aTextView */ - (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector { @@ -2439,7 +2437,28 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn { [NSApp stopModalWithCode:1]; return YES; - } else { + } + else if([[NSApp currentEvent] modifierFlags] & NSCommandKeyMask) + { + // increase text size by 1; ⌘+ and numpad + + if([[[NSApp currentEvent] charactersIgnoringModifiers] isEqualToString:@"+"]) + { + [aTextView makeTextSizeLarger]; + return YES; + } + // decrease text size by 1; ⌘- and numpad - + else if([[[NSApp currentEvent] charactersIgnoringModifiers] isEqualToString:@"-"]) + { + [aTextView makeTextSizeSmaller]; + return YES; + } + else + { + return NO; + } + } + else + { return NO; } } -- cgit v1.2.3