mirror of
https://github.com/transmission/transmission.git
synced 2026-05-08 09:39:08 +01:00
simplify the code for moving rows in the groups table and fix a bug with disabled elements when adding a group when there are no previous groups
This commit is contained in:
@@ -53,7 +53,7 @@
|
||||
- (void) addNewGroup;
|
||||
- (void) removeGroupWithRowIndex: (NSInteger) row;
|
||||
|
||||
- (NSIndexSet *) moveGroupsAtRowIndexes: (NSIndexSet *) indexes toRow: (NSInteger) newRow oldSelected: (NSIndexSet *) selectedIndexes;
|
||||
- (void) moveGroupAtRow: (NSInteger) oldRow toRow: (NSInteger) newRow;
|
||||
|
||||
- (NSMenu *) groupMenuWithTarget: (id) target action: (SEL) action isSmall: (BOOL) small;
|
||||
|
||||
|
||||
@@ -243,39 +243,22 @@ GroupsController * fGroupsInstance = nil;
|
||||
[self saveGroups];
|
||||
}
|
||||
|
||||
#warning rework for single row?
|
||||
- (NSIndexSet *) moveGroupsAtRowIndexes: (NSIndexSet *) indexes toRow: (NSInteger) newRow oldSelected: (NSIndexSet *) selectedIndexes
|
||||
- (void) moveGroupAtRow: (NSInteger) oldRow toRow: (NSInteger) newRow
|
||||
{
|
||||
NSArray * selectedGroups = [fGroups objectsAtIndexes: selectedIndexes];
|
||||
|
||||
//determine where to move them
|
||||
for (NSInteger i = [indexes firstIndex], startRow = newRow; i < startRow && i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
|
||||
if (oldRow < newRow)
|
||||
newRow--;
|
||||
|
||||
//remove objects to reinsert
|
||||
NSArray * movingGroups = [[fGroups objectsAtIndexes: indexes] retain];
|
||||
[fGroups removeObjectsAtIndexes: indexes];
|
||||
id movingGroup = [[fGroups objectAtIndex: oldRow] retain];
|
||||
[fGroups removeObjectAtIndex: oldRow];
|
||||
|
||||
//insert objects at new location
|
||||
for (NSInteger i = 0; i < [movingGroups count]; i++)
|
||||
[fGroups insertObject: [movingGroups objectAtIndex: i] atIndex: newRow + i];
|
||||
[fGroups insertObject: movingGroup atIndex: newRow];
|
||||
|
||||
[movingGroups release];
|
||||
[movingGroup release];
|
||||
|
||||
[self saveGroups];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateGroups" object: self];
|
||||
|
||||
NSMutableIndexSet * newSelectedIndexes = nil;
|
||||
if ([selectedGroups count] > 0)
|
||||
{
|
||||
newSelectedIndexes = [NSMutableIndexSet indexSet];
|
||||
NSEnumerator * enumerator = [selectedGroups objectEnumerator];
|
||||
NSDictionary * dict;
|
||||
while ((dict = [enumerator nextObject]))
|
||||
[newSelectedIndexes addIndex: [fGroups indexOfObject: dict]];
|
||||
}
|
||||
|
||||
return newSelectedIndexes;
|
||||
}
|
||||
|
||||
- (NSMenu *) groupMenuWithTarget: (id) target action: (SEL) action isSmall: (BOOL) small
|
||||
|
||||
@@ -125,11 +125,23 @@
|
||||
NSPasteboard * pasteboard = [info draggingPasteboard];
|
||||
if ([[pasteboard types] containsObject: GROUP_TABLE_VIEW_DATA_TYPE])
|
||||
{
|
||||
NSIndexSet * indexes = [NSKeyedUnarchiver unarchiveObjectWithData: [pasteboard dataForType: GROUP_TABLE_VIEW_DATA_TYPE]],
|
||||
* selectedIndexes = [[GroupsController groups] moveGroupsAtRowIndexes: indexes toRow: newRow
|
||||
oldSelected: [fTableView selectedRowIndexes]];
|
||||
NSIndexSet * indexes = [NSKeyedUnarchiver unarchiveObjectWithData: [pasteboard dataForType: GROUP_TABLE_VIEW_DATA_TYPE]];
|
||||
NSInteger oldRow = [indexes firstIndex], selectedRow = [fTableView selectedRow];
|
||||
|
||||
[fTableView selectRowIndexes: selectedIndexes byExtendingSelection: NO];
|
||||
[[GroupsController groups] moveGroupAtRow: oldRow toRow: newRow];
|
||||
|
||||
if (oldRow < newRow)
|
||||
newRow--;
|
||||
|
||||
if (selectedRow == oldRow)
|
||||
selectedRow = newRow;
|
||||
else if (selectedRow > oldRow && selectedRow <= newRow)
|
||||
selectedRow--;
|
||||
else if (selectedRow < oldRow && selectedRow >= newRow)
|
||||
selectedRow++;
|
||||
else;
|
||||
|
||||
[fTableView selectRow: selectedRow byExtendingSelection: NO];
|
||||
[fTableView reloadData];
|
||||
}
|
||||
|
||||
@@ -238,7 +250,8 @@
|
||||
[fSelectedColorNameField setStringValue: [[GroupsController groups] nameForIndex: index]];
|
||||
[fSelectedColorNameField setEnabled: YES];
|
||||
[fCustomLocationEnableCheck setState: [[GroupsController groups] usesCustomDownloadLocationForIndex: index]];
|
||||
[fCustomLocationPopUp setEnabled: ([fCustomLocationEnableCheck state] == NSOnState)];
|
||||
[fCustomLocationEnableCheck setEnabled: YES];
|
||||
[fCustomLocationPopUp setEnabled: [fCustomLocationEnableCheck state] == NSOnState];
|
||||
if ([[GroupsController groups] customDownloadLocationForIndex: index])
|
||||
{
|
||||
NSString * location = [[GroupsController groups] customDownloadLocationForIndex: index];
|
||||
|
||||
Reference in New Issue
Block a user