2023-11-01 21:11:11 +00:00
|
|
|
// This file Copyright © Transmission authors and contributors.
|
2022-01-20 18:27:56 +00:00
|
|
|
// It may be used under the MIT (SPDX: MIT) license.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2008-01-04 00:29:13 +00:00
|
|
|
|
|
|
|
#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"
|
2011-07-21 02:36:12 +00:00
|
|
|
#import "NSMutableArrayAdditions.h"
|
2011-09-19 00:48:30 +00:00
|
|
|
#import "NSStringAdditions.h"
|
2008-01-04 00:29:13 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
static CGFloat const kRowSmallHeight = 18.0;
|
2008-01-04 00:29:13 +00:00
|
|
|
|
2023-04-15 21:33:43 +00:00
|
|
|
typedef NS_ENUM(NSUInteger, FileCheckMenuTag) { //
|
|
|
|
FileCheckMenuTagCheck,
|
|
|
|
FileCheckMenuTagUncheck
|
2021-08-07 07:27:56 +00:00
|
|
|
};
|
2008-01-06 05:13:38 +00:00
|
|
|
|
2023-04-15 21:33:43 +00:00
|
|
|
typedef NS_ENUM(NSUInteger, FilePriorityMenuTag) { //
|
|
|
|
FilePriorityMenuTagHigh,
|
|
|
|
FilePriorityMenuTagNormal,
|
|
|
|
FilePriorityMenuTagLow
|
2021-08-07 07:27:56 +00:00
|
|
|
};
|
2008-01-06 05:13:38 +00:00
|
|
|
|
2022-01-24 01:32:45 +00:00
|
|
|
@interface FileOutlineController ()
|
2008-01-06 05:13:38 +00:00
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
@property(nonatomic) NSMutableArray<FileListNode*>* fFileList;
|
2022-02-22 16:04:20 +00:00
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet FileOutlineView* fOutline;
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
@property(nonatomic, readonly) NSMenu* menu;
|
2008-01-06 05:13:38 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
@implementation FileOutlineController
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)awakeFromNib
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2023-11-05 20:35:22 +00:00
|
|
|
[super awakeFromNib];
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fFileList = [[NSMutableArray alloc] init];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
//set table header tool tips
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fOutline tableColumnWithIdentifier:@"Check"].headerToolTip = NSLocalizedString(@"Download", "file table -> header tool tip");
|
|
|
|
[self.fOutline tableColumnWithIdentifier:@"Priority"].headerToolTip = NSLocalizedString(@"Priority", "file table -> header tool tip");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fOutline.menu = self.menu;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.torrent = nil;
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (FileOutlineView*)outlineView
|
2008-05-20 19:34:33 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return _fOutline;
|
2008-05-20 19:34:33 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setTorrent:(Torrent*)torrent
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
_torrent = torrent;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-11-07 15:57:35 +00:00
|
|
|
[self.fFileList setArray:torrent.fileList ?: @[]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.filterText = nil;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fOutline reloadData];
|
|
|
|
[self.fOutline deselectAll:nil]; //do this after reloading the data #4575
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setFilterText:(NSString*)text
|
2008-12-07 18:20:14 +00:00
|
|
|
{
|
2022-05-14 19:00:55 +00:00
|
|
|
NSArray* components = [text nonEmptyComponentsSeparatedByCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!components || components.count == 0)
|
2011-09-19 00:48:30 +00:00
|
|
|
{
|
2008-12-07 18:20:14 +00:00
|
|
|
text = nil;
|
2011-09-19 00:48:30 +00:00
|
|
|
components = nil;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if ((!text && !_filterText) || (text && _filterText && [text isEqualToString:_filterText]))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-12-07 18:20:14 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fOutline beginUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-07-21 02:36:12 +00:00
|
|
|
NSUInteger currentIndex = 0, totalCount = 0;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableArray* itemsToAdd = [NSMutableArray array];
|
|
|
|
NSMutableIndexSet* itemsToAddIndexes = [NSMutableIndexSet indexSet];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableDictionary* removedIndexesForParents = nil; //ugly, but we can't modify the actual file nodes
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSArray* tempList = !text ? self.torrent.fileList : self.torrent.flatFileList;
|
2021-08-15 09:41:48 +00:00
|
|
|
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)
|
|
|
|
{
|
2022-12-21 20:21:16 +00:00
|
|
|
[components enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(NSString* obj, NSUInteger /*idx*/, BOOL* stop) {
|
2022-05-14 19:00:55 +00:00
|
|
|
if ([item.name rangeOfString: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
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-09-19 00:48:30 +00:00
|
|
|
if (!filter)
|
2011-07-21 02:36:12 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
FileListNode* parent = nil;
|
|
|
|
NSUInteger previousIndex = !item.isFolder ?
|
2022-02-22 16:04:20 +00:00
|
|
|
[self findFileNode:item inList:self.fFileList
|
|
|
|
atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(currentIndex, self.fFileList.count - currentIndex)]
|
2021-08-15 09:41:48 +00:00
|
|
|
currentParent:nil
|
|
|
|
finalParent:&parent] :
|
|
|
|
NSNotFound;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-07-21 02:36:12 +00:00
|
|
|
if (previousIndex == NSNotFound)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[itemsToAdd addObject:item];
|
|
|
|
[itemsToAddIndexes addIndex:totalCount];
|
2011-07-21 02:36:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BOOL move = YES;
|
|
|
|
if (!parent)
|
|
|
|
{
|
|
|
|
if (previousIndex != currentIndex)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fFileList moveObjectAtIndex:previousIndex toIndex:currentIndex];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-07-21 02:36:12 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-07-21 02:36:12 +00:00
|
|
|
move = NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-07-21 02:36:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fFileList insertObject:item atIndex:currentIndex];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-07-21 02:36:12 +00:00
|
|
|
//figure out the index within the semi-edited table - UGLY
|
|
|
|
if (!removedIndexesForParents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-07-21 02:36:12 +00:00
|
|
|
removedIndexesForParents = [NSMutableDictionary dictionary];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableIndexSet* removedIndexes = removedIndexesForParents[parent];
|
2011-07-21 02:36:12 +00:00
|
|
|
if (!removedIndexes)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
removedIndexes = [NSMutableIndexSet indexSetWithIndex:previousIndex];
|
2017-07-08 14:38:47 +00:00
|
|
|
removedIndexesForParents[parent] = removedIndexes;
|
2011-07-21 02:36:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[removedIndexes addIndex:previousIndex];
|
|
|
|
previousIndex -= [removedIndexes countOfIndexesInRange:NSMakeRange(0, previousIndex)];
|
2011-07-21 02:36:12 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2016-01-06 11:05:37 +00:00
|
|
|
if (move)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fOutline moveItemAtIndex:previousIndex inParent:parent toIndex:currentIndex inParent:nil];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-07-21 02:36:12 +00:00
|
|
|
++currentIndex;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-07-21 02:36:12 +00:00
|
|
|
++totalCount;
|
|
|
|
}
|
2008-12-07 18:20:14 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-07-21 02:36:12 +00:00
|
|
|
//remove trailing items - those are the unused
|
2022-02-22 16:04:20 +00:00
|
|
|
if (currentIndex < self.fFileList.count)
|
2011-07-21 02:36:12 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSRange const removeRange = NSMakeRange(currentIndex, self.fFileList.count - currentIndex);
|
|
|
|
[self.fFileList removeObjectsInRange:removeRange];
|
|
|
|
[self.fOutline removeItemsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:removeRange] inParent:nil
|
2022-03-30 21:52:23 +00:00
|
|
|
withAnimation:NSTableViewAnimationSlideDown];
|
2011-07-21 02:36:12 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-07-21 02:36:12 +00:00
|
|
|
//add new items
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fFileList insertObjects:itemsToAdd atIndexes:itemsToAddIndexes];
|
|
|
|
[self.fOutline insertItemsAtIndexes:itemsToAddIndexes inParent:nil withAnimation:NSTableViewAnimationSlideUp];
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fOutline endUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_filterText = text;
|
2008-12-07 18:20:14 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)refresh
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fOutline.needsDisplay = YES;
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)outlineViewSelectionDidChange:(NSNotification*)notification
|
2008-12-07 18:20:14 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if ([QLPreviewPanel sharedPreviewPanelExists] && [QLPreviewPanel sharedPreviewPanel].visible)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-10-06 00:30:40 +00:00
|
|
|
[[QLPreviewPanel sharedPreviewPanel] reloadData];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-12-07 18:20:14 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSInteger)outlineView:(NSOutlineView*)outlineView numberOfChildrenOfItem:(id)item
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
|
|
|
if (!item)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fFileList ? self.fFileList.count : 0;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-04 04:45:31 +00:00
|
|
|
else
|
2008-05-22 18:39:49 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
FileListNode* node = (FileListNode*)item;
|
2021-08-07 07:27:56 +00:00
|
|
|
return node.isFolder ? node.children.count : 0;
|
2008-05-22 18:39:49 +00:00
|
|
|
}
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)outlineView:(NSOutlineView*)outlineView isItemExpandable:(id)item
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
return ((FileListNode*)item).isFolder;
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (id)outlineView:(NSOutlineView*)outlineView child:(NSInteger)index ofItem:(id)item
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return (item ? ((FileListNode*)item).children : self.fFileList)[index];
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (id)outlineView:(NSOutlineView*)outlineView objectValueForTableColumn:(NSTableColumn*)tableColumn byItem:(id)item
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([tableColumn.identifier isEqualToString:@"Check"])
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return @([self.torrent checkForFiles:((FileListNode*)item).indexes]);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-04 00:29:13 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-01-04 00:29:13 +00:00
|
|
|
return item;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)outlineView:(NSOutlineView*)outlineView
|
|
|
|
willDisplayCell:(id)cell
|
|
|
|
forTableColumn:(NSTableColumn*)tableColumn
|
|
|
|
item:(id)item
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* identifier = tableColumn.identifier;
|
|
|
|
if ([identifier isEqualToString:@"Check"])
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[cell setEnabled:[self.torrent canChangeDownloadCheckForFiles:((FileListNode*)item).indexes]];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([identifier isEqualToString:@"Priority"])
|
2008-03-25 03:17:35 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[cell setRepresentedObject:item];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSInteger hoveredRow = self.fOutline.hoveredRow;
|
|
|
|
((FilePriorityCell*)cell).hovered = hoveredRow != -1 && hoveredRow == [self.fOutline rowForItem:item];
|
2008-03-25 03:17:35 +00:00
|
|
|
}
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)outlineView:(NSOutlineView*)outlineView
|
|
|
|
setObjectValue:(id)object
|
|
|
|
forTableColumn:(NSTableColumn*)tableColumn
|
|
|
|
byItem:(id)item
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* identifier = tableColumn.identifier;
|
|
|
|
if ([identifier isEqualToString:@"Check"])
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* indexSet;
|
2021-10-31 15:18:27 +00:00
|
|
|
if (NSEvent.modifierFlags & NSEventModifierFlagOption)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.torrent.fileCount)];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-04 00:29:13 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
indexSet = ((FileListNode*)item).indexes;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-03-30 21:52:23 +00:00
|
|
|
[self.torrent setFileCheckState:[object intValue] != NSControlStateValueOff ? NSControlStateValueOn : NSControlStateValueOff
|
|
|
|
forIndexes:indexSet];
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fOutline.needsDisplay = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateUI" object:nil];
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)outlineView:(NSOutlineView*)outlineView typeSelectStringForTableColumn:(NSTableColumn*)tableColumn item:(id)item
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
return ((FileListNode*)item).name;
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)outlineView:(NSOutlineView*)outlineView
|
|
|
|
toolTipForCell:(NSCell*)cell
|
|
|
|
rect:(NSRectPointer)rect
|
|
|
|
tableColumn:(NSTableColumn*)tableColumn
|
|
|
|
item:(id)item
|
|
|
|
mouseLocation:(NSPoint)mouseLocation
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* ident = tableColumn.identifier;
|
|
|
|
if ([ident isEqualToString:@"Name"])
|
2011-05-09 02:13:39 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSString* path = [self.torrent fileLocation:item];
|
2021-08-15 09:41:48 +00:00
|
|
|
if (!path)
|
|
|
|
{
|
|
|
|
FileListNode* node = (FileListNode*)item;
|
|
|
|
path = [node.path stringByAppendingPathComponent:node.name];
|
2021-08-07 07:27:56 +00:00
|
|
|
}
|
2011-05-09 02:13:39 +00:00
|
|
|
return path;
|
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([ident isEqualToString:@"Check"])
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
switch (cell.state)
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
case NSControlStateValueOff:
|
2021-08-15 09:41:48 +00:00
|
|
|
return NSLocalizedString(@"Don't Download", "files tab -> tooltip");
|
2021-10-31 15:18:27 +00:00
|
|
|
case NSControlStateValueOn:
|
2021-08-15 09:41:48 +00:00
|
|
|
return NSLocalizedString(@"Download", "files tab -> tooltip");
|
2021-10-31 15:18:27 +00:00
|
|
|
case NSControlStateValueMixed:
|
2021-08-15 09:41:48 +00:00
|
|
|
return NSLocalizedString(@"Download Some", "files tab -> tooltip");
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else if ([ident isEqualToString:@"Priority"])
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSSet* priorities = [self.torrent filePrioritiesForIndexes:((FileListNode*)item).indexes];
|
2021-08-07 07:27:56 +00:00
|
|
|
switch (priorities.count)
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
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");
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (CGFloat)outlineView:(NSOutlineView*)outlineView heightOfRowByItem:(id)item
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if (((FileListNode*)item).isFolder)
|
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
return kRowSmallHeight;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-04 00:29:13 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
return outlineView.rowHeight;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setCheck:(id)sender
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2023-04-15 21:33:43 +00:00
|
|
|
NSInteger state = [sender tag] == FileCheckMenuTagUncheck ? NSControlStateValueOff : NSControlStateValueOn;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSIndexSet* indexSet = self.fOutline.selectedRowIndexes;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableIndexSet* itemIndexes = [NSMutableIndexSet indexSet];
|
|
|
|
for (NSInteger i = indexSet.firstIndex; i != NSNotFound; i = [indexSet indexGreaterThanIndex:i])
|
2021-08-07 07:27:56 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
FileListNode* item = [self.fOutline itemAtRow:i];
|
2021-08-15 09:41:48 +00:00
|
|
|
[itemIndexes addIndexes:item.indexes];
|
2021-08-07 07:27:56 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.torrent setFileCheckState:state forIndexes:itemIndexes];
|
|
|
|
self.fOutline.needsDisplay = YES;
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setOnlySelectedCheck:(id)sender
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSIndexSet* indexSet = self.fOutline.selectedRowIndexes;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableIndexSet* itemIndexes = [NSMutableIndexSet indexSet];
|
|
|
|
for (NSInteger i = indexSet.firstIndex; i != NSNotFound; i = [indexSet indexGreaterThanIndex:i])
|
2021-08-07 07:27:56 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
FileListNode* item = [self.fOutline itemAtRow:i];
|
2021-08-15 09:41:48 +00:00
|
|
|
[itemIndexes addIndexes:item.indexes];
|
2021-08-07 07:27:56 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.torrent setFileCheckState:NSControlStateValueOn forIndexes:itemIndexes];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSMutableIndexSet* remainingItemIndexes = [NSMutableIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.torrent.fileCount)];
|
2021-08-15 09:41:48 +00:00
|
|
|
[remainingItemIndexes removeIndexes:itemIndexes];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.torrent setFileCheckState:NSControlStateValueOff forIndexes:remainingItemIndexes];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fOutline.needsDisplay = YES;
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)checkAll
|
2012-05-14 00:00:19 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSIndexSet* indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.torrent.fileCount)];
|
|
|
|
[self.torrent setFileCheckState:NSControlStateValueOn forIndexes:indexSet];
|
|
|
|
self.fOutline.needsDisplay = YES;
|
2012-05-14 00:00:19 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)uncheckAll
|
2012-05-14 00:00:19 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSIndexSet* indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.torrent.fileCount)];
|
|
|
|
[self.torrent setFileCheckState:NSControlStateValueOff forIndexes:indexSet];
|
|
|
|
self.fOutline.needsDisplay = YES;
|
2012-05-14 00:00:19 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setPriority:(id)sender
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2009-04-20 02:45:27 +00:00
|
|
|
tr_priority_t priority;
|
2008-01-06 05:13:38 +00:00
|
|
|
switch ([sender tag])
|
|
|
|
{
|
2023-04-15 21:33:43 +00:00
|
|
|
case FilePriorityMenuTagHigh:
|
2021-08-15 09:41:48 +00:00
|
|
|
priority = TR_PRI_HIGH;
|
|
|
|
break;
|
2023-04-15 21:33:43 +00:00
|
|
|
case FilePriorityMenuTagNormal:
|
2021-08-15 09:41:48 +00:00
|
|
|
priority = TR_PRI_NORMAL;
|
|
|
|
break;
|
2023-04-15 21:33:43 +00:00
|
|
|
case FilePriorityMenuTagLow:
|
2021-08-15 09:41:48 +00:00
|
|
|
priority = TR_PRI_LOW;
|
2022-06-07 19:27:40 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NSAssert1(NO, @"Unknown sender tag: %ld", [sender tag]);
|
|
|
|
return;
|
2008-01-06 05:13:38 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSIndexSet* indexSet = self.fOutline.selectedRowIndexes;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableIndexSet* itemIndexes = [NSMutableIndexSet indexSet];
|
|
|
|
for (NSInteger i = indexSet.firstIndex; i != NSNotFound; i = [indexSet indexGreaterThanIndex:i])
|
2021-08-07 07:27:56 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
FileListNode* item = [self.fOutline itemAtRow:i];
|
2021-08-15 09:41:48 +00:00
|
|
|
[itemIndexes addIndexes:item.indexes];
|
2021-08-07 07:27:56 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.torrent setFilePriority:priority forIndexes:itemIndexes];
|
|
|
|
self.fOutline.needsDisplay = YES;
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)revealFile:(id)sender
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSIndexSet* indexes = self.fOutline.selectedRowIndexes;
|
2021-08-15 09:41:48 +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
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSString* path = [self.torrent fileLocation:[self.fOutline itemAtRow:i]];
|
2011-10-06 00:30:40 +00:00
|
|
|
if (path)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[paths addObject:[NSURL fileURLWithPath:path]];
|
|
|
|
}
|
2009-08-30 17:50:05 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (paths.count > 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[NSWorkspace.sharedWorkspace activateFileViewerSelectingURLs:paths];
|
|
|
|
}
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)renameSelected:(id)sender
|
2013-01-22 00:09:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSIndexSet* indexes = self.fOutline.selectedRowIndexes;
|
2021-08-07 07:27:56 +00:00
|
|
|
NSAssert(indexes.count == 1, @"1 file needs to be selected to rename, but %ld are selected", indexes.count);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
FileListNode* node = [self.fOutline itemAtRow:indexes.firstIndex];
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = node.torrent;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!torrent.folder)
|
2013-01-22 00:09:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[FileRenameSheetController presentSheetForTorrent:torrent modalForWindow:self.fOutline.window completionHandler:^(BOOL didRename) {
|
2013-01-22 00:09:48 +00:00
|
|
|
if (didRename)
|
2013-01-22 03:54:51 +00:00
|
|
|
{
|
2024-05-25 23:43:08 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateTorrentsState" object:nil];
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"ResetInspector" object:self
|
|
|
|
userInfo:@{ @"Torrent" : torrent }];
|
2013-01-22 03:54:51 +00:00
|
|
|
}
|
2013-01-22 00:09:48 +00:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[FileRenameSheetController presentSheetForFileListNode:node modalForWindow:self.fOutline.window completionHandler:^(BOOL didRename) {
|
2021-08-15 09:41:48 +00:00
|
|
|
#warning instead of calling reset inspector, just resort?
|
2013-01-22 00:09:48 +00:00
|
|
|
if (didRename)
|
2021-08-15 09:41:48 +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
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)validateMenuItem:(NSMenuItem*)menuItem
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.torrent)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-01-04 00:29:13 +00:00
|
|
|
return NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
SEL action = menuItem.action;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
if (action == @selector(revealFile:))
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSIndexSet* indexSet = self.fOutline.selectedRowIndexes;
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSInteger i = indexSet.firstIndex; i != NSNotFound; i = [indexSet indexGreaterThanIndex:i])
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.torrent fileLocation:[self.fOutline itemAtRow:i]] != nil)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-01-04 00:29:13 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-04 00:29:13 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
if (action == @selector(setCheck:))
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fOutline.numberOfSelectedRows == 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-01-04 00:29:13 +00:00
|
|
|
return NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSIndexSet* indexSet = self.fOutline.selectedRowIndexes;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableIndexSet* itemIndexes = [NSMutableIndexSet indexSet];
|
|
|
|
for (NSInteger i = indexSet.firstIndex; i != NSNotFound; i = [indexSet indexGreaterThanIndex:i])
|
2021-08-07 07:27:56 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
FileListNode* node = [self.fOutline itemAtRow:i];
|
2021-08-15 09:41:48 +00:00
|
|
|
[itemIndexes addIndexes:node.indexes];
|
2021-08-07 07:27:56 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2023-04-15 21:33:43 +00:00
|
|
|
NSInteger state = (menuItem.tag == FileCheckMenuTagCheck) ? NSControlStateValueOn : NSControlStateValueOff;
|
2022-02-22 16:04:20 +00:00
|
|
|
return [self.torrent checkForFiles:itemIndexes] != state && [self.torrent canChangeDownloadCheckForFiles:itemIndexes];
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
if (action == @selector(setOnlySelectedCheck:))
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fOutline.numberOfSelectedRows == 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-01-04 00:29:13 +00:00
|
|
|
return NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSIndexSet* indexSet = self.fOutline.selectedRowIndexes;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableIndexSet* itemIndexes = [NSMutableIndexSet indexSet];
|
|
|
|
for (NSInteger i = indexSet.firstIndex; i != NSNotFound; i = [indexSet indexGreaterThanIndex:i])
|
2021-08-07 07:27:56 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
FileListNode* node = [self.fOutline itemAtRow:i];
|
2021-08-15 09:41:48 +00:00
|
|
|
[itemIndexes addIndexes:node.indexes];
|
2021-08-07 07:27:56 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
return [self.torrent canChangeDownloadCheckForFiles:itemIndexes];
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
if (action == @selector(setPriority:))
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fOutline.numberOfSelectedRows == 0)
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
menuItem.state = NSControlStateValueOff;
|
2008-01-04 00:29:13 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
//determine which priorities are checked
|
2022-02-22 16:04:20 +00:00
|
|
|
NSIndexSet* indexSet = self.fOutline.selectedRowIndexes;
|
2009-04-20 02:45:27 +00:00
|
|
|
tr_priority_t priority;
|
2021-08-07 07:27:56 +00:00
|
|
|
switch (menuItem.tag)
|
2008-01-06 05:13:38 +00:00
|
|
|
{
|
2023-04-15 21:33:43 +00:00
|
|
|
case FilePriorityMenuTagHigh:
|
2021-08-15 09:41:48 +00:00
|
|
|
priority = TR_PRI_HIGH;
|
|
|
|
break;
|
2023-04-15 21:33:43 +00:00
|
|
|
case FilePriorityMenuTagNormal:
|
2021-08-15 09:41:48 +00:00
|
|
|
priority = TR_PRI_NORMAL;
|
|
|
|
break;
|
2023-04-15 21:33:43 +00:00
|
|
|
case FilePriorityMenuTagLow:
|
2021-08-15 09:41:48 +00:00
|
|
|
priority = TR_PRI_LOW;
|
|
|
|
break;
|
2022-06-07 19:27:40 +00:00
|
|
|
default:
|
|
|
|
NSAssert1(NO, @"Unknown menuItem tag: %ld", menuItem.tag);
|
|
|
|
return NO;
|
2008-01-06 05:13:38 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-10-12 21:38:13 +00:00
|
|
|
BOOL current = NO, canChange = NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSInteger i = indexSet.firstIndex; i != NSNotFound; i = [indexSet indexGreaterThanIndex:i])
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
FileListNode* node = [self.fOutline itemAtRow:i];
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* fileIndexSet = node.indexes;
|
2022-02-22 16:04:20 +00:00
|
|
|
if (![self.torrent canChangeDownloadCheckForFiles:fileIndexSet])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-01-04 00:29:13 +00:00
|
|
|
continue;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-10-12 21:38:13 +00:00
|
|
|
canChange = YES;
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.torrent 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
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-10-31 15:18:27 +00:00
|
|
|
menuItem.state = current ? NSControlStateValueOn : NSControlStateValueOff;
|
2008-10-12 21:38:13 +00:00
|
|
|
return canChange;
|
2008-01-04 00:29:13 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-01-22 00:09:48 +00:00
|
|
|
if (action == @selector(renameSelected:))
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fOutline.numberOfSelectedRows == 1;
|
2013-01-22 00:09:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
#pragma mark - Private
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSMenu*)menu
|
2008-01-06 05:13:38 +00:00
|
|
|
{
|
2022-10-31 14:37:34 +00:00
|
|
|
NSMenu* menu = [[NSMenu alloc] initWithTitle:@""];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-06 05:13:38 +00:00
|
|
|
//check and uncheck
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Check Selected", "File Outline -> Menu")
|
|
|
|
action:@selector(setCheck:)
|
|
|
|
keyEquivalent:@""];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
2023-04-15 21:33:43 +00:00
|
|
|
item.tag = FileCheckMenuTagCheck;
|
2021-08-15 09:41:48 +00:00
|
|
|
[menu addItem:item];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Uncheck Selected", "File Outline -> Menu")
|
|
|
|
action:@selector(setCheck:)
|
|
|
|
keyEquivalent:@""];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
2023-04-15 21:33:43 +00:00
|
|
|
item.tag = FileCheckMenuTagUncheck;
|
2021-08-15 09:41:48 +00:00
|
|
|
[menu addItem:item];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-06 05:13:38 +00:00
|
|
|
//only check selected
|
2021-08-15 09:41:48 +00:00
|
|
|
item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Only Check Selected", "File Outline -> Menu")
|
|
|
|
action:@selector(setOnlySelectedCheck:)
|
|
|
|
keyEquivalent:@""];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
2021-08-15 09:41:48 +00:00
|
|
|
[menu addItem:item];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[menu addItem:[NSMenuItem separatorItem]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-06 05:13:38 +00:00
|
|
|
//priority
|
2021-08-15 09:41:48 +00:00
|
|
|
item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Priority", "File Outline -> Menu") action:NULL keyEquivalent:@""];
|
2022-10-31 14:37:34 +00:00
|
|
|
NSMenu* priorityMenu = [[NSMenu alloc] initWithTitle:@""];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.submenu = priorityMenu;
|
2021-08-15 09:41:48 +00:00
|
|
|
[menu addItem:item];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"High", "File Outline -> Priority Menu")
|
|
|
|
action:@selector(setPriority:)
|
|
|
|
keyEquivalent:@""];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
2023-04-15 21:33:43 +00:00
|
|
|
item.tag = FilePriorityMenuTagHigh;
|
2021-08-15 09:41:48 +00:00
|
|
|
item.image = [NSImage imageNamed:@"PriorityHighTemplate"];
|
|
|
|
[priorityMenu addItem:item];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Normal", "File Outline -> Priority Menu")
|
|
|
|
action:@selector(setPriority:)
|
|
|
|
keyEquivalent:@""];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
2023-04-15 21:33:43 +00:00
|
|
|
item.tag = FilePriorityMenuTagNormal;
|
2021-08-15 09:41:48 +00:00
|
|
|
item.image = [NSImage imageNamed:@"PriorityNormalTemplate"];
|
|
|
|
[priorityMenu addItem:item];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Low", "File Outline -> Priority Menu")
|
|
|
|
action:@selector(setPriority:)
|
|
|
|
keyEquivalent:@""];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
2023-04-15 21:33:43 +00:00
|
|
|
item.tag = FilePriorityMenuTagLow;
|
2021-08-15 09:41:48 +00:00
|
|
|
item.image = [NSImage imageNamed:@"PriorityLowTemplate"];
|
|
|
|
[priorityMenu addItem:item];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[menu addItem:[NSMenuItem separatorItem]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-06 05:13:38 +00:00
|
|
|
//reveal in finder
|
2021-08-15 09:41:48 +00:00
|
|
|
item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Show in Finder", "File Outline -> Menu")
|
|
|
|
action:@selector(revealFile:)
|
|
|
|
keyEquivalent:@""];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
2021-08-15 09:41:48 +00:00
|
|
|
[menu addItem:item];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[menu addItem:[NSMenuItem separatorItem]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-01-26 22:39:32 +00:00
|
|
|
//rename
|
2021-08-15 09:41:48 +00:00
|
|
|
item = [[NSMenuItem alloc] initWithTitle:[NSLocalizedString(@"Rename File", "File Outline -> Menu") stringByAppendingEllipsis]
|
|
|
|
action:@selector(renameSelected:)
|
|
|
|
keyEquivalent:@""];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
2021-08-15 09:41:48 +00:00
|
|
|
[menu addItem:item];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2017-07-29 16:14:22 +00:00
|
|
|
return menu;
|
2008-01-06 05:13:38 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSUInteger)findFileNode:(FileListNode*)node
|
2022-04-29 22:51:40 +00:00
|
|
|
inList:(NSArray<FileListNode*>*)list
|
2021-08-15 09:41:48 +00:00
|
|
|
atIndexes:(NSIndexSet*)indexes
|
|
|
|
currentParent:(FileListNode*)currentParent
|
|
|
|
finalParent:(FileListNode* __autoreleasing*)parent
|
2011-07-21 02:36:12 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSAssert(!node.isFolder, @"Looking up folder node!");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-10-10 23:08:47 +00:00
|
|
|
__block FileListNode* retNode;
|
2012-01-08 05:05:47 +00:00
|
|
|
__block NSUInteger retIndex = NSNotFound;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-10-10 23:08:47 +00:00
|
|
|
using FindFileNode = void (^)(FileListNode*, NSArray<FileListNode*>*, NSIndexSet*, FileListNode*);
|
|
|
|
__weak __block FindFileNode weakFindFileNode;
|
|
|
|
FindFileNode findFileNode;
|
2022-12-21 20:21:16 +00:00
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wshadow"
|
2022-10-10 23:08:47 +00:00
|
|
|
weakFindFileNode = findFileNode = ^(FileListNode* node, NSArray<FileListNode*>* list, NSIndexSet* indexes, FileListNode* currentParent) {
|
2022-12-21 20:21:16 +00:00
|
|
|
#pragma clang diagnostic pop
|
2022-10-10 23:08:47 +00:00
|
|
|
[list enumerateObjectsAtIndexes:indexes options:NSEnumerationConcurrent
|
|
|
|
usingBlock:^(FileListNode* checkNode, NSUInteger index, BOOL* stop) {
|
|
|
|
if ([checkNode.indexes containsIndex:node.indexes.firstIndex])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-10 23:08:47 +00:00
|
|
|
if (!checkNode.isFolder)
|
|
|
|
{
|
|
|
|
NSAssert([checkNode isEqualTo:node], @"Expected file nodes to be equal: %@ %@", checkNode, node);
|
|
|
|
retNode = currentParent;
|
|
|
|
retIndex = index;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
weakFindFileNode(
|
|
|
|
node,
|
|
|
|
checkNode.children,
|
|
|
|
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, checkNode.children.count)],
|
|
|
|
checkNode);
|
|
|
|
NSAssert(retIndex != NSNotFound, @"We didn't find an expected file node.");
|
|
|
|
}
|
|
|
|
*stop = YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-10-10 23:08:47 +00:00
|
|
|
}];
|
|
|
|
};
|
|
|
|
findFileNode(node, list, indexes, currentParent);
|
2021-08-15 09:41:48 +00:00
|
|
|
|
2022-10-10 23:08:47 +00:00
|
|
|
if (retNode)
|
|
|
|
{
|
|
|
|
*parent = retNode;
|
|
|
|
}
|
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
|