summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/debugger/osx/debugcommandhistory.m
diff options
context:
space:
mode:
Diffstat (limited to 'src/osd/modules/debugger/osx/debugcommandhistory.m')
-rw-r--r--src/osd/modules/debugger/osx/debugcommandhistory.m116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/osd/modules/debugger/osx/debugcommandhistory.m b/src/osd/modules/debugger/osx/debugcommandhistory.m
new file mode 100644
index 00000000000..882c313000e
--- /dev/null
+++ b/src/osd/modules/debugger/osx/debugcommandhistory.m
@@ -0,0 +1,116 @@
+// license:BSD-3-Clause
+// copyright-holders:Vas Crabb
+//============================================================
+//
+// debugcommandhistory.m - MacOS X Cocoa debug window handling
+//
+// Copyright (c) 1996-2015, Nicola Salmoria and the MAME Team.
+// Visit http://mamedev.org for licensing and usage restrictions.
+//
+//============================================================
+
+//============================================================
+// MAMEDebugView class
+//============================================================
+
+#import "debugcommandhistory.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]) {
+ [history insertObject:entry atIndex:0];
+ while ([history count] > length)
+ [history removeLastObject];
+ }
+ 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];
+}
+
+@end