Skip to content

Instantly share code, notes, and snippets.

@BlairDuncan
Created June 12, 2010 19:12
Show Gist options
  • Save BlairDuncan/435989 to your computer and use it in GitHub Desktop.
Save BlairDuncan/435989 to your computer and use it in GitHub Desktop.
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