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

This commit is contained in:
Mitchell Livingston
2008-12-06 20:41:18 +00:00
parent 5e0550e3dc
commit 418d04374c
3 changed files with 25 additions and 29 deletions
+1 -1
View 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;
+6 -23
View 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
+18 -5
View File
@@ -125,11 +125,23 @@
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];
}
@@ -238,7 +250,8 @@
[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];