2010-10-05 18:56:45 +00:00
|
|
|
//
|
|
|
|
// EmulatorManager.m
|
|
|
|
// 2Term
|
|
|
|
//
|
|
|
|
// Created by Kelvin Sherlock on 10/5/2010.
|
|
|
|
// Copyright (c) 2010 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "Emulator.h"
|
|
|
|
#import <AppKit/AppKit.h>
|
|
|
|
|
|
|
|
@implementation EmulatorManager
|
|
|
|
|
|
|
|
static NSMutableArray *array = nil;
|
|
|
|
|
|
|
|
+(id)alloc
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
+(id)new
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(id)init
|
|
|
|
{
|
|
|
|
[self release];
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-06 00:39:09 +00:00
|
|
|
// can be called before +load.
|
2010-10-05 18:56:45 +00:00
|
|
|
+(void)registerClass: (Class)klass
|
|
|
|
{
|
|
|
|
if (klass && [klass conformsToProtocol: @protocol(Emulator)])
|
|
|
|
{
|
|
|
|
@synchronized (self)
|
|
|
|
{
|
2010-10-06 00:39:09 +00:00
|
|
|
if (!array)
|
|
|
|
array = [NSMutableArray new];
|
|
|
|
|
2010-10-05 18:56:45 +00:00
|
|
|
[array addObject: klass];
|
2010-12-23 20:40:48 +00:00
|
|
|
|
|
|
|
[array sortUsingComparator: ^(id lhs, id rhs){
|
|
|
|
NSString *a, *b;
|
|
|
|
|
|
|
|
a = (NSString *)[lhs name];
|
|
|
|
b = (NSString *)[rhs name];
|
|
|
|
|
|
|
|
return [a caseInsensitiveCompare: b];
|
|
|
|
}];
|
2010-10-05 18:56:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
+(NSMenu *)emulatorMenu
|
|
|
|
{
|
|
|
|
NSMenu *menu = [[[NSMenu alloc] initWithTitle: @"Terminal Type"] autorelease];
|
|
|
|
|
|
|
|
@synchronized (self)
|
|
|
|
{
|
|
|
|
unsigned index = 0;
|
|
|
|
for (Class klass in array)
|
|
|
|
{
|
|
|
|
NSMenuItem *item = [[NSMenuItem new] autorelease];
|
|
|
|
|
|
|
|
[item setTitle: [klass name]];
|
|
|
|
[item setTag: ++index];
|
|
|
|
[menu addItem: item];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
+(id)emulatorForTag: (unsigned)tag
|
|
|
|
{
|
|
|
|
@synchronized(self)
|
|
|
|
{
|
2010-10-06 00:39:09 +00:00
|
|
|
if (tag && tag <= [array count])
|
2010-10-05 18:56:45 +00:00
|
|
|
{
|
|
|
|
return [array objectAtIndex: tag - 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
}
|
|
|
|
@end
|