]> granicus.if.org Git - transmission/commitdiff
simplify the code for moving rows in the groups table and fix a bug with disabled...
authorMitchell Livingston <livings124@transmissionbt.com>
Sat, 6 Dec 2008 20:41:18 +0000 (20:41 +0000)
committerMitchell Livingston <livings124@transmissionbt.com>
Sat, 6 Dec 2008 20:41:18 +0000 (20:41 +0000)
macosx/GroupsController.h
macosx/GroupsController.m
macosx/GroupsPrefsController.m

index 754513158d302e9e1ac8d4976fb79f5adf5a0db1..7d3a7cdff7d9fa6b1aa8909d5f241d5b264251d6 100644 (file)
@@ -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;
 
index ba820d020687eb452b7b9fb3baa3e0e073cd811b..8a9ceff307e5e45fb4aeb3f197b23eb1f5c69797 100644 (file)
@@ -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
index 29d6256d192af81de41d30a41ab2d5f897602132..1fe00cb36c30c13dd1f6a6fd641f0a912b3b4765 100644 (file)
     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];
     }
     
         [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];