#4693 (Lion) animate adding/removing/dragging rows in the group pref table
This commit is contained in:
parent
cac5c360f2
commit
ff5510a3fc
|
@ -26,6 +26,7 @@
|
||||||
#import "GroupsController.h"
|
#import "GroupsController.h"
|
||||||
#import "ExpandedPathToPathTransformer.h"
|
#import "ExpandedPathToPathTransformer.h"
|
||||||
#import "ExpandedPathToIconTransformer.h"
|
#import "ExpandedPathToIconTransformer.h"
|
||||||
|
#import "NSApplicationAdditions.h"
|
||||||
|
|
||||||
#define GROUP_TABLE_VIEW_DATA_TYPE @"GroupTableViewDataType"
|
#define GROUP_TABLE_VIEW_DATA_TYPE @"GroupTableViewDataType"
|
||||||
|
|
||||||
|
@ -121,11 +122,22 @@
|
||||||
NSIndexSet * indexes = [NSKeyedUnarchiver unarchiveObjectWithData: [pasteboard dataForType: GROUP_TABLE_VIEW_DATA_TYPE]];
|
NSIndexSet * indexes = [NSKeyedUnarchiver unarchiveObjectWithData: [pasteboard dataForType: GROUP_TABLE_VIEW_DATA_TYPE]];
|
||||||
NSInteger oldRow = [indexes firstIndex], selectedRow = [fTableView selectedRow];
|
NSInteger oldRow = [indexes firstIndex], selectedRow = [fTableView selectedRow];
|
||||||
|
|
||||||
|
|
||||||
|
if ([NSApp isOnLionOrBetter])
|
||||||
|
[fTableView beginUpdates];
|
||||||
|
|
||||||
[[GroupsController groups] moveGroupAtRow: oldRow toRow: newRow];
|
[[GroupsController groups] moveGroupAtRow: oldRow toRow: newRow];
|
||||||
|
|
||||||
if (oldRow < newRow)
|
if (oldRow < newRow)
|
||||||
newRow--;
|
newRow--;
|
||||||
|
|
||||||
|
if ([NSApp isOnLionOrBetter])
|
||||||
|
{
|
||||||
|
[fTableView moveRowAtIndex: oldRow toIndex: newRow];
|
||||||
|
[fTableView endUpdates];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (selectedRow == oldRow)
|
if (selectedRow == oldRow)
|
||||||
selectedRow = newRow;
|
selectedRow = newRow;
|
||||||
else if (selectedRow > oldRow && selectedRow <= newRow)
|
else if (selectedRow > oldRow && selectedRow <= newRow)
|
||||||
|
@ -137,6 +149,7 @@
|
||||||
[fTableView selectRowIndexes: [NSIndexSet indexSetWithIndex: selectedRow] byExtendingSelection: NO];
|
[fTableView selectRowIndexes: [NSIndexSet indexSetWithIndex: selectedRow] byExtendingSelection: NO];
|
||||||
[fTableView reloadData];
|
[fTableView reloadData];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
@ -150,11 +163,21 @@
|
||||||
switch ([[sender cell] tagForSegment: [sender selectedSegment]])
|
switch ([[sender cell] tagForSegment: [sender selectedSegment]])
|
||||||
{
|
{
|
||||||
case ADD_TAG:
|
case ADD_TAG:
|
||||||
|
if ([NSApp isOnLionOrBetter])
|
||||||
|
[fTableView beginUpdates];
|
||||||
|
|
||||||
[[GroupsController groups] addNewGroup];
|
[[GroupsController groups] addNewGroup];
|
||||||
|
|
||||||
|
row = [fTableView numberOfRows];
|
||||||
|
|
||||||
|
if ([NSApp isOnLionOrBetter])
|
||||||
|
{
|
||||||
|
[fTableView insertRowsAtIndexes: [NSIndexSet indexSetWithIndex: row] withAnimation: NSTableViewAnimationSlideUp];
|
||||||
|
[fTableView endUpdates];
|
||||||
|
}
|
||||||
|
else
|
||||||
[fTableView reloadData];
|
[fTableView reloadData];
|
||||||
|
|
||||||
row = [fTableView numberOfRows]-1;
|
|
||||||
[fTableView selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
|
[fTableView selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
|
||||||
[fTableView scrollRowToVisible: row];
|
[fTableView scrollRowToVisible: row];
|
||||||
|
|
||||||
|
@ -164,20 +187,28 @@
|
||||||
|
|
||||||
case REMOVE_TAG:
|
case REMOVE_TAG:
|
||||||
row = [fTableView selectedRow];
|
row = [fTableView selectedRow];
|
||||||
|
|
||||||
|
|
||||||
|
if ([NSApp isOnLionOrBetter])
|
||||||
|
[fTableView beginUpdates];
|
||||||
|
|
||||||
[[GroupsController groups] removeGroupWithRowIndex: row];
|
[[GroupsController groups] removeGroupWithRowIndex: row];
|
||||||
|
|
||||||
|
if ([NSApp isOnLionOrBetter])
|
||||||
|
{
|
||||||
|
[fTableView removeRowsAtIndexes: [NSIndexSet indexSetWithIndex: row] withAnimation: NSTableViewAnimationSlideUp];
|
||||||
|
[fTableView endUpdates];
|
||||||
|
}
|
||||||
|
else
|
||||||
[fTableView reloadData];
|
[fTableView reloadData];
|
||||||
|
|
||||||
if ([fTableView numberOfRows] > 0)
|
if ([fTableView numberOfRows] > 0)
|
||||||
{
|
{
|
||||||
if (row == [fTableView numberOfRows])
|
if (row == [fTableView numberOfRows])
|
||||||
{
|
|
||||||
--row;
|
--row;
|
||||||
[fTableView selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
|
[fTableView selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
[fTableView scrollRowToVisible: row];
|
[fTableView scrollRowToVisible: row];
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue