mirror of
https://github.com/ksherlock/TwoTerm.git
synced 2025-01-22 08:31:45 +00:00
Emulator Manager
git-svn-id: svn://qnap.local/TwoTerm/branches/frameless@2465 5590a31f-7b70-45f8-8c82-aa3a8e5f4507
This commit is contained in:
parent
dd13a2d5c3
commit
8c65b9e6c5
122
Emulators/EmulatorManager.mm
Normal file
122
Emulators/EmulatorManager.mm
Normal file
@ -0,0 +1,122 @@
|
||||
//
|
||||
// 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>
|
||||
|
||||
|
||||
unsigned EventCharacters(NSEvent *event, std::u32string &rv)
|
||||
{
|
||||
unsigned flags = [event modifierFlags];
|
||||
NSString *chars = [event charactersIgnoringModifiers];
|
||||
unsigned length = [chars length];
|
||||
|
||||
rv.reserve(length);
|
||||
|
||||
// chars is expected to have 1 character but could have 0 (dead key)
|
||||
// or multiple
|
||||
for (unsigned i = 0; i < length; ++i)
|
||||
{
|
||||
unichar c = [chars characterAtIndex: i];
|
||||
if (c <= 0x7f)
|
||||
{
|
||||
if (flags & NSAlphaShiftKeyMask)
|
||||
{
|
||||
c = flags & NSShiftKeyMask ? tolower(c) : toupper(c);
|
||||
}
|
||||
|
||||
if (flags & NSControlKeyMask)
|
||||
c = CTRL(c);
|
||||
}
|
||||
|
||||
rv.push_back(c);
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@implementation EmulatorManager
|
||||
|
||||
static NSMutableArray *array = nil;
|
||||
|
||||
+(id)alloc
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
+(id)new
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(id)init
|
||||
{
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
// can be called before +load.
|
||||
+(void)registerClass: (Class)klass
|
||||
{
|
||||
if (klass && [klass conformsToProtocol: @protocol(Emulator)])
|
||||
{
|
||||
@synchronized (self)
|
||||
{
|
||||
if (!array)
|
||||
array = [NSMutableArray new];
|
||||
|
||||
[array addObject: klass];
|
||||
|
||||
[array sortUsingComparator: ^(id lhs, id rhs){
|
||||
NSString *a, *b;
|
||||
|
||||
a = (NSString *)[lhs name];
|
||||
b = (NSString *)[rhs name];
|
||||
|
||||
return [a caseInsensitiveCompare: b];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+(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)
|
||||
{
|
||||
if (tag && tag <= [array count])
|
||||
{
|
||||
return [array objectAtIndex: tag - 1];
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
|
||||
}
|
||||
@end
|
Loading…
x
Reference in New Issue
Block a user