Tab conversion into 4 spaces

This commit is contained in:
Mengjuei 2012-02-26 20:53:51 -08:00
parent 8e5c540597
commit 0d8e1ae20f
8 changed files with 343 additions and 343 deletions

View File

@ -132,8 +132,8 @@ public:
// text input from an IME // text input from an IME
self = [super initWithServer:server delegate:delegate client:client]; self = [super initWithServer:server delegate:delegate client:client];
if (self) { if (self) {
// create the reading buffer // create the reading buffer
_bpmfReadingBuffer = new BopomofoReadingBuffer(BopomofoKeyboardLayout::StandardLayout()); _bpmfReadingBuffer = new BopomofoReadingBuffer(BopomofoKeyboardLayout::StandardLayout());
// create the lattice builder // create the lattice builder
@ -149,17 +149,17 @@ public:
if (![[NSUserDefaults standardUserDefaults] objectForKey:kDisableUserCandidateSelectionLearning]) { if (![[NSUserDefaults standardUserDefaults] objectForKey:kDisableUserCandidateSelectionLearning]) {
[[NSUserDefaults standardUserDefaults] setObject:(id)kCFBooleanTrue forKey:kDisableUserCandidateSelectionLearning]; [[NSUserDefaults standardUserDefaults] setObject:(id)kCFBooleanTrue forKey:kDisableUserCandidateSelectionLearning];
} }
} }
return self; return self;
} }
- (NSMenu *)menu - (NSMenu *)menu
{ {
// a menu instance (autoreleased) is requested every time the user click on the input menu // a menu instance (autoreleased) is requested every time the user click on the input menu
NSMenu *menu = [[[NSMenu alloc] initWithTitle:@"Input Method Menu"] autorelease]; NSMenu *menu = [[[NSMenu alloc] initWithTitle:@"Input Method Menu"] autorelease];
NSMenuItem *preferenceMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"McBopomofo Preferences", @"") action:@selector(showPreferences:) keyEquivalent:@""] autorelease]; NSMenuItem *preferenceMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"McBopomofo Preferences", @"") action:@selector(showPreferences:) keyEquivalent:@""] autorelease];
[menu addItem:preferenceMenuItem]; [menu addItem:preferenceMenuItem];
// If Option key is pressed, show the learning-related menu // If Option key is pressed, show the learning-related menu
@ -190,8 +190,8 @@ public:
} }
#endif //DEBUG #endif //DEBUG
NSMenuItem *aboutMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"About McBopomofo…", @"") action:@selector(showAbout:) keyEquivalent:@""] autorelease]; NSMenuItem *aboutMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"About McBopomofo…", @"") action:@selector(showAbout:) keyEquivalent:@""] autorelease];
[menu addItem:aboutMenuItem]; [menu addItem:aboutMenuItem];
return menu; return menu;
} }
@ -229,9 +229,9 @@ public:
_bpmfReadingBuffer->setKeyboardLayout(BopomofoKeyboardLayout::StandardLayout()); _bpmfReadingBuffer->setKeyboardLayout(BopomofoKeyboardLayout::StandardLayout());
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:kKeyboardLayoutPreferenceKey]; [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:kKeyboardLayoutPreferenceKey];
} }
if (keyboardLayout < 4) { if (keyboardLayout < 4) {
[client overrideKeyboardWithKeyboardNamed:@"com.apple.keylayout.US"]; [client overrideKeyboardWithKeyboardNamed:@"com.apple.keylayout.US"];
} }
// set the size // set the size
NSInteger textSize = [[NSUserDefaults standardUserDefaults] integerForKey:kCandidateListTextSizeKey]; NSInteger textSize = [[NSUserDefaults standardUserDefaults] integerForKey:kCandidateListTextSizeKey];
@ -250,8 +250,8 @@ public:
[[NSUserDefaults standardUserDefaults] setInteger:textSize forKey:kCandidateListTextSizeKey]; [[NSUserDefaults standardUserDefaults] setInteger:textSize forKey:kCandidateListTextSizeKey];
} }
if (![[NSUserDefaults standardUserDefaults] objectForKey:kChooseCandidateUsingSpaceKey]) { if (![[NSUserDefaults standardUserDefaults] objectForKey:kChooseCandidateUsingSpaceKey]) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kChooseCandidateUsingSpaceKey]; [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kChooseCandidateUsingSpaceKey];
} }
[(AppDelegate *)[NSApp delegate] checkForUpdate]; [(AppDelegate *)[NSApp delegate] checkForUpdate];
} }
@ -344,11 +344,11 @@ public:
NSDictionary *attrDict = [NSDictionary dictionaryWithObjectsAndKeys: NSDictionary *attrDict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:NSUnderlineStyleSingle], NSUnderlineStyleAttributeName, [NSNumber numberWithInt:NSUnderlineStyleSingle], NSUnderlineStyleAttributeName,
[NSNumber numberWithInt:0], NSMarkedClauseSegmentAttributeName, nil]; [NSNumber numberWithInt:0], NSMarkedClauseSegmentAttributeName, nil];
NSMutableAttributedString *attrString = [[[NSMutableAttributedString alloc] initWithString:composedText attributes:attrDict] autorelease]; NSMutableAttributedString *attrString = [[[NSMutableAttributedString alloc] initWithString:composedText attributes:attrDict] autorelease];
// the selection range is where the cursor is, with the length being 0 and replacement range NSNotFound, // the selection range is where the cursor is, with the length being 0 and replacement range NSNotFound,
// i.e. the client app needs to take care of where to put ths composing buffer // i.e. the client app needs to take care of where to put ths composing buffer
[client setMarkedText:attrString selectionRange:NSMakeRange(cursorIndex, 0) replacementRange:NSMakeRange(NSNotFound, NSNotFound)]; [client setMarkedText:attrString selectionRange:NSMakeRange(cursorIndex, 0) replacementRange:NSMakeRange(NSNotFound, NSNotFound)];
} }
- (void)walk - (void)walk
@ -421,24 +421,24 @@ public:
- (BOOL)inputText:(NSString*)inputText key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)client - (BOOL)inputText:(NSString*)inputText key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)client
{ {
NSRect textFrame = NSZeroRect; NSRect textFrame = NSZeroRect;
NSDictionary *attributes = nil; NSDictionary *attributes = nil;
BOOL useVerticalMode = NO; BOOL useVerticalMode = NO;
@try { @try {
attributes = [client attributesForCharacterIndex:0 lineHeightRectangle:&textFrame]; attributes = [client attributesForCharacterIndex:0 lineHeightRectangle:&textFrame];
useVerticalMode = [attributes objectForKey:@"IMKTextOrientation"] && [[attributes objectForKey:@"IMKTextOrientation"] integerValue] == 0; useVerticalMode = [attributes objectForKey:@"IMKTextOrientation"] && [[attributes objectForKey:@"IMKTextOrientation"] integerValue] == 0;
} }
@catch (NSException *e) { @catch (NSException *e) {
// An exception may raise while using Twitter.app's search filed. // An exception may raise while using Twitter.app's search filed.
} }
NSInteger leftKey = useVerticalMode ? 125 : 124; NSInteger leftKey = useVerticalMode ? 125 : 124;
NSInteger rightKey = useVerticalMode ? 126 : 123; NSInteger rightKey = useVerticalMode ? 126 : 123;
NSInteger downKey = useVerticalMode ? 123 : 125; NSInteger downKey = useVerticalMode ? 123 : 125;
NSInteger upKey = useVerticalMode ? 124 : 126; NSInteger upKey = useVerticalMode ? 124 : 126;
// get the unicode character code // get the unicode character code
UniChar charCode = [inputText length] ? [inputText characterAtIndex:0] : 0; UniChar charCode = [inputText length] ? [inputText characterAtIndex:0] : 0;
if ([[client bundleIdentifier] isEqualToString:@"com.apple.Terminal"] && [NSStringFromClass([client class]) isEqualToString:@"IPMDServerClientWrapper"]) if ([[client bundleIdentifier] isEqualToString:@"com.apple.Terminal"] && [NSStringFromClass([client class]) isEqualToString:@"IPMDServerClientWrapper"])
{ {
@ -447,9 +447,9 @@ public:
} }
// if the inputText is empty, it's a function key combination, we ignore it // if the inputText is empty, it's a function key combination, we ignore it
if (![inputText length]) { if (![inputText length]) {
return NO; return NO;
} }
// if the composing buffer is empty and there's no reading, and there is some function key combination, we ignore it // if the composing buffer is empty and there's no reading, and there is some function key combination, we ignore it
if (![_composingBuffer length] && _bpmfReadingBuffer->isEmpty() && ((flags & NSCommandKeyMask) || (flags & NSControlKeyMask) || (flags & NSAlternateKeyMask) || (flags & NSNumericPadKeyMask))) { if (![_composingBuffer length] && _bpmfReadingBuffer->isEmpty() && ((flags & NSCommandKeyMask) || (flags & NSControlKeyMask) || (flags & NSAlternateKeyMask) || (flags & NSNumericPadKeyMask))) {
@ -460,29 +460,29 @@ public:
// caps lock processing : if caps is locked, temporarily disabled bopomofo. // caps lock processing : if caps is locked, temporarily disabled bopomofo.
if (charCode == 8 || charCode == 13 || if (charCode == 8 || charCode == 13 ||
keyCode == upKey || keyCode == downKey || keyCode == upKey || keyCode == downKey ||
keyCode == leftKey || keyCode == rightKey) { keyCode == leftKey || keyCode == rightKey) {
// Do nothing if backspace is pressed // Do nothing if backspace is pressed
} else if (flags & NSAlphaShiftKeyMask){ } else if (flags & NSAlphaShiftKeyMask){
// Now process all possible combination, we hope. // Now process all possible combination, we hope.
if ([_composingBuffer length]) [self commitComposition:client]; if ([_composingBuffer length]) [self commitComposition:client];
// First commit everything in the buffer. // First commit everything in the buffer.
if (flags & NSShiftKeyMask) return NO; if (flags & NSShiftKeyMask) return NO;
// when shift is pressed, don't do further processing, since it outputs // when shift is pressed, don't do further processing, since it outputs
// capital letter anyway. // capital letter anyway.
NSString *popedText = [inputText lowercaseString]; NSString *popedText = [inputText lowercaseString];
[client insertText:popedText replacementRange:NSMakeRange(NSNotFound, NSNotFound)]; [client insertText:popedText replacementRange:NSMakeRange(NSNotFound, NSNotFound)];
return YES; return YES;
} }
if (flags & NSNumericPadKeyMask) { if (flags & NSNumericPadKeyMask) {
if (keyCode != 123 && keyCode != 124 && keyCode != 125 && keyCode != 126 && charCode != 32 ) { if (keyCode != 123 && keyCode != 124 && keyCode != 125 && keyCode != 126 && charCode != 32 ) {
if ([_composingBuffer length]) [self commitComposition:client]; if ([_composingBuffer length]) [self commitComposition:client];
NSString *popedText = [inputText lowercaseString]; NSString *popedText = [inputText lowercaseString];
[client insertText:popedText replacementRange:NSMakeRange(NSNotFound, NSNotFound)]; [client insertText:popedText replacementRange:NSMakeRange(NSNotFound, NSNotFound)];
return YES; return YES;
} }
} }
// see if it's valid BPMF reading // see if it's valid BPMF reading
if (_bpmfReadingBuffer->isValidKey((char)charCode)) { if (_bpmfReadingBuffer->isValidKey((char)charCode)) {
@ -521,7 +521,7 @@ public:
if (![[NSUserDefaults standardUserDefaults] boolForKey:kDisableUserCandidateSelectionLearning]) { if (![[NSUserDefaults standardUserDefaults] boolForKey:kDisableUserCandidateSelectionLearning]) {
NSString *trigram = [self neighborTrigramString]; NSString *trigram = [self neighborTrigramString];
// Lookup from the user dict to see if the trigram fit or not // Lookup from the user dict to see if the trigram fit or not
NSString *overrideCandidateString = [TLCandidateLearningDictionary objectForKey:trigram]; NSString *overrideCandidateString = [TLCandidateLearningDictionary objectForKey:trigram];
if (overrideCandidateString) { if (overrideCandidateString) {
[self candidateSelected:(NSAttributedString *)overrideCandidateString]; [self candidateSelected:(NSAttributedString *)overrideCandidateString];
@ -538,24 +538,24 @@ public:
// keyCode 125 = Down, charCode 32 = Space // keyCode 125 = Down, charCode 32 = Space
if (_bpmfReadingBuffer->isEmpty() && [_composingBuffer length] > 0 && (keyCode == downKey || charCode == 32)) { if (_bpmfReadingBuffer->isEmpty() && [_composingBuffer length] > 0 && (keyCode == downKey || charCode == 32)) {
if (charCode == 32) { if (charCode == 32) {
// if the spacebar is NOT set to be a selection key // if the spacebar is NOT set to be a selection key
if (![[NSUserDefaults standardUserDefaults] boolForKey:kChooseCandidateUsingSpaceKey]) { if (![[NSUserDefaults standardUserDefaults] boolForKey:kChooseCandidateUsingSpaceKey]) {
if (_builder->cursorIndex() >= _builder->length()) { if (_builder->cursorIndex() >= _builder->length()) {
[_composingBuffer appendString:@" "]; [_composingBuffer appendString:@" "];
[self commitComposition:client]; [self commitComposition:client];
_bpmfReadingBuffer->clear(); _bpmfReadingBuffer->clear();
} }
else if (LTLanguageModel.hasUnigramsForKey(" ")) { else if (LTLanguageModel.hasUnigramsForKey(" ")) {
_builder->insertReadingAtCursor(" "); _builder->insertReadingAtCursor(" ");
[self popOverflowComposingTextAndWalk:client]; [self popOverflowComposingTextAndWalk:client];
[self updateClientComposingBuffer:client]; [self updateClientComposingBuffer:client];
} }
return YES; return YES;
} }
} }
[self _showCandidateWindowUsingVerticalMode:useVerticalMode client:client]; [self _showCandidateWindowUsingVerticalMode:useVerticalMode client:client];
return YES; return YES;
} }
@ -575,8 +575,8 @@ public:
[self updateClientComposingBuffer:client]; [self updateClientComposingBuffer:client];
return YES; return YES;
//可能的行為包括 1. 取消組字, 把字吃掉 2. 取消 candidate 選擇, 恢復原來的 //可能的行為包括 1. 取消組字, 把字吃掉 2. 取消 candidate 選擇, 恢復原來的
//3. 取消組字,現出注音 //3. 取消組字,現出注音
} }
// The Right key, note we use keyCode here // The Right key, note we use keyCode here
@ -623,13 +623,13 @@ public:
return YES; return YES;
} }
if (keyCode == upKey || keyCode == downKey) { if (keyCode == upKey || keyCode == downKey) {
if (!_bpmfReadingBuffer->isEmpty()) { if (!_bpmfReadingBuffer->isEmpty()) {
[self beep]; [self beep];
} }
[self updateClientComposingBuffer:client]; [self updateClientComposingBuffer:client];
return YES; return YES;
} }
// Backspace // Backspace
if (charCode == 8) { if (charCode == 8) {
@ -664,45 +664,45 @@ public:
return YES; return YES;
} }
if ((char)charCode == '`') { if ((char)charCode == '`') {
if (LTLanguageModel.hasUnigramsForKey(string("_punctuation_list"))) { if (LTLanguageModel.hasUnigramsForKey(string("_punctuation_list"))) {
if (_bpmfReadingBuffer->isEmpty()) { if (_bpmfReadingBuffer->isEmpty()) {
_builder->insertReadingAtCursor(string("_punctuation_list")); _builder->insertReadingAtCursor(string("_punctuation_list"));
[self popOverflowComposingTextAndWalk:client]; [self popOverflowComposingTextAndWalk:client];
[self _showCandidateWindowUsingVerticalMode:useVerticalMode client:client]; [self _showCandidateWindowUsingVerticalMode:useVerticalMode client:client];
} }
else { // If there is still unfinished bpmf reading, ignore the punctuation else { // If there is still unfinished bpmf reading, ignore the punctuation
[self beep]; [self beep];
} }
[self updateClientComposingBuffer:client]; [self updateClientComposingBuffer:client];
return YES; return YES;
} }
}
string layout = string("Standard_");;
NSInteger keyboardLayout = [[NSUserDefaults standardUserDefaults] integerForKey:kKeyboardLayoutPreferenceKey];
switch (keyboardLayout) {
case 0:
layout = string("Standard_");
break;
case 1:
layout = string("ETen_");
break;
case 2:
layout = string("ETen26_");
break;
case 3:
layout = string("Hsu_");
break;
case 4:
layout = string("HanyuPinyin_");
break;
default:
break;
} }
string customPunctuation = string("_punctuation_") + layout + string(1, (char)charCode); string layout = string("Standard_");;
if (LTLanguageModel.hasUnigramsForKey(customPunctuation)) { NSInteger keyboardLayout = [[NSUserDefaults standardUserDefaults] integerForKey:kKeyboardLayoutPreferenceKey];
switch (keyboardLayout) {
case 0:
layout = string("Standard_");
break;
case 1:
layout = string("ETen_");
break;
case 2:
layout = string("ETen26_");
break;
case 3:
layout = string("Hsu_");
break;
case 4:
layout = string("HanyuPinyin_");
break;
default:
break;
}
string customPunctuation = string("_punctuation_") + layout + string(1, (char)charCode);
if (LTLanguageModel.hasUnigramsForKey(customPunctuation)) {
if (_bpmfReadingBuffer->isEmpty()) { if (_bpmfReadingBuffer->isEmpty()) {
_builder->insertReadingAtCursor(customPunctuation); _builder->insertReadingAtCursor(customPunctuation);
[self popOverflowComposingTextAndWalk:client]; [self popOverflowComposingTextAndWalk:client];
@ -782,7 +782,7 @@ public:
[self saveUserCandidatesDictionary]; [self saveUserCandidatesDictionary];
} }
size_t cursorIndex = [self actualCandidateCursorIndex]; size_t cursorIndex = [self actualCandidateCursorIndex];
vector<NodeAnchor> nodes = _builder->grid().nodesCrossingOrEndingAt(cursorIndex); vector<NodeAnchor> nodes = _builder->grid().nodesCrossingOrEndingAt(cursorIndex);
for (vector<NodeAnchor>::iterator ni = nodes.begin(), ne = nodes.end(); ni != ne; ++ni) { for (vector<NodeAnchor>::iterator ni = nodes.begin(), ne = nodes.end(); ni != ne; ++ni) {
@ -831,7 +831,7 @@ public:
NSMutableArray *termArray = [NSMutableArray array]; NSMutableArray *termArray = [NSMutableArray array];
size_t cursorIndex = [self actualCandidateCursorIndex]; size_t cursorIndex = [self actualCandidateCursorIndex];
vector<NodeAnchor> nodes = _builder->grid().nodesCrossingOrEndingAt(cursorIndex); vector<NodeAnchor> nodes = _builder->grid().nodesCrossingOrEndingAt(cursorIndex);
const Node* prev = 0; const Node* prev = 0;
@ -899,38 +899,38 @@ public:
- (void)_showCandidateWindowUsingVerticalMode:(BOOL)useVerticalMode client:(id)client - (void)_showCandidateWindowUsingVerticalMode:(BOOL)useVerticalMode client:(id)client
{ {
// candidate // candidate
[LTSharedCandidates setDismissesAutomatically:YES]; [LTSharedCandidates setDismissesAutomatically:YES];
// wrap NSNumber; we only allow number keys 1-9 as selection keys in this project // wrap NSNumber; we only allow number keys 1-9 as selection keys in this project
#define LTUIntObj(x) ([NSNumber numberWithInteger:x]) #define LTUIntObj(x) ([NSNumber numberWithInteger:x])
[LTSharedCandidates setSelectionKeys:[NSArray arrayWithObjects:LTUIntObj(18), LTUIntObj(19), LTUIntObj(20), LTUIntObj(21), LTUIntObj(23), LTUIntObj(22), LTUIntObj(26), LTUIntObj(28), LTUIntObj(25), nil]]; [LTSharedCandidates setSelectionKeys:[NSArray arrayWithObjects:LTUIntObj(18), LTUIntObj(19), LTUIntObj(20), LTUIntObj(21), LTUIntObj(23), LTUIntObj(22), LTUIntObj(26), LTUIntObj(28), LTUIntObj(25), nil]];
#undef LTUIntObj #undef LTUIntObj
// set the candidate panel style // set the candidate panel style
BOOL useHorizontalCandidateList = [[NSUserDefaults standardUserDefaults] boolForKey:kUseHorizontalCandidateListPreferenceKey]; BOOL useHorizontalCandidateList = [[NSUserDefaults standardUserDefaults] boolForKey:kUseHorizontalCandidateListPreferenceKey];
if (useVerticalMode) { if (useVerticalMode) {
[LTSharedCandidates setPanelType:kIMKSingleColumnScrollingCandidatePanel]; [LTSharedCandidates setPanelType:kIMKSingleColumnScrollingCandidatePanel];
} }
else if (useHorizontalCandidateList) { else if (useHorizontalCandidateList) {
[LTSharedCandidates setPanelType:kIMKSingleRowSteppingCandidatePanel]; [LTSharedCandidates setPanelType:kIMKSingleRowSteppingCandidatePanel];
} }
else { else {
[LTSharedCandidates setPanelType:kIMKSingleColumnScrollingCandidatePanel]; [LTSharedCandidates setPanelType:kIMKSingleColumnScrollingCandidatePanel];
} }
// set the attributes for the candidate panel (which uses NSAttributedString) // set the attributes for the candidate panel (which uses NSAttributedString)
NSInteger textSize = [[NSUserDefaults standardUserDefaults] integerForKey:kCandidateListTextSizeKey]; NSInteger textSize = [[NSUserDefaults standardUserDefaults] integerForKey:kCandidateListTextSizeKey];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: [NSFont systemFontOfSize:textSize], NSFontAttributeName, nil]; NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: [NSFont systemFontOfSize:textSize], NSFontAttributeName, nil];
[LTSharedCandidates setAttributes:attributes]; [LTSharedCandidates setAttributes:attributes];
[LTSharedCandidates updateCandidates]; [LTSharedCandidates updateCandidates];
[LTSharedCandidates show:useVerticalMode ? kIMKLocateCandidatesLeftHint : kIMKLocateCandidatesBelowHint]; [LTSharedCandidates show:useVerticalMode ? kIMKLocateCandidatesLeftHint : kIMKLocateCandidatesBelowHint];
// update the composing text, set the client // update the composing text, set the client
[self updateClientComposingBuffer:client]; [self updateClientComposingBuffer:client];
_currentCandidateClient = client; _currentCandidateClient = client;
} }
#pragma mark - Misc menu items #pragma mark - Misc menu items
@ -994,7 +994,7 @@ void LTLoadLanguageModel()
} }
} }
ifs.close(); ifs.close();
LTLanguageModel.add(" ", " ", 0.0); LTLanguageModel.add(" ", " ", 0.0);
// initialize the singleton learning dictionary // initialize the singleton learning dictionary
// putting singleton in @synchronized is the standard way in Objective-C // putting singleton in @synchronized is the standard way in Objective-C

View File

@ -30,55 +30,55 @@
@implementation OVInputSourceHelper @implementation OVInputSourceHelper
+ (NSArray *)allInstalledInputSources + (NSArray *)allInstalledInputSources
{ {
CFArrayRef list = TISCreateInputSourceList(NULL, true); CFArrayRef list = TISCreateInputSourceList(NULL, true);
return [NSMakeCollectable(list) autorelease]; return [NSMakeCollectable(list) autorelease];
} }
+ (TISInputSourceRef)inputSourceForProperty:(CFStringRef)inPropertyKey stringValue:(NSString *)inValue + (TISInputSourceRef)inputSourceForProperty:(CFStringRef)inPropertyKey stringValue:(NSString *)inValue
{ {
CFTypeID stringID = CFStringGetTypeID(); CFTypeID stringID = CFStringGetTypeID();
for (id source in [self allInstalledInputSources]) { for (id source in [self allInstalledInputSources]) {
CFTypeRef property = TISGetInputSourceProperty((TISInputSourceRef)source, inPropertyKey); CFTypeRef property = TISGetInputSourceProperty((TISInputSourceRef)source, inPropertyKey);
if (!property || CFGetTypeID(property) != stringID) { if (!property || CFGetTypeID(property) != stringID) {
continue; continue;
} }
if (inValue && [inValue compare:(NSString *)property] == NSOrderedSame) { if (inValue && [inValue compare:(NSString *)property] == NSOrderedSame) {
return (TISInputSourceRef)source; return (TISInputSourceRef)source;
} }
} }
return NULL; return NULL;
} }
+ (TISInputSourceRef)inputSourceForInputSourceID:(NSString *)inID + (TISInputSourceRef)inputSourceForInputSourceID:(NSString *)inID
{ {
return [self inputSourceForProperty:kTISPropertyInputSourceID stringValue:inID]; return [self inputSourceForProperty:kTISPropertyInputSourceID stringValue:inID];
} }
+ (BOOL)inputSourceEnabled:(TISInputSourceRef)inInputSource + (BOOL)inputSourceEnabled:(TISInputSourceRef)inInputSource
{ {
CFBooleanRef value = TISGetInputSourceProperty(inInputSource, kTISPropertyInputSourceIsEnabled); CFBooleanRef value = TISGetInputSourceProperty(inInputSource, kTISPropertyInputSourceIsEnabled);
return value ? (BOOL)CFBooleanGetValue(value) : NO; return value ? (BOOL)CFBooleanGetValue(value) : NO;
} }
+ (BOOL)enableInputSource:(TISInputSourceRef)inInputSource + (BOOL)enableInputSource:(TISInputSourceRef)inInputSource
{ {
OSStatus status = TISEnableInputSource(inInputSource); OSStatus status = TISEnableInputSource(inInputSource);
return status == noErr; return status == noErr;
} }
+ (BOOL)disableInputSource:(TISInputSourceRef)inInputSource + (BOOL)disableInputSource:(TISInputSourceRef)inInputSource
{ {
OSStatus status = TISDisableInputSource(inInputSource); OSStatus status = TISDisableInputSource(inInputSource);
return status == noErr; return status == noErr;
} }
+ (BOOL)registerInputSource:(NSURL *)inBundleURL + (BOOL)registerInputSource:(NSURL *)inBundleURL
{ {
OSStatus status = TISRegisterInputSource((CFURLRef)inBundleURL); OSStatus status = TISRegisterInputSource((CFURLRef)inBundleURL);
return status == noErr; return status == noErr;
} }
@end @end

View File

@ -61,7 +61,7 @@ int main(int argc, char *argv[])
if (!inputSource) { if (!inputSource) {
NSLog(@"Registering input source %@ at %@.", bundleID, [bundleURL absoluteString]); NSLog(@"Registering input source %@ at %@.", bundleID, [bundleURL absoluteString]);
// then register // then register
BOOL status = [OVInputSourceHelper registerInputSource:bundleURL]; BOOL status = [OVInputSourceHelper registerInputSource:bundleURL];
if (!status) { if (!status) {
NSLog(@"Fatal error: Cannot register input source %@ at %@.", bundleID, [bundleURL absoluteString]); NSLog(@"Fatal error: Cannot register input source %@ at %@.", bundleID, [bundleURL absoluteString]);