2008-01-04 00:29:13 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2012-01-14 17:12:04 +00:00
|
|
|
* Copyright (c) 2008-2012 Transmission authors and contributors
|
2008-01-04 00:29:13 +00:00
|
|
|
*
|
|
|
|
* 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"
|
2013-01-22 00:09:48 +00:00
|
|
|
#import "FileListNode.h"
|
2008-01-04 00:29:13 +00:00
|
|
|
#import "FileOutlineView.h"
|
2008-03-25 03:17:35 +00:00
|
|
|
#import "FilePriorityCell.h"
|
2013-01-22 00:09:48 +00:00
|
|
|
#import "FileRenameSheetController.h"
|
2009-08-30 17:50:05 +00:00
|
|
|
#import "NSApplicationAdditions.h"
|
2011-07-21 02:36:12 +00:00
|
|
|
#import "NSMutableArrayAdditions.h"
|
2011-09-19 00:48:30 +00:00
|
|
|
#import "NSStringAdditions.h"
|
2009-09-04 04:10:46 +00:00
|
|
|
#import <Quartz/Quartz.h>
|
2008-01-04 00:29:13 +00:00
|
|
|
|
2009-01-26 02:16:03 +00:00
|
|
|
#define ROW_SMALL_HEIGHT 18.0
|
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;
|
|
|
|
|
2012-01-18 01:40:34 +00:00
|
|
|
- (NSUInteger) findFileNode: (FileListNode *) node inList: (NSArray *) list atIndexes: (NSIndexSet *) range currentParent: (FileListNode *) currentParent finalParent: (FileListNode **) parent;
|
2011-07-21 02:36:12 +00:00
|
|
|
|
2008-01-06 05:13:38 +00:00
|
|
|
@end
|
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
@implementation FileOutlineController
|
|
|
|
|
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
2011-07-21 02:36:12 +00:00
|
|
|
fFileList = [[NSMutableArray alloc] init];
|
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
[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
|
2011-07-21 02:36:12 +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];
|
|
|
|
}
|
|
|
|
|
2012-03-13 02:52:11 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[fFileList release];
|
|
|
|
[fFilterText release];
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2011-07-21 02:36:12 +00:00
|
|
|
[fFileList setArray: [fTorrent fileList]];
|
2008-12-07 18:20:14 +00:00
|
|
|
|
2012-03-13 02:52:11 +00:00
|
|
|
[fFilterText release];
|
2008-12-07 18:20:14 +00:00
|
|
|
fFilterText = nil;
|
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
[fOutline reloadData];
|
2011-10-19 02:10:56 +00:00
|
|
|
[fOutline deselectAll: nil]; //do this after reloading the data #4575
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2008-12-07 18:20:14 +00:00
|
|
|
- (void) setFilterText: (NSString *) text
|
|
|
|
{
|
2011-09-19 00:48:30 +00:00
|
|
|
NSArray * components = [text betterComponentsSeparatedByCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
|
|
|
if (!components || [components count] == 0)
|
|
|
|
{
|
2008-12-07 18:20:14 +00:00
|
|
|
text = nil;
|
2011-09-19 00:48:30 +00:00
|
|
|
components = nil;
|
|
|
|
}
|
2008-12-07 18:20:14 +00:00
|
|
|
|
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;
|
|
|
|
|
2011-07-21 02:36:12 +00:00
|
|
|
const BOOL onLion = [NSApp isOnLionOrBetter];
|
2008-12-07 18:20:14 +00:00
|
|
|
|
2011-07-21 02:36:12 +00:00
|
|
|
if (onLion)
|
|
|
|
[fOutline beginUpdates];
|
|
|
|
|
|
|
|
NSUInteger currentIndex = 0, totalCount = 0;
|
|
|
|
NSMutableArray * itemsToAdd = [NSMutableArray array];
|
|
|
|
NSMutableIndexSet * itemsToAddIndexes = [NSMutableIndexSet indexSet];
|
|
|
|
|
|
|
|
NSMutableDictionary * removedIndexesForParents = nil; //ugly, but we can't modify the actual file nodes
|
|
|
|
|
|
|
|
NSArray * tempList = !text ? [fTorrent fileList] : [fTorrent flatFileList];
|
|
|
|
for (FileListNode * item in tempList)
|
2008-12-07 18:20:14 +00:00
|
|
|
{
|
2012-01-08 05:37:18 +00:00
|
|
|
__block BOOL filter = NO;
|
2011-09-19 00:48:30 +00:00
|
|
|
if (components)
|
|
|
|
{
|
2012-01-08 05:37:18 +00:00
|
|
|
[components enumerateObjectsWithOptions: NSEnumerationConcurrent usingBlock: ^(id obj, NSUInteger idx, BOOL * stop) {
|
|
|
|
if ([[item name] rangeOfString: (NSString *)obj options: (NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch)].location == NSNotFound)
|
2011-09-19 00:48:30 +00:00
|
|
|
{
|
|
|
|
filter = YES;
|
2012-01-08 05:37:18 +00:00
|
|
|
*stop = YES;
|
2011-09-19 00:48:30 +00:00
|
|
|
}
|
2012-01-08 05:37:18 +00:00
|
|
|
}];
|
2011-09-19 00:48:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!filter)
|
2011-07-21 02:36:12 +00:00
|
|
|
{
|
|
|
|
FileListNode * parent = nil;
|
2012-01-18 01:40:34 +00:00
|
|
|
NSUInteger previousIndex = ![item isFolder] ? [self findFileNode: item inList: fFileList atIndexes: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(currentIndex, [fFileList count]-currentIndex)] currentParent: nil finalParent: &parent] : NSNotFound;
|
2011-07-21 02:36:12 +00:00
|
|
|
|
|
|
|
if (previousIndex == NSNotFound)
|
|
|
|
{
|
|
|
|
[itemsToAdd addObject: item];
|
|
|
|
[itemsToAddIndexes addIndex: totalCount];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BOOL move = YES;
|
|
|
|
if (!parent)
|
|
|
|
{
|
|
|
|
if (previousIndex != currentIndex)
|
|
|
|
[fFileList moveObjectAtIndex: previousIndex toIndex: currentIndex];
|
|
|
|
else
|
|
|
|
move = NO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[fFileList insertObject: item atIndex: currentIndex];
|
|
|
|
|
|
|
|
//figure out the index within the semi-edited table - UGLY
|
|
|
|
if (!removedIndexesForParents)
|
|
|
|
removedIndexesForParents = [NSMutableDictionary dictionary];
|
|
|
|
|
|
|
|
NSMutableIndexSet * removedIndexes = [removedIndexesForParents objectForKey: parent];
|
|
|
|
if (!removedIndexes)
|
|
|
|
{
|
|
|
|
removedIndexes = [NSMutableIndexSet indexSetWithIndex: previousIndex];
|
|
|
|
[removedIndexesForParents setObject: removedIndexes forKey: parent];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[removedIndexes addIndex: previousIndex];
|
|
|
|
previousIndex -= [removedIndexes countOfIndexesInRange: NSMakeRange(0, previousIndex)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (move && onLion)
|
|
|
|
[fOutline moveItemAtIndex: previousIndex inParent: parent toIndex: currentIndex inParent: nil];
|
|
|
|
|
|
|
|
++currentIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
++totalCount;
|
|
|
|
}
|
2008-12-07 18:20:14 +00:00
|
|
|
}
|
|
|
|
|
2011-07-21 02:36:12 +00:00
|
|
|
//remove trailing items - those are the unused
|
|
|
|
if (currentIndex < [fFileList count])
|
|
|
|
{
|
|
|
|
const NSRange removeRange = NSMakeRange(currentIndex, [fFileList count]-currentIndex);
|
|
|
|
[fFileList removeObjectsInRange: removeRange];
|
|
|
|
if (onLion)
|
|
|
|
[fOutline removeItemsAtIndexes: [NSIndexSet indexSetWithIndexesInRange: removeRange] inParent: nil withAnimation: NSTableViewAnimationSlideDown];
|
|
|
|
}
|
|
|
|
|
|
|
|
//add new items
|
|
|
|
[fFileList insertObjects: itemsToAdd atIndexes: itemsToAddIndexes];
|
|
|
|
if (onLion)
|
|
|
|
[fOutline insertItemsAtIndexes: itemsToAddIndexes inParent: nil withAnimation: NSTableViewAnimationSlideUp];
|
|
|
|
|
|
|
|
if (onLion)
|
|
|
|
[fOutline endUpdates];
|
|
|
|
else
|
|
|
|
[fOutline reloadData];
|
|
|
|
|
2012-03-13 02:52:11 +00:00
|
|
|
[fFilterText release];
|
|
|
|
fFilterText = [text retain];
|
2008-12-07 18:20:14 +00:00
|
|
|
}
|
|
|
|
|
2012-01-04 00:36:21 +00:00
|
|
|
- (void) refresh
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2008-01-09 21:08:43 +00:00
|
|
|
[fTorrent updateFileStat];
|
2011-07-21 02:36:12 +00:00
|
|
|
|
2012-01-04 00:36:21 +00:00
|
|
|
[fOutline setNeedsDisplay: YES];
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2008-12-07 18:20:14 +00:00
|
|
|
- (void) outlineViewSelectionDidChange: (NSNotification *) notification
|
|
|
|
{
|
2011-10-06 00:30:40 +00:00
|
|
|
if ([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isVisible])
|
|
|
|
[[QLPreviewPanel sharedPreviewPanel] reloadData];
|
2008-12-07 18:20:14 +00:00
|
|
|
}
|
|
|
|
|
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"])
|
2009-12-31 03:19:54 +00:00
|
|
|
return [NSNumber numberWithInteger: [fTorrent checkForFiles: [(FileListNode *)item indexes]]];
|
2008-01-04 00:29:13 +00:00
|
|
|
else
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2012-01-04 00:36:21 +00:00
|
|
|
- (void) outlineView: (NSOutlineView *) outlineView willDisplayCell: (id) cell forTableColumn: (NSTableColumn *) tableColumn item: (id) item
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-04 00:36:21 +00:00
|
|
|
- (void) outlineView: (NSOutlineView *) outlineView setObjectValue: (id) object forTableColumn: (NSTableColumn *) tableColumn byItem: (id) item
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
|
|
|
NSString * identifier = [tableColumn identifier];
|
|
|
|
if ([identifier isEqualToString: @"Check"])
|
|
|
|
{
|
|
|
|
NSIndexSet * indexSet;
|
2011-10-06 00:30:40 +00:00
|
|
|
if ([NSEvent modifierFlags] & NSAlternateKeyMask)
|
2008-01-04 00:29:13 +00:00
|
|
|
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];
|
2012-01-04 00:36:21 +00:00
|
|
|
[fOutline setNeedsDisplay: YES];
|
2008-01-04 00:29:13 +00:00
|
|
|
|
|
|
|
[[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"])
|
2011-05-09 02:13:39 +00:00
|
|
|
{
|
|
|
|
NSString * path = [fTorrent fileLocation: item];
|
|
|
|
if (!path)
|
2011-10-18 02:30:22 +00:00
|
|
|
path = [[(FileListNode *)item path] stringByAppendingPathComponent: [(FileListNode *)item name]];
|
2011-05-09 02:13:39 +00:00
|
|
|
return path;
|
|
|
|
}
|
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];
|
2012-01-04 00:36:21 +00:00
|
|
|
[fOutline setNeedsDisplay: YES];
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (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];
|
|
|
|
|
2012-01-04 00:36:21 +00:00
|
|
|
[fOutline setNeedsDisplay: YES];
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2012-05-14 00:00:19 +00:00
|
|
|
- (void) checkAll
|
|
|
|
{
|
|
|
|
NSIndexSet * indexSet = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fTorrent fileCount])];
|
|
|
|
[fTorrent setFileCheckState: NSOnState forIndexes: indexSet];
|
|
|
|
[fOutline setNeedsDisplay: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) uncheckAll
|
|
|
|
{
|
|
|
|
NSIndexSet * indexSet = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fTorrent fileCount])];
|
|
|
|
[fTorrent setFileCheckState: NSOffState forIndexes: indexSet];
|
|
|
|
[fOutline setNeedsDisplay: YES];
|
|
|
|
}
|
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
- (void) setPriority: (id) sender
|
|
|
|
{
|
2009-04-20 02:45:27 +00:00
|
|
|
tr_priority_t 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];
|
2012-01-04 00:36:21 +00:00
|
|
|
[fOutline setNeedsDisplay: YES];
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) revealFile: (id) sender
|
|
|
|
{
|
|
|
|
NSIndexSet * indexes = [fOutline selectedRowIndexes];
|
2011-10-06 00:30:40 +00:00
|
|
|
NSMutableArray * paths = [NSMutableArray arrayWithCapacity: [indexes count]];
|
|
|
|
for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
|
2009-08-30 17:50:05 +00:00
|
|
|
{
|
2011-10-06 00:30:40 +00:00
|
|
|
NSString * path = [fTorrent fileLocation: [fOutline itemAtRow: i]];
|
|
|
|
if (path)
|
|
|
|
[paths addObject: [NSURL fileURLWithPath: path]];
|
2009-08-30 17:50:05 +00:00
|
|
|
}
|
2011-07-21 02:36:12 +00:00
|
|
|
|
2011-10-06 00:30:40 +00:00
|
|
|
if ([paths count] > 0)
|
|
|
|
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs: paths];
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 13:02:16 +00:00
|
|
|
- (void) renameSelected: (id) sender
|
2013-01-22 00:09:48 +00:00
|
|
|
{
|
|
|
|
NSIndexSet * indexes = [fOutline selectedRowIndexes];
|
|
|
|
NSAssert([indexes count] == 1, @"1 file needs to be selected to rename, but %ld are selected", [indexes count]);
|
|
|
|
|
|
|
|
FileListNode * node = [fOutline itemAtRow: [indexes firstIndex]];
|
|
|
|
Torrent * torrent = [node torrent];
|
|
|
|
if (![torrent isFolder])
|
|
|
|
{
|
|
|
|
[FileRenameSheetController presentSheetForTorrent: torrent modalForWindow: [fOutline window] completionHandler: ^(BOOL didRename) {
|
|
|
|
if (didRename)
|
2013-01-22 03:54:51 +00:00
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self];
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"ResetInspector" object: self userInfo: @{ @"Torrent" : torrent }];
|
|
|
|
}
|
2013-01-22 00:09:48 +00:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[FileRenameSheetController presentSheetForFileListNode: node modalForWindow: [fOutline window] completionHandler: ^(BOOL didRename) {
|
2013-01-22 03:54:51 +00:00
|
|
|
#warning instead of calling reset inspector, just resort?
|
2013-01-22 00:09:48 +00:00
|
|
|
if (didRename)
|
2013-01-22 03:54:51 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"ResetInspector" object: self userInfo: @{ @"Torrent" : torrent }];
|
2013-01-22 00:09:48 +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:))
|
|
|
|
{
|
|
|
|
NSIndexSet * indexSet = [fOutline selectedRowIndexes];
|
2008-10-12 21:38:13 +00:00
|
|
|
for (NSInteger i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
|
2011-01-24 02:01:36 +00:00
|
|
|
if ([fTorrent fileLocation: [fOutline itemAtRow: i]] != nil)
|
2008-01-04 00:29:13 +00:00
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action == @selector(setCheck:))
|
|
|
|
{
|
2009-11-25 04:11:52 +00:00
|
|
|
if ([fOutline numberOfSelectedRows] == 0)
|
2008-01-04 00:29:13 +00:00
|
|
|
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:))
|
|
|
|
{
|
2009-11-25 04:11:52 +00:00
|
|
|
if ([fOutline numberOfSelectedRows] == 0)
|
2008-01-04 00:29:13 +00:00
|
|
|
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]];
|
2010-02-06 17:12:16 +00:00
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
return [fTorrent canChangeDownloadCheckForFiles: itemIndexes];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action == @selector(setPriority:))
|
|
|
|
{
|
2009-11-25 04:11:52 +00:00
|
|
|
if ([fOutline numberOfSelectedRows] == 0)
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
|
|
|
[menuItem setState: NSOffState];
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
//determine which priorities are checked
|
|
|
|
NSIndexSet * indexSet = [fOutline selectedRowIndexes];
|
2009-04-20 02:45:27 +00:00
|
|
|
tr_priority_t 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;
|
2009-11-25 04:11:52 +00:00
|
|
|
break;
|
2008-01-06 05:13:38 +00:00
|
|
|
}
|
2008-01-04 00:29:13 +00:00
|
|
|
|
2008-10-12 21:38:13 +00:00
|
|
|
BOOL current = NO, canChange = NO;
|
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
|
|
|
{
|
2009-11-25 04:11:52 +00:00
|
|
|
NSIndexSet * 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
|
|
|
}
|
|
|
|
|
2013-01-22 00:09:48 +00:00
|
|
|
if (action == @selector(renameSelected:))
|
|
|
|
{
|
|
|
|
return [fOutline numberOfSelectedRows] == 1;
|
|
|
|
}
|
|
|
|
|
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
|
2013-01-26 22:39:32 +00:00
|
|
|
NSMenuItem * item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"Check Selected", "File Outline -> Menu")
|
2013-01-22 00:09:48 +00:00
|
|
|
action: @selector(setCheck:) keyEquivalent: @""];
|
2008-01-06 05:13:38 +00:00
|
|
|
[item setTarget: self];
|
|
|
|
[item setTag: FILE_CHECK_TAG];
|
|
|
|
[menu addItem: item];
|
2012-03-13 02:52:11 +00:00
|
|
|
[item release];
|
2008-01-06 05:13:38 +00:00
|
|
|
|
|
|
|
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];
|
2012-03-13 02:52:11 +00:00
|
|
|
[item release];
|
2008-01-06 05:13:38 +00:00
|
|
|
|
|
|
|
//only check selected
|
|
|
|
item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"Only Check Selected", "File Outline -> Menu")
|
|
|
|
action: @selector(setOnlySelectedCheck:) keyEquivalent: @""];
|
|
|
|
[item setTarget: self];
|
|
|
|
[menu addItem: item];
|
2012-03-13 02:52:11 +00:00
|
|
|
[item release];
|
2008-01-06 05:13:38 +00:00
|
|
|
|
|
|
|
[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];
|
2012-03-13 02:52:11 +00:00
|
|
|
[item release];
|
2008-01-06 05:13:38 +00:00
|
|
|
|
|
|
|
item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"High", "File Outline -> Priority Menu")
|
|
|
|
action: @selector(setPriority:) keyEquivalent: @""];
|
|
|
|
[item setTarget: self];
|
|
|
|
[item setTag: FILE_PRIORITY_HIGH_TAG];
|
2012-06-10 02:35:58 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"PriorityHighTemplate"]];
|
2008-01-06 05:13:38 +00:00
|
|
|
[priorityMenu addItem: item];
|
2012-03-13 02:52:11 +00:00
|
|
|
[item release];
|
2008-01-06 05:13:38 +00:00
|
|
|
|
|
|
|
item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"Normal", "File Outline -> Priority Menu")
|
|
|
|
action: @selector(setPriority:) keyEquivalent: @""];
|
|
|
|
[item setTarget: self];
|
|
|
|
[item setTag: FILE_PRIORITY_NORMAL_TAG];
|
2012-06-10 02:35:58 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"PriorityNormalTemplate"]];
|
2008-01-06 05:13:38 +00:00
|
|
|
[priorityMenu addItem: item];
|
2012-03-13 02:52:11 +00:00
|
|
|
[item release];
|
2008-01-06 05:13:38 +00:00
|
|
|
|
|
|
|
item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"Low", "File Outline -> Priority Menu")
|
|
|
|
action: @selector(setPriority:) keyEquivalent: @""];
|
|
|
|
[item setTarget: self];
|
|
|
|
[item setTag: FILE_PRIORITY_LOW_TAG];
|
2012-06-10 02:35:58 +00:00
|
|
|
[item setImage: [NSImage imageNamed: @"PriorityLowTemplate"]];
|
2008-01-06 05:13:38 +00:00
|
|
|
[priorityMenu addItem: item];
|
2012-03-13 02:52:11 +00:00
|
|
|
[item release];
|
2008-01-06 05:13:38 +00:00
|
|
|
|
2012-03-13 02:52:11 +00:00
|
|
|
[priorityMenu release];
|
2008-01-06 05:13:38 +00:00
|
|
|
|
|
|
|
[menu addItem: [NSMenuItem separatorItem]];
|
|
|
|
|
|
|
|
//reveal in finder
|
2009-05-18 22:27:40 +00:00
|
|
|
item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"Show in Finder", "File Outline -> Menu")
|
2013-01-26 22:39:32 +00:00
|
|
|
action: @selector(revealFile:) keyEquivalent: @""];
|
|
|
|
[item setTarget: self];
|
|
|
|
[menu addItem: item];
|
|
|
|
[item release];
|
|
|
|
|
|
|
|
[menu addItem: [NSMenuItem separatorItem]];
|
|
|
|
|
|
|
|
//rename
|
|
|
|
item = [[NSMenuItem alloc] initWithTitle: [NSLocalizedString(@"Rename File", "File Outline -> Menu") stringByAppendingEllipsis]
|
|
|
|
action: @selector(renameSelected:) keyEquivalent: @""];
|
2008-01-06 05:13:38 +00:00
|
|
|
[item setTarget: self];
|
|
|
|
[menu addItem: item];
|
2012-03-13 02:52:11 +00:00
|
|
|
[item release];
|
2008-01-06 05:13:38 +00:00
|
|
|
|
2012-03-13 02:52:11 +00:00
|
|
|
return [menu autorelease];
|
2008-01-06 05:13:38 +00:00
|
|
|
}
|
|
|
|
|
2012-01-18 01:40:34 +00:00
|
|
|
- (NSUInteger) findFileNode: (FileListNode *) node inList: (NSArray *) list atIndexes: (NSIndexSet *) indexes currentParent: (FileListNode *) currentParent finalParent: (FileListNode **) parent
|
2011-07-21 02:36:12 +00:00
|
|
|
{
|
|
|
|
NSAssert(![node isFolder], @"Looking up folder node!");
|
|
|
|
|
2012-01-08 05:05:47 +00:00
|
|
|
__block NSUInteger retIndex = NSNotFound;
|
|
|
|
|
2012-01-18 01:40:34 +00:00
|
|
|
[list enumerateObjectsAtIndexes: indexes options: NSEnumerationConcurrent usingBlock: ^(id checkNode, NSUInteger index, BOOL * stop) {
|
|
|
|
if ([[checkNode indexes] containsIndex: [[node indexes] firstIndex]])
|
2011-07-21 02:36:12 +00:00
|
|
|
{
|
2012-01-18 01:40:34 +00:00
|
|
|
if (![checkNode isFolder])
|
|
|
|
{
|
|
|
|
NSAssert2([checkNode isEqualTo: node], @"Expected file nodes to be equal: %@ %@", checkNode, node);
|
|
|
|
|
|
|
|
*parent = currentParent;
|
|
|
|
retIndex = index;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const NSUInteger subIndex = [self findFileNode: node inList: [checkNode children] atIndexes: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [[checkNode children] count])] currentParent: checkNode finalParent: parent];
|
|
|
|
NSAssert(subIndex != NSNotFound, @"We didn't find an expected file node.");
|
|
|
|
retIndex = subIndex;
|
|
|
|
}
|
|
|
|
|
2012-01-08 05:05:47 +00:00
|
|
|
*stop = YES;
|
2011-07-21 02:36:12 +00:00
|
|
|
}
|
2012-01-08 05:05:47 +00:00
|
|
|
}];
|
2011-07-21 02:36:12 +00:00
|
|
|
|
2012-01-08 05:05:47 +00:00
|
|
|
return retIndex;
|
2011-07-21 02:36:12 +00:00
|
|
|
}
|
|
|
|
|
2008-01-06 05:13:38 +00:00
|
|
|
@end
|