1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00

Multiple selection

This commit is contained in:
Eric Petit 2006-04-07 13:09:19 +00:00
parent b9a53769f9
commit 55295baf13
5 changed files with 169 additions and 130 deletions

View file

@ -88,26 +88,26 @@
contextInfo: (void *) info;
- (void) quitSheetDidEnd: (NSWindow *)sheet returnCode:(int)returnCode
contextInfo:(void *)contextInfo;
contextInfo:(void *)contextInfo;
- (void) stopTorrent: (id) sender;
- (void) stopAllTorrents: (id) sender;
- (void) stopTorrentWithIndex: (int) index;
- (void) resumeTorrent: (id) sender;
- (void) resumeAllTorrents: (id) sender;
- (void) resumeTorrentWithIndex: (int) index;
- (void) resumeTorrentWithIndex: (NSIndexSet *) indexSet;
- (void) stopTorrent: (id) sender;
- (void) stopAllTorrents: (id) sender;
- (void) stopTorrentWithIndex: (NSIndexSet *) indexSet;
- (void) removeTorrent: (id) sender;
- (void) removeTorrentDeleteFile: (id) sender;
- (void) removeTorrentDeleteData: (id) sender;
- (void) removeTorrentDeleteBoth: (id) sender;
- (void) removeTorrentWithIndex: (int) idx
- (void) removeTorrentWithIndex: (NSIndexSet *) indexSet
deleteTorrent: (BOOL) deleteTorrent
deleteData: (BOOL) deleteData;
- (void) removeSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode
contextInfo:(NSDictionary *)dict;
- (void) confirmRemoveTorrentWithIndex: (int) idx
contextInfo:(NSDictionary *)dict;
- (void) confirmRemoveTorrentWithIndex: (NSIndexSet *) indexSet
deleteTorrent: (BOOL) deleteTorrent
deleteData: (BOOL) deleteData;

View file

@ -398,91 +398,116 @@ static void sleepCallBack( void * controller, io_service_t y,
- (void) resumeTorrent: (id) sender
{
[self resumeTorrentWithIndex: [fTableView selectedRow]];
[self resumeTorrentWithIndex: [fTableView selectedRowIndexes]];
}
- (void) resumeAllTorrents: (id) sender
{
Torrent * torrent;
NSEnumerator * enumerator = [fTorrents objectEnumerator];
while( ( torrent = [enumerator nextObject] ) )
{
[torrent start];
}
[self updateUI: nil];
[self updateTorrentHistory];
[self resumeTorrentWithIndex: [NSIndexSet indexSetWithIndexesInRange:
NSMakeRange(0, [fTorrents count])]];
}
- (void) resumeTorrentWithIndex: (int) idx
- (void) resumeTorrentWithIndex: (NSIndexSet *) indexSet
{
Torrent * torrent = [fTorrents objectAtIndex: idx];
[torrent start];
Torrent * torrent;
unsigned int i;
for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
{
torrent = [fTorrents objectAtIndex: i];
[torrent start];
}
[self updateUI: nil];
[self updateTorrentHistory];
}
- (void) stopTorrent: (id) sender
{
[self stopTorrentWithIndex: [fTableView selectedRow]];
[self stopTorrentWithIndex: [fTableView selectedRowIndexes]];
}
- (void) stopAllTorrents: (id) sender
{
Torrent * torrent;
NSEnumerator * enumerator = [fTorrents objectEnumerator];
while( ( torrent = [enumerator nextObject] ) )
{
[torrent stop];
}
[self updateUI: nil];
[self updateTorrentHistory];
[self stopTorrentWithIndex: [NSIndexSet indexSetWithIndexesInRange:
NSMakeRange(0, [fTorrents count])]];
}
- (void) stopTorrentWithIndex: (int) idx
- (void) stopTorrentWithIndex: (NSIndexSet *) indexSet
{
Torrent * torrent = [fTorrents objectAtIndex: idx];
[torrent stop];
Torrent * torrent;
unsigned int i;
for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
{
torrent = [fTorrents objectAtIndex: i];
[torrent stop];
}
[self updateUI: nil];
[self updateTorrentHistory];
}
- (void) removeTorrentWithIndex: (int) idx
- (void) removeTorrentWithIndex: (NSIndexSet *) indexSet
deleteTorrent: (BOOL) deleteTorrent
deleteData: (BOOL) deleteData
{
Torrent * torrent = [fTorrents objectAtIndex: idx];
int active = 0;
unsigned int i;
for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
if ([[fTorrents objectAtIndex: i] isActive])
active++;
if( [torrent isActive] && [fDefaults boolForKey: @"CheckRemove"] )
if( active > 0 && [fDefaults boolForKey: @"CheckRemove"] )
{
NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: idx], @"Index",
[fTableView selectedRowIndexes], @"Index",
[NSNumber numberWithBool: deleteTorrent], @"DeleteTorrent",
[NSNumber numberWithBool: deleteData], @"DeleteData",
nil];
[dict retain];
NSBeginAlertSheet(@"Confirm Remove",
NSString * title, * message;
int selected = [fTableView numberOfSelectedRows];
if (selected == 1)
{
title = [NSString stringWithFormat: @"Comfirm Removal of %@",
[[fTorrents objectAtIndex: [fTableView selectedRow]] name]];
message = @"This torrent is active. Do you really want to remove it?";
}
else
{
title = [NSString stringWithFormat: @"Comfirm Removal of %d Torrents", active];
if (selected == active)
message = [NSString stringWithFormat:
@"There are %d active torrents. Do you really want to remove them?", active];
else
message = [NSString stringWithFormat:
@"There are %d torrents (%d active). Do you really want to remove them?", selected, active];
}
NSBeginAlertSheet(title,
@"Remove", @"Cancel", nil, fWindow, self,
@selector(removeSheetDidEnd:returnCode:contextInfo:), NULL, dict,
@"This torrent is active. Do you really want to remove it?");
@selector(removeSheetDidEnd:returnCode:contextInfo:),
nil, dict, message);
}
else
{
[self confirmRemoveTorrentWithIndex: idx
[self confirmRemoveTorrentWithIndex: indexSet
deleteTorrent: deleteTorrent
deleteData: deleteData];
}
}
- (void) removeSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode
contextInfo:(NSDictionary *)dict
contextInfo:(NSDictionary *)dict
{
[NSApp stopModal];
if( returnCode == NSAlertDefaultReturn )
{
[self confirmRemoveTorrentWithIndex:
[[dict objectForKey:@"Index"] intValue]
[self confirmRemoveTorrentWithIndex: [dict objectForKey:@"Index"]
deleteTorrent: [[dict objectForKey:@"DeleteTorrent"] boolValue]
deleteData: [[dict objectForKey:@"DeleteData"] boolValue]];
}
@ -490,26 +515,28 @@ static void sleepCallBack( void * controller, io_service_t y,
[dict release];
}
- (void) confirmRemoveTorrentWithIndex: (int) idx
- (void) confirmRemoveTorrentWithIndex: (NSIndexSet *) indexSet
deleteTorrent: (BOOL) deleteTorrent
deleteData: (BOOL) deleteData
{
Torrent * torrent = [fTorrents objectAtIndex: idx];
Torrent * torrent;
unsigned int i;
/* Pause if not paused already */
[torrent stop];
for (i = [indexSet lastIndex]; i != NSNotFound; i = [indexSet indexLessThanIndex: i])
{
torrent = [fTorrents objectAtIndex: i];
if( deleteData )
{
[torrent trashData];
}
if( deleteTorrent )
{
[torrent trashTorrent];
}
[torrent stop];
[fTorrents removeObject: torrent];
[torrent release];
if( deleteData )
[torrent trashData];
if( deleteTorrent )
[torrent trashTorrent];
[fTorrents removeObject: torrent];
[torrent release];
}
[self updateUI: nil];
[self updateTorrentHistory];
@ -517,22 +544,22 @@ static void sleepCallBack( void * controller, io_service_t y,
- (void) removeTorrent: (id) sender
{
[self removeTorrentWithIndex: [fTableView selectedRow] deleteTorrent: NO deleteData: NO ];
[self removeTorrentWithIndex: [fTableView selectedRowIndexes] deleteTorrent: NO deleteData: NO ];
}
- (void) removeTorrentDeleteFile: (id) sender
{
[self removeTorrentWithIndex: [fTableView selectedRow] deleteTorrent: YES deleteData: NO];
[self removeTorrentWithIndex: [fTableView selectedRowIndexes] deleteTorrent: YES deleteData: NO];
}
- (void) removeTorrentDeleteData: (id) sender
{
[self removeTorrentWithIndex: [fTableView selectedRow] deleteTorrent: NO deleteData: YES];
[self removeTorrentWithIndex: [fTableView selectedRowIndexes] deleteTorrent: NO deleteData: YES];
}
- (void) removeTorrentDeleteBoth: (id) sender
{
[self removeTorrentWithIndex: [fTableView selectedRow] deleteTorrent: YES deleteData: YES];
[self removeTorrentWithIndex: [fTableView selectedRowIndexes] deleteTorrent: YES deleteData: YES];
}
- (void) showInfo: (id) sender
@ -549,12 +576,16 @@ static void sleepCallBack( void * controller, io_service_t y,
- (void) updateInfoPanel
{
int row = [fTableView selectedRow];
if( row < 0 )
int numberSelected = [fTableView numberOfSelectedRows];
if( numberSelected != 1 )
{
[fInfoImageView setImage: fAppIcon];
[fInfoName setStringValue: @"No Torrent Selected"];
[fInfoName setStringValue: numberSelected == 0
? @"No Torrent Selected"
: [[NSString stringWithInt: numberSelected]
stringByAppendingString: @" Torrents Selected"]];
[fInfoSize setStringValue: @""];
[fInfoTracker setStringValue: @""];
[fInfoAnnounce setStringValue: @""];
@ -569,6 +600,8 @@ static void sleepCallBack( void * controller, io_service_t y,
return;
}
int row = [fTableView selectedRow];
Torrent * torrent = [fTorrents objectAtIndex: row];
[fInfoImageView setImage: [torrent iconNonFlipped]];
[fInfoName setStringValue: [torrent name]];
@ -663,14 +696,13 @@ static void sleepCallBack( void * controller, io_service_t y,
return nil;
}
- (void) tableView: (NSTableView *) t willDisplayCell: (id) cell
forTableColumn: (NSTableColumn *) tableColumn row: (int) rowIndex
{
[cell setTorrent: [fTorrents objectAtIndex: rowIndex]];
if( OSX_VERSION >= 10.3 && [fWindow isKeyWindow] &&
rowIndex == [fTableView selectedRow] )
[fTableView isRowSelected: rowIndex] )
[cell setTextColor: [NSColor whiteColor]];
else
[cell setTextColor: [NSColor blackColor]];
@ -761,7 +793,7 @@ static void sleepCallBack( void * controller, io_service_t y,
else
{
[item release];
return NULL;
return nil;
}
return item;
@ -807,7 +839,7 @@ static void sleepCallBack( void * controller, io_service_t y,
//enable remove item
if (action == @selector(removeTorrent:))
return [fTableView selectedRow] >= 0;
return [fTableView numberOfSelectedRows] > 0;
Torrent * torrent;
NSEnumerator * enumerator;
@ -857,13 +889,11 @@ static void sleepCallBack( void * controller, io_service_t y,
return YES;
}
Torrent * torrent;
NSEnumerator * enumerator;
//enable resume all item
if (action == @selector(resumeAllTorrents:))
{
enumerator = [fTorrents objectEnumerator];
Torrent * torrent;
NSEnumerator * enumerator = [fTorrents objectEnumerator];
while( ( torrent = [enumerator nextObject] ) )
if( [torrent isPaused] )
return YES;
@ -873,19 +903,17 @@ static void sleepCallBack( void * controller, io_service_t y,
//enable pause all item
if (action == @selector(stopAllTorrents:))
{
enumerator = [fTorrents objectEnumerator];
Torrent * torrent;
NSEnumerator * enumerator = [fTorrents objectEnumerator];
while( ( torrent = [enumerator nextObject] ) )
if( [torrent isActive] )
return YES;
return NO;
}
int row = [fTableView selectedRow];
torrent = ( row < 0 ) ? nil : [fTorrents objectAtIndex: row];
if (action == @selector(revealFromMenu:))
{
return ( torrent != nil );
return [fTableView numberOfSelectedRows] > 0;
}
//enable remove items
@ -894,9 +922,23 @@ static void sleepCallBack( void * controller, io_service_t y,
|| action == @selector(removeTorrentDeleteData:)
|| action == @selector(removeTorrentDeleteBoth:))
{
BOOL active = NO;
Torrent * torrent;
NSIndexSet * indexSet = [fTableView selectedRowIndexes];
unsigned int i;
for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
{
torrent = [fTorrents objectAtIndex: i];
if ([torrent isActive])
{
active = YES;
break;
}
}
//append or remove ellipsis when needed
if( torrent && [torrent isActive] &&
[fDefaults boolForKey: @"CheckRemove"] )
if( active && [fDefaults boolForKey: @"CheckRemove"] )
{
if (![[menuItem title] hasSuffix:NS_ELLIPSIS])
[menuItem setTitle:[[menuItem title] stringByAppendingString:NS_ELLIPSIS]];
@ -906,24 +948,39 @@ static void sleepCallBack( void * controller, io_service_t y,
if ([[menuItem title] hasSuffix:NS_ELLIPSIS])
[menuItem setTitle:[[menuItem title] substringToIndex:[[menuItem title] length]-[NS_ELLIPSIS length]]];
}
return ( torrent != nil );
return [fTableView numberOfSelectedRows] > 0;
}
//enable and change pause / remove item
if( action == @selector(resumeTorrent:) ||
action == @selector(stopTorrent:) )
//enable pause item
if( action == @selector(stopTorrent:) )
{
if( !torrent || [torrent isActive] )
{
[menuItem setTitle: @"Pause"];
[menuItem setAction: @selector( stopTorrent: )];
}
else
{
[menuItem setTitle: @"Resume"];
[menuItem setAction: @selector( resumeTorrent: )];
}
return ( torrent != nil );
Torrent * torrent;
NSIndexSet * indexSet = [fTableView selectedRowIndexes];
unsigned int i;
for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
{
torrent = [fTorrents objectAtIndex: i];
if ([torrent isActive])
return YES;
}
return NO;
}
//enable resume item
if( action == @selector(resumeTorrent:) )
{
Torrent * torrent;
NSIndexSet * indexSet = [fTableView selectedRowIndexes];
unsigned int i;
for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
{
torrent = [fTorrents objectAtIndex: i];
if ([torrent isPaused])
return YES;
}
return NO;
}
return YES;

View file

@ -7,7 +7,7 @@
<key>IBEditorPositions</key>
<dict>
<key>29</key>
<string>92 768 371 44 0 0 1280 832 </string>
<string>79 778 371 44 0 0 1152 842 </string>
<key>456</key>
<string>212 488 144 118 0 0 1152 842 </string>
<key>581</key>
@ -27,7 +27,7 @@
<integer>3</integer>
<key>IBOpenObjects</key>
<array>
<integer>273</integer>
<integer>21</integer>
</array>
<key>IBSystem Version</key>
<string>8I127</string>

Binary file not shown.

View file

@ -32,21 +32,6 @@
fTorrents = torrents;
}
- (void) pauseOrResume: (int) row
{
Torrent * torrent = [fTorrents objectAtIndex: row];
if( [torrent isPaused] )
{
[fController resumeTorrentWithIndex: row];
}
else if( [torrent isActive] )
{
[fController stopTorrentWithIndex: row];
}
else;
}
- (NSRect) pauseRectForRow: (int) row
{
int col;
@ -99,18 +84,7 @@
else if( ![self pointInPauseRect: fClickPoint] &&
![self pointInRevealRect: fClickPoint] )
{
if( row >= 0 )
{
if( OSX_VERSION >= 10.3 )
[self selectRowIndexes: [NSIndexSet indexSetWithIndex: row]
byExtendingSelection: NO];
else
[self selectRow: row byExtendingSelection: NO];
}
else
{
[self deselectAll: self];
}
[super mouseDown: e];
}
else;
@ -131,7 +105,13 @@
if( sameRow && [self pointInPauseRect: point]
&& [self pointInPauseRect: fClickPoint] )
{
[self pauseOrResume: row];
torrent = [fTorrents objectAtIndex: row];
if( [torrent isPaused] )
[fController resumeTorrentWithIndex: [NSIndexSet indexSetWithIndex: row]];
else if( [torrent isActive] )
[fController stopTorrentWithIndex: [NSIndexSet indexSetWithIndex: row]];
else;
}
else if( sameRow && [self pointInRevealRect: point]
&& [self pointInRevealRect: fClickPoint] )
@ -139,7 +119,9 @@
torrent = [fTorrents objectAtIndex: row];
[torrent reveal];
}
else;
else;
[super mouseUp: e];
fClickPoint = NSMakePoint( 0, 0 );
[self display];
@ -157,9 +139,9 @@
{
if( OSX_VERSION >= 10.3 )
[self selectRowIndexes: [NSIndexSet indexSetWithIndex: row]
byExtendingSelection: NO];
byExtendingSelection: [self isRowSelected: row]];
else
[self selectRow: row byExtendingSelection: NO];
[self selectRow: row byExtendingSelection: [self isRowSelected: row]];
return fContextRow;
}
else