]> granicus.if.org Git - transmission/commitdiff
eliminate some redundant methods in the group controller
authorMitchell Livingston <livings124@transmissionbt.com>
Mon, 24 Mar 2008 23:06:04 +0000 (23:06 +0000)
committerMitchell Livingston <livings124@transmissionbt.com>
Mon, 24 Mar 2008 23:06:04 +0000 (23:06 +0000)
macosx/GroupsController.h
macosx/GroupsController.m
macosx/GroupsWindowController.m

index f422c8e1f5c8c56f3c718ab3fd7f96500be21ffa..86031900331472c40bec353f05897f8e435991ca 100644 (file)
 - (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;
 
index 4f6a133d0e71c24939083118e101baf8c3cf26c3..0ae4b3e1e9cc1e9535face66968249a0508e5af6 100644 (file)
@@ -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];
     
index b35dad0f9b607c5b606864b983d0b5c1829c0b13..a2f74fa4b5aca679eef0b46f4ad88002cd6a6047 100644 (file)
@@ -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];