mirror of
https://github.com/transmission/transmission
synced 2024-12-24 16:52:39 +00:00
fix a whoops with group row removal; when removing a row, select the row below it
This commit is contained in:
parent
69877384f1
commit
128c91479a
2 changed files with 39 additions and 26 deletions
|
@ -196,7 +196,7 @@ GroupsController * fGroupsInstance = nil;
|
||||||
- (void) removeGroupWithRowIndex: (NSInteger) row
|
- (void) removeGroupWithRowIndex: (NSInteger) row
|
||||||
{
|
{
|
||||||
NSInteger index = [[[fGroups objectAtIndex: row] objectForKey: @"Index"] intValue];
|
NSInteger index = [[[fGroups objectAtIndex: row] objectForKey: @"Index"] intValue];
|
||||||
[fGroups removeObjectAtIndex: index];
|
[fGroups removeObjectAtIndex: row];
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName: @"GroupValueRemoved" object: self userInfo:
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"GroupValueRemoved" object: self userInfo:
|
||||||
[NSDictionary dictionaryWithObject: [NSNumber numberWithInt: index] forKey: @"Index"]];
|
[NSDictionary dictionaryWithObject: [NSNumber numberWithInt: index] forKey: @"Index"]];
|
||||||
|
|
|
@ -57,7 +57,11 @@
|
||||||
|
|
||||||
[fAddRemoveControl setEnabled: NO forSegment: REMOVE_TAG];
|
[fAddRemoveControl setEnabled: NO forSegment: REMOVE_TAG];
|
||||||
[fSelectedColorView addObserver: self forKeyPath: @"color" options: 0 context: NULL];
|
[fSelectedColorView addObserver: self forKeyPath: @"color" options: 0 context: NULL];
|
||||||
[self updateSelectedColor];
|
|
||||||
|
if ([fTableView numberOfRows] > 0)
|
||||||
|
[fTableView selectRow: 0 byExtendingSelection: NO];
|
||||||
|
else
|
||||||
|
[self updateSelectedColor]; //make sure all fields are disabled
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSInteger) numberOfRowsInTableView: (NSTableView *) tableview
|
- (NSInteger) numberOfRowsInTableView: (NSTableView *) tableview
|
||||||
|
@ -82,26 +86,6 @@
|
||||||
[self updateSelectedColor];
|
[self updateSelectedColor];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) updateSelectedColor
|
|
||||||
{
|
|
||||||
[fAddRemoveControl setEnabled: [fTableView numberOfSelectedRows] > 0 forSegment: REMOVE_TAG];
|
|
||||||
if ([fTableView numberOfSelectedRows] == 1)
|
|
||||||
{
|
|
||||||
NSInteger index = [[GroupsController groups] indexForRow: [fTableView selectedRow]];
|
|
||||||
[fSelectedColorView setColor: [[GroupsController groups] colorForIndex: index]];
|
|
||||||
[fSelectedColorView setEnabled: YES];
|
|
||||||
[fSelectedColorNameField setStringValue: [[GroupsController groups] nameForIndex: index]];
|
|
||||||
[fSelectedColorNameField setEnabled: YES];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
[fSelectedColorView setColor: [NSColor whiteColor]];
|
|
||||||
[fSelectedColorView setEnabled: NO];
|
|
||||||
[fSelectedColorNameField setStringValue: @""];
|
|
||||||
[fSelectedColorNameField setEnabled: NO];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) observeValueForKeyPath: (NSString *) keyPath ofObject: (id) object change: (NSDictionary *) change context: (void *) context
|
- (void) observeValueForKeyPath: (NSString *) keyPath ofObject: (id) object change: (NSDictionary *) change context: (void *) context
|
||||||
{
|
{
|
||||||
if (object == fSelectedColorView && [fTableView numberOfSelectedRows] == 1)
|
if (object == fSelectedColorView && [fTableView numberOfSelectedRows] == 1)
|
||||||
|
@ -171,7 +155,7 @@
|
||||||
[fTableView reloadData];
|
[fTableView reloadData];
|
||||||
|
|
||||||
row = [fTableView numberOfRows]-1;
|
row = [fTableView numberOfRows]-1;
|
||||||
[fTableView selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
|
[fTableView selectRow: row byExtendingSelection: NO];
|
||||||
[fTableView scrollRowToVisible: row];
|
[fTableView scrollRowToVisible: row];
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -184,13 +168,42 @@
|
||||||
&& row == [[GroupsController groups] rowValueForIndex: fCurrentColorIndex])
|
&& row == [[GroupsController groups] rowValueForIndex: fCurrentColorIndex])
|
||||||
[[NSColorPanel sharedColorPanel] close];
|
[[NSColorPanel sharedColorPanel] close];
|
||||||
|
|
||||||
[[GroupsController groups] removeGroupWithRowIndex: row];
|
[[GroupsController groups] removeGroupWithRowIndex: row];
|
||||||
|
|
||||||
[fTableView deselectAll: self];
|
|
||||||
[fTableView reloadData];
|
[fTableView reloadData];
|
||||||
|
|
||||||
|
//select the next row
|
||||||
|
if (row == [fTableView numberOfRows])
|
||||||
|
row--;
|
||||||
|
if (row >= 0)
|
||||||
|
[fTableView selectRow: row byExtendingSelection: NO];
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@implementation GroupsWindowController (Private)
|
||||||
|
|
||||||
|
- (void) updateSelectedColor
|
||||||
|
{
|
||||||
|
[fAddRemoveControl setEnabled: [fTableView numberOfSelectedRows] > 0 forSegment: REMOVE_TAG];
|
||||||
|
if ([fTableView numberOfSelectedRows] == 1)
|
||||||
|
{
|
||||||
|
NSInteger index = [[GroupsController groups] indexForRow: [fTableView selectedRow]];
|
||||||
|
[fSelectedColorView setColor: [[GroupsController groups] colorForIndex: index]];
|
||||||
|
[fSelectedColorView setEnabled: YES];
|
||||||
|
[fSelectedColorNameField setStringValue: [[GroupsController groups] nameForIndex: index]];
|
||||||
|
[fSelectedColorNameField setEnabled: YES];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[fSelectedColorView setColor: [NSColor whiteColor]];
|
||||||
|
[fSelectedColorView setEnabled: NO];
|
||||||
|
[fSelectedColorNameField setStringValue: @""];
|
||||||
|
[fSelectedColorNameField setEnabled: NO];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
Loading…
Reference in a new issue