From 3bac97b9485d0bfbece16b276a838aac568a28d0 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Wed, 21 May 2008 18:59:18 +0000 Subject: [PATCH] enable/disable the quicklook menu item/toolbar item --- macosx/Controller.h | 1 + macosx/Controller.m | 26 ++++++++++++++++++++++++-- macosx/InfoWindowController.h | 1 + macosx/InfoWindowController.m | 20 ++++++++++++++++++-- macosx/QuickLookController.h | 1 + macosx/QuickLookController.m | 8 ++++++++ 6 files changed, 53 insertions(+), 4 deletions(-) diff --git a/macosx/Controller.h b/macosx/Controller.h index d43586339..6a50e3d87 100644 --- a/macosx/Controller.h +++ b/macosx/Controller.h @@ -256,6 +256,7 @@ typedef enum - (void) showMainWindow: (id) sender; - (NSArray *) quickLookURLs; +- (BOOL) canQuickLook; - (NSRect) quickLookFrameWithURL: (NSURL*) url; - (void) toggleQuickLook: (id) sender; diff --git a/macosx/Controller.m b/macosx/Controller.m index 5c51f81fe..054826c8b 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -3408,6 +3408,10 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy [toolbarItem setImage: ![fFilterBar isHidden] ? [NSImage imageNamed: @"FilterBlue.png"] : [NSImage imageNamed: @"Filter.png"]]; return YES; } + + //enable quicklook item + if ([ident isEqualToString: TOOLBAR_QUICKLOOK]) + return [[QuickLookController quickLook] canQuickLook]; return YES; } @@ -3603,7 +3607,11 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy //enable prev/next filter button if (action == @selector(switchFilter:)) return [fWindow isVisible] && ![fFilterBar isHidden]; - + + //enable quicklook item + if (action == @selector(toggleQuickLook:)) + return [[QuickLookController quickLook] canQuickLook]; + //enable reveal in finder if (action == @selector(revealFile:)) return canUseTable && [fTableView numberOfSelectedRows] > 0; @@ -4041,7 +4049,6 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy { NSArray * selectedTorrents = [fTableView selectedTorrents]; NSMutableArray * urlArray = [NSMutableArray arrayWithCapacity: [selectedTorrents count]]; - NSEnumerator * enumerator = [selectedTorrents objectEnumerator]; Torrent * torrent; @@ -4054,6 +4061,21 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy return urlArray; } +- (BOOL) canQuickLook +{ + NSArray * selectedTorrents = [fTableView selectedTorrents]; + NSEnumerator * enumerator = [selectedTorrents objectEnumerator]; + Torrent * torrent; + + while ((torrent = [enumerator nextObject])) + { + if ([torrent folder] || [torrent isComplete]) + return YES; + } + + return NO; +} + - (NSRect) quickLookFrameWithURL: (NSURL *) url { if ([fWindow isVisible]) diff --git a/macosx/InfoWindowController.h b/macosx/InfoWindowController.h index f2ed63fbf..b0781ddaf 100644 --- a/macosx/InfoWindowController.h +++ b/macosx/InfoWindowController.h @@ -80,6 +80,7 @@ - (BOOL) shouldQuickLookFileView; - (NSArray *) quickLookURLs; +- (BOOL) canQuickLook; - (NSRect) quickLookFrameWithURL: (NSURL*) url; - (void) setPiecesView: (id) sender; diff --git a/macosx/InfoWindowController.m b/macosx/InfoWindowController.m index d7cd9d5d8..148095822 100644 --- a/macosx/InfoWindowController.m +++ b/macosx/InfoWindowController.m @@ -907,14 +907,30 @@ typedef enum for (i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i]) { NSDictionary * item = [fileOutlineView itemAtRow: i]; - if ([[item objectForKey: @"IsFolder"] boolValue] - || [torrent fileProgress: [[item objectForKey: @"Indexes"] firstIndex]] == 1.0) + if ([[item objectForKey: @"IsFolder"] boolValue] || [torrent fileProgress: [[item objectForKey: @"Indexes"] firstIndex]] == 1.0) [urlArray addObject: [NSURL fileURLWithPath: [folder stringByAppendingPathComponent: [item objectForKey: @"Path"]]]]; } return urlArray; } +- (BOOL) canQuickLook +{ + FileOutlineView * fileOutlineView = [fFileController outlineView]; + Torrent * torrent = [fTorrents objectAtIndex: 0]; + NSIndexSet * indexes = [fileOutlineView selectedRowIndexes]; + + int i; + for (i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i]) + { + NSDictionary * item = [fileOutlineView itemAtRow: i]; + if ([[item objectForKey: @"IsFolder"] boolValue] || [torrent fileProgress: [[item objectForKey: @"Indexes"] firstIndex]] == 1.0) + return YES; + } + + return NO; +} + - (NSRect) quickLookFrameWithURL: (NSURL *) url { FileOutlineView * fileOutlineView = [fFileController outlineView]; diff --git a/macosx/QuickLookController.h b/macosx/QuickLookController.h index ae3091dea..a1ed8fbed 100644 --- a/macosx/QuickLookController.h +++ b/macosx/QuickLookController.h @@ -42,6 +42,7 @@ + (QuickLookController *) quickLook; - (BOOL) quickLookSelectItems; +- (BOOL) canQuickLook; - (void) toggleQuickLook; - (void) updateQuickLook; diff --git a/macosx/QuickLookController.m b/macosx/QuickLookController.m index 58645b391..96e738e06 100644 --- a/macosx/QuickLookController.m +++ b/macosx/QuickLookController.m @@ -81,6 +81,14 @@ QuickLookController * fQuickLookInstance = nil; return NO; } +- (BOOL) canQuickLook +{ + if ([fInfoController shouldQuickLookFileView]) + return [fInfoController canQuickLook]; + else + return [fMainController canQuickLook]; +} + - (void) toggleQuickLook { if (!fQuickLookAvailable) -- 2.40.0