blob: e2292f973b0289fe23fce36d5e0af9553a274617 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
// license:BSD-3-Clause
// copyright-holders:Vas Crabb
//============================================================
//
// debugcommandhistory.m - MacOS X Cocoa debug window handling
//
//============================================================
//============================================================
// MAMEDebugView class
//============================================================
#import "debugcommandhistory.h"
#include "util/xmlfile.h"
@implementation MAMEDebugCommandHistory
+ (NSInteger)defaultLength {
return 100;
}
- (id)init {
if (!(self = [super init]))
return nil;
length = [[self class] defaultLength];
position = -1;
current = nil;
history = [[NSMutableArray alloc] initWithCapacity:length];
return self;
}
- (void)dealloc {
if (current != nil)
[current release];
if (history != nil)
[history release];
[super dealloc];
}
- (NSInteger)length {
return length;
}
- (void)setLength:(NSInteger)l {
length = l;
if ([history count] > length)
[history removeObjectsInRange:NSMakeRange(length, [history count] - length)];
}
- (void)add:(NSString *)entry {
if (([history count] == 0) || ![[history objectAtIndex:0] isEqualToString:entry]) {
while ([history count] >= length)
[history removeLastObject];
[history insertObject:entry atIndex:0];
}
position = 0;
}
- (NSString *)previous:(NSString *)cur {
if ((position + 1) < [history count]) {
if (position < 0) {
[current autorelease];
current = [cur copy];
}
return [history objectAtIndex:++position];
} else {
return nil;
}
}
- (NSString *)next:(NSString *)cur {
if (position > 0) {
return [history objectAtIndex:--position];
} else if ((position == 0) && (current != nil) && ![current isEqualToString:[history objectAtIndex:0]]) {
position--;
return [[current retain] autorelease];
} else {
return nil;
}
}
- (void)edit {
if (position == 0)
position--;
}
- (void)reset {
position = -1;
if (current != nil) {
[current release];
current = nil;
}
}
- (void)clear {
position = -1;
if (current != nil) {
[current release];
current = nil;
}
[history removeAllObjects];
}
- (void)saveConfigurationToNode:(util::xml::data_node *)node {
util::xml::data_node *const hist = node->add_child(osd::debugger::NODE_WINDOW_HISTORY, nullptr);
if (hist) {
for (NSInteger i = [history count]; 0 < i; --i)
hist->add_child(osd::debugger::NODE_HISTORY_ITEM, [[history objectAtIndex:(i - 1)] UTF8String]);
}
}
- (void)restoreConfigurationFromNode:(util::xml::data_node const *)node {
[self clear];
util::xml::data_node const *const hist = node->get_child(osd::debugger::NODE_WINDOW_HISTORY);
if (hist) {
util::xml::data_node const *item = hist->get_child(osd::debugger::NODE_HISTORY_ITEM);
while (item) {
if (item->get_value() && *item->get_value()) {
while ([history count] >= length)
[history removeLastObject];
[history insertObject:[NSString stringWithUTF8String:item->get_value()] atIndex:0];
}
item = item->get_next_sibling(osd::debugger::NODE_HISTORY_ITEM);
}
}
}
@end
|