Changeset 12570


Ignore:
Timestamp:
Jul 21, 2011, 2:35:03 AM (10 years ago)
Author:
livings124
Message:

#4376 Lion: Use popovers for per-torrent gear button

Location:
trunk/macosx
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/NSApplicationAdditions.h

    r11617 r12570  
    2525#define QLPreviewPanelSL NSClassFromString(@"QLPreviewPanel")
    2626#define NSRunningApplicationSL NSClassFromString(@"NSRunningApplication")
     27#define NSPopoverLion NSClassFromString(@"NSPopover")
    2728
    2829@interface NSApplication (NSApplicationAdditions)
    2930
    3031- (BOOL) isOnSnowLeopardOrBetter;
     32- (BOOL) isOnLionOrBetter;
    3133
    3234@end
  • trunk/macosx/NSApplicationAdditions.m

    r11617 r12570  
    3232}
    3333
     34- (BOOL) isOnLionOrBetter
     35{
     36        return floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
     37}
     38
    3439@end
  • trunk/macosx/TorrentTableView.h

    r12472 r12570  
    7676- (void) toggleControlForTorrent: (Torrent *) torrent;
    7777
    78 - (void) displayTorrentMenuForEvent: (NSEvent *) event;
     78- (void) displayTorrentActionPopoverForEvent: (NSEvent *) event;
    7979
    8080- (void) setQuickLimitMode: (id) sender;
  • trunk/macosx/TorrentTableView.m

    r12496 r12570  
    2626#import "Controller.h"
    2727#import "FileListNode.h"
     28#import "InfoOptionsViewController.h"
    2829#import "NSApplicationAdditions.h"
    2930#import "NSStringAdditions.h"
     
    152153    if ([item isKindOfClass: [Torrent class]])
    153154    {
    154         [cell setRepresentedObject: item];
    155        
    156         const NSInteger row = [self rowForItem: item];
    157         [cell setHover: row == fMouseRow];
    158         [cell setControlHover: row == fMouseControlRow];
    159         [cell setRevealHover: row == fMouseRevealRow];
    160         [cell setActionHover: row == fMouseActionRow];
    161         [cell setActionPushed: row == fActionPushedRow];
     155        if (!tableColumn)
     156        {
     157            [cell setRepresentedObject: item];
     158           
     159            const NSInteger row = [self rowForItem: item];
     160            [cell setHover: row == fMouseRow];
     161            [cell setControlHover: row == fMouseControlRow];
     162            [cell setRevealHover: row == fMouseRevealRow];
     163            [cell setActionHover: row == fMouseActionRow];
     164            [cell setActionPushed: row == fActionPushedRow];
     165        }
    162166    }
    163167    else
     
    404408        [self setNeedsDisplayInRect: [self rectOfRow: row]]; //ensure button is pushed down
    405409       
    406         [self displayTorrentMenuForEvent: event];
     410        #warning maybe make appear on mouse down
     411        [self displayTorrentActionPopoverForEvent: event];
    407412       
    408413        fActionPushedRow = -1;
     
    565570}
    566571
    567 - (void) displayTorrentMenuForEvent: (NSEvent *) event
     572- (void) displayTorrentActionPopoverForEvent: (NSEvent *) event
    568573{
    569574    const NSInteger row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
     
    571576        return;
    572577   
    573     //update file action menu
    574     fMenuTorrent = [[self itemAtRow: row] retain];
    575    
    576     //update global limit check
    577     [fGlobalLimitItem setState: [fMenuTorrent usesGlobalSpeedLimit] ? NSOnState : NSOffState];
    578    
    579     //place menu below button
    580     NSRect rect = [fTorrentCell iconRectForBounds: [self rectOfRow: row]];
    581     NSPoint location = rect.origin;
    582     location.y += rect.size.height + 5.0;
    583    
    584     if ([NSApp isOnSnowLeopardOrBetter])
    585     {
    586         location = [self convertPoint: location toView: self];
    587         [fActionMenu popUpMenuPositioningItem: nil atLocation: location inView: self];
     578    const NSRect rect = [fTorrentCell iconRectForBounds: [self rectOfRow: row]];
     579   
     580    if ([NSApp isOnLionOrBetter])
     581    {
     582        Torrent * torrent = [self itemAtRow: row];
     583       
     584        NSPopover * popover = [[NSPopoverLion alloc] init];
     585        [popover setBehavior: NSPopoverBehaviorTransient];
     586        InfoOptionsViewController * infoViewController = [[InfoOptionsViewController alloc] init];
     587        [popover setContentViewController: infoViewController];
     588       
     589        [popover showRelativeToRect: rect ofView: self preferredEdge: NSMaxYEdge];
     590        [infoViewController setInfoForTorrents: [NSArray arrayWithObject: torrent]];
     591        [infoViewController updateInfo];
     592       
     593        [infoViewController release];
     594        [popover release];
    588595    }
    589596    else
    590597    {
    591         location = [self convertPoint: location toView: nil];
    592         NSEvent * newEvent = [NSEvent mouseEventWithType: [event type] location: location
    593             modifierFlags: [event modifierFlags] timestamp: [event timestamp] windowNumber: [event windowNumber]
    594             context: [event context] eventNumber: [event eventNumber] clickCount: [event clickCount] pressure: [event pressure]];
    595        
    596         [NSMenu popUpContextMenu: fActionMenu withEvent: newEvent forView: self];
    597     }
    598    
    599     [fMenuTorrent release];
    600     fMenuTorrent = nil;
     598        //update file action menu
     599        fMenuTorrent = [[self itemAtRow: row] retain];
     600       
     601        //update global limit check
     602        [fGlobalLimitItem setState: [fMenuTorrent usesGlobalSpeedLimit] ? NSOnState : NSOffState];
     603       
     604        //place menu below button
     605        NSPoint location = rect.origin;
     606        location.y += NSHeight(rect) + 5.0;
     607       
     608        if ([NSApp isOnSnowLeopardOrBetter])
     609        {
     610            location = [self convertPoint: location toView: self];
     611            [fActionMenu popUpMenuPositioningItem: nil atLocation: location inView: self];
     612        }
     613        else
     614        {
     615            location = [self convertPoint: location toView: nil];
     616            NSEvent * newEvent = [NSEvent mouseEventWithType: [event type] location: location
     617                modifierFlags: [event modifierFlags] timestamp: [event timestamp] windowNumber: [event windowNumber]
     618                context: [event context] eventNumber: [event eventNumber] clickCount: [event clickCount] pressure: [event pressure]];
     619           
     620            [NSMenu popUpContextMenu: fActionMenu withEvent: newEvent forView: self];
     621        }
     622       
     623        [fMenuTorrent release];
     624        fMenuTorrent = nil;
     625    }
    601626}
    602627
Note: See TracChangeset for help on using the changeset viewer.