2008-01-04 00:29:13 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (c) 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 "FileOutlineController.h"
|
|
|
|
#import "Torrent.h"
|
|
|
|
#import "FileOutlineView.h"
|
2008-03-25 03:17:35 +00:00
|
|
|
#import "FilePriorityCell.h"
|
2008-05-22 18:39:49 +00:00
|
|
|
#import "FileListNode.h"
|
2008-05-21 15:23:26 +00:00
|
|
|
#import "QuickLookController.h"
|
2008-01-04 00:29:13 +00:00
|
|
|
|
2008-11-01 14:26:51 +00:00
|
|
|
#define ROW_SMALL_HEIGHT 18.0f
|
2008-01-04 00:29:13 +00:00
|
|
|
|
2008-01-06 05:13:38 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
FILE_CHECK_TAG,
|
|
|
|
FILE_UNCHECK_TAG
|
|
|
|
} fileCheckMenuTag;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
FILE_PRIORITY_HIGH_TAG,
|
|
|
|
FILE_PRIORITY_NORMAL_TAG,
|
|
|
|
FILE_PRIORITY_LOW_TAG
|
|
|
|
} filePriorityMenuTag;
|
|
|
|
|
|
|
|
@interface FileOutlineController (Private)
|
|
|
|
|
|
|
|
- (NSMenu *) menu;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
@implementation FileOutlineController
|
|
|
|
|
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
|
|
|
[fOutline setDoubleAction: @selector(revealFile:)];
|
2008-01-17 02:54:01 +00:00
|
|
|
[fOutline setTarget: self];
|
2008-01-04 00:29:13 +00:00
|
|
|
|
|
|
|
//set table header tool tips
|
2008-12-26 05:57:51 +00:00
|
|
|
[[fOutline tableColumnWithIdentifier: @"Check"] setHeaderToolTip: NSLocalizedString(@"Download",
|
|
|
|
"file table -> header tool tip")];
|
|
|
|
[[fOutline tableColumnWithIdentifier: @"Priority"] setHeaderToolTip: NSLocalizedString(@"Priority",
|
|
|
|
"file table -> header tool tip")];
|
2008-01-04 00:29:13 +00:00
|
|
|
|
2008-01-06 05:13:38 +00:00
|
|
|
[fOutline setMenu: [self menu]];
|
2008-01-04 00:29:13 +00:00
|
|
|
|
|
|
|
[self setTorrent: nil];
|
|
|
|
}
|
|
|
|
|
2008-12-07 18:20:14 +00:00
|
|
|
- (void) dealloc
|
2008-05-20 19:34:33 +00:00
|
|
|
{
|
2008-12-07 18:20:14 +00:00
|
|
|
[fFileList release];
|
|
|
|
[fFilterText release];
|
|
|
|
[super dealloc];
|
2008-05-20 19:34:33 +00:00
|
|
|
}
|
|
|
|
|
2008-12-07 18:20:14 +00:00
|
|
|
- (FileOutlineView *) outlineView
|
2008-05-20 19:34:33 +00:00
|
|
|
{
|
2008-12-07 18:20:14 +00:00
|
|
|
return fOutline;
|
2008-05-20 19:34:33 +00:00
|
|
|
}
|
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
- (void) setTorrent: (Torrent *) torrent
|
|
|
|
{
|
|
|
|
fTorrent = torrent;
|
|
|
|
[fOutline setTorrent: fTorrent];
|
|
|
|
|
2008-12-07 18:20:14 +00:00
|
|
|
[fFileList release];
|
|
|
|
fFileList = [[fTorrent fileList] retain];
|
|
|
|
|
|
|
|
[fFilterText release];
|
|
|
|
fFilterText = nil;
|
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
[fOutline deselectAll: nil];
|
|
|
|
[fOutline reloadData];
|
|
|
|
}
|
|
|
|
|
2008-12-07 18:20:14 +00:00
|
|
|
- (void) setFilterText: (NSString *) text
|
|
|
|
{
|
|
|
|
if ([text isEqualToString: @""])
|
|
|
|
text = nil;
|
|
|
|
|
2008-12-07 19:44:47 +00:00
|
|
|
if ((!text && !fFilterText) || (text && fFilterText && [text isEqualToString: fFilterText]))
|
2008-12-07 18:20:14 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
[fFilterText release];
|
|
|
|
fFilterText = [text retain];
|
|
|
|
|
|
|
|
[fFileList release];
|
|
|
|
if (!fFilterText)
|
|
|
|
fFileList = [[fTorrent fileList] retain];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSMutableArray * list = [NSMutableArray arrayWithCapacity: [fTorrent fileCount]];
|
|
|
|
|
2008-12-26 07:25:17 +00:00
|
|
|
for (FileListNode * node in [fTorrent flatFileList])
|
2008-12-07 21:43:29 +00:00
|
|
|
if ([[node name] rangeOfString: fFilterText options: NSCaseInsensitiveSearch].location != NSNotFound)
|
|
|
|
[list addObject: node];
|
2008-12-07 18:20:14 +00:00
|
|
|
|
|
|
|
fFileList = [[NSArray alloc] initWithArray: list];
|
|
|
|
}
|
|
|
|
|
|
|
|
[fOutline reloadData];
|
|
|
|
}
|
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
- (void) reloadData
|
|
|
|
{
|
2008-01-09 21:08:43 +00:00
|
|
|
[fTorrent updateFileStat];
|
2008-01-04 00:29:13 +00:00
|
|
|
[fOutline reloadData];
|
|
|
|
}
|
|
|
|
|
2008-12-07 18:20:14 +00:00
|
|
|
- (void) outlineViewSelectionDidChange: (NSNotification *) notification
|
|
|
|
{
|
|
|
|
[[QuickLookController quickLook] updateQuickLook];
|
|
|
|
}
|
|
|
|
|
2008-11-01 14:26:51 +00:00
|
|
|
- (NSInteger) outlineView: (NSOutlineView *) outlineView numberOfChildrenOfItem: (id) item
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
|
|
|
if (!item)
|
2008-12-07 18:20:14 +00:00
|
|
|
return fFileList ? [fFileList count] : 0;
|
2008-01-04 04:45:31 +00:00
|
|
|
else
|
2008-05-22 18:39:49 +00:00
|
|
|
{
|
|
|
|
FileListNode * node = (FileListNode *)item;
|
|
|
|
return [node isFolder] ? [[node children] count] : 0;
|
|
|
|
}
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) outlineView: (NSOutlineView *) outlineView isItemExpandable: (id) item
|
|
|
|
{
|
2008-05-22 18:39:49 +00:00
|
|
|
return [(FileListNode *)item isFolder];
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2008-11-01 14:26:51 +00:00
|
|
|
- (id) outlineView: (NSOutlineView *) outlineView child: (NSInteger) index ofItem: (id) item
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2008-12-07 18:20:14 +00:00
|
|
|
return [(item ? [(FileListNode *)item children] : fFileList) objectAtIndex: index];
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) outlineView: (NSOutlineView *) outlineView objectValueForTableColumn: (NSTableColumn *) tableColumn byItem: (id) item
|
|
|
|
{
|
|
|
|
if ([[tableColumn identifier] isEqualToString: @"Check"])
|
2008-05-22 18:39:49 +00:00
|
|
|
return [NSNumber numberWithInt: [fTorrent checkForFiles: [(FileListNode *)item indexes]]];
|
2008-01-04 00:29:13 +00:00
|
|
|
else
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) outlineView: (NSOutlineView *) outlineView willDisplayCell: (id) cell
|
|
|
|
forTableColumn: (NSTableColumn *) tableColumn item: (id) item
|
|
|
|
{
|
|
|
|
NSString * identifier = [tableColumn identifier];
|
|
|
|
if ([identifier isEqualToString: @"Check"])
|
2008-05-22 18:39:49 +00:00
|
|
|
[cell setEnabled: [fTorrent canChangeDownloadCheckForFiles: [(FileListNode *)item indexes]]];
|
2008-01-04 00:29:13 +00:00
|
|
|
else if ([identifier isEqualToString: @"Priority"])
|
2008-03-25 03:17:35 +00:00
|
|
|
{
|
2008-01-04 00:29:13 +00:00
|
|
|
[cell setRepresentedObject: item];
|
2008-03-25 14:10:05 +00:00
|
|
|
|
2008-11-01 14:26:51 +00:00
|
|
|
NSInteger hoveredRow = [fOutline hoveredRow];
|
2008-03-25 14:10:05 +00:00
|
|
|
[(FilePriorityCell *)cell setHovered: hoveredRow != -1 && hoveredRow == [fOutline rowForItem: item]];
|
2008-03-25 03:17:35 +00:00
|
|
|
}
|
2008-01-04 00:29:13 +00:00
|
|
|
else;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) outlineView: (NSOutlineView *) outlineView setObjectValue: (id) object
|
|
|
|
forTableColumn: (NSTableColumn *) tableColumn byItem: (id) item
|
|
|
|
{
|
|
|
|
NSString * identifier = [tableColumn identifier];
|
|
|
|
if ([identifier isEqualToString: @"Check"])
|
|
|
|
{
|
|
|
|
NSIndexSet * indexSet;
|
|
|
|
if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
|
|
|
|
indexSet = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fTorrent fileCount])];
|
|
|
|
else
|
2008-05-22 18:39:49 +00:00
|
|
|
indexSet = [(FileListNode *)item indexes];
|
2008-01-04 00:29:13 +00:00
|
|
|
|
|
|
|
[fTorrent setFileCheckState: [object intValue] != NSOffState ? NSOnState : NSOffState forIndexes: indexSet];
|
|
|
|
[fOutline reloadData];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) outlineView: (NSOutlineView *) outlineView typeSelectStringForTableColumn: (NSTableColumn *) tableColumn item: (id) item
|
|
|
|
{
|
2008-05-22 18:39:49 +00:00
|
|
|
return [(FileListNode *)item name];
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) outlineView: (NSOutlineView *) outlineView toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect
|
|
|
|
tableColumn: (NSTableColumn *) tableColumn item: (id) item mouseLocation: (NSPoint) mouseLocation
|
|
|
|
{
|
|
|
|
NSString * ident = [tableColumn identifier];
|
|
|
|
if ([ident isEqualToString: @"Name"])
|
2008-05-22 18:39:49 +00:00
|
|
|
return [[fTorrent downloadFolder] stringByAppendingPathComponent: [(FileListNode *)item fullPath]];
|
2008-01-04 00:29:13 +00:00
|
|
|
else if ([ident isEqualToString: @"Check"])
|
|
|
|
{
|
|
|
|
switch ([cell state])
|
|
|
|
{
|
|
|
|
case NSOffState:
|
|
|
|
return NSLocalizedString(@"Don't Download", "files tab -> tooltip");
|
|
|
|
case NSOnState:
|
|
|
|
return NSLocalizedString(@"Download", "files tab -> tooltip");
|
|
|
|
case NSMixedState:
|
|
|
|
return NSLocalizedString(@"Download Some", "files tab -> tooltip");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ([ident isEqualToString: @"Priority"])
|
|
|
|
{
|
2008-05-22 18:39:49 +00:00
|
|
|
NSSet * priorities = [fTorrent filePrioritiesForIndexes: [(FileListNode *)item indexes]];
|
2008-01-04 00:29:13 +00:00
|
|
|
switch ([priorities count])
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return NSLocalizedString(@"Priority Not Available", "files tab -> tooltip");
|
|
|
|
case 1:
|
|
|
|
switch ([[priorities anyObject] intValue])
|
|
|
|
{
|
|
|
|
case TR_PRI_LOW:
|
|
|
|
return NSLocalizedString(@"Low Priority", "files tab -> tooltip");
|
|
|
|
case TR_PRI_HIGH:
|
|
|
|
return NSLocalizedString(@"High Priority", "files tab -> tooltip");
|
|
|
|
case TR_PRI_NORMAL:
|
|
|
|
return NSLocalizedString(@"Normal Priority", "files tab -> tooltip");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NSLocalizedString(@"Multiple Priorities", "files tab -> tooltip");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else;
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2008-11-01 14:26:51 +00:00
|
|
|
- (CGFloat) outlineView: (NSOutlineView *) outlineView heightOfRowByItem: (id) item
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2008-05-22 18:39:49 +00:00
|
|
|
if ([(FileListNode *)item isFolder])
|
2008-01-04 00:29:13 +00:00
|
|
|
return ROW_SMALL_HEIGHT;
|
|
|
|
else
|
|
|
|
return [outlineView rowHeight];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setCheck: (id) sender
|
|
|
|
{
|
2008-11-01 14:26:51 +00:00
|
|
|
NSInteger state = [sender tag] == FILE_UNCHECK_TAG ? NSOffState : NSOnState;
|
2008-01-04 00:29:13 +00:00
|
|
|
|
|
|
|
NSIndexSet * indexSet = [fOutline selectedRowIndexes];
|
|
|
|
NSMutableIndexSet * itemIndexes = [NSMutableIndexSet indexSet];
|
2008-10-12 21:38:13 +00:00
|
|
|
for (NSInteger i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
|
2008-05-22 18:39:49 +00:00
|
|
|
[itemIndexes addIndexes: [[fOutline itemAtRow: i] indexes]];
|
2008-01-04 00:29:13 +00:00
|
|
|
|
|
|
|
[fTorrent setFileCheckState: state forIndexes: itemIndexes];
|
|
|
|
[fOutline reloadData];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setOnlySelectedCheck: (id) sender
|
|
|
|
{
|
|
|
|
NSIndexSet * indexSet = [fOutline selectedRowIndexes];
|
|
|
|
NSMutableIndexSet * itemIndexes = [NSMutableIndexSet indexSet];
|
2008-10-12 21:38:13 +00:00
|
|
|
for (NSInteger i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
|
2008-05-22 18:39:49 +00:00
|
|
|
[itemIndexes addIndexes: [[fOutline itemAtRow: i] indexes]];
|
2008-01-04 00:29:13 +00:00
|
|
|
|
|
|
|
[fTorrent setFileCheckState: NSOnState forIndexes: itemIndexes];
|
|
|
|
|
|
|
|
NSMutableIndexSet * remainingItemIndexes = [NSMutableIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fTorrent fileCount])];
|
|
|
|
[remainingItemIndexes removeIndexes: itemIndexes];
|
|
|
|
[fTorrent setFileCheckState: NSOffState forIndexes: remainingItemIndexes];
|
|
|
|
|
|
|
|
[fOutline reloadData];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPriority: (id) sender
|
|
|
|
{
|
2008-11-01 14:26:51 +00:00
|
|
|
NSInteger priority;
|
2008-01-06 05:13:38 +00:00
|
|
|
switch ([sender tag])
|
|
|
|
{
|
|
|
|
case FILE_PRIORITY_HIGH_TAG:
|
|
|
|
priority = TR_PRI_HIGH;
|
|
|
|
break;
|
|
|
|
case FILE_PRIORITY_NORMAL_TAG:
|
|
|
|
priority = TR_PRI_NORMAL;
|
|
|
|
break;
|
|
|
|
case FILE_PRIORITY_LOW_TAG:
|
|
|
|
priority = TR_PRI_LOW;
|
|
|
|
}
|
2008-01-04 00:29:13 +00:00
|
|
|
|
|
|
|
NSIndexSet * indexSet = [fOutline selectedRowIndexes];
|
|
|
|
NSMutableIndexSet * itemIndexes = [NSMutableIndexSet indexSet];
|
2008-10-12 21:38:13 +00:00
|
|
|
for (NSInteger i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
|
2008-05-22 18:39:49 +00:00
|
|
|
[itemIndexes addIndexes: [[fOutline itemAtRow: i] indexes]];
|
2008-01-04 00:29:13 +00:00
|
|
|
|
|
|
|
[fTorrent setFilePriority: priority forIndexes: itemIndexes];
|
|
|
|
[fOutline reloadData];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) revealFile: (id) sender
|
|
|
|
{
|
|
|
|
NSString * folder = [fTorrent downloadFolder];
|
|
|
|
NSIndexSet * indexes = [fOutline selectedRowIndexes];
|
2008-10-12 21:38:13 +00:00
|
|
|
for (NSInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
|
2008-01-04 00:29:13 +00:00
|
|
|
[[NSWorkspace sharedWorkspace] selectFile: [folder stringByAppendingPathComponent:
|
2008-05-22 18:39:49 +00:00
|
|
|
[[fOutline itemAtRow: i] fullPath]] inFileViewerRootedAtPath: nil];
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2008-01-17 04:20:52 +00:00
|
|
|
#warning make real view controller (Leopard-only) so that Command-R will work
|
2008-01-04 00:29:13 +00:00
|
|
|
- (BOOL) validateMenuItem: (NSMenuItem *) menuItem
|
|
|
|
{
|
|
|
|
if (!fTorrent)
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
SEL action = [menuItem action];
|
|
|
|
|
|
|
|
if (action == @selector(revealFile:))
|
|
|
|
{
|
|
|
|
NSString * downloadFolder = [fTorrent downloadFolder];
|
|
|
|
NSIndexSet * indexSet = [fOutline selectedRowIndexes];
|
2008-10-12 21:38:13 +00:00
|
|
|
for (NSInteger i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
|
2008-01-04 00:29:13 +00:00
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath:
|
2008-12-07 18:20:14 +00:00
|
|
|
[downloadFolder stringByAppendingPathComponent: [[fFileList objectAtIndex: i] fullPath]]])
|
2008-01-04 00:29:13 +00:00
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action == @selector(setCheck:))
|
|
|
|
{
|
|
|
|
if ([fOutline numberOfSelectedRows] <= 0)
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
NSIndexSet * indexSet = [fOutline selectedRowIndexes];
|
|
|
|
NSMutableIndexSet * itemIndexes = [NSMutableIndexSet indexSet];
|
2008-10-12 21:38:13 +00:00
|
|
|
for (NSInteger i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
|
2008-05-22 18:39:49 +00:00
|
|
|
[itemIndexes addIndexes: [[fOutline itemAtRow: i] indexes]];
|
2008-01-04 00:29:13 +00:00
|
|
|
|
2008-10-12 21:38:13 +00:00
|
|
|
NSInteger state = ([menuItem tag] == FILE_CHECK_TAG) ? NSOnState : NSOffState;
|
2008-01-04 00:29:13 +00:00
|
|
|
return [fTorrent checkForFiles: itemIndexes] != state && [fTorrent canChangeDownloadCheckForFiles: itemIndexes];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action == @selector(setOnlySelectedCheck:))
|
|
|
|
{
|
|
|
|
if ([fOutline numberOfSelectedRows] <= 0)
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
NSIndexSet * indexSet = [fOutline selectedRowIndexes];
|
|
|
|
NSMutableIndexSet * itemIndexes = [NSMutableIndexSet indexSet];
|
2008-10-12 21:38:13 +00:00
|
|
|
for (NSInteger i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
|
2008-05-22 18:39:49 +00:00
|
|
|
[itemIndexes addIndexes: [[fOutline itemAtRow: i] indexes]];
|
2008-01-04 00:29:13 +00:00
|
|
|
|
|
|
|
return [fTorrent canChangeDownloadCheckForFiles: itemIndexes];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action == @selector(setPriority:))
|
|
|
|
{
|
|
|
|
if ([fOutline numberOfSelectedRows] <= 0)
|
|
|
|
{
|
|
|
|
[menuItem setState: NSOffState];
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
//determine which priorities are checked
|
|
|
|
NSIndexSet * indexSet = [fOutline selectedRowIndexes];
|
2008-10-12 21:38:13 +00:00
|
|
|
NSInteger priority;
|
2008-01-06 05:13:38 +00:00
|
|
|
switch ([menuItem tag])
|
|
|
|
{
|
|
|
|
case FILE_PRIORITY_HIGH_TAG:
|
|
|
|
priority = TR_PRI_HIGH;
|
|
|
|
break;
|
|
|
|
case FILE_PRIORITY_NORMAL_TAG:
|
|
|
|
priority = TR_PRI_NORMAL;
|
|
|
|
break;
|
|
|
|
case FILE_PRIORITY_LOW_TAG:
|
|
|
|
priority = TR_PRI_LOW;
|
|
|
|
}
|
2008-01-04 00:29:13 +00:00
|
|
|
|
2008-10-12 21:38:13 +00:00
|
|
|
BOOL current = NO, canChange = NO;
|
2008-01-04 00:29:13 +00:00
|
|
|
NSIndexSet * fileIndexSet;
|
2008-10-12 21:39:12 +00:00
|
|
|
for (NSInteger i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2008-05-22 18:39:49 +00:00
|
|
|
fileIndexSet = [[fOutline itemAtRow: i] indexes];
|
2008-01-04 00:29:13 +00:00
|
|
|
if (![fTorrent canChangeDownloadCheckForFiles: fileIndexSet])
|
|
|
|
continue;
|
2008-10-12 21:38:13 +00:00
|
|
|
|
|
|
|
canChange = YES;
|
|
|
|
if ([fTorrent hasFilePriority: priority forIndexes: fileIndexSet])
|
2008-10-12 21:39:12 +00:00
|
|
|
{
|
2008-01-04 00:29:13 +00:00
|
|
|
current = YES;
|
2008-10-12 21:39:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[menuItem setState: current ? NSOnState : NSOffState];
|
2008-10-12 21:38:13 +00:00
|
|
|
return canChange;
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2008-01-06 05:13:38 +00:00
|
|
|
|
|
|
|
@implementation FileOutlineController (Private)
|
|
|
|
|
|
|
|
- (NSMenu *) menu
|
|
|
|
{
|
|
|
|
NSMenu * menu = [[NSMenu alloc] initWithTitle: @"File Outline Menu"];
|
|
|
|
|
|
|
|
//check and uncheck
|
|
|
|
NSMenuItem * item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"Check Selected", "File Outline -> Menu")
|
|
|
|
action: @selector(setCheck:) keyEquivalent: @""];
|
|
|
|
[item setTarget: self];
|
|
|
|
[item setTag: FILE_CHECK_TAG];
|
|
|
|
[menu addItem: item];
|
|
|
|
[item release];
|
|
|
|
|
|
|
|
item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"Uncheck Selected", "File Outline -> Menu")
|
|
|
|
action: @selector(setCheck:) keyEquivalent: @""];
|
|
|
|
[item setTarget: self];
|
|
|
|
[item setTag: FILE_UNCHECK_TAG];
|
|
|
|
[menu addItem: item];
|
|
|
|
[item release];
|
|
|
|
|
|
|
|
//only check selected
|
|
|
|
item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"Only Check Selected", "File Outline -> Menu")
|
|
|
|
action: @selector(setOnlySelectedCheck:) keyEquivalent: @""];
|
|
|
|
[item setTarget: self];
|
|
|
|
[menu addItem: item];
|
|
|
|
[item release];
|
|
|
|
|
|
|
|
[menu addItem: [NSMenuItem separatorItem]];
|
|
|
|
|
|
|
|
//priority
|
|
|
|
item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"Priority", "File Outline -> Menu") action: NULL keyEquivalent: @""];
|
|
|
|
NSMenu * priorityMenu = [[NSMenu alloc] initWithTitle: @"File Priority Menu"];
|
|
|
|
[item setSubmenu: priorityMenu];
|
|
|
|
[menu addItem: item];
|
|
|
|
[item release];
|
|
|
|
|
|
|
|
item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"High", "File Outline -> Priority Menu")
|
|
|
|
action: @selector(setPriority:) keyEquivalent: @""];
|
|
|
|
[item setTarget: self];
|
|
|
|
[item setTag: FILE_PRIORITY_HIGH_TAG];
|
|
|
|
[item setImage: [NSImage imageNamed: @"PriorityHigh.png"]];
|
|
|
|
[priorityMenu addItem: item];
|
|
|
|
[item release];
|
|
|
|
|
|
|
|
item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"Normal", "File Outline -> Priority Menu")
|
|
|
|
action: @selector(setPriority:) keyEquivalent: @""];
|
|
|
|
[item setTarget: self];
|
|
|
|
[item setTag: FILE_PRIORITY_NORMAL_TAG];
|
|
|
|
[item setImage: [NSImage imageNamed: @"PriorityNormal.png"]];
|
|
|
|
[priorityMenu addItem: item];
|
|
|
|
[item release];
|
|
|
|
|
|
|
|
item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"Low", "File Outline -> Priority Menu")
|
|
|
|
action: @selector(setPriority:) keyEquivalent: @""];
|
|
|
|
[item setTarget: self];
|
|
|
|
[item setTag: FILE_PRIORITY_LOW_TAG];
|
|
|
|
[item setImage: [NSImage imageNamed: @"PriorityLow.png"]];
|
|
|
|
[priorityMenu addItem: item];
|
|
|
|
[item release];
|
|
|
|
|
|
|
|
[priorityMenu release];
|
|
|
|
|
|
|
|
[menu addItem: [NSMenuItem separatorItem]];
|
|
|
|
|
|
|
|
//reveal in finder
|
|
|
|
item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"Reveal in Finder", "File Outline -> Menu")
|
|
|
|
action: @selector(revealFile:) keyEquivalent: @""];
|
|
|
|
[item setTarget: self];
|
|
|
|
[menu addItem: item];
|
|
|
|
[item release];
|
|
|
|
|
|
|
|
return [menu autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|