2008-01-04 00:29:13 +00:00
|
|
|
/******************************************************************************
|
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.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2018-09-30 10:37:30 +00:00
|
|
|
#import <Quartz/Quartz.h>
|
|
|
|
|
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"
|
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"
|
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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
typedef NS_ENUM(unsigned int, fileCheckMenuTag) { //
|
2008-01-06 05:13:38 +00:00
|
|
|
FILE_CHECK_TAG,
|
|
|
|
FILE_UNCHECK_TAG
|
2021-08-07 07:27:56 +00:00
|
|
|
};
|
2008-01-06 05:13:38 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
typedef NS_ENUM(unsigned int, filePriorityMenuTag) { //
|
2008-01-06 05:13:38 +00:00
|
|
|
FILE_PRIORITY_HIGH_TAG,
|
|
|
|
FILE_PRIORITY_NORMAL_TAG,
|
|
|
|
FILE_PRIORITY_LOW_TAG
|
2021-08-07 07:27:56 +00:00
|
|
|
};
|
2008-01-06 05:13:38 +00:00
|
|
|
|
|
|
|
@interface FileOutlineController (Private)
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
@property(nonatomic, readonly) NSMenu* menu;
|
2008-01-06 05:13:38 +00:00
|
|
|
|
2021-08-15 09:41:48 +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
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)awakeFromNib
|
2008-01-04 00:29:13 +00:00
|
|
|
{
|
2011-07-21 02:36:12 +00:00
|
|
|
fFileList = [[NSMutableArray alloc] init];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fOutline.doubleAction = @selector(revealFile:);
|
|
|
|
fOutline.target = self;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
//set table header tool tips
|
2021-08-15 09:41:48 +00:00
|
|
|
[fOutline tableColumnWithIdentifier:@"Check"].headerToolTip = NSLocalizedString(@"Download", "file table -> header tool tip");
|
|
|
|
[fOutline tableColumnWithIdentifier:@"Priority"].headerToolTip = NSLocalizedString(@"Priority", "file table -> header tool tip");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fOutline.menu = self.menu;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self setTorrent: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
|
|
|
{
|
2008-12-07 18:20:14 +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
|
|
|
{
|
|
|
|
fTorrent = torrent;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fFileList setArray:fTorrent.fileList];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-12-07 18:20:14 +00:00
|
|
|
fFilterText = nil;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
[fOutline reloadData];
|
2021-08-15 09:41:48 +00:00
|
|
|
[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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray* components = [text betterComponentsSeparatedByCharactersInSet: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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if ((!text && !fFilterText) || (text && fFilterText && [text isEqualToString:fFilterText]))
|
|
|
|
{
|
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
|
|
|
|
|
|
|
[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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
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)
|
|
|
|
{
|
2021-08-15 09:41:48 +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
|
|
|
}
|
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 ?
|
|
|
|
[self findFileNode:item inList:fFileList
|
|
|
|
atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(currentIndex, fFileList.count - currentIndex)]
|
|
|
|
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
|
|
|
{
|
|
|
|
[fFileList moveObjectAtIndex:previousIndex toIndex:currentIndex];
|
|
|
|
}
|
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
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[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
|
|
|
{
|
|
|
|
[fOutline moveItemAtIndex:previousIndex inParent:parent toIndex:currentIndex inParent:nil];
|
|
|
|
}
|
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
|
2021-08-15 09:41:48 +00:00
|
|
|
if (currentIndex < fFileList.count)
|
2011-07-21 02:36:12 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRange const removeRange = NSMakeRange(currentIndex, fFileList.count - currentIndex);
|
|
|
|
[fFileList removeObjectsInRange:removeRange];
|
|
|
|
[fOutline removeItemsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:removeRange] inParent:nil
|
|
|
|
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
|
2021-08-15 09:41:48 +00:00
|
|
|
[fFileList insertObjects:itemsToAdd atIndexes:itemsToAddIndexes];
|
|
|
|
[fOutline insertItemsAtIndexes:itemsToAddIndexes inParent:nil withAnimation:NSTableViewAnimationSlideUp];
|
2016-01-06 11:05:37 +00:00
|
|
|
|
|
|
|
[fOutline endUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2017-07-29 16:14:22 +00:00
|
|
|
fFilterText = 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
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
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
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
return fFileList ? 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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
return (item ? ((FileListNode*)item).children : 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"])
|
|
|
|
{
|
|
|
|
return @([fTorrent checkForFiles:((FileListNode*)item).indexes]);
|
|
|
|
}
|
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"])
|
|
|
|
{
|
|
|
|
[cell setEnabled:[fTorrent canChangeDownloadCheckForFiles:((FileListNode*)item).indexes]];
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger hoveredRow = fOutline.hoveredRow;
|
2021-08-15 09:41:48 +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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, fTorrent.fileCount)];
|
|
|
|
}
|
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
|
|
|
|
2021-10-31 15:18:27 +00:00
|
|
|
[fTorrent setFileCheckState:[object intValue] != NSControlStateValueOff ? NSControlStateValueOn
|
|
|
|
: NSControlStateValueOff
|
|
|
|
forIndexes:indexSet];
|
2021-08-07 07:27:56 +00:00
|
|
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* path = [fTorrent fileLocation:item];
|
|
|
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSet* priorities = [fTorrent 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)
|
|
|
|
{
|
2008-01-04 00:29:13 +00:00
|
|
|
return ROW_SMALL_HEIGHT;
|
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
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
NSInteger state = [sender tag] == FILE_UNCHECK_TAG ? NSControlStateValueOff : NSControlStateValueOn;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* indexSet = fOutline.selectedRowIndexes;
|
|
|
|
NSMutableIndexSet* itemIndexes = [NSMutableIndexSet indexSet];
|
|
|
|
for (NSInteger i = indexSet.firstIndex; i != NSNotFound; i = [indexSet indexGreaterThanIndex:i])
|
2021-08-07 07:27:56 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
FileListNode* item = [fOutline itemAtRow:i];
|
|
|
|
[itemIndexes addIndexes:item.indexes];
|
2021-08-07 07:27:56 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fTorrent setFileCheckState:state forIndexes:itemIndexes];
|
2021-08-07 07:27:56 +00:00
|
|
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* indexSet = fOutline.selectedRowIndexes;
|
|
|
|
NSMutableIndexSet* itemIndexes = [NSMutableIndexSet indexSet];
|
|
|
|
for (NSInteger i = indexSet.firstIndex; i != NSNotFound; i = [indexSet indexGreaterThanIndex:i])
|
2021-08-07 07:27:56 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
FileListNode* item = [fOutline itemAtRow:i];
|
|
|
|
[itemIndexes addIndexes:item.indexes];
|
2021-08-07 07:27:56 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-10-31 15:18:27 +00:00
|
|
|
[fTorrent setFileCheckState:NSControlStateValueOn forIndexes:itemIndexes];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableIndexSet* remainingItemIndexes = [NSMutableIndexSet indexSetWithIndexesInRange:NSMakeRange(0, fTorrent.fileCount)];
|
|
|
|
[remainingItemIndexes removeIndexes:itemIndexes];
|
2021-10-31 15:18:27 +00:00
|
|
|
[fTorrent setFileCheckState:NSControlStateValueOff forIndexes:remainingItemIndexes];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, fTorrent.fileCount)];
|
2021-10-31 15:18:27 +00:00
|
|
|
[fTorrent setFileCheckState:NSControlStateValueOn forIndexes:indexSet];
|
2021-08-07 07:27:56 +00:00
|
|
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, fTorrent.fileCount)];
|
2021-10-31 15:18:27 +00:00
|
|
|
[fTorrent setFileCheckState:NSControlStateValueOff forIndexes:indexSet];
|
2021-08-07 07:27:56 +00:00
|
|
|
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])
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
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-06 05:13:38 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* indexSet = fOutline.selectedRowIndexes;
|
|
|
|
NSMutableIndexSet* itemIndexes = [NSMutableIndexSet indexSet];
|
|
|
|
for (NSInteger i = indexSet.firstIndex; i != NSNotFound; i = [indexSet indexGreaterThanIndex:i])
|
2021-08-07 07:27:56 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
FileListNode* item = [fOutline itemAtRow:i];
|
|
|
|
[itemIndexes addIndexes:item.indexes];
|
2021-08-07 07:27:56 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fTorrent setFilePriority:priority forIndexes:itemIndexes];
|
2021-08-07 07:27:56 +00:00
|
|
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* indexes = fOutline.selectedRowIndexes;
|
|
|
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* path = [fTorrent fileLocation:[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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* indexes = 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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
FileListNode* node = [fOutline itemAtRow:indexes.firstIndex];
|
|
|
|
Torrent* torrent = node.torrent;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!torrent.folder)
|
2013-01-22 00:09:48 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[FileRenameSheetController presentSheetForTorrent:torrent modalForWindow:fOutline.window completionHandler:^(BOOL didRename) {
|
2013-01-22 00:09:48 +00:00
|
|
|
if (didRename)
|
2013-01-22 03:54:51 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateQueue" object:self];
|
|
|
|
[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
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[FileRenameSheetController presentSheetForFileListNode:node modalForWindow:fOutline.window completionHandler:^(BOOL didRename) {
|
|
|
|
#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
|
|
|
{
|
|
|
|
if (!fTorrent)
|
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:))
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* indexSet = fOutline.selectedRowIndexes;
|
|
|
|
for (NSInteger i = indexSet.firstIndex; i != NSNotFound; i = [indexSet indexGreaterThanIndex:i])
|
|
|
|
{
|
|
|
|
if ([fTorrent fileLocation:[fOutline itemAtRow:i]] != nil)
|
|
|
|
{
|
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:))
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* indexSet = fOutline.selectedRowIndexes;
|
|
|
|
NSMutableIndexSet* itemIndexes = [NSMutableIndexSet indexSet];
|
|
|
|
for (NSInteger i = indexSet.firstIndex; i != NSNotFound; i = [indexSet indexGreaterThanIndex:i])
|
2021-08-07 07:27:56 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
FileListNode* node = [fOutline itemAtRow:i];
|
|
|
|
[itemIndexes addIndexes:node.indexes];
|
2021-08-07 07:27:56 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-10-31 15:18:27 +00:00
|
|
|
NSInteger state = (menuItem.tag == FILE_CHECK_TAG) ? NSControlStateValueOn : NSControlStateValueOff;
|
2021-08-15 09:41:48 +00:00
|
|
|
return [fTorrent checkForFiles:itemIndexes] != state && [fTorrent 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:))
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* indexSet = fOutline.selectedRowIndexes;
|
|
|
|
NSMutableIndexSet* itemIndexes = [NSMutableIndexSet indexSet];
|
|
|
|
for (NSInteger i = indexSet.firstIndex; i != NSNotFound; i = [indexSet indexGreaterThanIndex:i])
|
2021-08-07 07:27:56 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
FileListNode* node = [fOutline itemAtRow:i];
|
|
|
|
[itemIndexes addIndexes:node.indexes];
|
2021-08-07 07:27:56 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
return [fTorrent 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:))
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (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
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* indexSet = 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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
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;
|
|
|
|
break;
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
FileListNode* node = [fOutline itemAtRow:i];
|
|
|
|
NSIndexSet* fileIndexSet = node.indexes;
|
|
|
|
if (![fTorrent canChangeDownloadCheckForFiles:fileIndexSet])
|
|
|
|
{
|
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;
|
2021-08-15 09:41:48 +00:00
|
|
|
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
|
|
|
}
|
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:))
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
return 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2008-01-06 05:13:38 +00:00
|
|
|
|
|
|
|
@implementation FileOutlineController (Private)
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSMenu*)menu
|
2008-01-06 05:13:38 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMenu* menu = [[NSMenu alloc] initWithTitle:@"File Outline Menu"];
|
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;
|
|
|
|
item.tag = FILE_CHECK_TAG;
|
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;
|
|
|
|
item.tag = FILE_UNCHECK_TAG;
|
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:@""];
|
|
|
|
NSMenu* priorityMenu = [[NSMenu alloc] initWithTitle:@"File Priority Menu"];
|
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;
|
|
|
|
item.tag = FILE_PRIORITY_HIGH_TAG;
|
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;
|
|
|
|
item.tag = FILE_PRIORITY_NORMAL_TAG;
|
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;
|
|
|
|
item.tag = FILE_PRIORITY_LOW_TAG;
|
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
|
|
|
|
inList:(NSArray*)list
|
|
|
|
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
|
|
|
|
2012-01-08 05:05:47 +00:00
|
|
|
__block NSUInteger retIndex = NSNotFound;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[list enumerateObjectsAtIndexes:indexes options:NSEnumerationConcurrent
|
|
|
|
usingBlock:^(FileListNode* checkNode, NSUInteger index, BOOL* stop) {
|
|
|
|
if ([checkNode.indexes containsIndex:node.indexes.firstIndex])
|
|
|
|
{
|
|
|
|
if (!checkNode.isFolder)
|
|
|
|
{
|
|
|
|
NSAssert2([checkNode isEqualTo:node], @"Expected file nodes to be equal: %@ %@", checkNode, node);
|
|
|
|
|
|
|
|
*parent = currentParent;
|
|
|
|
retIndex = index;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSUInteger const 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
*stop = YES;
|
|
|
|
}
|
|
|
|
}];
|
2017-01-24 17:53:16 +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
|