From 155e66d1b9a6d1108ba4b29397fe3b04a77737f0 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 17 Jul 2009 15:10:22 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed:=20caching=20of=20QuickLook=20preview?= =?UTF-8?q?=20in=20Field=20Editor=20sheet=20is=20suppressed=20by=20alterna?= =?UTF-8?q?ting=20the=20temporary=20file=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPFieldEditorController.h | 3 +++ Source/SPFieldEditorController.m | 42 ++++++++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 17 deletions(-) (limited to 'Source') diff --git a/Source/SPFieldEditorController.h b/Source/SPFieldEditorController.h index 51956bc0..f369951f 100644 --- a/Source/SPFieldEditorController.h +++ b/Source/SPFieldEditorController.h @@ -43,6 +43,9 @@ int quickLookCloseMarker; NSStringEncoding encoding; NSString *stringValue; + NSString *tmpFileName; + + int counter; NSUserDefaults *prefs; } diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m index 12fcb6a5..1a5a19a3 100644 --- a/Source/SPFieldEditorController.m +++ b/Source/SPFieldEditorController.m @@ -37,6 +37,7 @@ if ((self = [super initWithWindowNibName:@"FieldEditorSheet"])) { // force the nib to be loaded (void) [self window]; + counter = 0; } return self; @@ -72,7 +73,7 @@ editSheetWillBeInitialized = YES; encoding = anEncoding; - + isBlob = isFieldBlob; sheetEditData = [data retain]; @@ -171,7 +172,7 @@ // For safety reasons inform QuickLook to quit quickLookCloseMarker = 1; - + return ( code ) ? [sheetEditData retain] : nil; } @@ -269,6 +270,7 @@ [[self window] makeFirstResponder:editImage]; break; case 2: // hex - load on demand + [[self window] makeFirstResponder:hexTextView]; if([sheetEditData length] && [[hexTextView string] isEqualToString:@""]) { [editSheetProgressBar startAnimation:self]; if([sheetEditData isKindOfClass:[NSData class]]) { @@ -283,7 +285,6 @@ [editImage setHidden:YES]; [hexTextView setHidden:NO]; [hexTextScrollView setHidden:NO]; - [[self window] makeFirstResponder:hexTextView]; break; } } @@ -350,10 +351,9 @@ // Create a temporary file name to store the data as file // since QuickLook only works on files. - NSString *tmpFileName = [NSString stringWithFormat:@"/tmp/SequelProQuickLook.%@", type]; - - [self removeQuickLooksTempFile:tmpFileName]; - + // Alternate the file name to suppress caching by using counter%2. + tmpFileName = [NSString stringWithFormat:@"%@SequelProQuickLook%d.%@", NSTemporaryDirectory(), counter%2, type]; + // if data are binary if ( [sheetEditData isKindOfClass:[NSData class]] && !isText) { [sheetEditData writeToFile:tmpFileName atomically:YES]; @@ -375,26 +375,29 @@ default: enc = @"US-ASCII"; } - [[NSString stringWithFormat:@"%@", enc, [editTextView string]] writeToFile:tmpFileName - atomically:YES - encoding:encoding - error:NULL]; + atomically:YES + encoding:encoding + error:NULL]; } else { [[sheetEditData description] writeToFile:tmpFileName - atomically:YES - encoding:encoding - error:NULL]; + atomically:YES + encoding:encoding + error:NULL]; } } + counter++; + // Init QuickLook id ql = [NSClassFromString(@"QLPreviewPanel") sharedPreviewPanel]; - [[ql windowController] setDelegate:self]; + [[ql delegate] setDelegate:self]; [ql setURLs:[NSArray arrayWithObject: [NSURL fileURLWithPath:tmpFileName]] currentIndex:0 preservingDisplayState:YES]; + + // 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]; @@ -433,7 +436,11 @@ // 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]; + // [NSObject cancelPreviousPerformRequestsWithTarget:self + // selector:@selector(removeQuickLooksTempFile) + // object:tmpFileName]; + + [self performSelector:@selector(removeQuickLooksTempFile:) withObject:tmpFileName afterDelay:.1]; } @@ -441,7 +448,8 @@ - (void)removeQuickLooksTempFile:(NSString*)aPath { - [[NSFileManager defaultManager] removeItemAtPath:aPath error:NULL]; + if(![[NSFileManager defaultManager] removeItemAtPath:aPath error:NULL]) + NSLog(@"Couldn't delete temp file at path '%@'", aPath); } // This is the delegate method -- cgit v1.2.3