35@interface OOTextFieldHistoryManager (Private)
39- (void)moveHistoryCursorTo:(NSUInteger)newCursor fieldEditor:(NSTextView *)fieldEditor;
40- (void)moveHistoryCursorBy:(NSInteger)offset fieldEditor:(NSTextView *)fieldEditor;
48- (BOOL) control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(
SEL)commandSelector
50 if (control == textField)
52 if (commandSelector ==
@selector(moveToBeginningOfParagraph:) ||
53 commandSelector ==
@selector(scrollPageUp:))
59 else if (commandSelector ==
@selector(moveToEndOfParagraph:) ||
60 commandSelector ==
@selector(scrollPageDown:))
77 _history = [[NSMutableArray alloc] initWithCapacity:kDefaultHistorySize];
78 [
self checkInvariant];
94 return [[_history copy] autorelease];
98- (void) setHistory:(NSArray *)history
100 if (history ==
nil) [_history removeAllObjects];
103 _history = [history mutableCopy];
105 [
self maintainInvariant];
107 [
self checkInvariant];
111- (void) addToHistory:(NSString *)string
113 [
self checkInvariant];
115 if (_historyCurrSize == 0 || ![
string isEqual:[_history objectAtIndex:_historyCurrSize - 1]])
117 [_history addObject:[[string copy] autorelease]];
123 [
self maintainInvariant];
127- (NSUInteger) historySize
129 return _historyMaxSize;
133- (void) setHistorySize:(NSUInteger)size
135 _historyMaxSize =
size;
136 [
self maintainInvariant];
142@implementation OOTextFieldHistoryManager (Private)
146 NSAssert(_history !=
nil &&
147 _historyCurrSize == [_history
count] &&
148 ((_historyCurrSize <= _historyMaxSize) || (_historyMaxSize == 0)) &&
149 _historyCursor <= _historyCurrSize + 1,
150 @"Invalid history buffer state in OOTextFieldHistoryManager.");
156 _historyCurrSize = [_history count];
158 if (_historyMaxSize && (_historyMaxSize < _historyCurrSize))
160 [_history removeObjectsInRange:NSMakeRange(0, _historyCurrSize - _historyMaxSize)];
161 _historyCurrSize = _historyMaxSize;
164 [
self checkInvariant];
168- (void) moveHistoryCursorTo:(NSUInteger)newCursor fieldEditor:(NSTextView *)fieldEditor
170 NSString *value =
nil;
171 NSTextStorage *textStorage =
nil;
173 if (_historyCurrSize < newCursor)
179 [
self checkInvariant];
180 textStorage = [fieldEditor textStorage];
184 NSUInteger index = _historyCurrSize - newCursor;
185 value = [_history objectAtIndex:index];
186 if (_historyCursor == 0) _latest = [[textStorage string] copy];
190 value = [_latest autorelease];
194 _historyCursor = newCursor;
196 [textStorage setString:value];
197 [textField selectText:self];
199 [
self checkInvariant];
203- (void) moveHistoryCursorBy:(NSInteger)offset fieldEditor:(NSTextView *)fieldEditor
206 if (((
offset < 0) && (_historyCursor < (NSUInteger)-
offset))
207 || (_historyCurrSize < (
offset + _historyCursor)))
212 [
self moveHistoryCursorTo:_historyCursor + offset fieldEditor:fieldEditor];
void moveHistoryCursorBy:fieldEditor:(NSInteger offset,[fieldEditor] NSTextView *fieldEditor)