Ignore:
Timestamp:
May 20, 2008, 7:34:33 PM (14 years ago)
Author:
livings124
Message:

#958 QuickLook? from within the Inspector - thanks Waldorf!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/FileOutlineController.m

    r5383 r5862  
    2929#import "NSApplicationAdditions.h"
    3030
     31#import "QuickLook.h"
     32#define QLPreviewPanel NSClassFromString(@"QLPreviewPanel")
     33
    3134#define ROW_SMALL_HEIGHT 18.0
    3235
     
    6366                                                                            "file table -> header tool tip")];
    6467        [[fOutline tableColumnWithIdentifier: @"Priority"] setHeaderToolTip: NSLocalizedString(@"Priority",
    65                                                                             "file table -> header tool tip")];                                                               
     68                                                                            "file table -> header tool tip")];
     69       
     70        //load the QuickLook framework and set the delegate, no point on trying this on Tiger
     71        //animation types: 0 = none; 1 = fade; 2 = zoom
     72        fQuickLookAvailable = [[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/QuickLookUI.framework"] load];
     73        if (fQuickLookAvailable)
     74                [[[QLPreviewPanel sharedPreviewPanel] windowController] setDelegate: self];
    6675    }
    6776   
     
    6978   
    7079    [self setTorrent: nil];
     80}
     81
     82- (void) fileTabClosed
     83{
     84    if (fQuickLookAvailable)
     85    {
     86        if ([[QLPreviewPanel sharedPreviewPanel] isOpen])
     87            [[QLPreviewPanel sharedPreviewPanel] closeWithEffect: 1];
     88    }
     89}
     90
     91// This is the QuickLook delegate method
     92// It should return the frame for the item represented by the URL
     93// If an empty frame is returned then the panel will fade in/out instead
     94- (NSRect) previewPanel: (NSPanel *) panel frameForURL: (NSURL *) url
     95{
     96    NSRect frame = NSMakeRect(0, 0, 0, 0);
     97    int row = [self visibleRowWithURL: url];
     98   
     99    if (row != -1)
     100    {
     101        frame = [fOutline rectOfRow:row];
     102        frame.origin = [fOutline convertPoint: frame.origin toView: nil];
     103        frame.origin = [[fOutline window] convertBaseToScreen: frame.origin];
     104        frame.origin.y -= frame.size.height;
     105    }
     106   
     107    return frame;
     108}
     109
     110- (int) visibleRowWithURL: (NSURL *) url
     111{
     112    NSString * fullPath = [url path];
     113    NSString * folder = [fTorrent downloadFolder];
     114    NSRange visibleRows = [fOutline rowsInRect: [fOutline bounds]];
     115   
     116    int row;
     117    for (row = visibleRows.location; row <= row + visibleRows.length; row++)
     118    {
     119        id rowItem = [fOutline itemAtRow: row];
     120        if ([[folder stringByAppendingPathComponent: [rowItem objectForKey: @"Path"]] isEqualToString: fullPath])
     121            return row;
     122    }
     123    return -1;
     124}
     125
     126- (void) userDidPressSpaceInOutlineView: (id) outlineView
     127{
     128    if (fQuickLookAvailable)
     129    {
     130        if ([[QLPreviewPanel sharedPreviewPanel] isOpen])
     131            [[QLPreviewPanel sharedPreviewPanel] closeWithEffect: 2];
     132        else
     133        {
     134            if ([self quickLookSelectedItems])
     135            {
     136                [[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFrontWithEffect: 2];
     137                // Restore the focus to our window to demo the selection changing, scrolling (left/right)
     138                // and closing (space) functionality
     139                [[fOutline window] makeKeyWindow];
     140            }
     141        }
     142    }
     143}
     144
     145- (void) userDidPressRightInOutlineView: (id) outlineView
     146{
     147    if (fQuickLookAvailable && [[QLPreviewPanel sharedPreviewPanel] isOpen])
     148        [[QLPreviewPanel sharedPreviewPanel] selectNextItem];
     149}
     150
     151- (void) userDidPressLeftInOutlineView: (id) outlineView
     152{
     153    if (fQuickLookAvailable && [[QLPreviewPanel sharedPreviewPanel] isOpen])
     154        [[QLPreviewPanel sharedPreviewPanel] selectPreviousItem];
     155}
     156
     157- (BOOL) quickLookSelectedItems
     158{
     159    if (fQuickLookAvailable)
     160    {
     161        NSString * folder = [fTorrent downloadFolder];
     162        NSIndexSet * indexes = [fOutline selectedRowIndexes];
     163        NSMutableArray * urlArray = [NSMutableArray arrayWithCapacity: [indexes count]];
     164
     165        int i;
     166        for (i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
     167        {
     168            id item = [fOutline itemAtRow: i];
     169            if ([[item objectForKey: @"IsFolder"] boolValue]
     170                || [fTorrent fileProgress: [[item objectForKey: @"Indexes"] firstIndex]] == 1.0)
     171                [urlArray addObject: [NSURL fileURLWithPath: [folder stringByAppendingPathComponent: [item objectForKey: @"Path"]]]];
     172        }
     173       
     174        if ([urlArray count])
     175        {
     176            [[QLPreviewPanel sharedPreviewPanel] setURLs: urlArray currentIndex: 0 preservingDisplayState: YES];
     177            return YES;
     178        }
     179        else
     180            return NO;
     181    }
     182}
     183
     184- (void) outlineViewSelectionDidChange: (NSNotification *) notification
     185{
     186    if (fQuickLookAvailable)
     187    {
     188        // If the user changes the selection while the panel is open then update the current items
     189        if ([[QLPreviewPanel sharedPreviewPanel] isOpen] && ![self quickLookSelectedItems])
     190            [[QLPreviewPanel sharedPreviewPanel] closeWithEffect: 1];
     191    }
    71192}
    72193
Note: See TracChangeset for help on using the changeset viewer.