From 0d8e1ae20f306581c523e8c7b00fa6479afa68e9 Mon Sep 17 00:00:00 2001 From: Mengjuei Date: Sun, 26 Feb 2012 20:53:51 -0800 Subject: [PATCH] Tab conversion into 4 spaces --- Source/AppDelegate.m | 40 +- Source/InputMethodController.h | 10 +- Source/InputMethodController.mm | 522 +++++++++++++------------- Source/OVInputSourceHelper.m | 50 +-- Source/PreferencesWindowController.m | 6 +- Source/UpdateNotificationController.h | 2 +- Source/UpdateNotificationController.m | 6 +- Source/main.m | 50 +-- 8 files changed, 343 insertions(+), 343 deletions(-) diff --git a/Source/AppDelegate.m b/Source/AppDelegate.m index 0921d4fd..d8ba0e15 100644 --- a/Source/AppDelegate.m +++ b/Source/AppDelegate.m @@ -56,7 +56,7 @@ static const NSTimeInterval kNextCheckInterval = 86400.0; - (void)applicationDidFinishLaunching:(NSNotification *)inNotification { LTLoadLanguageModel(); - + [self checkForUpdate]; } @@ -70,36 +70,36 @@ static const NSTimeInterval kNextCheckInterval = 86400.0; if ([(NSDate *)[NSDate date] compare:date] == NSOrderedAscending) { return; } - + NSDate *nextUpdateDate = [NSDate dateWithTimeInterval:kNextCheckInterval sinceDate:[NSDate date]]; [[NSUserDefaults standardUserDefaults] setObject:nextUpdateDate forKey:kNextUpdateCheckDateKey]; - + if (_updateCheckConnection) { [_updateCheckConnection release]; _updateCheckConnection = nil; } - + NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; NSString *updateInfoURLString = [infoDict objectForKey:kUpdateInfoEndpointKey]; - + if (![updateInfoURLString length]) { return; } - + NSURL *updateInfoURL = [NSURL URLWithString:updateInfoURLString]; if (!updateInfoURL) { return; } - + NSURLRequest *request = [NSURLRequest requestWithURL:updateInfoURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:kTimeoutInterval]; - + if (!request) { return; } #if DEBUG NSLog(@"about to request update url %@ ",updateInfoURL); #endif - + _updateCheckConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; [_updateCheckConnection start]; } @@ -118,7 +118,7 @@ NSLog(@"error"); if (!plist) { return; } - + NSString *remoteVersion = [plist objectForKey:(id)kCFBundleVersionKey]; #if DEBUG NSLog(@"the remoteversion is %@",remoteVersion); @@ -126,10 +126,10 @@ NSLog(@"error"); if (!remoteVersion) { return; } - + // TODO: Validate info (e.g. bundle identifier) // TODO: Use HTML to display change log, need a new key like UpdateInfoChangeLogURL for this - + NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; NSString *currentVersion = [infoDict objectForKey:(id)kCFBundleVersionKey]; NSComparisonResult result = [currentVersion compare:remoteVersion options:NSNumericSearch]; @@ -137,25 +137,25 @@ NSLog(@"error"); if (result != NSOrderedAscending) { return; } - - + + NSString *siteInfoURLString = [plist objectForKey:kUpdateInfoSiteKey]; if (!siteInfoURLString) { return; } - + NSURL *siteInfoURL = [NSURL URLWithString:siteInfoURLString]; if (!siteInfoURL) { return; } - - + + if (_updateNotificationController) { [_updateNotificationController release], _updateNotificationController = nil; } - + _updateNotificationController = [[UpdateNotificationController alloc] initWithWindowNibName:@"UpdateNotificationController"]; - + _updateNotificationController.siteURL = siteInfoURL; _updateNotificationController.infoText = [NSString stringWithFormat:NSLocalizedString(@"You are running version %@ (%@), and the new version %@ (%@) is now available.\n\nVisit the website to download it?", @""), [infoDict objectForKey:@"CFBundleShortVersionString"], @@ -163,7 +163,7 @@ NSLog(@"error"); [plist objectForKey:@"CFBundleShortVersionString"], [plist objectForKey:(id)kCFBundleVersionKey], nil]; - + [_updateNotificationController showWindow:self]; [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; } diff --git a/Source/InputMethodController.h b/Source/InputMethodController.h index 30c3ef08..19ee2ef9 100644 --- a/Source/InputMethodController.h +++ b/Source/InputMethodController.h @@ -42,19 +42,19 @@ @private // the reading buffer that takes user input Formosa::Mandarin::BopomofoReadingBuffer* _bpmfReadingBuffer; - + // the grid (lattice) builder for the unigrams (and bigrams) Formosa::Gramambular::BlockReadingBuilder* _builder; - + // latest walked path (trellis) using the Viterbi algorithm std::vector _walkedNodes; - + // the latest composing buffer that is updated to the foreground app NSMutableString *_composingBuffer; - + // the current text input client; we need to keep this when candidate panel is on id _currentCandidateClient; - + // a special deferred client for Terminal.app fix id _currentDeferredClient; } diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index 99212f3d..9be7162e 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -9,7 +9,7 @@ // // Based on the Syrup Project and the Formosana Library // by Lukhnos Liu (@lukhnos). -// +// // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without @@ -117,12 +117,12 @@ public: if (_builder) { delete _builder; } - + [_composingBuffer release]; - + // the two client pointers are weak pointers (i.e. we don't retain them) // therefore we don't do anything about it - + [super dealloc]; } @@ -130,44 +130,44 @@ public: { // an instance is initialized whenever a text input client (a Mac app) requires // text input from an IME - + self = [super initWithServer:server delegate:delegate client:client]; - if (self) { - // create the reading buffer + if (self) { + // create the reading buffer _bpmfReadingBuffer = new BopomofoReadingBuffer(BopomofoKeyboardLayout::StandardLayout()); - + // create the lattice builder _builder = new BlockReadingBuilder(<LanguageModel); - + // each Mandarin syllable is separated by a hyphen _builder->setJoinSeparator("-"); - + // create the composing buffer _composingBuffer = [[NSMutableString alloc] init]; - + // populate the settings, by default, DISABLE user candidate learning if (![[NSUserDefaults standardUserDefaults] objectForKey:kDisableUserCandidateSelectionLearning]) { [[NSUserDefaults standardUserDefaults] setObject:(id)kCFBooleanTrue forKey:kDisableUserCandidateSelectionLearning]; } - } - - return self; + } + + return self; } - (NSMenu *)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]; - NSMenuItem *preferenceMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"McBopomofo Preferences", @"") action:@selector(showPreferences:) keyEquivalent:@""] autorelease]; - [menu addItem:preferenceMenuItem]; + NSMenu *menu = [[[NSMenu alloc] initWithTitle:@"Input Method Menu"] autorelease]; + NSMenuItem *preferenceMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"McBopomofo Preferences", @"") action:@selector(showPreferences:) keyEquivalent:@""] autorelease]; + [menu addItem:preferenceMenuItem]; // If Option key is pressed, show the learning-related menu - + #if DEBUG if ([[NSEvent class] respondsToSelector:@selector(modifierFlags)] && ([NSEvent modifierFlags] & NSAlternateKeyMask)) { - + BOOL learningEnabled = ![[NSUserDefaults standardUserDefaults] boolForKey:kDisableUserCandidateSelectionLearning]; - + NSMenuItem *learnMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Enable Selection Learning", @"") action:@selector(toggleLearning:) keyEquivalent:@""] autorelease]; if (learningEnabled) { [learnMenuItem setState:NSOnState]; @@ -175,7 +175,7 @@ public: else { [learnMenuItem setState:NSOffState]; } - + [menu addItem:learnMenuItem]; if (learningEnabled) { @@ -183,16 +183,16 @@ public: NSMenuItem *clearMenuItem = [[[NSMenuItem alloc] initWithTitle:clearMenuItemTitle action:@selector(clearLearningDictionary:) keyEquivalent:@""] autorelease]; [menu addItem:clearMenuItem]; - + NSMenuItem *dumpMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Dump Learning Data to Console", @"") action:@selector(dumpLearningDictionary:) keyEquivalent:@""] autorelease]; [menu addItem:dumpMenuItem]; } } #endif //DEBUG - - NSMenuItem *aboutMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"About McBopomofo…", @"") action:@selector(showAbout:) keyEquivalent:@""] autorelease]; - [menu addItem:aboutMenuItem]; - + + NSMenuItem *aboutMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"About McBopomofo…", @"") action:@selector(showAbout:) keyEquivalent:@""] autorelease]; + [menu addItem:aboutMenuItem]; + return menu; } @@ -201,7 +201,7 @@ public: - (void)activateServer:(id)client { // reset the state - _currentDeferredClient = nil; + _currentDeferredClient = nil; _currentCandidateClient = nil; _builder->clear(); _walkedNodes.clear(); @@ -211,7 +211,7 @@ public: NSInteger keyboardLayout = [[NSUserDefaults standardUserDefaults] integerForKey:kKeyboardLayoutPreferenceKey]; switch (keyboardLayout) { case 0: - _bpmfReadingBuffer->setKeyboardLayout(BopomofoKeyboardLayout::StandardLayout()); + _bpmfReadingBuffer->setKeyboardLayout(BopomofoKeyboardLayout::StandardLayout()); break; case 1: _bpmfReadingBuffer->setKeyboardLayout(BopomofoKeyboardLayout::ETenLayout()); @@ -229,12 +229,12 @@ public: _bpmfReadingBuffer->setKeyboardLayout(BopomofoKeyboardLayout::StandardLayout()); [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:kKeyboardLayoutPreferenceKey]; } - if (keyboardLayout < 4) { - [client overrideKeyboardWithKeyboardNamed:@"com.apple.keylayout.US"]; - } + if (keyboardLayout < 4) { + [client overrideKeyboardWithKeyboardNamed:@"com.apple.keylayout.US"]; + } // set the size - NSInteger textSize = [[NSUserDefaults standardUserDefaults] integerForKey:kCandidateListTextSizeKey]; + NSInteger textSize = [[NSUserDefaults standardUserDefaults] integerForKey:kCandidateListTextSizeKey]; NSInteger previousTextSize = textSize; if (textSize == 0) { textSize = kDefaultCandidateListTextSize; @@ -245,14 +245,14 @@ public: else if (textSize > kMaxCandidateListTextSize) { textSize = kMaxCandidateListTextSize; } - + if (textSize != previousTextSize) { [[NSUserDefaults standardUserDefaults] setInteger:textSize forKey:kCandidateListTextSizeKey]; } if (![[NSUserDefaults standardUserDefaults] objectForKey:kChooseCandidateUsingSpaceKey]) { - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kChooseCandidateUsingSpaceKey]; - } - + [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kChooseCandidateUsingSpaceKey]; + } + [(AppDelegate *)[NSApp delegate] checkForUpdate]; } @@ -260,14 +260,14 @@ public: { // commit any residue in the composing buffer [self commitComposition:client]; - _currentDeferredClient = nil; + _currentDeferredClient = nil; _currentCandidateClient = nil; } #pragma mark - IMKServerInput protocol methods -- (void)commitComposition:(id)client -{ +- (void)commitComposition:(id)client +{ // if it's Terminal, we don't commit at the first call (the client of which will not be IPMDServerClientWrapper) // then we defer the update in the next runloop round -- so that the composing buffer is not // meaninglessly flushed, an annoying bug in Terminal.app since Mac OS X 10.5 @@ -278,9 +278,9 @@ public: } return; } - + // commit the text, clear the state - [client insertText:_composingBuffer replacementRange:NSMakeRange(NSNotFound, NSNotFound)]; + [client insertText:_composingBuffer replacementRange:NSMakeRange(NSNotFound, NSNotFound)]; _builder->clear(); _walkedNodes.clear(); [_composingBuffer setString:@""]; @@ -291,7 +291,7 @@ public: { // "updating the composing buffer" means to request the client to "refresh" the text input buffer // with our "composing text" - + [_composingBuffer setString:@""]; NSInteger composedStringCursorIndex = 0; @@ -306,10 +306,10 @@ public: string nodeStr = (*wi).node->currentKeyValue().value; vector codepoints = OVUTF8Helper::SplitStringByCodePoint(nodeStr); size_t codepointCount = codepoints.size(); - + NSString *valueString = [NSString stringWithUTF8String:nodeStr.c_str()]; [_composingBuffer appendString:valueString]; - + // this re-aligns the cursor index in the composed string // (the actual cursor on the screen) with the builder's logical // cursor (reading) cursor; each built node has a "spanning length" @@ -328,7 +328,7 @@ public: } } } - } + } // now we gather all the info, we separate the composing buffer to two parts, head and tail, // and insert the reading text (the Mandarin syllable) in between them; @@ -344,11 +344,11 @@ public: NSDictionary *attrDict = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:NSUnderlineStyleSingle], NSUnderlineStyleAttributeName, [NSNumber numberWithInt:0], NSMarkedClauseSegmentAttributeName, nil]; - 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, - // 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)]; + 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, + // 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)]; } - (void)walk @@ -357,19 +357,19 @@ public: // of the best possible Mandarain characters given the input syllables, // using the Viterbi algorithm implemented in the Gramambular library Walker walker(&_builder->grid()); - - // the reverse walk traces the trellis from the end + + // the reverse walk traces the trellis from the end _walkedNodes = walker.reverseWalk(_builder->grid().width()); - + // then we reverse the nodes so that we get the forward-walked nodes reverse(_walkedNodes.begin(), _walkedNodes.end()); - // if DEBUG is defined, a GraphViz file is written to kGraphVizOutputfile - #if DEBUG + // if DEBUG is defined, a GraphViz file is written to kGraphVizOutputfile + #if DEBUG string dotDump = _builder->grid().dumpDOT(); NSString *dotStr = [NSString stringWithUTF8String:dotDump.c_str()]; NSError *error = nil; - + BOOL __unused success = [dotStr writeToFile:kGraphVizOutputfile atomically:YES encoding:NSUTF8StringEncoding error:&error]; #endif } @@ -383,10 +383,10 @@ public: // lose their influence over the whole MLE anyway -- so tht when // the user type along, the already composed text at front will // be popped out - + NSInteger _composingBufferSize = [[NSUserDefaults standardUserDefaults] integerForKey:kComposingBufferSizePreferenceKey]; NSInteger previousComposingBufferSize = _composingBufferSize; - + if (_composingBufferSize == 0) { _composingBufferSize = kDefaultComposingBufferSize; } @@ -396,20 +396,20 @@ public: else if (_composingBufferSize > kMaxComposingBufferSize) { _composingBufferSize = kMaxComposingBufferSize; } - + if (_composingBufferSize != previousComposingBufferSize) { [[NSUserDefaults standardUserDefaults] setInteger:_composingBufferSize forKey:kComposingBufferSizePreferenceKey]; } - + if (_builder->grid().width() > (size_t)_composingBufferSize) { if (_walkedNodes.size() > 0) { NodeAnchor &anchor = _walkedNodes[0]; - NSString *popedText = [NSString stringWithUTF8String:anchor.node->currentKeyValue().value.c_str()]; + NSString *popedText = [NSString stringWithUTF8String:anchor.node->currentKeyValue().value.c_str()]; [client insertText:popedText replacementRange:NSMakeRange(NSNotFound, NSNotFound)]; _builder->removeHeadReadings(anchor.spanningLength); } } - + [self walk]; } @@ -421,73 +421,73 @@ public: - (BOOL)inputText:(NSString*)inputText key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)client { - NSRect textFrame = NSZeroRect; - NSDictionary *attributes = nil; - BOOL useVerticalMode = NO; - @try { - attributes = [client attributesForCharacterIndex:0 lineHeightRectangle:&textFrame]; - useVerticalMode = [attributes objectForKey:@"IMKTextOrientation"] && [[attributes objectForKey:@"IMKTextOrientation"] integerValue] == 0; - } - @catch (NSException *e) { - // An exception may raise while using Twitter.app's search filed. - } - - NSInteger leftKey = useVerticalMode ? 125 : 124; - NSInteger rightKey = useVerticalMode ? 126 : 123; - NSInteger downKey = useVerticalMode ? 123 : 125; - NSInteger upKey = useVerticalMode ? 124 : 126; - + NSRect textFrame = NSZeroRect; + NSDictionary *attributes = nil; + BOOL useVerticalMode = NO; + @try { + attributes = [client attributesForCharacterIndex:0 lineHeightRectangle:&textFrame]; + useVerticalMode = [attributes objectForKey:@"IMKTextOrientation"] && [[attributes objectForKey:@"IMKTextOrientation"] integerValue] == 0; + } + @catch (NSException *e) { + // An exception may raise while using Twitter.app's search filed. + } + + NSInteger leftKey = useVerticalMode ? 125 : 124; + NSInteger rightKey = useVerticalMode ? 126 : 123; + NSInteger downKey = useVerticalMode ? 123 : 125; + NSInteger upKey = useVerticalMode ? 124 : 126; + // 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"]) { // special handling for com.apple.Terminal _currentDeferredClient = client; } - + // if the inputText is empty, it's a function key combination, we ignore it - if (![inputText length]) { - return NO; - } + if (![inputText length]) { + return NO; + } // 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))) { return NO; - } - + } + bool composeReading = false; - + // caps lock processing : if caps is locked, temporarily disabled bopomofo. - if (charCode == 8 || charCode == 13 || - keyCode == upKey || keyCode == downKey || + if (charCode == 8 || charCode == 13 || + keyCode == upKey || keyCode == downKey || keyCode == leftKey || keyCode == rightKey) { // Do nothing if backspace is pressed - } else if (flags & NSAlphaShiftKeyMask){ + } else if (flags & NSAlphaShiftKeyMask){ // 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. - if (flags & NSShiftKeyMask) return NO; + if (flags & NSShiftKeyMask) return NO; // when shift is pressed, don't do further processing, since it outputs // capital letter anyway. - NSString *popedText = [inputText lowercaseString]; - [client insertText:popedText replacementRange:NSMakeRange(NSNotFound, NSNotFound)]; - return YES; - } - if (flags & NSNumericPadKeyMask) { - if (keyCode != 123 && keyCode != 124 && keyCode != 125 && keyCode != 126 && charCode != 32 ) { - if ([_composingBuffer length]) [self commitComposition:client]; - NSString *popedText = [inputText lowercaseString]; - [client insertText:popedText replacementRange:NSMakeRange(NSNotFound, NSNotFound)]; - return YES; - } - } - + NSString *popedText = [inputText lowercaseString]; + [client insertText:popedText replacementRange:NSMakeRange(NSNotFound, NSNotFound)]; + return YES; + } + if (flags & NSNumericPadKeyMask) { + if (keyCode != 123 && keyCode != 124 && keyCode != 125 && keyCode != 126 && charCode != 32 ) { + if ([_composingBuffer length]) [self commitComposition:client]; + NSString *popedText = [inputText lowercaseString]; + [client insertText:popedText replacementRange:NSMakeRange(NSNotFound, NSNotFound)]; + return YES; + } + } + // see if it's valid BPMF reading if (_bpmfReadingBuffer->isValidKey((char)charCode)) { _bpmfReadingBuffer->combineKey((char)charCode); - + // if we have a tone marker, we have to insert the reading to the builder // in other words, if we don't have a tone marker, we just update the composing buffer composeReading = _bpmfReadingBuffer->hasToneMarker(); @@ -496,76 +496,76 @@ public: return YES; } } - + // see if we have composition if Enter/Space is hit and buffer is not empty // this is bit-OR'ed so that the tone marker key is also taken into account composeReading |= (!_bpmfReadingBuffer->isEmpty() && (charCode == 32 || charCode == 13)); if (composeReading) { // combine the reading string reading = _bpmfReadingBuffer->syllable().composedString(); - + // see if we have a unigram for this if (!LTLanguageModel.hasUnigramsForKey(reading)) { [self beep]; [self updateClientComposingBuffer:client]; return YES; } - + // and insert it into the lattice _builder->insertReadingAtCursor(reading); - + // then walk the lattice [self popOverflowComposingTextAndWalk:client]; - + // see if we need to override the selection if a learned one exists if (![[NSUserDefaults standardUserDefaults] boolForKey:kDisableUserCandidateSelectionLearning]) { 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]; if (overrideCandidateString) { [self candidateSelected:(NSAttributedString *)overrideCandidateString]; } } - + // then update the text _bpmfReadingBuffer->clear(); [self updateClientComposingBuffer:client]; - + // and tells the client that the key is consumed - return YES; + return YES; } // keyCode 125 = Down, charCode 32 = Space if (_bpmfReadingBuffer->isEmpty() && [_composingBuffer length] > 0 && (keyCode == downKey || charCode == 32)) { - if (charCode == 32) { - // if the spacebar is NOT set to be a selection key - if (![[NSUserDefaults standardUserDefaults] boolForKey:kChooseCandidateUsingSpaceKey]) { - if (_builder->cursorIndex() >= _builder->length()) { - [_composingBuffer appendString:@" "]; - [self commitComposition:client]; - _bpmfReadingBuffer->clear(); - } - else if (LTLanguageModel.hasUnigramsForKey(" ")) { - _builder->insertReadingAtCursor(" "); - [self popOverflowComposingTextAndWalk:client]; - [self updateClientComposingBuffer:client]; - } - return YES; - - } - } - [self _showCandidateWindowUsingVerticalMode:useVerticalMode client:client]; + if (charCode == 32) { + // if the spacebar is NOT set to be a selection key + if (![[NSUserDefaults standardUserDefaults] boolForKey:kChooseCandidateUsingSpaceKey]) { + if (_builder->cursorIndex() >= _builder->length()) { + [_composingBuffer appendString:@" "]; + [self commitComposition:client]; + _bpmfReadingBuffer->clear(); + } + else if (LTLanguageModel.hasUnigramsForKey(" ")) { + _builder->insertReadingAtCursor(" "); + [self popOverflowComposingTextAndWalk:client]; + [self updateClientComposingBuffer:client]; + } + return YES; + + } + } + [self _showCandidateWindowUsingVerticalMode:useVerticalMode client:client]; return YES; } - + // Esc - if (charCode == 27) { + if (charCode == 27) { if (_bpmfReadingBuffer->isEmpty()) { if (![_composingBuffer length]) { return NO; } - + //[self beep]; //如果要按 ESC 的時候都已經知道要取消些啥,不必beep } @@ -575,20 +575,20 @@ public: [self updateClientComposingBuffer:client]; return YES; - //可能的行為包括 1. 取消組字, 把字吃掉 2. 取消 candidate 選擇, 恢復原來的 - //3. 取消組字,現出注音 + //可能的行為包括 1. 取消組字, 把字吃掉 2. 取消 candidate 選擇, 恢復原來的 + //3. 取消組字,現出注音 } - + // The Right key, note we use keyCode here if (keyCode == rightKey) { - if (!_bpmfReadingBuffer->isEmpty()) { + if (!_bpmfReadingBuffer->isEmpty()) { [self beep]; } else { if (![_composingBuffer length]) { return NO; } - + if (_builder->cursorIndex() > 0) { _builder->setCursorIndex(_builder->cursorIndex() - 1); } @@ -596,21 +596,21 @@ public: [self beep]; } } - + [self updateClientComposingBuffer:client]; return YES; } - + // The Left key, note we use keyCode here if (keyCode == leftKey) { - if (!_bpmfReadingBuffer->isEmpty()) { + if (!_bpmfReadingBuffer->isEmpty()) { [self beep]; } else { if (![_composingBuffer length]) { return NO; } - + if (_builder->cursorIndex() < [_composingBuffer length]) { _builder->setCursorIndex(_builder->cursorIndex() + 1); } @@ -618,29 +618,29 @@ public: [self beep]; } } - + [self updateClientComposingBuffer:client]; return YES; } - if (keyCode == upKey || keyCode == downKey) { - if (!_bpmfReadingBuffer->isEmpty()) { + if (keyCode == upKey || keyCode == downKey) { + if (!_bpmfReadingBuffer->isEmpty()) { [self beep]; } [self updateClientComposingBuffer:client]; - return YES; - } - + return YES; + } + // Backspace if (charCode == 8) { if (_bpmfReadingBuffer->isEmpty()) { if (![_composingBuffer length]) { return NO; } - + if (_builder->cursorIndex()) { _builder->deleteReadingBeforeCursor(); - [self walk]; + [self walk]; } else { [self beep]; @@ -649,60 +649,60 @@ public: else { _bpmfReadingBuffer->backspace(); } - + [self updateClientComposingBuffer:client]; return YES; } - + // Enter if (charCode == 13) { if (![_composingBuffer length]) { return NO; } - + [self commitComposition:client]; return YES; } - if ((char)charCode == '`') { - if (LTLanguageModel.hasUnigramsForKey(string("_punctuation_list"))) { - if (_bpmfReadingBuffer->isEmpty()) { - _builder->insertReadingAtCursor(string("_punctuation_list")); - [self popOverflowComposingTextAndWalk:client]; - [self _showCandidateWindowUsingVerticalMode:useVerticalMode client:client]; - } - else { // If there is still unfinished bpmf reading, ignore the punctuation - [self beep]; - } - [self updateClientComposingBuffer:client]; - return YES; - } - } - - string layout = string("Standard_");; - NSInteger keyboardLayout = [[NSUserDefaults standardUserDefaults] integerForKey:kKeyboardLayoutPreferenceKey]; + if ((char)charCode == '`') { + if (LTLanguageModel.hasUnigramsForKey(string("_punctuation_list"))) { + if (_bpmfReadingBuffer->isEmpty()) { + _builder->insertReadingAtCursor(string("_punctuation_list")); + [self popOverflowComposingTextAndWalk:client]; + [self _showCandidateWindowUsingVerticalMode:useVerticalMode client:client]; + } + else { // If there is still unfinished bpmf reading, ignore the punctuation + [self beep]; + } + [self updateClientComposingBuffer:client]; + return YES; + } + } + + string layout = string("Standard_");; + NSInteger keyboardLayout = [[NSUserDefaults standardUserDefaults] integerForKey:kKeyboardLayoutPreferenceKey]; switch (keyboardLayout) { case 0: - layout = string("Standard_"); + layout = string("Standard_"); break; case 1: - layout = string("ETen_"); + layout = string("ETen_"); break; case 2: - layout = string("ETen26_"); + layout = string("ETen26_"); break; case 3: - layout = string("Hsu_"); + layout = string("Hsu_"); break; case 4: - layout = string("HanyuPinyin_"); + layout = string("HanyuPinyin_"); break; default: - break; + break; } - - string customPunctuation = string("_punctuation_") + layout + string(1, (char)charCode); - if (LTLanguageModel.hasUnigramsForKey(customPunctuation)) { + + string customPunctuation = string("_punctuation_") + layout + string(1, (char)charCode); + if (LTLanguageModel.hasUnigramsForKey(customPunctuation)) { if (_bpmfReadingBuffer->isEmpty()) { _builder->insertReadingAtCursor(customPunctuation); [self popOverflowComposingTextAndWalk:client]; @@ -713,7 +713,7 @@ public: [self updateClientComposingBuffer:client]; return YES; } - + // if nothing is matched, see if it's a punctuation key string punctuation = string("_punctuation_") + string(1, (char)charCode); if (LTLanguageModel.hasUnigramsForKey(punctuation)) { @@ -743,11 +743,11 @@ public: - (NSArray*)candidates:(id)client { // returns the candidate - + NSMutableArray *results = [NSMutableArray array]; size_t cursorIndex = [self actualCandidateCursorIndex]; vector nodes = _builder->grid().nodesCrossingOrEndingAt(cursorIndex); - + // sort the nodes, so that longer nodes (representing longer phrases) are placed at the top of the candidate list sort(nodes.begin(), nodes.end(), NodeAnchorDescendingSorter()); @@ -758,23 +758,23 @@ public: [results addObject:[NSString stringWithUTF8String:(*ci).value.c_str()]]; } } - + return results; } - + - (void)candidateSelected:(NSAttributedString *)candidateString { // candidate selected, override the node with selection - + string selectedValue; - + if ([candidateString isKindOfClass:[NSString class]]) { selectedValue = [(NSString *)candidateString UTF8String]; } else { selectedValue = [[candidateString string] UTF8String]; } - + if (![[NSUserDefaults standardUserDefaults] boolForKey:kDisableUserCandidateSelectionLearning]) { NSString *trigram = [self neighborTrigramString]; NSString *selectedNSString = [NSString stringWithUTF8String:selectedValue.c_str()]; @@ -782,9 +782,9 @@ public: [self saveUserCandidatesDictionary]; } - size_t cursorIndex = [self actualCandidateCursorIndex]; + size_t cursorIndex = [self actualCandidateCursorIndex]; vector nodes = _builder->grid().nodesCrossingOrEndingAt(cursorIndex); - + for (vector::iterator ni = nodes.begin(), ne = nodes.end(); ni != ne; ++ni) { const vector& candidates = (*ni).node->candidates(); @@ -796,7 +796,7 @@ public: } } } - + [self walk]; [self updateClientComposingBuffer:_currentCandidateClient]; _currentCandidateClient = nil; @@ -807,37 +807,37 @@ public: - (size_t)actualCandidateCursorIndex { size_t cursorIndex = _builder->cursorIndex(); - + BOOL candidatePhraseLocatedAfterCursor = [[NSUserDefaults standardUserDefaults] boolForKey:kSelectPhraseAfterCursorAsCandidatePreferenceKey]; - + if (candidatePhraseLocatedAfterCursor) { // MS Phonetics IME style, phrase is *after* the cursor, i.e. cursor is always *before* the phrase if (cursorIndex < _builder->length()) { ++cursorIndex; - } + } } else { if (!cursorIndex) { ++cursorIndex; - } + } } - + return cursorIndex; } - (NSString *)neighborTrigramString { // gather the "trigram" for user candidate selection learning - + NSMutableArray *termArray = [NSMutableArray array]; - - size_t cursorIndex = [self actualCandidateCursorIndex]; + + size_t cursorIndex = [self actualCandidateCursorIndex]; vector nodes = _builder->grid().nodesCrossingOrEndingAt(cursorIndex); - + const Node* prev = 0; const Node* current = 0; const Node* next = 0; - + size_t wni = 0; size_t wnc = _walkedNodes.size(); size_t accuSpanningLength = 0; @@ -846,37 +846,37 @@ public: if (!anchor.node) { continue; } - + accuSpanningLength += anchor.spanningLength; - if (accuSpanningLength >= cursorIndex) { + if (accuSpanningLength >= cursorIndex) { prev = current; current = anchor.node; break; } - + current = anchor.node; } - + if (wni + 1 < wnc) { next = _walkedNodes[wni + 1].node; } - + string term; if (prev) { term = prev->currentKeyValue().key; [termArray addObject:[NSString stringWithUTF8String:term.c_str()]]; } - + if (current) { term = current->currentKeyValue().key; [termArray addObject:[NSString stringWithUTF8String:term.c_str()]]; } - + if (next) { term = next->currentKeyValue().key; [termArray addObject:[NSString stringWithUTF8String:term.c_str()]]; } - + return [termArray componentsJoinedByString:@"-"]; } @@ -890,47 +890,47 @@ public: if (!TLUserCandidatesDictionaryPath) { return; } - + [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_performDeferredSaveUserCandidatesDictionary) object:nil]; - + // TODO: Const-ize the delay [self performSelector:@selector(_performDeferredSaveUserCandidatesDictionary) withObject:nil afterDelay:5.0]; } - (void)_showCandidateWindowUsingVerticalMode:(BOOL)useVerticalMode client:(id)client { - // candidate - [LTSharedCandidates setDismissesAutomatically:YES]; - - // wrap NSNumber; we only allow number keys 1-9 as selection keys in this project -#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]]; + // candidate + [LTSharedCandidates setDismissesAutomatically:YES]; + + // wrap NSNumber; we only allow number keys 1-9 as selection keys in this project +#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]]; #undef LTUIntObj - - // set the candidate panel style - BOOL useHorizontalCandidateList = [[NSUserDefaults standardUserDefaults] boolForKey:kUseHorizontalCandidateListPreferenceKey]; - - if (useVerticalMode) { - [LTSharedCandidates setPanelType:kIMKSingleColumnScrollingCandidatePanel]; - } - else if (useHorizontalCandidateList) { - [LTSharedCandidates setPanelType:kIMKSingleRowSteppingCandidatePanel]; - } - else { - [LTSharedCandidates setPanelType:kIMKSingleColumnScrollingCandidatePanel]; - } - - // set the attributes for the candidate panel (which uses NSAttributedString) - NSInteger textSize = [[NSUserDefaults standardUserDefaults] integerForKey:kCandidateListTextSizeKey]; - NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: [NSFont systemFontOfSize:textSize], NSFontAttributeName, nil]; - [LTSharedCandidates setAttributes:attributes]; - - [LTSharedCandidates updateCandidates]; - [LTSharedCandidates show:useVerticalMode ? kIMKLocateCandidatesLeftHint : kIMKLocateCandidatesBelowHint]; - - // update the composing text, set the client - [self updateClientComposingBuffer:client]; - _currentCandidateClient = client; + + // set the candidate panel style + BOOL useHorizontalCandidateList = [[NSUserDefaults standardUserDefaults] boolForKey:kUseHorizontalCandidateListPreferenceKey]; + + if (useVerticalMode) { + [LTSharedCandidates setPanelType:kIMKSingleColumnScrollingCandidatePanel]; + } + else if (useHorizontalCandidateList) { + [LTSharedCandidates setPanelType:kIMKSingleRowSteppingCandidatePanel]; + } + else { + [LTSharedCandidates setPanelType:kIMKSingleColumnScrollingCandidatePanel]; + } + + // set the attributes for the candidate panel (which uses NSAttributedString) + NSInteger textSize = [[NSUserDefaults standardUserDefaults] integerForKey:kCandidateListTextSizeKey]; + NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: [NSFont systemFontOfSize:textSize], NSFontAttributeName, nil]; + [LTSharedCandidates setAttributes:attributes]; + + [LTSharedCandidates updateCandidates]; + [LTSharedCandidates show:useVerticalMode ? kIMKLocateCandidatesLeftHint : kIMKLocateCandidatesBelowHint]; + + // update the composing text, set the client + [self updateClientComposingBuffer:client]; + _currentCandidateClient = client; } #pragma mark - Misc menu items @@ -951,7 +951,7 @@ public: - (void)toggleLearning:(id)sender { BOOL toggle = ![[NSUserDefaults standardUserDefaults] boolForKey:kDisableUserCandidateSelectionLearning]; - + [[NSUserDefaults standardUserDefaults] setBool:toggle forKey:kDisableUserCandidateSelectionLearning]; } @@ -972,49 +972,49 @@ void LTLoadLanguageModel() { // load the language model; the performance of this function can be greatly improved // with better loading/parsing methods - + NSDate *__unused startTime = [NSDate date]; NSString *dataPath = [[NSBundle bundleForClass:[LettuceInputMethodController class]] pathForResource:@"data" ofType:@"txt"]; - + ifstream ifs; ifs.open([dataPath UTF8String]); while (ifs.good()) { string line; getline(ifs, line); - + if (!line.size() || (line.size() && line[0] == '#')) { continue; } - + vector p = OVStringHelper::SplitBySpacesOrTabs(line); - + if (p.size() == 3) { LTLanguageModel.add(p[1], p[0], atof(p[2].c_str())); } } ifs.close(); - LTLanguageModel.add(" ", " ", 0.0); - + LTLanguageModel.add(" ", " ", 0.0); + // initialize the singleton learning dictionary // putting singleton in @synchronized is the standard way in Objective-C // to avoid race condition TLCandidateLearningDictionary = [[NSMutableDictionary alloc] init]; - + // the first instance is also responsible for loading the dictionary NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDirectory, YES); if (![paths count]) { NSLog(@"Fatal error: cannot find Applicaiton Support directory."); return; } - + NSString *appSupportPath = [paths objectAtIndex:0]; - + NSString *userDictPath = [appSupportPath stringByAppendingPathComponent:@"McBopomofo"]; BOOL isDir = NO; BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:userDictPath isDirectory:&isDir]; - + if (exists) { if (!isDir) { NSLog(@"Fatal error: Path '%@' is not a directory", userDictPath); @@ -1029,7 +1029,7 @@ void LTLoadLanguageModel() return; } } - + // TODO: Change this NSString *userDictFile = [userDictPath stringByAppendingPathComponent:@"UserCandidatesCache.plist"]; TLUserCandidatesDictionaryPath = [userDictFile retain]; @@ -1040,14 +1040,14 @@ void LTLoadLanguageModel() if (!data) { return; } - + NSString *errorStr = nil; NSPropertyListFormat format = 0; id plist = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&errorStr]; if (plist && [plist isKindOfClass:[NSDictionary class]]) { [TLCandidateLearningDictionary setDictionary:(NSDictionary *)plist]; NSLog(@"User dictionary read, item count: %ju", (uintmax_t)[TLCandidateLearningDictionary count]); - } + } } - + } diff --git a/Source/OVInputSourceHelper.m b/Source/OVInputSourceHelper.m index 4e93faf9..3f0e429f 100644 --- a/Source/OVInputSourceHelper.m +++ b/Source/OVInputSourceHelper.m @@ -2,7 +2,7 @@ // OVInputSourceHelper.m // // Copyright (c) 2010-2011 Lukhnos D. Liu (lukhnos at lukhnos dot org) -// +// // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without @@ -30,55 +30,55 @@ @implementation OVInputSourceHelper + (NSArray *)allInstalledInputSources { - CFArrayRef list = TISCreateInputSourceList(NULL, true); - return [NSMakeCollectable(list) autorelease]; + CFArrayRef list = TISCreateInputSourceList(NULL, true); + return [NSMakeCollectable(list) autorelease]; } + (TISInputSourceRef)inputSourceForProperty:(CFStringRef)inPropertyKey stringValue:(NSString *)inValue { - - CFTypeID stringID = CFStringGetTypeID(); - for (id source in [self allInstalledInputSources]) { - CFTypeRef property = TISGetInputSourceProperty((TISInputSourceRef)source, inPropertyKey); - if (!property || CFGetTypeID(property) != stringID) { - continue; - } + CFTypeID stringID = CFStringGetTypeID(); - if (inValue && [inValue compare:(NSString *)property] == NSOrderedSame) { - return (TISInputSourceRef)source; - } - } - - return NULL; + for (id source in [self allInstalledInputSources]) { + CFTypeRef property = TISGetInputSourceProperty((TISInputSourceRef)source, inPropertyKey); + if (!property || CFGetTypeID(property) != stringID) { + continue; + } + + if (inValue && [inValue compare:(NSString *)property] == NSOrderedSame) { + return (TISInputSourceRef)source; + } + } + + return NULL; } + (TISInputSourceRef)inputSourceForInputSourceID:(NSString *)inID { - return [self inputSourceForProperty:kTISPropertyInputSourceID stringValue:inID]; + return [self inputSourceForProperty:kTISPropertyInputSourceID stringValue:inID]; } + (BOOL)inputSourceEnabled:(TISInputSourceRef)inInputSource { - CFBooleanRef value = TISGetInputSourceProperty(inInputSource, kTISPropertyInputSourceIsEnabled); - return value ? (BOOL)CFBooleanGetValue(value) : NO; + CFBooleanRef value = TISGetInputSourceProperty(inInputSource, kTISPropertyInputSourceIsEnabled); + return value ? (BOOL)CFBooleanGetValue(value) : NO; } + (BOOL)enableInputSource:(TISInputSourceRef)inInputSource { - OSStatus status = TISEnableInputSource(inInputSource); - return status == noErr; + OSStatus status = TISEnableInputSource(inInputSource); + return status == noErr; } + (BOOL)disableInputSource:(TISInputSourceRef)inInputSource { - OSStatus status = TISDisableInputSource(inInputSource); - return status == noErr; + OSStatus status = TISDisableInputSource(inInputSource); + return status == noErr; } + (BOOL)registerInputSource:(NSURL *)inBundleURL { - OSStatus status = TISRegisterInputSource((CFURLRef)inBundleURL); - return status == noErr; + OSStatus status = TISRegisterInputSource((CFURLRef)inBundleURL); + return status == noErr; } @end diff --git a/Source/PreferencesWindowController.m b/Source/PreferencesWindowController.m index 611cbc60..3fc49cdf 100644 --- a/Source/PreferencesWindowController.m +++ b/Source/PreferencesWindowController.m @@ -42,13 +42,13 @@ // if (![[NSApplication sharedApplication] respondsToSelector:@selector(disableRelaunchOnLogin)]) { // return; // } - + NSMenu *menu = [_fontSizePopUpButton menu]; NSArray *menuItems = [menu itemArray]; - + for (NSMenuItem *item in menuItems) { NSUInteger tag = [item tag]; - + if (tag != 14 && tag != 24) { [menu removeItem:item]; } diff --git a/Source/UpdateNotificationController.h b/Source/UpdateNotificationController.h index 489840bc..4392bee8 100644 --- a/Source/UpdateNotificationController.h +++ b/Source/UpdateNotificationController.h @@ -39,7 +39,7 @@ NSButton *_visitButton; NSButton *_laterButton; NSTextField *_infoTextField; - + NSURL *_siteURL; NSString *_infoText; } diff --git a/Source/UpdateNotificationController.m b/Source/UpdateNotificationController.m index d96a6171..76636592 100644 --- a/Source/UpdateNotificationController.m +++ b/Source/UpdateNotificationController.m @@ -47,7 +47,7 @@ if (self) { _infoText = @"Version info here"; } - + return self; } @@ -64,14 +64,14 @@ [_visitButton setTitle:NSLocalizedString(@"Visit Website", @"")]; [_laterButton setTitle:NSLocalizedString(@"Check Later", @"")]; [_infoTextField setStringValue:_infoText]; - + [[self window] makeFirstResponder:_visitButton]; } - (void)windowDidLoad { [super windowDidLoad]; - + // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. } diff --git a/Source/main.m b/Source/main.m index dffaa583..c1a5053b 100644 --- a/Source/main.m +++ b/Source/main.m @@ -9,7 +9,7 @@ // // Based on the Syrup Project and the Formosana Library // by Lukhnos Liu (@lukhnos). -// +// // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without @@ -41,7 +41,7 @@ IMKCandidates *LTSharedCandidates = nil; int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - + // register and enable the input source (along with all its input modes) if (argc > 1 && !strcmp(argv[1], "install")) { NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier]; @@ -54,35 +54,35 @@ int main(int argc, char *argv[]) // For Mac OS X 10.5 bundleURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]; } - + TISInputSourceRef inputSource = [OVInputSourceHelper inputSourceForInputSourceID:bundleID]; // if this IME name is not found in the list of available IMEs if (!inputSource) { NSLog(@"Registering input source %@ at %@.", bundleID, [bundleURL absoluteString]); // then register - BOOL status = [OVInputSourceHelper registerInputSource:bundleURL]; - + BOOL status = [OVInputSourceHelper registerInputSource:bundleURL]; + if (!status) { NSLog(@"Fatal error: Cannot register input source %@ at %@.", bundleID, [bundleURL absoluteString]); [pool drain]; - return -1; + return -1; } - + inputSource = [OVInputSourceHelper inputSourceForInputSourceID:bundleID]; // if it still doesn't register successfully, bail. if (!inputSource) { NSLog(@"Fatal error: Cannot find input source %@ after registration.", bundleID); [pool drain]; - return -1; + return -1; } } - + // if it's not enabled, just enabled it - if (inputSource && ![OVInputSourceHelper inputSourceEnabled:inputSource]) { + if (inputSource && ![OVInputSourceHelper inputSourceEnabled:inputSource]) { NSLog(@"Enabling input source %@ at %@.", bundleID, [bundleURL absoluteString]); BOOL status = [OVInputSourceHelper enableInputSource:inputSource]; - + if (!status != noErr) { NSLog(@"Fatal error: Cannot enable input source %@.", bundleID); [pool drain]; @@ -94,42 +94,42 @@ int main(int argc, char *argv[]) return -1; } } - + return 0; } - - + + NSString *mainNibName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"NSMainNibFile"]; if (!mainNibName) { NSLog(@"Fatal error: NSMainNibFile key not defined in Info.plist."); - [pool drain]; + [pool drain]; return -1; } BOOL loadResult = [NSBundle loadNibNamed:mainNibName owner:[NSApplication sharedApplication]]; if (!loadResult) { NSLog(@"Fatal error: Cannot load %@.", mainNibName); - [pool drain]; - return -1; + [pool drain]; + return -1; } - + IMKServer *server = [[IMKServer alloc] initWithName:kConnectionName bundleIdentifier:[[NSBundle mainBundle] bundleIdentifier]]; if (!server) { NSLog(@"Fatal error: Cannot initialize input method server with connection %@.", kConnectionName); - [pool drain]; - return -1; + [pool drain]; + return -1; } - + LTSharedCandidates = [[IMKCandidates alloc] initWithServer:server panelType:kIMKSingleColumnScrollingCandidatePanel]; if (!LTSharedCandidates) { NSLog(@"Fatal error: Cannot initialize shared candidate panel with connection %@.", kConnectionName); [server release]; - [pool drain]; - return -1; - } + [pool drain]; + return -1; + } [[NSApplication sharedApplication] run]; - [server release]; + [server release]; [pool drain]; return 0; }