first go at using an outline view for files....what a pain parsing the file names
This commit is contained in:
parent
348f35f505
commit
b7e3c9af5a
|
@ -37,7 +37,7 @@
|
|||
fDownloadedValidField = NSTextField;
|
||||
fDownloadingFromField = NSTextField;
|
||||
fErrorMessageView = NSTextView;
|
||||
fFileTable = NSTableView;
|
||||
fFileOutline = NSOutlineView;
|
||||
fFileTableStatusField = NSTextField;
|
||||
fHashField = NSTextField;
|
||||
fImageView = NSImageView;
|
||||
|
|
Binary file not shown.
|
@ -53,7 +53,7 @@
|
|||
IBOutlet NSTextView * fErrorMessageView;
|
||||
IBOutlet PiecesView * fPiecesView;
|
||||
|
||||
IBOutlet NSTableView * fFileTable;
|
||||
IBOutlet NSOutlineView * fFileOutline;
|
||||
IBOutlet NSTextField * fFileTableStatusField;
|
||||
|
||||
IBOutlet NSButton * fRatioCustomCheck, * fRatioStopCheck,
|
||||
|
|
|
@ -70,8 +70,6 @@
|
|||
|
||||
- (void) awakeFromNib
|
||||
{
|
||||
[fFileTable setDoubleAction: @selector(revealFile:)];
|
||||
|
||||
//window location and size
|
||||
NSPanel * window = (NSPanel *)[self window];
|
||||
|
||||
|
@ -93,6 +91,12 @@
|
|||
[fPeerTable setSortDescriptors: [NSArray arrayWithObject: [[fPeerTable tableColumnWithIdentifier: @"IP"]
|
||||
sortDescriptorPrototype]]];
|
||||
|
||||
//set file table
|
||||
NSBrowserCell * browserCell = [[[NSBrowserCell alloc] init] autorelease];
|
||||
[browserCell setLeaf: YES];
|
||||
[[fFileOutline tableColumnWithIdentifier: @"Name"] setDataCell: browserCell];
|
||||
[fFileOutline setDoubleAction: @selector(revealFile:)];
|
||||
|
||||
[self updateInfoForTorrents: [NSArray array]];
|
||||
}
|
||||
|
||||
|
@ -254,11 +258,12 @@
|
|||
[fPiecesView setTorrent: torrent];
|
||||
|
||||
//set file table
|
||||
[fFileTable deselectAll: nil];
|
||||
[fFileOutline deselectAll: nil];
|
||||
if (fFiles)
|
||||
[fFiles release];
|
||||
fFiles = [[torrent fileList] retain];
|
||||
|
||||
#warning change!
|
||||
if ([fFiles count] > 1)
|
||||
[fFileTableStatusField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%d files",
|
||||
"Inspector -> Files tab -> bottom text (number of files)"), [fFiles count]]];
|
||||
|
@ -272,7 +277,7 @@
|
|||
[self updateInfoSettings];
|
||||
|
||||
[fPeerTable reloadData];
|
||||
[fFileTable reloadData];
|
||||
[fFileOutline reloadData];
|
||||
}
|
||||
|
||||
- (void) updateInfoStats
|
||||
|
@ -505,7 +510,7 @@
|
|||
SEL action = [menuItem action];
|
||||
|
||||
if (action == @selector(revealFile:))
|
||||
return [fFileTable numberOfSelectedRows] > 0 &&
|
||||
return [fFileOutline numberOfSelectedRows] > 0 &&
|
||||
[[[fTabView selectedTabViewItem] identifier] isEqualToString: TAB_FILES_IDENT];
|
||||
|
||||
return YES;
|
||||
|
@ -585,15 +590,14 @@
|
|||
{
|
||||
if (tableView == fPeerTable)
|
||||
return fPeers ? [fPeers count] : 0;
|
||||
else
|
||||
return fFiles ? [fFiles count] : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (id) tableView: (NSTableView *) tableView objectValueForTableColumn: (NSTableColumn *) column row: (int) row
|
||||
{
|
||||
NSString * ident = [column identifier];
|
||||
if (tableView == fPeerTable)
|
||||
{
|
||||
NSString * ident = [column identifier];
|
||||
NSDictionary * peer = [fPeers objectAtIndex: row];
|
||||
|
||||
if ([ident isEqualToString: @"Connected"])
|
||||
|
@ -611,16 +615,7 @@
|
|||
else
|
||||
return [peer objectForKey: @"IP"];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSDictionary * file = [fFiles objectAtIndex: row];
|
||||
if ([ident isEqualToString: @"Icon"])
|
||||
return [[NSWorkspace sharedWorkspace] iconForFileType: [[file objectForKey: @"Name"] pathExtension]];
|
||||
else if ([ident isEqualToString: @"Size"])
|
||||
return [NSString stringForFileSize: [[file objectForKey: @"Size"] unsignedLongLongValue]];
|
||||
else
|
||||
return [file objectForKey: @"Name"];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void) tableView: (NSTableView *) tableView didClickTableColumn: (NSTableColumn *) tableColumn
|
||||
|
@ -646,16 +641,8 @@
|
|||
rect: (NSRectPointer) rect tableColumn: (NSTableColumn *) column
|
||||
row: (int) row mouseLocation: (NSPoint) mouseLocation
|
||||
{
|
||||
if (tableView == fFileTable)
|
||||
{
|
||||
NSDictionary * file = [fFiles objectAtIndex: row];
|
||||
if ([[column identifier] isEqualToString: @"Size"])
|
||||
return [[[file objectForKey: @"Size"] stringValue] stringByAppendingString: NSLocalizedString(@" bytes",
|
||||
"Inspector -> Files tab -> table row tooltip")];
|
||||
else
|
||||
return [file objectForKey: @"Name"];
|
||||
}
|
||||
else if (tableView == fPeerTable)
|
||||
#warning tooltip for file table?
|
||||
if (tableView == fPeerTable)
|
||||
{
|
||||
NSDictionary * peerDic = [fPeers objectAtIndex: row];
|
||||
return [NSString stringWithFormat: NSLocalizedString(@"Progress: %.1f%%"
|
||||
|
@ -667,8 +654,41 @@
|
|||
? NSLocalizedString(@"incoming", "Inspector -> Peers tab -> table row tooltip")
|
||||
: NSLocalizedString(@"outgoing", "Inspector -> Peers tab -> table row tooltip")];
|
||||
}
|
||||
else
|
||||
return nil;
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (int) outlineView: (NSOutlineView *) outlineView numberOfChildrenOfItem: (id) item
|
||||
{
|
||||
if (!item)
|
||||
return [fFiles count];
|
||||
return [[item objectForKey: @"IsFolder"] boolValue] ? [[item objectForKey: @"Children"] count] : 0;
|
||||
}
|
||||
|
||||
- (BOOL) outlineView: (NSOutlineView *) outlineView isItemExpandable: (id) item
|
||||
{
|
||||
return [[item objectForKey: @"IsFolder"] boolValue];
|
||||
}
|
||||
|
||||
- (id) outlineView: (NSOutlineView *) outlineView child: (int) index ofItem: (id) item
|
||||
{
|
||||
return [(item ? [item objectForKey: @"Children"] : fFiles) objectAtIndex: index];
|
||||
}
|
||||
|
||||
- (id) outlineView: (NSOutlineView *) outlineView objectValueForTableColumn: (NSTableColumn *) tableColumn
|
||||
byItem: (id) item
|
||||
{
|
||||
NSString * ident = [tableColumn identifier];
|
||||
return [item objectForKey: @"Name"];
|
||||
}
|
||||
|
||||
- (void) outlineView: (NSOutlineView *) outlineView willDisplayCell: (id) cell
|
||||
forTableColumn: (NSTableColumn *) tableColumn item:(id) item
|
||||
{
|
||||
NSImage * icon = [[NSWorkspace sharedWorkspace] iconForFileType: ![[item objectForKey: @"IsFolder"] boolValue]
|
||||
? [[item objectForKey: @"Name"] pathExtension] : NSFileTypeForHFSTypeCode('fldr')];
|
||||
[icon setScalesWhenResized: YES];
|
||||
[icon setSize: NSMakeSize(16.0, 16.0)];
|
||||
[cell setImage: icon];
|
||||
}
|
||||
|
||||
- (NSArray *) peerSortDescriptors
|
||||
|
@ -698,12 +718,16 @@
|
|||
|
||||
- (void) revealFile: (id) sender
|
||||
{
|
||||
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
||||
NSEnumerator * enumerator = [[fFiles objectsAtIndexes: [fFileTable selectedRowIndexes]] objectEnumerator];
|
||||
if (!fFiles)
|
||||
return;
|
||||
|
||||
#warning get working
|
||||
/*Torrent * torrent = [fTorrents objectAtIndex: 0];
|
||||
NSEnumerator * enumerator = [[fFiles objectsAtIndexes: [fFileOutline selectedRowIndexes]] objectEnumerator];
|
||||
NSDictionary * file;
|
||||
while ((file = [enumerator nextObject]))
|
||||
[[NSWorkspace sharedWorkspace] selectFile: [[torrent downloadFolder]
|
||||
stringByAppendingPathComponent: [file objectForKey: @"Name"]] inFileViewerRootedAtPath: nil];
|
||||
stringByAppendingPathComponent: [file objectForKey: @"Name"]] inFileViewerRootedAtPath: nil];*/
|
||||
}
|
||||
|
||||
- (void) setLimitCustom: (id) sender
|
||||
|
|
|
@ -43,8 +43,8 @@
|
|||
checkDownload: (NSNumber *) checkDownload downloadLimit: (NSNumber *) downloadLimit
|
||||
waitToStart: (NSNumber *) waitToStart orderValue: (NSNumber *) orderValue;
|
||||
|
||||
- (void) insertPath: (NSMutableArray *) components withParent: (NSMutableArray *) parent;
|
||||
- (NSImage *) advancedBar;
|
||||
|
||||
- (void) trashFile: (NSString *) path;
|
||||
|
||||
@end
|
||||
|
@ -1068,16 +1068,17 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
|
|||
{
|
||||
int count = fInfo->fileCount, i;
|
||||
tr_file_t file;
|
||||
NSMutableArray * files = [NSMutableArray arrayWithCapacity: count];
|
||||
NSMutableArray * files = [NSMutableArray array];
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
file = fInfo->files[i];
|
||||
[files addObject: [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
|
||||
[self insertPath: [[[NSString stringWithUTF8String: file.name] pathComponents] mutableCopy] withParent: files];
|
||||
/*[files addObject: [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSString stringWithUTF8String: file.name], @"Name",
|
||||
[NSNumber numberWithUnsignedLongLong: file.length], @"Size", nil]];
|
||||
[NSNumber numberWithUnsignedLongLong: file.length], @"Size", nil]];*/
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
|
@ -1204,6 +1205,39 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
|
|||
return self;
|
||||
}
|
||||
|
||||
- (void) insertPath: (NSMutableArray *) components withParent: (NSMutableArray *) parent
|
||||
{
|
||||
NSString * name = [components objectAtIndex: 0];
|
||||
BOOL isFolder = [components count] > 1;
|
||||
|
||||
NSMutableDictionary * dict = nil;
|
||||
if (isFolder)
|
||||
{
|
||||
NSEnumerator * enumerator = [parent objectEnumerator];
|
||||
while ((dict = [enumerator nextObject]))
|
||||
if ([[dict objectForKey: @"Name"] isEqualToString: name] && [[dict objectForKey: @"IsFolder"] boolValue])
|
||||
break;
|
||||
}
|
||||
|
||||
//create new folder or item if it doesn't already exist
|
||||
if (!dict)
|
||||
{
|
||||
#warning put size and full path here for item later
|
||||
dict = [NSMutableDictionary dictionaryWithObjectsAndKeys: name, @"Name",
|
||||
[NSNumber numberWithBool: isFolder], @"IsFolder", nil];
|
||||
if (isFolder)
|
||||
[dict setObject: [NSMutableArray array] forKey: @"Children"];
|
||||
|
||||
[parent addObject: dict];
|
||||
}
|
||||
|
||||
if (isFolder)
|
||||
{
|
||||
[components removeObjectAtIndex: 0];
|
||||
[self insertPath: components withParent: [dict objectForKey: @"Children"]];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSImage *) advancedBar
|
||||
{
|
||||
int h, w;
|
||||
|
|
Loading…
Reference in New Issue