From 39c34617b01f72c7466eee98675447e277e326cb Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 15 Jun 2009 14:18:51 +0000 Subject: =?UTF-8?q?=E2=80=A2=20improved=20event=20handling=20while=20showi?= =?UTF-8?q?ng=20QuickLook=20preview=20in=20editSheet=20-=20this=20also=20f?= =?UTF-8?q?ixes=20the=20issue=20to=20play=20sound=20files=20properly=20?= =?UTF-8?q?=E2=80=A2=20QuickLook's=20temp=20file=20will=20be=20deleted=20a?= =?UTF-8?q?fter=20closing=20the=20editSheet=20to=20allow=20double-click=20?= =?UTF-8?q?at=20the=20QuickLook=20preview=20for=20opening=20it=20in=20the?= =?UTF-8?q?=20default=20app=20=E2=80=A2=20fixed=20some=20issues=20of=20loa?= =?UTF-8?q?ding=20data=20into=20the=20editSheet=20(data/string=20recogniti?= =?UTF-8?q?on)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/TableContent.m | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/Source/TableContent.m b/Source/TableContent.m index eb36e9ba..551ddd59 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -858,7 +858,9 @@ if ( [panel runModal] == NSOKButton ) { NSString *fileName = [panel filename]; NSString *contents = nil; - + + editSheetWillBeInitialized = YES; + [editSheetProgressBar startAnimation:self]; // free old data @@ -868,12 +870,13 @@ // load new data/images editData = [[NSData alloc] initWithContentsOfFile:fileName]; + NSImage *image = [[NSImage alloc] initWithData:editData]; contents = [[NSString alloc] initWithData:editData encoding:[mySQLConnection encoding]]; - // NSString *contents = [NSString stringWithContentsOfFile:fileName encoding:[mySQLConnection encoding] error:nil]; // set the image preview, string contents and hex representation [editImage setImage:image]; + if(contents) [editTextView setString:contents]; @@ -905,6 +908,7 @@ if(contents) [contents release]; [editSheetProgressBar stopAnimation:self]; + editSheetWillBeInitialized = NO; } } @@ -1020,7 +1024,8 @@ [[ql delegate] setDelegate:self]; [ql setURLs:[NSArray arrayWithObject: [NSURL fileURLWithPath:tmpFileName]] currentIndex:0 preservingDisplayState:YES]; - // No interaction with iChat and iPhoto + // TODO: No interaction with iChat and iPhoto due to .scriptSuite warning: + // for superclass of class 'MainController' in suite 'Sequel Pro': 'NSCoreSuite.NSAbstractObject' is not a valid class name. [ql setShowsAddToiPhotoButton:NO]; [ql setShowsiChatTheaterButton:NO]; // Since we are inside of editSheet we have to avoid full-screen zooming @@ -1028,7 +1033,7 @@ [ql setShowsFullscreenButton:NO]; [ql setEnableDragNDrop:NO]; // Order out QuickLook with animation effect according to self:previewPanel:frameForURL: - [ql makeKeyAndOrderFrontWithEffect:2 canClose:YES]; // 1 = fade in + [ql makeKeyAndOrderFrontWithEffect:2]; // 1 = fade in // quickLookCloseMarker == 1 break the modal session quickLookCloseMarker = 0; @@ -1043,16 +1048,29 @@ || quickLookCloseMarker == 1 || ![ql isVisible]) break; + [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode + beforeDate:[NSDate distantFuture]]; + } [NSApp endModalSession:session]; + + // Remove temp file after closing the sheet to allow double-click event at the QuickLook preview. + // The afterDelay: time is a kind of dummy, because after double-clicking the model session loop + // will break (ql not visible) and returns the event handling back to the editSheet which by itself + // blocks the execution of removeQuickLooksTempFile: until the editSheet is closed. + [self performSelector:@selector(removeQuickLooksTempFile:) withObject:tmpFileName afterDelay:2]; - // remove temp file - [[NSFileManager defaultManager] removeItemAtPath:tmpFileName error:NULL]; + // [[NSFileManager defaultManager] removeItemAtPath:tmpFileName error:NULL]; } } +- (void)removeQuickLooksTempFile:(NSString*)aPath +{ + [[NSFileManager defaultManager] removeItemAtPath:aPath error:NULL]; +} + // This is the delegate method // It should return the frame for the item represented by the URL // If an empty frame is returned then the panel will fade in/out instead @@ -1079,6 +1097,9 @@ */ - (void)processUpdatedImageData:(NSData *)data { + + editSheetWillBeInitialized = YES; + if (nil != editData) [editData release]; // If the image was not processed, set a blank string as the contents of the edit and hex views. @@ -1086,6 +1107,7 @@ editData = [[NSData alloc] init]; [editTextView setString:@""]; [hexTextView setString:@""]; + editSheetWillBeInitialized = NO; return; } @@ -1099,6 +1121,7 @@ [hexTextView setString:[self dataToHex:editData]]; [contents release]; + editSheetWillBeInitialized = NO; } - (IBAction)dropImage:(id)sender @@ -2284,6 +2307,16 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn } 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)]; -- cgit v1.2.3