// // History.m // RCocoaBundle // // Created by Simon Urbanek on Sat Mar 06 2004. // Copyright (c) 2004 R Development Core Team. All rights reserved. // #import "History.h" @implementation History /** implements a history with one dirt entry (i.e. an entry which is still being edited but not cimmited yet) */ - (id) init { hist = [[NSMutableArray alloc] initWithCapacity: 16]; dirtyEntry=nil; pos=0; return self; } - (void) dealloc { [self resetAll]; [hist release]; [super dealloc]; } /** commits an entry to the end of the history, except it equals to the last entry; moves the current position past the last entry and also deletes any dirty entry */ - (void) commit: (NSString*) entry { int ac = [hist count]; if (ac==0 || ![[hist objectAtIndex: ac-1] isEqualToString:entry]) { // only add if it's not equal to the last one [hist addObject: entry]; } if (dirtyEntry!=nil) [dirtyEntry release]; dirtyEntry=nil; pos=[hist count]; } /** moves to the next entry; if out of the history, returns the dirty entry */ - (NSString*) next { int ac = [hist count]; if (pos0) { pos--; return (NSString*) [hist objectAtIndex: pos]; }; return nil; } /** returns the current entry (can be the dirty entry, too) */ - (NSString*) current { int ac = [hist count]; if (pos