mgrPrefs, etc. // Nomenclatural updates.

- KeyLayout -> MandarinParser.
- BasisKeyboardLayout -> BasicKeyboardLayout.
- Also optimizing KeyCov.isDynamicBasicKeyboardLayoutEnabled().
This commit is contained in:
ShikiSuen 2022-04-08 15:09:53 +08:00
parent 3452f4bffa
commit 8a4c2b5910
6 changed files with 85 additions and 251 deletions

View File

@ -25,43 +25,30 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import Cocoa import Cocoa
@objc class AppleKeyboardConverter: NSObject { @objc class AppleKeyboardConverter: NSObject {
@objc class func isDynamicBaseKeyboardLayoutEnabled() -> Bool { static let arrDynamicBasicKeyLayout: [String] = [
switch mgrPrefs.basisKeyboardLayout { "com.apple.keylayout.ZhuyinBopomofo",
case "com.apple.keylayout.ZhuyinBopomofo": "com.apple.keylayout.ZhuyinEten",
return true "org.atelierInmu.vChewing.keyLayouts.vchewingdachen",
case "com.apple.keylayout.ZhuyinEten": "org.atelierInmu.vChewing.keyLayouts.vchewingmitac",
return true "org.atelierInmu.vChewing.keyLayouts.vchewingibm",
case "org.atelierInmu.vChewing.keyLayouts.vchewingdachen": "org.atelierInmu.vChewing.keyLayouts.vchewingseigyou",
return true "org.atelierInmu.vChewing.keyLayouts.vchewingeten",
case "org.atelierInmu.vChewing.keyLayouts.vchewingmitac": "org.unknown.keylayout.vChewingDachen",
return true "org.unknown.keylayout.vChewingFakeSeigyou",
case "org.atelierInmu.vChewing.keyLayouts.vchewingibm": "org.unknown.keylayout.vChewingETen",
return true "org.unknown.keylayout.vChewingIBM",
case "org.atelierInmu.vChewing.keyLayouts.vchewingseigyou": "org.unknown.keylayout.vChewingMiTAC",
return true ]
case "org.atelierInmu.vChewing.keyLayouts.vchewingeten": @objc class func isDynamicBasicKeyboardLayoutEnabled() -> Bool {
return true return AppleKeyboardConverter.arrDynamicBasicKeyLayout.contains(mgrPrefs.basicKeyboardLayout)
case "org.unknown.keylayout.vChewingDachen":
return true
case "org.unknown.keylayout.vChewingFakeSeigyou":
return true
case "org.unknown.keylayout.vChewingETen":
return true
case "org.unknown.keylayout.vChewingIBM":
return true
case "org.unknown.keylayout.vChewingMiTAC":
return true
default:
return false
}
} }
// Apple // Apple
@objc class func cnvApple2ABC(_ charCode: UniChar) -> UniChar { @objc class func cnvApple2ABC(_ charCode: UniChar) -> UniChar {
var charCode = charCode var charCode = charCode
// OVMandarin OVMandarin // OVMandarin OVMandarin
if self.isDynamicBaseKeyboardLayoutEnabled() { if self.isDynamicBasicKeyboardLayoutEnabled() {
// Apple // Apple
switch mgrPrefs.basisKeyboardLayout { switch mgrPrefs.basicKeyboardLayout {
case "com.apple.keylayout.ZhuyinBopomofo": case "com.apple.keylayout.ZhuyinBopomofo":
do { do {
if charCode == 97 { charCode = UniChar(65) } if charCode == 97 { charCode = UniChar(65) }
@ -186,7 +173,7 @@ import Cocoa
// Alt // Alt
if charCode == 8212 { charCode = UniChar(45) } if charCode == 8212 { charCode = UniChar(45) }
// Apple // Apple
if mgrPrefs.basisKeyboardLayout == "com.apple.keylayout.ZhuyinEten" { if mgrPrefs.basicKeyboardLayout == "com.apple.keylayout.ZhuyinEten" {
if charCode == 65343 { charCode = UniChar(95) } if charCode == 65343 { charCode = UniChar(95) }
if charCode == 65306 { charCode = UniChar(58) } if charCode == 65306 { charCode = UniChar(58) }
if charCode == 65311 { charCode = UniChar(63) } if charCode == 65311 { charCode = UniChar(63) }
@ -199,9 +186,9 @@ import Cocoa
@objc class func cnvStringApple2ABC(_ strProcessed: String) -> String { @objc class func cnvStringApple2ABC(_ strProcessed: String) -> String {
var strProcessed = strProcessed var strProcessed = strProcessed
if self.isDynamicBaseKeyboardLayoutEnabled() { if self.isDynamicBasicKeyboardLayoutEnabled() {
// Apple // Apple
switch mgrPrefs.basisKeyboardLayout { switch mgrPrefs.basicKeyboardLayout {
case "com.apple.keylayout.ZhuyinBopomofo": case "com.apple.keylayout.ZhuyinBopomofo":
do { do {
if strProcessed == "a" { strProcessed = "A" } if strProcessed == "a" { strProcessed = "A" }
@ -326,7 +313,7 @@ import Cocoa
// Alt // Alt
if strProcessed == "" { strProcessed = "-" } if strProcessed == "" { strProcessed = "-" }
// Apple // Apple
if mgrPrefs.basisKeyboardLayout == "com.apple.keylayout.ZhuyinEten" { if mgrPrefs.basicKeyboardLayout == "com.apple.keylayout.ZhuyinEten" {
if strProcessed == "_" { strProcessed = "_" } if strProcessed == "_" { strProcessed = "_" }
if strProcessed == "" { strProcessed = ":" } if strProcessed == "" { strProcessed = ":" }
if strProcessed == "" { strProcessed = "?" } if strProcessed == "" { strProcessed = "?" }

View File

@ -46,9 +46,7 @@ static double FindHighestScore(const std::vector<Gramambular::NodeAnchor> &nodes
{ {
double score = ni->node->highestUnigramScore(); double score = ni->node->highestUnigramScore();
if (score > highestScore) if (score > highestScore)
{
highestScore = score; highestScore = score;
}
} }
return highestScore + epsilon; return highestScore + epsilon;
} }
@ -98,14 +96,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
- (BOOL)isBuilderEmpty - (BOOL)isBuilderEmpty
{ {
if (_builder->grid().width() == 0) return (_builder->grid().width() == 0);
{
return YES;
}
else
{
return NO;
}
} }
- (void)setInputMode:(NSString *)value - (void)setInputMode:(NSString *)value
@ -114,25 +105,17 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
vChewing::LMInstantiator *newLanguageModel; vChewing::LMInstantiator *newLanguageModel;
vChewing::UserOverrideModel *newUserOverrideModel; vChewing::UserOverrideModel *newUserOverrideModel;
if ([value isKindOfClass:[NSString class]] && [value isEqual:imeModeCHS]) BOOL isCHS = [value isKindOfClass:[NSString class]] && [value isEqual:imeModeCHS];
{
newInputMode = imeModeCHS; newInputMode = isCHS ? imeModeCHS : imeModeCHT;
newLanguageModel = [mgrLangModel lmCHS]; newLanguageModel = isCHS ? [mgrLangModel lmCHS] : [mgrLangModel lmCHT];
newUserOverrideModel = [mgrLangModel userOverrideModelCHS]; newUserOverrideModel = isCHS ? [mgrLangModel userOverrideModelCHS] : [mgrLangModel userOverrideModelCHT];
}
else
{
newInputMode = imeModeCHT;
newLanguageModel = [mgrLangModel lmCHT];
newUserOverrideModel = [mgrLangModel userOverrideModelCHT];
}
// Report the current Input Mode to ctlInputMethod: // Report the current Input Mode to ctlInputMethod:
ctlInputMethod.currentInputMode = newInputMode; ctlInputMethod.currentInputMode = newInputMode;
// Synchronize the Preference Setting "setPhraseReplacementEnabled" to the new LM. // Synchronize the sub-languageModel state settings to the new LM.
newLanguageModel->setPhraseReplacementEnabled(mgrPrefs.phraseReplacementEnabled); newLanguageModel->setPhraseReplacementEnabled(mgrPrefs.phraseReplacementEnabled);
// Also other sub language models:
newLanguageModel->setSymbolEnabled(mgrPrefs.symbolInputEnabled); newLanguageModel->setSymbolEnabled(mgrPrefs.symbolInputEnabled);
newLanguageModel->setCNSEnabled(mgrPrefs.cns11643Enabled); newLanguageModel->setCNSEnabled(mgrPrefs.cns11643Enabled);
@ -151,24 +134,16 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
} }
if (!_bpmfReadingBuffer->isEmpty()) if (!_bpmfReadingBuffer->isEmpty())
{
_bpmfReadingBuffer->clear(); _bpmfReadingBuffer->clear();
}
} }
} }
- (void)dealloc - (void)dealloc
{ { // clean up everything
// clean up everything
if (_bpmfReadingBuffer) if (_bpmfReadingBuffer)
{
delete _bpmfReadingBuffer; delete _bpmfReadingBuffer;
}
if (_builder) if (_builder)
{
delete _builder; delete _builder;
}
} }
- (instancetype)init - (instancetype)init
@ -196,36 +171,35 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
- (void)syncWithPreferences - (void)syncWithPreferences
{ {
NSInteger layout = mgrPrefs.keyboardLayout; switch (mgrPrefs.mandarinParser)
switch (layout)
{ {
case KeyboardLayoutOfStandard: case MandarinParserOfStandard:
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::StandardLayout()); _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::StandardLayout());
break; break;
case KeyboardLayoutOfEten: case MandarinParserOfEten:
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::ETenLayout()); _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::ETenLayout());
break; break;
case KeyboardLayoutOfHsu: case MandarinParserOfHsu:
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::HsuLayout()); _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::HsuLayout());
break; break;
case KeyboardLayoutOfEen26: case MandarinParserOfEen26:
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::ETen26Layout()); _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::ETen26Layout());
break; break;
case KeyboardLayoutOfIBM: case MandarinParserOfIBM:
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::IBMLayout()); _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::IBMLayout());
break; break;
case KeyboardLayoutOfMiTAC: case MandarinParserOfMiTAC:
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::MiTACLayout()); _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::MiTACLayout());
break; break;
case KeyboardLayoutOfFakeSeigyou: case MandarinParserOfFakeSeigyou:
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::FakeSeigyouLayout()); _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::FakeSeigyouLayout());
break; break;
case KeyboardLayoutOfHanyuPinyin: case MandarinParserOfHanyuPinyin:
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::HanyuPinyinLayout()); _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::HanyuPinyinLayout());
break; break;
default: default:
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::StandardLayout()); _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::StandardLayout());
mgrPrefs.keyboardLayout = KeyboardLayoutOfStandard; mgrPrefs.mandarinParser = MandarinParserOfStandard;
} }
} }
@ -241,21 +215,16 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
// in the user override model. // in the user override model.
BOOL addToOverrideModel = YES; BOOL addToOverrideModel = YES;
if (selectedNode.spanningLength != [value count]) if (selectedNode.spanningLength != [value count])
{
addToOverrideModel = NO; addToOverrideModel = NO;
}
if (addToOverrideModel) if (addToOverrideModel)
{ {
double score = selectedNode.node->scoreForCandidate(stringValue); double score = selectedNode.node->scoreForCandidate(stringValue);
if (score <= -12) if (score <= -12) // 威注音的 SymbolLM 的 Score 是 -12。
{ // 威注音的 SymbolLM 的 Score 是 -12。
addToOverrideModel = NO; addToOverrideModel = NO;
}
} }
if (addToOverrideModel) if (addToOverrideModel)
{
_userOverrideModel->observe(_walkedNodes, cursorIndex, stringValue, [[NSDate date] timeIntervalSince1970]); _userOverrideModel->observe(_walkedNodes, cursorIndex, stringValue, [[NSDate date] timeIntervalSince1970]);
}
} }
[self _walk]; [self _walk];
@ -265,15 +234,11 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
for (auto node : _walkedNodes) for (auto node : _walkedNodes)
{ {
if (nextPosition >= cursorIndex) if (nextPosition >= cursorIndex)
{
break; break;
}
nextPosition += node.spanningLength; nextPosition += node.spanningLength;
} }
if (nextPosition <= _builder->length()) if (nextPosition <= _builder->length())
{
_builder->setCursorIndex(nextPosition); _builder->setCursorIndex(nextPosition);
}
} }
} }
@ -284,13 +249,13 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
_walkedNodes.clear(); _walkedNodes.clear();
} }
- (std::string)_currentLayout - (std::string)_currentMandarinParser
{ {
NSString *keyboardLayoutName = mgrPrefs.keyboardLayoutName; return std::string(mgrPrefs.mandarinParserName.UTF8String) + std::string("_");
std::string layout = std::string(keyboardLayoutName.UTF8String) + std::string("_");
return layout;
} }
// MARK: - Handling Input
- (BOOL)handleInput:(keyParser *)input - (BOOL)handleInput:(keyParser *)input
state:(InputState *)inState state:(InputState *)inState
stateCallback:(void (^)(InputState *))stateCallback stateCallback:(void (^)(InputState *))stateCallback
@ -302,18 +267,14 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
// 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 (!input.inputText.length) if (!input.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
BOOL isFunctionKey = BOOL isFunctionKey =
([input isCommandHold] || [input isOptionHotKey] || [input isNumericPad]) || [input isControlHotKey]; ([input isCommandHold] || [input isOptionHotKey] || [input isNumericPad]) || [input isControlHotKey];
if (![state isKindOfClass:[InputStateNotEmpty class]] && if (![state isKindOfClass:[InputStateNotEmpty class]] &&
![state isKindOfClass:[InputStateAssociatedPhrases class]] && isFunctionKey) ![state isKindOfClass:[InputStateAssociatedPhrases class]] && isFunctionKey)
{
return NO; return NO;
}
// Caps Lock processing: if Caps Lock is ON, temporarily disable bopomofo. // Caps Lock processing: if Caps Lock is ON, temporarily disable bopomofo.
// Note: Alphanumerical mode processing. // Note: Alphanumerical mode processing.
@ -331,16 +292,12 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
// When shift is pressed, don't do further processing, since it outputs capital letter anyway. // When shift is pressed, don't do further processing, since it outputs capital letter anyway.
if ([input isShiftHold]) if ([input isShiftHold])
{
return NO; return NO;
}
// if ASCII but not printable, don't use insertText:replacementRange: as many apps don't handle non-ASCII char // if ASCII but not printable, don't use insertText:replacementRange: as many apps don't handle non-ASCII char
// insertions. // insertions.
if (charCode < 0x80 && !isprint(charCode)) if (charCode < 0x80 && !isprint(charCode))
{
return NO; return NO;
}
// commit everything in the buffer. // commit everything in the buffer.
InputStateCommitting *committingState = InputStateCommitting *committingState =
@ -369,9 +326,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
// MARK: Handle Candidates // MARK: Handle Candidates
if ([state isKindOfClass:[InputStateChoosingCandidate class]]) if ([state isKindOfClass:[InputStateChoosingCandidate class]])
{
return [self _handleCandidateState:state input:input stateCallback:stateCallback errorCallback:errorCallback]; return [self _handleCandidateState:state input:input stateCallback:stateCallback errorCallback:errorCallback];
}
// MARK: Handle Associated Phrases // MARK: Handle Associated Phrases
if ([state isKindOfClass:[InputStateAssociatedPhrases class]]) if ([state isKindOfClass:[InputStateAssociatedPhrases class]])
@ -381,9 +336,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
stateCallback:stateCallback stateCallback:stateCallback
errorCallback:errorCallback]; errorCallback:errorCallback];
if (result) if (result)
{
return YES; return YES;
}
state = [[InputStateEmpty alloc] init]; state = [[InputStateEmpty alloc] init];
stateCallback(state); stateCallback(state);
} }
@ -396,9 +349,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
input:input input:input
stateCallback:stateCallback stateCallback:stateCallback
errorCallback:errorCallback]) errorCallback:errorCallback])
{
return YES; return YES;
}
state = [marking convertToInputting]; state = [marking convertToInputting];
stateCallback(state); stateCallback(state);
} }
@ -493,9 +444,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
(InputStateAssociatedPhrases *)[self buildAssociatePhraseStateWithKey:text (InputStateAssociatedPhrases *)[self buildAssociatePhraseStateWithKey:text
useVerticalMode:input.useVerticalMode]; useVerticalMode:input.useVerticalMode];
if (associatedPhrases) if (associatedPhrases)
{
stateCallback(associatedPhrases); stateCallback(associatedPhrases);
}
else else
{ {
InputStateEmpty *empty = [[InputStateEmpty alloc] init]; InputStateEmpty *empty = [[InputStateEmpty alloc] init];
@ -504,9 +453,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
} }
} }
else else
{
stateCallback(choosingCandidates); stateCallback(choosingCandidates);
}
} }
// and tells the client that the key is consumed // and tells the client that the key is consumed
@ -558,82 +505,54 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
// MARK: Esc // MARK: Esc
if ([input isESC]) if ([input isESC])
{
return [self _handleEscWithState:state stateCallback:stateCallback errorCallback:errorCallback]; return [self _handleEscWithState:state stateCallback:stateCallback errorCallback:errorCallback];
}
// MARK: Cursor backward // MARK: Cursor backward
if ([input isCursorBackward] || emacsKey == vChewingEmacsKeyBackward) if ([input isCursorBackward] || emacsKey == vChewingEmacsKeyBackward)
{
return [self _handleBackwardWithState:state return [self _handleBackwardWithState:state
input:input input:input
stateCallback:stateCallback stateCallback:stateCallback
errorCallback:errorCallback]; errorCallback:errorCallback];
}
// MARK: Cursor forward // MARK: Cursor forward
if ([input isCursorForward] || emacsKey == vChewingEmacsKeyForward) if ([input isCursorForward] || emacsKey == vChewingEmacsKeyForward)
{
return [self _handleForwardWithState:state input:input stateCallback:stateCallback errorCallback:errorCallback]; return [self _handleForwardWithState:state input:input stateCallback:stateCallback errorCallback:errorCallback];
}
// MARK: Home // MARK: Home
if ([input isHome] || emacsKey == vChewingEmacsKeyHome) if ([input isHome] || emacsKey == vChewingEmacsKeyHome)
{
return [self _handleHomeWithState:state stateCallback:stateCallback errorCallback:errorCallback]; return [self _handleHomeWithState:state stateCallback:stateCallback errorCallback:errorCallback];
}
// MARK: End // MARK: End
if ([input isEnd] || emacsKey == vChewingEmacsKeyEnd) if ([input isEnd] || emacsKey == vChewingEmacsKeyEnd)
{
return [self _handleEndWithState:state stateCallback:stateCallback errorCallback:errorCallback]; return [self _handleEndWithState:state stateCallback:stateCallback errorCallback:errorCallback];
}
// MARK: Ctrl+PgLf or Shift+PgLf // MARK: Ctrl+PgLf or Shift+PgLf
if ([input isControlHold] || [input isShiftHold]) if (([input isControlHold] || [input isShiftHold]) && ([input isOptionHold] && [input isLeft]))
{ return [self _handleHomeWithState:state stateCallback:stateCallback errorCallback:errorCallback];
if ([input isOptionHold] && [input isLeft])
{
return [self _handleHomeWithState:state stateCallback:stateCallback errorCallback:errorCallback];
}
}
// MARK: Ctrl+PgRt or Shift+PgRt // MARK: Ctrl+PgRt or Shift+PgRt
if ([input isControlHold] || [input isShiftHold]) if (([input isControlHold] || [input isShiftHold]) && ([input isOptionHold] && [input isRight]))
{ return [self _handleEndWithState:state stateCallback:stateCallback errorCallback:errorCallback];
if ([input isOptionHold] && [input isRight])
{
return [self _handleEndWithState:state stateCallback:stateCallback errorCallback:errorCallback];
}
}
// MARK: AbsorbedArrowKey // MARK: AbsorbedArrowKey
if ([input isAbsorbedArrowKey] || [input isExtraChooseCandidateKey] || [input isExtraChooseCandidateKeyReverse]) if ([input isAbsorbedArrowKey] || [input isExtraChooseCandidateKey] || [input isExtraChooseCandidateKeyReverse])
{
return [self _handleAbsorbedArrowKeyWithState:state stateCallback:stateCallback errorCallback:errorCallback]; return [self _handleAbsorbedArrowKeyWithState:state stateCallback:stateCallback errorCallback:errorCallback];
}
// MARK: Backspace // MARK: Backspace
if ([input isBackSpace]) if ([input isBackSpace])
{
return [self _handleBackspaceWithState:state stateCallback:stateCallback errorCallback:errorCallback]; return [self _handleBackspaceWithState:state stateCallback:stateCallback errorCallback:errorCallback];
}
// MARK: Delete // MARK: Delete
if ([input isDelete] || emacsKey == vChewingEmacsKeyDelete) if ([input isDelete] || emacsKey == vChewingEmacsKeyDelete)
{
return [self _handleDeleteWithState:state stateCallback:stateCallback errorCallback:errorCallback]; return [self _handleDeleteWithState:state stateCallback:stateCallback errorCallback:errorCallback];
}
// MARK: Enter // MARK: Enter
if ([input isEnter]) if ([input isEnter])
{
return ([input isControlHold] && [input isCommandHold]) return ([input isControlHold] && [input isCommandHold])
? [self _handleCtrlCommandEnterWithState:state ? [self _handleCtrlCommandEnterWithState:state
stateCallback:stateCallback stateCallback:stateCallback
errorCallback:errorCallback] errorCallback:errorCallback]
: [self _handleEnterWithState:state stateCallback:stateCallback errorCallback:errorCallback]; : [self _handleEnterWithState:state stateCallback:stateCallback errorCallback:errorCallback];
}
// MARK: Punctuation list // MARK: Punctuation list
if ([input isSymbolMenuPhysicalKey] && ![input isShiftHold]) if ([input isSymbolMenuPhysicalKey] && ![input isShiftHold])
@ -679,32 +598,24 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
// if nothing is matched, see if it's a punctuation key for current layout. // if nothing is matched, see if it's a punctuation key for current layout.
std::string punctuationNamePrefix; std::string punctuationNamePrefix;
if ([input isOptionHold]) if ([input isOptionHold])
{
punctuationNamePrefix = std::string("_alt_punctuation_"); punctuationNamePrefix = std::string("_alt_punctuation_");
}
else if ([input isControlHold]) else if ([input isControlHold])
{
punctuationNamePrefix = std::string("_ctrl_punctuation_"); punctuationNamePrefix = std::string("_ctrl_punctuation_");
}
else if (mgrPrefs.halfWidthPunctuationEnabled) else if (mgrPrefs.halfWidthPunctuationEnabled)
{
punctuationNamePrefix = std::string("_half_punctuation_"); punctuationNamePrefix = std::string("_half_punctuation_");
}
else else
{
punctuationNamePrefix = std::string("_punctuation_"); punctuationNamePrefix = std::string("_punctuation_");
}
std::string layout = [self _currentLayout]; std::string parser = [self _currentMandarinParser];
std::string customPunctuation = punctuationNamePrefix + layout + std::string(1, (char)charCode); std::string customPunctuation = punctuationNamePrefix + parser + std::string(1, (char)charCode);
if ([self _handlePunctuation:customPunctuation if ([self _handlePunctuation:customPunctuation
state:state state:state
usingVerticalMode:input.useVerticalMode usingVerticalMode:input.useVerticalMode
stateCallback:stateCallback stateCallback:stateCallback
errorCallback:errorCallback]) errorCallback:errorCallback])
{
return YES; return YES;
}
// if nothing is matched, see if it's a punctuation key. // if nothing is matched, see if it's a punctuation key.
std::string punctuation = punctuationNamePrefix + std::string(1, (char)charCode); std::string punctuation = punctuationNamePrefix + std::string(1, (char)charCode);
@ -713,9 +624,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
usingVerticalMode:input.useVerticalMode usingVerticalMode:input.useVerticalMode
stateCallback:stateCallback stateCallback:stateCallback
errorCallback:errorCallback]) errorCallback:errorCallback])
{
return YES; return YES;
}
// Lukhnos 這裡的處理反而會使得 Apple 倚天注音動態鍵盤佈局「敲不了半形大寫英文」的缺點曝露無疑,所以注釋掉。 // Lukhnos 這裡的處理反而會使得 Apple 倚天注音動態鍵盤佈局「敲不了半形大寫英文」的缺點曝露無疑,所以注釋掉。
// 至於他試圖用這種處理來解決的上游 UPR293 // 至於他試圖用這種處理來解決的上游 UPR293
@ -728,9 +637,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
usingVerticalMode:input.useVerticalMode usingVerticalMode:input.useVerticalMode
stateCallback:stateCallback stateCallback:stateCallback
errorCallback:errorCallback]) errorCallback:errorCallback])
{
return YES; return YES;
}
} }
// still nothing, then we update the composing buffer (some app has strange behavior if we don't do this, "thinking" // still nothing, then we update the composing buffer (some app has strange behavior if we don't do this, "thinking"
@ -754,9 +661,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
errorCallback:(void (^)(void))errorCallback errorCallback:(void (^)(void))errorCallback
{ {
if (![state isKindOfClass:[InputStateInputting class]]) if (![state isKindOfClass:[InputStateInputting class]])
{
return NO; return NO;
}
BOOL escToClearInputBufferEnabled = mgrPrefs.escToCleanInputBuffer; BOOL escToClearInputBufferEnabled = mgrPrefs.escToCleanInputBuffer;
@ -800,9 +705,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
errorCallback:(void (^)(void))errorCallback errorCallback:(void (^)(void))errorCallback
{ {
if (![state isKindOfClass:[InputStateInputting class]]) if (![state isKindOfClass:[InputStateInputting class]])
{
return NO; return NO;
}
if (!_bpmfReadingBuffer->isEmpty()) if (!_bpmfReadingBuffer->isEmpty())
{ {
@ -859,9 +762,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
errorCallback:(void (^)(void))errorCallback errorCallback:(void (^)(void))errorCallback
{ {
if (![state isKindOfClass:[InputStateInputting class]]) if (![state isKindOfClass:[InputStateInputting class]])
{
return NO; return NO;
}
if (!_bpmfReadingBuffer->isEmpty()) if (!_bpmfReadingBuffer->isEmpty())
{ {
@ -917,9 +818,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
errorCallback:(void (^)(void))errorCallback errorCallback:(void (^)(void))errorCallback
{ {
if (![state isKindOfClass:[InputStateInputting class]]) if (![state isKindOfClass:[InputStateInputting class]])
{
return NO; return NO;
}
if (!_bpmfReadingBuffer->isEmpty()) if (!_bpmfReadingBuffer->isEmpty())
{ {
@ -950,9 +849,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
errorCallback:(void (^)(void))errorCallback errorCallback:(void (^)(void))errorCallback
{ {
if (![state isKindOfClass:[InputStateInputting class]]) if (![state isKindOfClass:[InputStateInputting class]])
{
return NO; return NO;
}
if (!_bpmfReadingBuffer->isEmpty()) if (!_bpmfReadingBuffer->isEmpty())
{ {
@ -983,9 +880,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
errorCallback:(void (^)(void))errorCallback errorCallback:(void (^)(void))errorCallback
{ {
if (![state isKindOfClass:[InputStateInputting class]]) if (![state isKindOfClass:[InputStateInputting class]])
{
return NO; return NO;
}
if (!_bpmfReadingBuffer->isEmpty()) if (!_bpmfReadingBuffer->isEmpty())
{ {
@ -1001,9 +896,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
errorCallback:(void (^)(void))errorCallback errorCallback:(void (^)(void))errorCallback
{ {
if (![state isKindOfClass:[InputStateInputting class]]) if (![state isKindOfClass:[InputStateInputting class]])
{
return NO; return NO;
}
if (_bpmfReadingBuffer->isEmpty()) if (_bpmfReadingBuffer->isEmpty())
{ {
@ -1021,9 +914,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
} }
} }
else else
{
_bpmfReadingBuffer->backspace(); _bpmfReadingBuffer->backspace();
}
if (_bpmfReadingBuffer->isEmpty() && !_builder->length()) if (_bpmfReadingBuffer->isEmpty() && !_builder->length())
{ {
@ -1043,9 +934,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
errorCallback:(void (^)(void))errorCallback errorCallback:(void (^)(void))errorCallback
{ {
if (![state isKindOfClass:[InputStateInputting class]]) if (![state isKindOfClass:[InputStateInputting class]])
{
return NO; return NO;
}
if (_bpmfReadingBuffer->isEmpty()) if (_bpmfReadingBuffer->isEmpty())
{ {
@ -1106,9 +995,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
errorCallback:(void (^)(void))errorCallback errorCallback:(void (^)(void))errorCallback
{ {
if (![state isKindOfClass:[InputStateInputting class]]) if (![state isKindOfClass:[InputStateInputting class]])
{
return NO; return NO;
}
[self clear]; [self clear];
@ -1128,9 +1015,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
errorCallback:(void (^)(void))errorCallback errorCallback:(void (^)(void))errorCallback
{ {
if (!_languageModel->hasUnigramsForKey(customPunctuation)) if (!_languageModel->hasUnigramsForKey(customPunctuation))
{
return NO; return NO;
}
NSString *poppedText; NSString *poppedText;
if (_bpmfReadingBuffer->isEmpty()) if (_bpmfReadingBuffer->isEmpty())
@ -1165,9 +1050,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
stateCallback(empty); stateCallback(empty);
} }
else else
{
stateCallback(candidateState); stateCallback(candidateState);
}
} }
return YES; return YES;
} }
@ -1218,9 +1101,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
stateCallback(inputting); stateCallback(inputting);
} }
else else
{
stateCallback(marking); stateCallback(marking);
}
} }
else else
{ {
@ -1249,9 +1130,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
stateCallback(inputting); stateCallback(inputting);
} }
else else
{
stateCallback(marking); stateCallback(marking);
}
} }
else else
{ {
@ -1495,9 +1374,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
errorCallback(); errorCallback();
} }
else else
{
ctlCandidateCurrent.selectedCandidateIndex = 0; ctlCandidateCurrent.selectedCandidateIndex = 0;
}
return YES; return YES;
} }
@ -1505,18 +1382,12 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
NSArray *candidates; NSArray *candidates;
if ([state isKindOfClass:[InputStateChoosingCandidate class]]) if ([state isKindOfClass:[InputStateChoosingCandidate class]])
{
candidates = [(InputStateChoosingCandidate *)state candidates]; candidates = [(InputStateChoosingCandidate *)state candidates];
}
else if ([state isKindOfClass:[InputStateAssociatedPhrases class]]) else if ([state isKindOfClass:[InputStateAssociatedPhrases class]])
{
candidates = [(InputStateAssociatedPhrases *)state candidates]; candidates = [(InputStateAssociatedPhrases *)state candidates];
}
if (!candidates) if (!candidates)
{
return NO; return NO;
}
if (([input isEnd] || input.emacsKey == vChewingEmacsKeyEnd) && candidates.count > 0) if (([input isEnd] || input.emacsKey == vChewingEmacsKeyEnd) && candidates.count > 0)
{ {
@ -1526,30 +1397,23 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
errorCallback(); errorCallback();
} }
else else
{
ctlCandidateCurrent.selectedCandidateIndex = candidates.count - 1; ctlCandidateCurrent.selectedCandidateIndex = candidates.count - 1;
}
return YES; return YES;
} }
if ([state isKindOfClass:[InputStateAssociatedPhrases class]]) if ([state isKindOfClass:[InputStateAssociatedPhrases class]])
{ {
if (![input isShiftHold]) if (![input isShiftHold])
{
return NO; return NO;
}
} }
NSInteger index = NSNotFound; NSInteger index = NSNotFound;
NSString *match; NSString *match;
if ([state isKindOfClass:[InputStateAssociatedPhrases class]]) if ([state isKindOfClass:[InputStateAssociatedPhrases class]])
{
match = input.inputTextIgnoringModifiers; match = input.inputTextIgnoringModifiers;
}
else else
{
match = inputText; match = inputText;
}
for (NSUInteger j = 0, c = [ctlCandidateCurrent.keyLabels count]; j < c; j++) for (NSUInteger j = 0, c = [ctlCandidateCurrent.keyLabels count]; j < c; j++)
{ {
@ -1572,31 +1436,22 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
} }
if ([state isKindOfClass:[InputStateAssociatedPhrases class]]) if ([state isKindOfClass:[InputStateAssociatedPhrases class]])
{
return NO; return NO;
}
if (mgrPrefs.useSCPCTypingMode) if (mgrPrefs.useSCPCTypingMode)
{ {
std::string layout = [self _currentLayout];
std::string punctuationNamePrefix; std::string punctuationNamePrefix;
if ([input isOptionHold]) if ([input isOptionHold])
{
punctuationNamePrefix = std::string("_alt_punctuation_"); punctuationNamePrefix = std::string("_alt_punctuation_");
}
else if ([input isControlHold]) else if ([input isControlHold])
{
punctuationNamePrefix = std::string("_ctrl_punctuation_"); punctuationNamePrefix = std::string("_ctrl_punctuation_");
}
else if (mgrPrefs.halfWidthPunctuationEnabled) else if (mgrPrefs.halfWidthPunctuationEnabled)
{
punctuationNamePrefix = std::string("_half_punctuation_"); punctuationNamePrefix = std::string("_half_punctuation_");
}
else else
{
punctuationNamePrefix = std::string("_punctuation_"); punctuationNamePrefix = std::string("_punctuation_");
}
std::string customPunctuation = punctuationNamePrefix + layout + std::string(1, (char)charCode); std::string parser = [self _currentMandarinParser];
std::string customPunctuation = punctuationNamePrefix + parser + std::string(1, (char)charCode);
std::string punctuation = punctuationNamePrefix + std::string(1, (char)charCode); std::string punctuation = punctuationNamePrefix + std::string(1, (char)charCode);
BOOL shouldAutoSelectCandidate = _bpmfReadingBuffer->isValidKey((char)charCode) || BOOL shouldAutoSelectCandidate = _bpmfReadingBuffer->isValidKey((char)charCode) ||
@ -1607,9 +1462,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
{ {
std::string letter = std::string("_letter_") + std::string(1, (char)charCode); std::string letter = std::string("_letter_") + std::string(1, (char)charCode);
if (_languageModel->hasUnigramsForKey(letter)) if (_languageModel->hasUnigramsForKey(letter))
{
shouldAutoSelectCandidate = YES; shouldAutoSelectCandidate = YES;
}
} }
if (shouldAutoSelectCandidate) if (shouldAutoSelectCandidate)
@ -1813,9 +1666,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
const std::vector<Gramambular::KeyValuePair> &candidates = (*ni).node->candidates(); const std::vector<Gramambular::KeyValuePair> &candidates = (*ni).node->candidates();
for (std::vector<Gramambular::KeyValuePair>::const_iterator ci = candidates.begin(), ce = candidates.end(); for (std::vector<Gramambular::KeyValuePair>::const_iterator ci = candidates.begin(), ce = candidates.end();
ci != ce; ++ci) ci != ce; ++ci)
{
[candidatesArray addObject:[NSString stringWithUTF8String:(*ci).value.c_str()]]; [candidatesArray addObject:[NSString stringWithUTF8String:(*ci).value.c_str()]];
}
} }
InputStateChoosingCandidate *state = InputStateChoosingCandidate *state =
@ -1831,9 +1682,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
size_t cursorIndex = _builder->cursorIndex(); size_t cursorIndex = _builder->cursorIndex();
// MS Phonetics IME style, phrase is *after* the cursor, i.e. cursor is always *before* the phrase // MS Phonetics IME style, phrase is *after* the cursor, i.e. cursor is always *before* the phrase
if ((mgrPrefs.selectPhraseAfterCursorAsCandidate && (cursorIndex < _builder->length())) || !cursorIndex) if ((mgrPrefs.selectPhraseAfterCursorAsCandidate && (cursorIndex < _builder->length())) || !cursorIndex)
{
++cursorIndex; ++cursorIndex;
}
return cursorIndex; return cursorIndex;
} }
@ -1843,9 +1692,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
NSMutableArray *readingsArray = [[NSMutableArray alloc] init]; NSMutableArray *readingsArray = [[NSMutableArray alloc] init];
std::vector<std::string> v = _builder->readings(); std::vector<std::string> v = _builder->readings();
for (std::vector<std::string>::iterator it_i = v.begin(); it_i != v.end(); ++it_i) for (std::vector<std::string>::iterator it_i = v.begin(); it_i != v.end(); ++it_i)
{
[readingsArray addObject:[NSString stringWithUTF8String:it_i->c_str()]]; [readingsArray addObject:[NSString stringWithUTF8String:it_i->c_str()]];
}
return readingsArray; return readingsArray;
} }

View File

@ -66,7 +66,7 @@ class ctlInputMethod: IMKInputController {
@objc func setKeyLayout() { @objc func setKeyLayout() {
let client = client().self as IMKTextInput let client = client().self as IMKTextInput
client.overrideKeyboard(withKeyboardNamed: mgrPrefs.basisKeyboardLayout) client.overrideKeyboard(withKeyboardNamed: mgrPrefs.basicKeyboardLayout)
} }
// MARK: - IMKInputController methods // MARK: - IMKInputController methods

View File

@ -30,8 +30,8 @@ struct UserDef {
static let kIsDebugModeEnabled = "_DebugMode" static let kIsDebugModeEnabled = "_DebugMode"
static let kUserDataFolderSpecified = "UserDataFolderSpecified" static let kUserDataFolderSpecified = "UserDataFolderSpecified"
static let kCheckUpdateAutomatically = "CheckUpdateAutomatically" static let kCheckUpdateAutomatically = "CheckUpdateAutomatically"
static let kKeyboardLayout = "KeyboardLayout" static let kMandarinParser = "MandarinParser"
static let kBasisKeyboardLayout = "BasisKeyboardLayout" static let kBasicKeyboardLayout = "BasicKeyboardLayout"
static let kShowPageButtonsInCandidateWindow = "ShowPageButtonsInCandidateWindow" static let kShowPageButtonsInCandidateWindow = "ShowPageButtonsInCandidateWindow"
static let kCandidateListTextSize = "CandidateListTextSize" static let kCandidateListTextSize = "CandidateListTextSize"
static let kAppleLanguages = "AppleLanguages" static let kAppleLanguages = "AppleLanguages"
@ -167,7 +167,7 @@ struct ComposingBufferSize {
// MARK: - // MARK: -
@objc enum KeyboardLayout: Int { @objc enum MandarinParser: Int {
case ofStandard = 0 case ofStandard = 0
case ofEten = 1 case ofEten = 1
case ofHsu = 2 case ofHsu = 2
@ -205,8 +205,8 @@ struct ComposingBufferSize {
[ [
UserDef.kIsDebugModeEnabled, UserDef.kIsDebugModeEnabled,
UserDef.kUserDataFolderSpecified, UserDef.kUserDataFolderSpecified,
UserDef.kKeyboardLayout, UserDef.kMandarinParser,
UserDef.kBasisKeyboardLayout, UserDef.kBasicKeyboardLayout,
UserDef.kShowPageButtonsInCandidateWindow, UserDef.kShowPageButtonsInCandidateWindow,
UserDef.kCandidateListTextSize, UserDef.kCandidateListTextSize,
UserDef.kAppleLanguages, UserDef.kAppleLanguages,
@ -289,16 +289,16 @@ struct ComposingBufferSize {
@UserDefault(key: UserDef.kAppleLanguages, defaultValue: []) @UserDefault(key: UserDef.kAppleLanguages, defaultValue: [])
@objc static var appleLanguages: [String] @objc static var appleLanguages: [String]
@UserDefault(key: UserDef.kKeyboardLayout, defaultValue: 0) @UserDefault(key: UserDef.kMandarinParser, defaultValue: 0)
@objc static var keyboardLayout: Int @objc static var mandarinParser: Int
@objc static var keyboardLayoutName: String { @objc static var mandarinParserName: String {
(KeyboardLayout(rawValue: self.keyboardLayout) ?? KeyboardLayout.ofStandard).name (MandarinParser(rawValue: self.mandarinParser) ?? MandarinParser.ofStandard).name
} }
@UserDefault( @UserDefault(
key: UserDef.kBasisKeyboardLayout, defaultValue: "com.apple.keylayout.ZhuyinBopomofo") key: UserDef.kBasicKeyboardLayout, defaultValue: "com.apple.keylayout.ZhuyinBopomofo")
@objc static var basisKeyboardLayout: String @objc static var basicKeyboardLayout: String
@UserDefault(key: UserDef.kShowPageButtonsInCandidateWindow, defaultValue: true) @UserDefault(key: UserDef.kShowPageButtonsInCandidateWindow, defaultValue: true)
@objc static var showPageButtonsInCandidateWindow: Bool @objc static var showPageButtonsInCandidateWindow: Bool

View File

@ -33,7 +33,7 @@ import Cocoa
@objc(ctlPrefWindow) class ctlPrefWindow: NSWindowController { @objc(ctlPrefWindow) class ctlPrefWindow: NSWindowController {
@IBOutlet weak var fontSizePopUpButton: NSPopUpButton! @IBOutlet weak var fontSizePopUpButton: NSPopUpButton!
@IBOutlet weak var uiLanguageButton: NSPopUpButton! @IBOutlet weak var uiLanguageButton: NSPopUpButton!
@IBOutlet weak var basisKeyboardLayoutButton: NSPopUpButton! @IBOutlet weak var basicKeyboardLayoutButton: NSPopUpButton!
@IBOutlet weak var selectionKeyComboBox: NSComboBox! @IBOutlet weak var selectionKeyComboBox: NSComboBox!
@IBOutlet weak var chkTrad2KangXi: NSButton! @IBOutlet weak var chkTrad2KangXi: NSButton!
@IBOutlet weak var chkTrad2JISShinjitai: NSButton! @IBOutlet weak var chkTrad2JISShinjitai: NSButton!
@ -77,22 +77,22 @@ import Cocoa
var usKeyboardLayoutItem: NSMenuItem? = nil var usKeyboardLayoutItem: NSMenuItem? = nil
var chosenBaseKeyboardLayoutItem: NSMenuItem? = nil var chosenBaseKeyboardLayoutItem: NSMenuItem? = nil
basisKeyboardLayoutButton.menu?.removeAllItems() basicKeyboardLayoutButton.menu?.removeAllItems()
let itmAppleZhuyinBopomofo = NSMenuItem() let itmAppleZhuyinBopomofo = NSMenuItem()
itmAppleZhuyinBopomofo.title = String( itmAppleZhuyinBopomofo.title = String(
format: NSLocalizedString("Apple Zhuyin Bopomofo (Dachen)", comment: "")) format: NSLocalizedString("Apple Zhuyin Bopomofo (Dachen)", comment: ""))
itmAppleZhuyinBopomofo.representedObject = String( itmAppleZhuyinBopomofo.representedObject = String(
"com.apple.keylayout.ZhuyinBopomofo") "com.apple.keylayout.ZhuyinBopomofo")
basisKeyboardLayoutButton.menu?.addItem(itmAppleZhuyinBopomofo) basicKeyboardLayoutButton.menu?.addItem(itmAppleZhuyinBopomofo)
let itmAppleZhuyinEten = NSMenuItem() let itmAppleZhuyinEten = NSMenuItem()
itmAppleZhuyinEten.title = String( itmAppleZhuyinEten.title = String(
format: NSLocalizedString("Apple Zhuyin Eten (Traditional)", comment: "")) format: NSLocalizedString("Apple Zhuyin Eten (Traditional)", comment: ""))
itmAppleZhuyinEten.representedObject = String("com.apple.keylayout.ZhuyinEten") itmAppleZhuyinEten.representedObject = String("com.apple.keylayout.ZhuyinEten")
basisKeyboardLayoutButton.menu?.addItem(itmAppleZhuyinEten) basicKeyboardLayoutButton.menu?.addItem(itmAppleZhuyinEten)
let basisKeyboardLayoutID = mgrPrefs.basisKeyboardLayout let basicKeyboardLayoutID = mgrPrefs.basicKeyboardLayout
for source in list { for source in list {
if let categoryPtr = TISGetInputSourceProperty(source, kTISPropertyInputSourceCategory) { if let categoryPtr = TISGetInputSourceProperty(source, kTISPropertyInputSourceCategory) {
@ -142,13 +142,13 @@ import Cocoa
if sourceID == "com.apple.keylayout.US" { if sourceID == "com.apple.keylayout.US" {
usKeyboardLayoutItem = menuItem usKeyboardLayoutItem = menuItem
} }
if basisKeyboardLayoutID == sourceID { if basicKeyboardLayoutID == sourceID {
chosenBaseKeyboardLayoutItem = menuItem chosenBaseKeyboardLayoutItem = menuItem
} }
basisKeyboardLayoutButton.menu?.addItem(menuItem) basicKeyboardLayoutButton.menu?.addItem(menuItem)
} }
switch basisKeyboardLayoutID { switch basicKeyboardLayoutID {
case "com.apple.keylayout.ZhuyinBopomofo": case "com.apple.keylayout.ZhuyinBopomofo":
chosenBaseKeyboardLayoutItem = itmAppleZhuyinBopomofo chosenBaseKeyboardLayoutItem = itmAppleZhuyinBopomofo
case "com.apple.keylayout.ZhuyinEten": case "com.apple.keylayout.ZhuyinEten":
@ -157,7 +157,7 @@ import Cocoa
break // nothing to do break // nothing to do
} }
basisKeyboardLayoutButton.select(chosenBaseKeyboardLayoutItem ?? usKeyboardLayoutItem) basicKeyboardLayoutButton.select(chosenBaseKeyboardLayoutItem ?? usKeyboardLayoutItem)
selectionKeyComboBox.usesDataSource = false selectionKeyComboBox.usesDataSource = false
selectionKeyComboBox.removeAllItems() selectionKeyComboBox.removeAllItems()
@ -193,9 +193,9 @@ import Cocoa
} }
} }
@IBAction func updateBasisKeyboardLayoutAction(_ sender: Any) { @IBAction func updateBasicKeyboardLayoutAction(_ sender: Any) {
if let sourceID = basisKeyboardLayoutButton.selectedItem?.representedObject as? String { if let sourceID = basicKeyboardLayoutButton.selectedItem?.representedObject as? String {
mgrPrefs.basisKeyboardLayout = sourceID mgrPrefs.basicKeyboardLayout = sourceID
} }
} }

View File

@ -8,7 +8,7 @@
<objects> <objects>
<customObject id="-2" userLabel="File's Owner" customClass="ctlPrefWindow"> <customObject id="-2" userLabel="File's Owner" customClass="ctlPrefWindow">
<connections> <connections>
<outlet property="basisKeyboardLayoutButton" destination="124" id="135"/> <outlet property="basicKeyboardLayoutButton" destination="124" id="135"/>
<outlet property="chkTrad2JISShinjitai" destination="h4r-Sp-LBI" id="pk8-xi-IJi"/> <outlet property="chkTrad2JISShinjitai" destination="h4r-Sp-LBI" id="pk8-xi-IJi"/>
<outlet property="chkTrad2KangXi" destination="5IL-zZ-CL9" id="PGS-Dy-BBY"/> <outlet property="chkTrad2KangXi" destination="5IL-zZ-CL9" id="PGS-Dy-BBY"/>
<outlet property="fontSizePopUpButton" destination="90" id="108"/> <outlet property="fontSizePopUpButton" destination="90" id="108"/>
@ -764,7 +764,7 @@
</items> </items>
</menu> </menu>
<connections> <connections>
<binding destination="32" name="selectedTag" keyPath="values.KeyboardLayout" id="103"/> <binding destination="32" name="selectedTag" keyPath="values.MandarinParser" id="n3r-9x-E3p"/>
</connections> </connections>
</popUpButtonCell> </popUpButtonCell>
</popUpButton> </popUpButton>
@ -779,7 +779,7 @@
<menu key="menu" title="OtherViews" id="128"/> <menu key="menu" title="OtherViews" id="128"/>
</popUpButtonCell> </popUpButtonCell>
<connections> <connections>
<action selector="updateBasisKeyboardLayoutAction:" target="-2" id="136"/> <action selector="updateBasicKeyboardLayoutAction:" target="-2" id="136"/>
</connections> </connections>
</popUpButton> </popUpButton>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="125"> <textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="125">