Created
June 12, 2010 19:12
-
-
Save BlairDuncan/435989 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tempSaveSelections = Nil; | |
- (void)saveOutlineSelections | |
{ | |
var rows = [outlineView selectedRowIndexes], | |
dataSet = outlineView._itemsForRows; | |
tempSaveSelections = [dataSet objectsAtIndexes:rows]; | |
// add the current selection at the end for later restore | |
if([outlineView selectedRow] != CPNotFound) | |
tempSaveSelections = [tempSaveSelections arrayByAddingObject:[dataSet objectAtIndex:[outlineView selectedRow]]]; | |
[outlineView _updateHighlightWithOldRows:rows newRows:[CPIndexSet indexSet]]; | |
} | |
- (void)restoreOutlineSelections | |
{ | |
// build a new index set of all the saved objects but first restore the current selected row | |
var newIndexSet = [CPIndexSet indexSet], | |
dataSet = outlineView._itemsForRows, | |
index = [tempSaveSelections count] -1; | |
if(index != CPNotFound) | |
{ outlineView._selectedRow = [dataSet indexOfObject:[tempSaveSelections objectAtIndex:index]]; | |
while(index--) | |
[newIndexSet addIndex:[dataSet indexOfObject:[tempSaveSelections objectAtIndex:index]]]; | |
} | |
[outlineView _updateHighlightWithOldRows:[CPIndexSet indexSet] newRows:newIndexSet]; | |
outlineView._selectedRowIndexes = newIndexSet; | |
} | |
- (void)outlineViewItemWillExpand:sender | |
{ | |
[self saveOutlineSelections]; | |
} | |
- (void)outlineViewItemDidExpand:sender | |
{ | |
[self restoreOutlineSelections]; | |
} | |
- (void)outlineViewItemWillCollapse:sender | |
{ | |
[self saveOutlineSelections]; | |
} | |
- (void)outlineViewItemDidCollapse:sender | |
{ | |
[self restoreOutlineSelections]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment