Changeset 7306


Ignore:
Timestamp:
Dec 6, 2008, 8:41:18 PM (12 years ago)
Author:
livings124
Message:

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

Location:
trunk/macosx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/GroupsController.h

    r7210 r7306  
    5454- (void) removeGroupWithRowIndex: (NSInteger) row;
    5555
    56 - (NSIndexSet *) moveGroupsAtRowIndexes: (NSIndexSet *) indexes toRow: (NSInteger) newRow oldSelected: (NSIndexSet *) selectedIndexes;
     56- (void) moveGroupAtRow: (NSInteger) oldRow toRow: (NSInteger) newRow;
    5757
    5858- (NSMenu *) groupMenuWithTarget: (id) target action: (SEL) action isSmall: (BOOL) small;
  • trunk/macosx/GroupsController.m

    r7210 r7306  
    244244}
    245245
    246 #warning rework for single row?
    247 - (NSIndexSet *) moveGroupsAtRowIndexes: (NSIndexSet *) indexes toRow: (NSInteger) newRow oldSelected: (NSIndexSet *) selectedIndexes
    248 {
    249     NSArray * selectedGroups = [fGroups objectsAtIndexes: selectedIndexes];
    250    
    251     //determine where to move them
    252     for (NSInteger i = [indexes firstIndex], startRow = newRow; i < startRow && i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
     246- (void) moveGroupAtRow: (NSInteger) oldRow toRow: (NSInteger) newRow
     247{
     248    if (oldRow < newRow)
    253249        newRow--;
    254250   
    255251    //remove objects to reinsert
    256     NSArray * movingGroups = [[fGroups objectsAtIndexes: indexes] retain];
    257     [fGroups removeObjectsAtIndexes: indexes];
     252    id movingGroup = [[fGroups objectAtIndex: oldRow] retain];
     253    [fGroups removeObjectAtIndex: oldRow];
    258254   
    259255    //insert objects at new location
    260     for (NSInteger i = 0; i < [movingGroups count]; i++)
    261         [fGroups insertObject: [movingGroups objectAtIndex: i] atIndex: newRow + i];
    262    
    263     [movingGroups release];
     256    [fGroups insertObject: movingGroup atIndex: newRow];
     257   
     258    [movingGroup release];
    264259   
    265260    [self saveGroups];
    266261    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateGroups" object: self];
    267    
    268     NSMutableIndexSet * newSelectedIndexes = nil;
    269     if ([selectedGroups count] > 0)
    270     {
    271         newSelectedIndexes = [NSMutableIndexSet indexSet];
    272         NSEnumerator * enumerator = [selectedGroups objectEnumerator];
    273         NSDictionary * dict;
    274         while ((dict = [enumerator nextObject]))
    275             [newSelectedIndexes addIndex: [fGroups indexOfObject: dict]];
    276     }
    277    
    278     return newSelectedIndexes;
    279262}
    280263
  • trunk/macosx/GroupsPrefsController.m

    r7216 r7306  
    126126    if ([[pasteboard types] containsObject: GROUP_TABLE_VIEW_DATA_TYPE])
    127127    {
    128         NSIndexSet * indexes = [NSKeyedUnarchiver unarchiveObjectWithData: [pasteboard dataForType: GROUP_TABLE_VIEW_DATA_TYPE]],
    129             * selectedIndexes = [[GroupsController groups] moveGroupsAtRowIndexes: indexes toRow: newRow
    130                                         oldSelected: [fTableView selectedRowIndexes]];
    131        
    132         [fTableView selectRowIndexes: selectedIndexes byExtendingSelection: NO];
     128        NSIndexSet * indexes = [NSKeyedUnarchiver unarchiveObjectWithData: [pasteboard dataForType: GROUP_TABLE_VIEW_DATA_TYPE]];
     129        NSInteger oldRow = [indexes firstIndex], selectedRow = [fTableView selectedRow];
     130       
     131        [[GroupsController groups] moveGroupAtRow: oldRow toRow: newRow];
     132       
     133        if (oldRow < newRow)
     134            newRow--;
     135       
     136        if (selectedRow == oldRow)
     137            selectedRow = newRow;
     138        else if (selectedRow > oldRow && selectedRow <= newRow)
     139            selectedRow--;
     140        else if (selectedRow < oldRow && selectedRow >= newRow)
     141            selectedRow++;
     142        else;
     143       
     144        [fTableView selectRow: selectedRow byExtendingSelection: NO];
    133145        [fTableView reloadData];
    134146    }
     
    239251        [fSelectedColorNameField setEnabled: YES];
    240252        [fCustomLocationEnableCheck setState: [[GroupsController groups] usesCustomDownloadLocationForIndex: index]];
    241         [fCustomLocationPopUp setEnabled: ([fCustomLocationEnableCheck state] == NSOnState)];
     253        [fCustomLocationEnableCheck setEnabled: YES];
     254        [fCustomLocationPopUp setEnabled: [fCustomLocationEnableCheck state] == NSOnState];
    242255        if ([[GroupsController groups] customDownloadLocationForIndex: index])
    243256        {
Note: See TracChangeset for help on using the changeset viewer.