2008-05-21 15:23:26 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007-2008 Transmission authors and contributors
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#import "QuickLookController.h"
|
|
|
|
#import "QuickLook.h"
|
|
|
|
#define QLPreviewPanel NSClassFromString(@"QLPreviewPanel")
|
|
|
|
|
|
|
|
#import "Controller.h"
|
|
|
|
#import "InfoWindowController.h"
|
|
|
|
|
2008-05-21 16:14:44 +00:00
|
|
|
@interface QuickLookController (Private)
|
|
|
|
|
|
|
|
- (id) initWithMainController: (Controller *) controller infoController: (InfoWindowController *) infoController;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2008-05-21 15:23:26 +00:00
|
|
|
@implementation QuickLookController
|
|
|
|
|
|
|
|
QuickLookController * fQuickLookInstance = nil;
|
|
|
|
+ (void) quickLookControllerInitializeWithController: (Controller *) controller infoController: (InfoWindowController *) infoController
|
|
|
|
{
|
|
|
|
if (!fQuickLookInstance)
|
|
|
|
fQuickLookInstance = [[QuickLookController alloc] initWithMainController: controller infoController: infoController];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (QuickLookController *) quickLook
|
|
|
|
{
|
|
|
|
return fQuickLookInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is the QuickLook 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
|
|
|
|
- (NSRect) previewPanel: (NSPanel *) panel frameForURL: (NSURL *) url
|
|
|
|
{
|
|
|
|
if ([fInfoController shouldQuickLookFileView])
|
|
|
|
return [fInfoController quickLookFrameWithURL: url];
|
|
|
|
else
|
2008-05-21 15:45:27 +00:00
|
|
|
return [fMainController quickLookFrameWithURL: url];
|
2008-05-21 15:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) quickLookSelectItems
|
|
|
|
{
|
|
|
|
if (!fQuickLookAvailable)
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
NSArray * urlArray = nil;
|
|
|
|
|
|
|
|
if ([fInfoController shouldQuickLookFileView])
|
|
|
|
urlArray = [fInfoController quickLookURLs];
|
|
|
|
else
|
2008-05-21 15:45:27 +00:00
|
|
|
urlArray = [fMainController quickLookURLs];
|
2008-05-21 15:23:26 +00:00
|
|
|
|
|
|
|
if (urlArray && [urlArray count] > 0)
|
|
|
|
{
|
|
|
|
[[QLPreviewPanel sharedPreviewPanel] setURLs: urlArray currentIndex: 0 preservingDisplayState: YES];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2008-05-21 18:59:18 +00:00
|
|
|
- (BOOL) canQuickLook
|
|
|
|
{
|
|
|
|
if ([fInfoController shouldQuickLookFileView])
|
|
|
|
return [fInfoController canQuickLook];
|
|
|
|
else
|
|
|
|
return [fMainController canQuickLook];
|
|
|
|
}
|
|
|
|
|
2008-05-21 15:23:26 +00:00
|
|
|
- (void) toggleQuickLook
|
|
|
|
{
|
|
|
|
if (!fQuickLookAvailable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ([[QLPreviewPanel sharedPreviewPanel] isOpen])
|
|
|
|
[[QLPreviewPanel sharedPreviewPanel] closeWithEffect: 2];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ([self quickLookSelectItems])
|
|
|
|
{
|
2008-05-21 18:47:48 +00:00
|
|
|
NSWindow * keyWindow = [NSApp keyWindow];
|
|
|
|
|
2008-05-21 15:23:26 +00:00
|
|
|
[[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFrontWithEffect: 2];
|
2008-05-21 18:47:48 +00:00
|
|
|
|
|
|
|
//restore the focus to previous key window
|
|
|
|
[keyWindow makeKeyWindow];
|
2008-05-21 15:23:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateQuickLook
|
|
|
|
{
|
|
|
|
if (!fQuickLookAvailable || ![[QLPreviewPanel sharedPreviewPanel] isOpen])
|
|
|
|
return;
|
|
|
|
|
|
|
|
//if the user changes the selection while the panel is open then update the current items
|
|
|
|
if (![self quickLookSelectItems])
|
|
|
|
[[QLPreviewPanel sharedPreviewPanel] closeWithEffect: 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) pressLeft
|
|
|
|
{
|
|
|
|
if (fQuickLookAvailable && [[QLPreviewPanel sharedPreviewPanel] isOpen])
|
|
|
|
[[QLPreviewPanel sharedPreviewPanel] selectPreviousItem];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) pressRight
|
|
|
|
{
|
|
|
|
if (fQuickLookAvailable && [[QLPreviewPanel sharedPreviewPanel] isOpen])
|
|
|
|
[[QLPreviewPanel sharedPreviewPanel] selectNextItem];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2008-05-21 16:14:44 +00:00
|
|
|
|
|
|
|
@implementation QuickLookController (Private)
|
|
|
|
|
|
|
|
- (id) initWithMainController: (Controller *) controller infoController: (InfoWindowController *) infoController
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
fMainController = controller;
|
|
|
|
fInfoController = infoController;
|
|
|
|
|
|
|
|
//load the QuickLook framework and set the delegate, no point on trying this on Tiger
|
|
|
|
//animation types: 0 = none; 1 = fade; 2 = zoom
|
|
|
|
fQuickLookAvailable = [[NSBundle bundleWithPath: @"/System/Library/PrivateFrameworks/QuickLookUI.framework"] load];
|
|
|
|
if (fQuickLookAvailable)
|
|
|
|
[[[QLPreviewPanel sharedPreviewPanel] windowController] setDelegate: self];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|