Changeset 5862


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

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

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Transmission.xcodeproj/project.pbxproj

    r5858 r5862  
    214214                A2DA362C0CBC674900C2ED41 /* InfoPeers.png in Resources */ = {isa = PBXBuildFile; fileRef = A2DA36290CBC674900C2ED41 /* InfoPeers.png */; };
    215215                A2DF37070C220D03006523C1 /* CreatorWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = A2DF37050C220D03006523C1 /* CreatorWindowController.m */; };
     216                A2DF567D0DE323D3000795D5 /* QuickLook.h in Headers */ = {isa = PBXBuildFile; fileRef = A2DF567C0DE323D3000795D5 /* QuickLook.h */; };
    216217                A2E23AC60CB5E1930002BB25 /* InfoTabButtonCell.m in Sources */ = {isa = PBXBuildFile; fileRef = A2E23AC40CB5E1930002BB25 /* InfoTabButtonCell.m */; };
    217218                A2E9AA760C249AF400085DCF /* Create.png in Resources */ = {isa = PBXBuildFile; fileRef = A2E9AA750C249AF400085DCF /* Create.png */; };
     
    681682                A2DF37040C220D03006523C1 /* CreatorWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CreatorWindowController.h; path = macosx/CreatorWindowController.h; sourceTree = "<group>"; };
    682683                A2DF37050C220D03006523C1 /* CreatorWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CreatorWindowController.m; path = macosx/CreatorWindowController.m; sourceTree = "<group>"; };
     684                A2DF567C0DE323D3000795D5 /* QuickLook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QuickLook.h; path = macosx/QuickLook.h; sourceTree = "<group>"; };
    683685                A2E23AC30CB5E1930002BB25 /* InfoTabButtonCell.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = InfoTabButtonCell.h; path = macosx/InfoTabButtonCell.h; sourceTree = "<group>"; };
    684686                A2E23AC40CB5E1930002BB25 /* InfoTabButtonCell.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = InfoTabButtonCell.m; path = macosx/InfoTabButtonCell.m; sourceTree = "<group>"; };
     
    950952                                A2D307A20D9EC6870051FD27 /* BlocklistDownloader.h */,
    951953                                A2D307A30D9EC6870051FD27 /* BlocklistDownloader.m */,
     954                                A2DF567C0DE323D3000795D5 /* QuickLook.h */,
    952955                        );
    953956                        name = Sources;
     
    14791482                                A2A4EA000DE1065C000CE197 /* config.h in Headers */,
    14801483                                A2A4EA010DE1065D000CE197 /* compat_unix.h in Headers */,
     1484                                A2DF567D0DE323D3000795D5 /* QuickLook.h in Headers */,
    14811485                        );
    14821486                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/macosx/FileOutlineController.h

    r4639 r5862  
    3333   
    3434    IBOutlet FileOutlineView * fOutline;
     35       
     36        BOOL fQuickLookAvailable;
    3537}
    3638
     
    4547- (void) revealFile: (id) sender;
    4648
     49- (void) userDidPressSpaceInOutlineView: (id) outlineView;
     50- (void) userDidPressRightInOutlineView: (id) outlineView;
     51- (void) userDidPressLeftInOutlineView: (id) outlineView;
     52
     53- (BOOL) quickLookSelectedItems;
     54- (int) visibleRowWithURL: (NSURL*) url;
     55
     56- (void) fileTabClosed;
     57
    4758@end
  • 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
  • trunk/macosx/FileOutlineView.m

    r5383 r5862  
    2424
    2525#import "FileOutlineView.h"
     26#import "FileOutlineController.h"
    2627#import "FileNameCell.h"
    2728#import "FilePriorityCell.h"
     
    8283    [[self window] makeKeyWindow];
    8384    [super mouseDown: event];
     85}
     86
     87- (void) keyDown: (NSEvent *) event
     88{
     89    unichar firstChar = [[event charactersIgnoringModifiers] characterAtIndex: 0];
     90    if (firstChar == ' ')
     91        [(FileOutlineController *)[super delegate] userDidPressSpaceInOutlineView: self];
     92    else if (firstChar == NSRightArrowFunctionKey)
     93        [(FileOutlineController *)[super delegate] userDidPressRightInOutlineView: self];
     94    else if (firstChar == NSLeftArrowFunctionKey)
     95        [(FileOutlineController *)[super delegate] userDidPressLeftInOutlineView: self];
     96    else;
     97   
     98    [super keyDown: event]; 
    8499}
    85100
  • trunk/macosx/InfoWindowController.m

    r5751 r5862  
    591591}
    592592
     593- (void) windowWillClose: (NSNotification *) notification
     594{
     595    [fFileController fileTabClosed];
     596}
     597
    593598- (void) setTab: (id) sender
    594599{
     
    620625                break;
    621626            case TAB_FILES_TAG:
     627                [fFileController fileTabClosed];
     628               
    622629                oldResizeSaveKey = @"InspectorContentHeightFiles";
    623630                break;
Note: See TracChangeset for help on using the changeset viewer.