mirror of
https://github.com/transmission/transmission.git
synced 2026-05-08 17:49:52 +01:00
eliminate some redundant methods in the group controller
This commit is contained in:
@@ -41,11 +41,9 @@
|
||||
- (CTGradient *) gradientForIndex: (int) index;
|
||||
|
||||
- (NSString *) nameForIndex: (int) index;
|
||||
- (NSString *) nameForRowIndex: (int) row;
|
||||
- (void) setName: (NSString *) name forRowIndex: (int) index;
|
||||
- (void) setName: (NSString *) name forIndex: (int) index;
|
||||
|
||||
- (NSImage *) imageForIndex: (int) index isSmall: (BOOL) small;
|
||||
- (NSImage *) imageForRowIndex: (int) row isSmall: (BOOL) small;
|
||||
|
||||
- (NSColor *) colorForIndex: (int) index;
|
||||
- (NSColor *) setColor: (NSColor *) color forIndex: (int) index;
|
||||
@@ -53,7 +51,7 @@
|
||||
- (void) addGroupWithName: (NSString *) name color: (NSColor *) color;
|
||||
- (void) removeGroupWithRowIndexes: (NSIndexSet *) rowIndexes;
|
||||
|
||||
- (NSIndexSet *) moveGroupsAtIndexes: (NSIndexSet *) indexes toRow: (int) newRow oldSelected: (NSIndexSet *) selectedIndexes;
|
||||
- (NSIndexSet *) moveGroupsAtRowIndexes: (NSIndexSet *) indexes toRow: (int) newRow oldSelected: (NSIndexSet *) selectedIndexes;
|
||||
|
||||
- (NSMenu *) groupMenuWithTarget: (id) target action: (SEL) action isSmall: (BOOL) small;
|
||||
|
||||
|
||||
@@ -138,17 +138,13 @@ GroupsController * fGroupsInstance = nil;
|
||||
- (NSString *) nameForIndex: (int) index
|
||||
{
|
||||
int orderIndex = [self rowValueForIndex: index];
|
||||
return orderIndex != -1 ? [self nameForRowIndex: orderIndex] : nil;
|
||||
return orderIndex != -1 ? [[fGroups objectAtIndex: orderIndex] objectForKey: @"Name"] : nil;
|
||||
}
|
||||
|
||||
- (NSString *) nameForRowIndex: (int) index
|
||||
- (void) setName: (NSString *) name forIndex: (int) index
|
||||
{
|
||||
return [[fGroups objectAtIndex: index] objectForKey: @"Name"];
|
||||
}
|
||||
|
||||
- (void) setName: (NSString *) name forRowIndex: (int) row
|
||||
{
|
||||
[[fGroups objectAtIndex: row] setObject: name forKey: @"Name"];
|
||||
int orderIndex = [self rowValueForIndex: index];
|
||||
[[fGroups objectAtIndex: orderIndex] setObject: name forKey: @"Name"];
|
||||
[self saveGroups];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateGroups" object: self];
|
||||
@@ -157,12 +153,7 @@ GroupsController * fGroupsInstance = nil;
|
||||
- (NSImage *) imageForIndex: (int) index isSmall: (BOOL) small
|
||||
{
|
||||
int orderIndex = [self rowValueForIndex: index];
|
||||
return orderIndex != -1 ? [self imageForRowIndex: orderIndex isSmall: small] : nil;
|
||||
}
|
||||
|
||||
- (NSImage *) imageForRowIndex: (int) row isSmall: (BOOL) small
|
||||
{
|
||||
return [self imageForGroup: [fGroups objectAtIndex: row] isSmall: small];
|
||||
return orderIndex != -1 ? [self imageForGroup: [fGroups objectAtIndex: orderIndex] isSmall: small] : nil;
|
||||
}
|
||||
|
||||
- (NSColor *) colorForIndex: (int) index
|
||||
@@ -225,7 +216,7 @@ GroupsController * fGroupsInstance = nil;
|
||||
[self saveGroups];
|
||||
}
|
||||
|
||||
- (NSIndexSet *) moveGroupsAtIndexes: (NSIndexSet *) indexes toRow: (int) newRow oldSelected: (NSIndexSet *) selectedIndexes
|
||||
- (NSIndexSet *) moveGroupsAtRowIndexes: (NSIndexSet *) indexes toRow: (int) newRow oldSelected: (NSIndexSet *) selectedIndexes
|
||||
{
|
||||
NSArray * selectedGroups = [fGroups objectsAtIndexes: selectedIndexes];
|
||||
|
||||
|
||||
@@ -82,11 +82,14 @@ GroupsWindowController * fGroupsWindowInstance = nil;
|
||||
|
||||
- (id) tableView: (NSTableView *) tableView objectValueForTableColumn: (NSTableColumn *) tableColumn row: (NSInteger) row
|
||||
{
|
||||
GroupsController * groupsController = [GroupsController groups];
|
||||
int groupsIndex = [groupsController indexForRow: row];
|
||||
|
||||
NSString * identifier = [tableColumn identifier];
|
||||
if ([identifier isEqualToString: @"Color"])
|
||||
return [[GroupsController groups] imageForRowIndex: row isSmall: NO];
|
||||
return [groupsController imageForIndex: groupsIndex isSmall: NO];
|
||||
else
|
||||
return [[GroupsController groups] nameForRowIndex: row];
|
||||
return [groupsController nameForIndex: groupsIndex];
|
||||
}
|
||||
|
||||
- (void) tableView: (NSTableView *) tableView setObjectValue: (id) object forTableColumn: (NSTableColumn *) tableColumn
|
||||
@@ -94,7 +97,7 @@ GroupsWindowController * fGroupsWindowInstance = nil;
|
||||
{
|
||||
NSString * identifier = [tableColumn identifier];
|
||||
if ([identifier isEqualToString: @"Name"])
|
||||
[[GroupsController groups] setName: object forRowIndex: row];
|
||||
[[GroupsController groups] setName: object forIndex: [[GroupsController groups] indexForRow: row]];
|
||||
else if ([identifier isEqualToString: @"Button"])
|
||||
{
|
||||
fCurrentColorIndex = [[GroupsController groups] indexForRow: row];
|
||||
@@ -143,7 +146,7 @@ GroupsWindowController * fGroupsWindowInstance = nil;
|
||||
if ([[pasteboard types] containsObject: GROUP_TABLE_VIEW_DATA_TYPE])
|
||||
{
|
||||
NSIndexSet * indexes = [NSKeyedUnarchiver unarchiveObjectWithData: [pasteboard dataForType: GROUP_TABLE_VIEW_DATA_TYPE]],
|
||||
* selectedIndexes = [[GroupsController groups] moveGroupsAtIndexes: indexes toRow: newRow
|
||||
* selectedIndexes = [[GroupsController groups] moveGroupsAtRowIndexes: indexes toRow: newRow
|
||||
oldSelected: [fTableView selectedRowIndexes]];
|
||||
|
||||
[fTableView selectRowIndexes: selectedIndexes byExtendingSelection: NO];
|
||||
|
||||
Reference in New Issue
Block a user