Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOTextFieldHistoryManager Class Reference

#include <OOTextFieldHistoryManager.h>

+ Inheritance diagram for OOTextFieldHistoryManager:
+ Collaboration diagram for OOTextFieldHistoryManager:

Instance Methods

(NSArray *) - history
 
(void) - setHistory:
 
(void) - addToHistory:
 
(NSUInteger) - historySize
 
(void) - setHistorySize:
 
(BOOL) - control:textView:doCommandBySelector: [implementation]
 
(id) - init [implementation]
 
(void) - dealloc [implementation]
 
(void) - checkInvariant [implementation]
 
(void) - maintainInvariant [implementation]
 
(void) - moveHistoryCursorTo:fieldEditor: [implementation]
 
(void) - moveHistoryCursorBy:fieldEditor: [implementation]
 

Private Attributes

IBOutlet NSTextField * textField
 
NSMutableArray * _history
 
NSUInteger _historyMaxSize
 
NSUInteger _historyCurrSize
 
NSUInteger _historyCursor
 
NSString * _latest
 

Detailed Description

Definition at line 41 of file OOTextFieldHistoryManager.h.

Method Documentation

◆ addToHistory:

- (void) addToHistory: (NSString *) string

Definition at line 1 of file OOTextFieldHistoryManager.m.

111 :(NSString *)string
112{
113 [self checkInvariant];
114
115 if (_historyCurrSize == 0 || ![string isEqual:[_history objectAtIndex:_historyCurrSize - 1]])
116 {
117 [_history addObject:[[string copy] autorelease]];
118 }
119 _historyCursor = 0;
120 [_latest release];
121 _latest = nil;
122
123 [self maintainInvariant];
124}
return nil

◆ checkInvariant

- (void) checkInvariant
implementation

Provided by category OOTextFieldHistoryManager(Private).

Definition at line 1 of file OOTextFieldHistoryManager.m.

145{
146 NSAssert(_history != nil && // History buffer must exist
147 _historyCurrSize == [_history count] && // Size must be correct
148 ((_historyCurrSize <= _historyMaxSize) || (_historyMaxSize == 0)) && // Size must be in bounds
149 _historyCursor <= _historyCurrSize + 1, // Cursor must be in bounds
150 @"Invalid history buffer state in OOTextFieldHistoryManager.");
151}
unsigned count

◆ control:textView:doCommandBySelector:

- (BOOL) control: (NSControl *) control
textView: (NSTextView *) textView
doCommandBySelector: (SEL) commandSelector 
implementation

Definition at line 1 of file OOTextFieldHistoryManager.m.

48 :(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector
49{
50 if (control == textField)
51 {
52 if (commandSelector == @selector(moveToBeginningOfParagraph:) ||
53 commandSelector == @selector(scrollPageUp:))
54 {
55 // Option-up arrow or page up. (For just up arrow, use moveUp:.)
56 [self moveHistoryCursorBy:1 fieldEditor:textView];
57 return YES;
58 }
59 else if (commandSelector == @selector(moveToEndOfParagraph:) ||
60 commandSelector == @selector(scrollPageDown:))
61 {
62 // Option-down arrow or page down. (For just down arrow, use moveDown:.)
63 [self moveHistoryCursorBy:-1 fieldEditor:textView];
64 return YES;
65 }
66 }
67 return NO;
68}

◆ dealloc

- (void) dealloc
implementation

Definition at line 1 of file OOTextFieldHistoryManager.m.

85{
86 [_history release];
87
88 [super dealloc];
89}

◆ history

- (NSArray *) history

Definition at line 1 of file OOTextFieldHistoryManager.m.

93{
94 return [[_history copy] autorelease];
95}

◆ historySize

- (NSUInteger) historySize

Definition at line 1 of file OOTextFieldHistoryManager.m.

128{
129 return _historyMaxSize;
130}

◆ init

- (id) init
implementation

Definition at line 1 of file OOTextFieldHistoryManager.m.

72{
73 self = [super init];
74 if (self != nil)
75 {
77 _history = [[NSMutableArray alloc] initWithCapacity:kDefaultHistorySize];
78 [self checkInvariant];
79 }
80 return self;
81}

◆ maintainInvariant

- (void) maintainInvariant
implementation

Provided by category OOTextFieldHistoryManager(Private).

Definition at line 1 of file OOTextFieldHistoryManager.m.

155{
156 _historyCurrSize = [_history count];
157
158 if (_historyMaxSize && (_historyMaxSize < _historyCurrSize))
159 {
160 [_history removeObjectsInRange:NSMakeRange(0, _historyCurrSize - _historyMaxSize)];
161 _historyCurrSize = _historyMaxSize;
162 }
163
164 [self checkInvariant];
165}

◆ moveHistoryCursorBy:fieldEditor:

- (void) moveHistoryCursorBy: (NSInteger) offset
fieldEditor: (NSTextView *) fieldEditor 
implementation

Provided by category OOTextFieldHistoryManager(Private).

Definition at line 1 of file OOTextFieldHistoryManager.m.

203 :(NSInteger)offset fieldEditor:(NSTextView *)fieldEditor
204{
205 // Range check
206 if (((offset < 0) && (_historyCursor < (NSUInteger)-offset)) // Destination < 0
207 || (_historyCurrSize < (offset + _historyCursor))) // Destination > _historyCurrSize
208 {
209 NSBeep();
210 return;
211 }
212 [self moveHistoryCursorTo:_historyCursor + offset fieldEditor:fieldEditor];
213}
voidpf uLong offset
Definition ioapi.h:140

◆ moveHistoryCursorTo:fieldEditor:

- (void) moveHistoryCursorTo: (NSUInteger) newCursor
fieldEditor: (NSTextView *) fieldEditor 
implementation

Provided by category OOTextFieldHistoryManager(Private).

Definition at line 1 of file OOTextFieldHistoryManager.m.

168 :(NSUInteger)newCursor fieldEditor:(NSTextView *)fieldEditor
169{
170 NSString *value = nil;
171 NSTextStorage *textStorage = nil;
172
173 if (_historyCurrSize < newCursor)
174 {
175 NSBeep();
176 return;
177 }
178
179 [self checkInvariant];
180 textStorage = [fieldEditor textStorage];
181
182 if (newCursor > 0)
183 {
184 NSUInteger index = _historyCurrSize - newCursor;
185 value = [_history objectAtIndex:index];
186 if (_historyCursor == 0) _latest = [[textStorage string] copy];
187 }
188 else
189 {
190 value = [_latest autorelease];
191 _latest = nil;
192 }
193
194 _historyCursor = newCursor;
195
196 [textStorage setString:value];
197 [textField selectText:self];
198
199 [self checkInvariant];
200}

◆ setHistory:

- (void) setHistory: (NSArray *) history

Definition at line 1 of file OOTextFieldHistoryManager.m.

98 :(NSArray *)history
99{
100 if (history == nil) [_history removeAllObjects];
101 else
102 {
103 _history = [history mutableCopy];
104 _historyCursor = 0;
105 [self maintainInvariant];
106 }
107 [self checkInvariant];
108}

◆ setHistorySize:

- (void) setHistorySize: (NSUInteger) size

Definition at line 1 of file OOTextFieldHistoryManager.m.

133 :(NSUInteger)size
134{
136 [self maintainInvariant];
137}
voidpf void uLong size
Definition ioapi.h:134

Member Data Documentation

◆ _history

- (NSMutableArray*) _history
private

Definition at line 46 of file OOTextFieldHistoryManager.h.

◆ _historyCurrSize

- (NSUInteger) _historyCurrSize
private

Definition at line 48 of file OOTextFieldHistoryManager.h.

◆ _historyCursor

- (NSUInteger) _historyCursor
private

Definition at line 49 of file OOTextFieldHistoryManager.h.

◆ _historyMaxSize

- (NSUInteger) _historyMaxSize
private

Definition at line 47 of file OOTextFieldHistoryManager.h.

◆ _latest

- (NSString*) _latest
private

Definition at line 50 of file OOTextFieldHistoryManager.h.

◆ textField

- (IBOutlet NSTextField*) textField
private

Definition at line 44 of file OOTextFieldHistoryManager.h.


The documentation for this class was generated from the following files: