add a menu item in the context menu to only check selected (and uncheck others)

This commit is contained in:
Mitchell Livingston 2007-06-21 22:36:01 +00:00
parent e161544761
commit f1a2fe0218
5 changed files with 34 additions and 11 deletions

View File

@ -9,6 +9,7 @@
revealTorrentFile = id; revealTorrentFile = id;
setCheck = id; setCheck = id;
setLimitSetting = id; setLimitSetting = id;
setOnlySelectedCheck = id;
setPex = id; setPex = id;
setPiecesView = id; setPiecesView = id;
setPriority = id; setPriority = id;

View File

@ -21,6 +21,7 @@
</array> </array>
<key>IBOpenObjects</key> <key>IBOpenObjects</key>
<array> <array>
<integer>549</integer>
<integer>5</integer> <integer>5</integer>
</array> </array>
<key>IBSystem Version</key> <key>IBSystem Version</key>

View File

@ -79,6 +79,7 @@
- (void) revealFile: (id) sender; - (void) revealFile: (id) sender;
- (void) setCheck: (id) sender; - (void) setCheck: (id) sender;
- (void) setOnlySelectedCheck: (id) sender;
- (void) setPriority: (id) sender; - (void) setPriority: (id) sender;
- (void) setLimitSetting: (id) sender; - (void) setLimitSetting: (id) sender;

View File

@ -600,6 +600,9 @@
- (BOOL) validateMenuItem: (NSMenuItem *) menuItem - (BOOL) validateMenuItem: (NSMenuItem *) menuItem
{ {
if ([fTorrents count] != 1)
return NO;
SEL action = [menuItem action]; SEL action = [menuItem action];
if (action == @selector(revealFile:)) if (action == @selector(revealFile:))
@ -626,6 +629,9 @@
return NO; return NO;
} }
if (action == @selector(setOnlySelectedCheck:))
return [fFileOutline selectedRow] != -1;
if (action == @selector(setPriority:)) if (action == @selector(setPriority:))
{ {
if ([fFileOutline numberOfSelectedRows] <= 0) if ([fFileOutline numberOfSelectedRows] <= 0)
@ -1022,18 +1028,30 @@
int state = sender == fFileCheckItem ? NSOnState : NSOffState; int state = sender == fFileCheckItem ? NSOnState : NSOffState;
Torrent * torrent = [fTorrents objectAtIndex: 0]; Torrent * torrent = [fTorrents objectAtIndex: 0];
NSIndexSet * indexSet = [fFileOutline selectedRowIndexes], * itemIndexes; NSIndexSet * indexSet = [fFileOutline selectedRowIndexes];
NSMutableIndexSet * usedIndexes = [NSMutableIndexSet indexSet]; NSMutableIndexSet * itemIndexes = [NSMutableIndexSet indexSet];
int i; int i;
for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i]) for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
{ [itemIndexes addIndexes: [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"]];
itemIndexes = [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"];
if (![usedIndexes containsIndexes: itemIndexes]) [torrent setFileCheckState: state forIndexes: itemIndexes];
{ [fFileOutline reloadData];
[torrent setFileCheckState: state forIndexes: itemIndexes]; }
[usedIndexes addIndexes: itemIndexes];
} - (void) setOnlySelectedCheck: (id) sender
} {
Torrent * torrent = [fTorrents objectAtIndex: 0];
NSIndexSet * indexSet = [fFileOutline selectedRowIndexes];
NSMutableIndexSet * itemIndexes = [NSMutableIndexSet indexSet];
int i;
for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
[itemIndexes addIndexes: [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"]];
[torrent setFileCheckState: NSOnState forIndexes: itemIndexes];
NSMutableIndexSet * remainingItemIndexes = [NSMutableIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [torrent fileCount])];
[remainingItemIndexes removeIndexes: indexSet];
[torrent setFileCheckState: NSOffState forIndexes: remainingItemIndexes];
[fFileOutline reloadData]; [fFileOutline reloadData];
} }
@ -1050,10 +1068,12 @@
Torrent * torrent = [fTorrents objectAtIndex: 0]; Torrent * torrent = [fTorrents objectAtIndex: 0];
NSIndexSet * indexSet = [fFileOutline selectedRowIndexes]; NSIndexSet * indexSet = [fFileOutline selectedRowIndexes];
NSMutableIndexSet * itemIndexes = [NSMutableIndexSet indexSet];
int i; int i;
for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i]) for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
[torrent setFilePriority: priority forIndexes: [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"]]; [itemIndexes addIndexes: [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"]];
[torrent setFilePriority: priority forIndexes: itemIndexes];
[fFileOutline reloadData]; [fFileOutline reloadData];
} }