選択状態も Undo/Redo してみる。
選択状態の Undo/Redo
NSArrayController の選択に関係するメソッドをすべてオーバーライドしてやる。
- (void)_registSelectionToUndo { [[self.undoManagerprepareWithInvocationTarget:self] setSelectionIndexes:[selfselectionIndexes]]; } - (BOOL)setSelectionIndex:(NSUInteger)index { BOOL result = [supersetSelectionIndex:index]; if (result) { [self_registSelectionToUndo]; } return result; } - (BOOL)setSelectionIndexes:(NSIndexSet *)indexes { BOOL result = [supersetSelectionIndexes:indexes]; if (result) { [self_registSelectionToUndo]; } return result; } - (BOOL)setSelectedObjects:(NSArray *)objects { BOOL result = [supersetSelectedObjects:objects]; if (result) { [self_registSelectionToUndo]; } return result; } - (BOOL)addSelectedObjects:(NSArray *)objects { BOOL result = [superaddSelectedObjects:objects]; if (result) { [self_registSelectionToUndo]; } return result; } - (void)selectPrevious:(id)sender { if ([selfcanSelectPrevious]) { [self_registSelectionToUndo]; } [superselectPrevious:sender]; } - (void)selectNext:(id)sender { if ([selfcanSelectNext]) { [self_registSelectionToUndo]; } [superselectNext:sender]; }
できた(画像じゃわかりずらいが)
ソースコード
GitHubからどうぞ。
ArrayControllerUndoSample at 2011-01-03 from xcatsan/MacOSX-Sample-Code - GitHub
Responses
Leave a Response