diff --git a/macosx/English.lproj/InfoWindow.nib/keyedobjects.nib b/macosx/English.lproj/InfoWindow.nib/keyedobjects.nib index 4923d0d7d..992f51849 100644 Binary files a/macosx/English.lproj/InfoWindow.nib/keyedobjects.nib and b/macosx/English.lproj/InfoWindow.nib/keyedobjects.nib differ diff --git a/macosx/InfoWindowController.m b/macosx/InfoWindowController.m index 2b37dede8..790df0a56 100644 --- a/macosx/InfoWindowController.m +++ b/macosx/InfoWindowController.m @@ -53,6 +53,9 @@ - (void) setWindowForTab: (NSString *) identifier animate: (BOOL) animate; - (NSArray *) peerSortDescriptors; +- (void) setFileCheckState: (int) state forItem: (NSMutableDictionary *) item; +- (void) resetFileCheckStateForItem: (NSMutableDictionary *) item; + @end @implementation InfoWindowController @@ -676,21 +679,85 @@ if ([[tableColumn identifier] isEqualToString: @"Size"]) return ![[item objectForKey: @"IsFolder"] boolValue] ? [NSString stringForFileSize: [[item objectForKey: @"Size"] unsignedLongLongValue]] : @""; + else if ([[tableColumn identifier] isEqualToString: @"Check"]) + return [item objectForKey: @"Check"]; else return [item objectForKey: @"Name"]; } +- (void) outlineView: (NSOutlineView *) outlineView setObjectValue: (id) object + forTableColumn: (NSTableColumn *) tableColumn byItem: (id) item +{ + int state = [object intValue] != NSOffState; + + [self setFileCheckState: state forItem: item]; + [self resetFileCheckStateForItem: [item objectForKey: @"Parent"]]; + + [fFileOutline reloadData]; +} + +- (void) setFileCheckState: (int) state forItem: (NSMutableDictionary *) item +{ + [item setObject: [NSNumber numberWithInt: state] forKey: @"Check"]; + + if (![[item objectForKey: @"IsFolder"] boolValue]) + return; + + NSMutableDictionary * child; + NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator]; + while ((child = [enumerator nextObject])) + { + if ([[child objectForKey: @"Check"] intValue] != state) + [self setFileCheckState: state forItem: child]; + } +} + +- (void) resetFileCheckStateForItem: (NSMutableDictionary *) item +{ + if (!item) + return; + + int state = INVALID; + + NSMutableDictionary * child; + NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator]; + while ((child = [enumerator nextObject])) + { + if (state == INVALID) + { + state = [[child objectForKey: @"Check"] intValue]; + if (state == NSMixedState) + break; + } + else if (state != [[child objectForKey: @"Check"] intValue]) + { + state = NSMixedState; + break; + } + else; + } + + if ([[item objectForKey: @"Check"] intValue] != state) + { + [item setObject: [NSNumber numberWithInt: state] forKey: @"Check"]; + [self resetFileCheckStateForItem: [item objectForKey: @"Parent"]]; + } +} + - (void) outlineView: (NSOutlineView *) outlineView willDisplayCell: (id) cell forTableColumn: (NSTableColumn *) tableColumn item:(id) item { - if (![[tableColumn identifier] isEqualToString: @"Name"]) - return; - - 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]; + if ([[tableColumn identifier] isEqualToString: @"Name"]) + { + 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]; + } + else if ([[tableColumn identifier] isEqualToString: @"Check"]) + [cell setEnabled: NO]; + else; } - (NSString *) outlineView: (NSOutlineView *) outlineView toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 4fcf90b35..93bd37ff5 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -44,8 +44,8 @@ waitToStart: (NSNumber *) waitToStart orderValue: (NSNumber *) orderValue; - (NSArray *) createFileList; -- (void) insertPath: (NSMutableArray *) components withParent: (NSMutableArray *) parent - previousPath: (NSString *) previousPath fileSize: (uint64_t) size; +- (void) insertPath: (NSMutableArray *) components forSiblings: (NSMutableArray *) siblings + withParent: (NSMutableDictionary *) parent previousPath: (NSString *) previousPath fileSize: (uint64_t) size; - (NSImage *) advancedBar; - (void) trashFile: (NSString *) path; @@ -1109,7 +1109,6 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80 @end - @implementation Torrent (Private) //if a hash is given, attempt to load that; otherwise, attempt to open file at path @@ -1223,14 +1222,14 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80 else path = @""; - [self insertPath: pathComponents withParent: files previousPath: path fileSize: file->length]; + [self insertPath: pathComponents forSiblings: files withParent: nil previousPath: path fileSize: file->length]; [pathComponents autorelease]; } return files; } -- (void) insertPath: (NSMutableArray *) components withParent: (NSMutableArray *) parent - previousPath: (NSString *) previousPath fileSize: (uint64_t) size +- (void) insertPath: (NSMutableArray *) components forSiblings: (NSMutableArray *) siblings + withParent: (NSMutableDictionary *) parent previousPath: (NSString *) previousPath fileSize: (uint64_t) size { NSString * name = [components objectAtIndex: 0]; BOOL isFolder = [components count] > 1; @@ -1238,7 +1237,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80 NSMutableDictionary * dict = nil; if (isFolder) { - NSEnumerator * enumerator = [parent objectEnumerator]; + NSEnumerator * enumerator = [siblings objectEnumerator]; while ((dict = [enumerator nextObject])) if ([[dict objectForKey: @"Name"] isEqualToString: name] && [[dict objectForKey: @"IsFolder"] boolValue]) break; @@ -1257,13 +1256,18 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80 else [dict setObject: [NSNumber numberWithUnsignedLongLong: size] forKey: @"Size"]; - [parent addObject: dict]; + if (parent) + [dict setObject: parent forKey: @"Parent"]; + [dict setObject: [NSNumber numberWithInt: NSOnState] forKey: @"Check"]; + + [siblings addObject: dict]; } if (isFolder) { [components removeObjectAtIndex: 0]; - [self insertPath: components withParent: [dict objectForKey: @"Children"] previousPath: currentPath fileSize: size]; + [self insertPath: components forSiblings: [dict objectForKey: @"Children"] + withParent: dict previousPath: currentPath fileSize: size]; } }