Pref // Rename the Pref module to mgrPrefs.

This commit is contained in:
ShikiSuen 2022-03-19 12:55:38 +08:00
parent 9151c0d3ae
commit 43a4426836
12 changed files with 118 additions and 118 deletions

View File

@ -148,7 +148,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega
func helper(_ helper: FSEventStreamHelper, didReceive events: [FSEventStreamHelper.Event]) { func helper(_ helper: FSEventStreamHelper, didReceive events: [FSEventStreamHelper.Event]) {
// 100ms 使使 // 100ms 使使
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) {
if Preferences.shouldAutoReloadUserDataFiles { if mgrPrefs.shouldAutoReloadUserDataFiles {
mgrLangModel.loadUserPhrases() mgrLangModel.loadUserPhrases()
mgrLangModel.loadUserPhraseReplacement() mgrLangModel.loadUserPhraseReplacement()
mgrLangModel.loadUserAssociatedPhrases() mgrLangModel.loadUserAssociatedPhrases()
@ -184,7 +184,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega
fsStreamHelper.delegate = self fsStreamHelper.delegate = self
_ = fsStreamHelper.start() _ = fsStreamHelper.start()
Preferences.setMissingDefaults() mgrPrefs.setMissingDefaults()
// 使 // 使
if (UserDefaults.standard.object(forKey: kCheckUpdateAutomatically) != nil) == true { if (UserDefaults.standard.object(forKey: kCheckUpdateAutomatically) != nil) == true {
@ -296,7 +296,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega
@objc public class IME: NSObject { @objc public class IME: NSObject {
// Print debug information to the console. // Print debug information to the console.
@objc static func prtDebugIntel(_ strPrint: String) { @objc static func prtDebugIntel(_ strPrint: String) {
if Preferences.isDebugModeEnabled { if mgrPrefs.isDebugModeEnabled {
NSLog("vChewingErrorCallback: %@", strPrint) NSLog("vChewingErrorCallback: %@", strPrint)
} }
} }

View File

@ -20,7 +20,7 @@ import Cocoa
@objc class AppleKeyboardConverter: NSObject { @objc class AppleKeyboardConverter: NSObject {
@objc class func isDynamicBaseKeyboardLayoutEnabled() -> Bool { @objc class func isDynamicBaseKeyboardLayoutEnabled() -> Bool {
switch Preferences.basisKeyboardLayout { switch mgrPrefs.basisKeyboardLayout {
case "com.apple.keylayout.ZhuyinBopomofo": case "com.apple.keylayout.ZhuyinBopomofo":
return true return true
case "com.apple.keylayout.ZhuyinEten": case "com.apple.keylayout.ZhuyinEten":
@ -45,7 +45,7 @@ import Cocoa
// OVMandarin OVMandarin // OVMandarin OVMandarin
if self.isDynamicBaseKeyboardLayoutEnabled() { if self.isDynamicBaseKeyboardLayoutEnabled() {
// Apple // Apple
switch Preferences.basisKeyboardLayout { switch mgrPrefs.basisKeyboardLayout {
case "com.apple.keylayout.ZhuyinBopomofo": do { case "com.apple.keylayout.ZhuyinBopomofo": do {
if (charCode == 97) {charCode = UniChar(65)} if (charCode == 97) {charCode = UniChar(65)}
if (charCode == 98) {charCode = UniChar(66)} if (charCode == 98) {charCode = UniChar(66)}
@ -166,7 +166,7 @@ import Cocoa
if (charCode == 65288) {charCode = UniChar(40)} if (charCode == 65288) {charCode = UniChar(40)}
if (charCode == 65289) {charCode = UniChar(41)} if (charCode == 65289) {charCode = UniChar(41)}
// Apple // Apple
if Preferences.basisKeyboardLayout == "com.apple.keylayout.ZhuyinEten" { if mgrPrefs.basisKeyboardLayout == "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)}
@ -181,7 +181,7 @@ import Cocoa
var strProcessed = strProcessed var strProcessed = strProcessed
if self.isDynamicBaseKeyboardLayoutEnabled() { if self.isDynamicBaseKeyboardLayoutEnabled() {
// Apple // Apple
switch Preferences.basisKeyboardLayout { switch mgrPrefs.basisKeyboardLayout {
case "com.apple.keylayout.ZhuyinBopomofo": do { case "com.apple.keylayout.ZhuyinBopomofo": do {
if (strProcessed == "a") {strProcessed = "A"} if (strProcessed == "a") {strProcessed = "A"}
if (strProcessed == "b") {strProcessed = "B"} if (strProcessed == "b") {strProcessed = "B"}
@ -302,7 +302,7 @@ import Cocoa
if (strProcessed == "") {strProcessed = "("} if (strProcessed == "") {strProcessed = "("}
if (strProcessed == "") {strProcessed = ")"} if (strProcessed == "") {strProcessed = ")"}
// Apple // Apple
if Preferences.basisKeyboardLayout == "com.apple.keylayout.ZhuyinEten" { if mgrPrefs.basisKeyboardLayout == "com.apple.keylayout.ZhuyinEten" {
if (strProcessed == "_") {strProcessed = "_"} if (strProcessed == "_") {strProcessed = "_"}
if (strProcessed == "") {strProcessed = ":"} if (strProcessed == "") {strProcessed = ":"}
if (strProcessed == "") {strProcessed = "?"} if (strProcessed == "") {strProcessed = "?"}

View File

@ -150,7 +150,7 @@ class InputState: NSObject {
// MARK: - // MARK: -
private let kMinMarkRangeLength = 2 private let kMinMarkRangeLength = 2
private let kMaxMarkRangeLength = Preferences.maxCandidateLength private let kMaxMarkRangeLength = mgrPrefs.maxCandidateLength
/// Represents that the user is marking a range in the composing buffer. /// Represents that the user is marking a range in the composing buffer.
@objc (InputStateMarking) @objc (InputStateMarking)
@ -166,7 +166,7 @@ class InputState: NSObject {
return NSLocalizedString("⚠︎ Unhandlable char selected for user phrases.", comment: "") return NSLocalizedString("⚠︎ Unhandlable char selected for user phrases.", comment: "")
} }
if Preferences.phraseReplacementEnabled { if mgrPrefs.phraseReplacementEnabled {
TooltipController.backgroundColor = NSColor.purple TooltipController.backgroundColor = NSColor.purple
TooltipController.textColor = NSColor.white TooltipController.textColor = NSColor.white
return NSLocalizedString("⚠︎ Phrase replacement mode enabled, interfering user phrase entry.", comment: "") return NSLocalizedString("⚠︎ Phrase replacement mode enabled, interfering user phrase entry.", comment: "")

View File

@ -115,10 +115,10 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
ctlInputMethod.currentInputMode = newInputMode; ctlInputMethod.currentInputMode = newInputMode;
// Synchronize the Preference Setting "setPhraseReplacementEnabled" to the new LM. // Synchronize the Preference Setting "setPhraseReplacementEnabled" to the new LM.
newLanguageModel->setPhraseReplacementEnabled(Preferences.phraseReplacementEnabled); newLanguageModel->setPhraseReplacementEnabled(mgrPrefs.phraseReplacementEnabled);
// Also other sub language models: // Also other sub language models:
newLanguageModel->setSymbolEnabled(Preferences.symbolInputEnabled); newLanguageModel->setSymbolEnabled(mgrPrefs.symbolInputEnabled);
newLanguageModel->setCNSEnabled(Preferences.cns11643Enabled); newLanguageModel->setCNSEnabled(mgrPrefs.cns11643Enabled);
// Only apply the changes if the value is changed // Only apply the changes if the value is changed
if (![_inputMode isEqualToString:newInputMode]) { if (![_inputMode isEqualToString:newInputMode]) {
@ -158,9 +158,9 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
// create the lattice builder // create the lattice builder
_languageModel = [mgrLangModel lmCHT]; _languageModel = [mgrLangModel lmCHT];
_languageModel->setPhraseReplacementEnabled(Preferences.phraseReplacementEnabled); _languageModel->setPhraseReplacementEnabled(mgrPrefs.phraseReplacementEnabled);
_languageModel->setCNSEnabled(Preferences.cns11643Enabled); _languageModel->setCNSEnabled(mgrPrefs.cns11643Enabled);
_languageModel->setSymbolEnabled(Preferences.symbolInputEnabled); _languageModel->setSymbolEnabled(mgrPrefs.symbolInputEnabled);
_userOverrideModel = [mgrLangModel userOverrideModelCHT]; _userOverrideModel = [mgrLangModel userOverrideModelCHT];
_builder = new Gramambular::BlockReadingBuilder(_languageModel); _builder = new Gramambular::BlockReadingBuilder(_languageModel);
@ -174,7 +174,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
- (void)syncWithPreferences - (void)syncWithPreferences
{ {
NSInteger layout = Preferences.keyboardLayout; NSInteger layout = mgrPrefs.keyboardLayout;
switch (layout) { switch (layout) {
case KeyboardLayoutStandard: case KeyboardLayoutStandard:
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::StandardLayout()); _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::StandardLayout());
@ -202,7 +202,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
break; break;
default: default:
_bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::StandardLayout()); _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::StandardLayout());
Preferences.keyboardLayout = KeyboardLayoutStandard; mgrPrefs.keyboardLayout = KeyboardLayoutStandard;
} }
} }
@ -211,7 +211,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
size_t cursorIndex = [self _actualCandidateCursorIndex]; size_t cursorIndex = [self _actualCandidateCursorIndex];
std::string stringValue(value.UTF8String); std::string stringValue(value.UTF8String);
Gramambular::NodeAnchor selectedNode = _builder->grid().fixNodeSelectedCandidate(cursorIndex, stringValue); Gramambular::NodeAnchor selectedNode = _builder->grid().fixNodeSelectedCandidate(cursorIndex, stringValue);
if (!Preferences.useSCPCTypingMode) { // 不要針對逐字選字模式啟用臨時半衰記憶模型。 if (!mgrPrefs.useSCPCTypingMode) { // 不要針對逐字選字模式啟用臨時半衰記憶模型。
// If the length of the readings and the characters do not match, // If the length of the readings and the characters do not match,
// it often means it is a special symbol and it should not be stored // it often means it is a special symbol and it should not be stored
// in the user override model. // in the user override model.
@ -231,8 +231,8 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
} }
[self _walk]; [self _walk];
if (Preferences.selectPhraseAfterCursorAsCandidate && if (mgrPrefs.selectPhraseAfterCursorAsCandidate &&
Preferences.moveCursorAfterSelectingCandidate) { mgrPrefs.moveCursorAfterSelectingCandidate) {
size_t nextPosition = 0; size_t nextPosition = 0;
for (auto node: _walkedNodes) { for (auto node: _walkedNodes) {
if (nextPosition >= cursorIndex) { if (nextPosition >= cursorIndex) {
@ -255,7 +255,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
- (std::string)_currentLayout - (std::string)_currentLayout
{ {
NSString *keyboardLayoutName = Preferences.keyboardLayoutName; NSString *keyboardLayoutName = mgrPrefs.keyboardLayoutName;
std::string layout = std::string(keyboardLayoutName.UTF8String) + std::string("_"); std::string layout = std::string(keyboardLayoutName.UTF8String) + std::string("_");
return layout; return layout;
} }
@ -387,7 +387,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
NSString *poppedText = [self _popOverflowComposingTextAndWalk]; NSString *poppedText = [self _popOverflowComposingTextAndWalk];
// get user override model suggestion // get user override model suggestion
std::string overrideValue = (Preferences.useSCPCTypingMode) ? "" : std::string overrideValue = (mgrPrefs.useSCPCTypingMode) ? "" :
_userOverrideModel->suggest(_walkedNodes, _builder->cursorIndex(), [[NSDate date] timeIntervalSince1970]); _userOverrideModel->suggest(_walkedNodes, _builder->cursorIndex(), [[NSDate date] timeIntervalSince1970]);
if (!overrideValue.empty()) { if (!overrideValue.empty()) {
@ -404,7 +404,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
inputting.poppedText = poppedText; inputting.poppedText = poppedText;
stateCallback(inputting); stateCallback(inputting);
if (Preferences.useSCPCTypingMode) { if (mgrPrefs.useSCPCTypingMode) {
InputStateChoosingCandidate *choosingCandidates = [self _buildCandidateState:inputting useVerticalMode:input.useVerticalMode]; InputStateChoosingCandidate *choosingCandidates = [self _buildCandidateState:inputting useVerticalMode:input.useVerticalMode];
if (choosingCandidates.candidates.count == 1) { if (choosingCandidates.candidates.count == 1) {
[self clear]; [self clear];
@ -412,7 +412,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
InputStateCommitting *committing = [[InputStateCommitting alloc] initWithPoppedText:text]; InputStateCommitting *committing = [[InputStateCommitting alloc] initWithPoppedText:text];
stateCallback(committing); stateCallback(committing);
if (!Preferences.associatedPhrasesEnabled) { if (!mgrPrefs.associatedPhrasesEnabled) {
InputStateEmpty *empty = [[InputStateEmpty alloc] init]; InputStateEmpty *empty = [[InputStateEmpty alloc] init];
stateCallback(empty); stateCallback(empty);
} else { } else {
@ -441,7 +441,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|| (input.useVerticalMode && ([input isVerticalModeOnlyChooseCandidateKey])))) { || (input.useVerticalMode && ([input isVerticalModeOnlyChooseCandidateKey])))) {
if ([input isSpace]) { if ([input isSpace]) {
// if the spacebar is NOT set to be a selection key // if the spacebar is NOT set to be a selection key
if ([input isShiftHold] || !Preferences.chooseCandidateUsingSpace) { if ([input isShiftHold] || !mgrPrefs.chooseCandidateUsingSpace) {
if (_builder->cursorIndex() >= _builder->length()) { if (_builder->cursorIndex() >= _builder->length()) {
NSString *composingBuffer = [(InputStateNotEmpty*) state composingBuffer]; NSString *composingBuffer = [(InputStateNotEmpty*) state composingBuffer];
if (composingBuffer.length) { if (composingBuffer.length) {
@ -566,7 +566,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
std::string punctuationNamePrefix; std::string punctuationNamePrefix;
if ([input isControlHold]) { if ([input isControlHold]) {
punctuationNamePrefix = std::string("_ctrl_punctuation_"); punctuationNamePrefix = std::string("_ctrl_punctuation_");
} else if (Preferences.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_");
@ -611,7 +611,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
return NO; return NO;
} }
BOOL escToClearInputBufferEnabled = Preferences.escToCleanInputBuffer; BOOL escToClearInputBufferEnabled = mgrPrefs.escToCleanInputBuffer;
if (escToClearInputBufferEnabled) { if (escToClearInputBufferEnabled) {
// if the option is enabled, we clear everything including the composing // if the option is enabled, we clear everything including the composing
@ -904,7 +904,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
inputting.poppedText = poppedText; inputting.poppedText = poppedText;
stateCallback(inputting); stateCallback(inputting);
if (Preferences.useSCPCTypingMode && _bpmfReadingBuffer->isEmpty()) { if (mgrPrefs.useSCPCTypingMode && _bpmfReadingBuffer->isEmpty()) {
InputStateChoosingCandidate *candidateState = [self _buildCandidateState:inputting useVerticalMode:useVerticalMode]; InputStateChoosingCandidate *candidateState = [self _buildCandidateState:inputting useVerticalMode:useVerticalMode];
if ([candidateState.candidates count] == 1) { if ([candidateState.candidates count] == 1) {
@ -1010,7 +1010,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
InputStateEmptyIgnoringPreviousState *empty = [[InputStateEmptyIgnoringPreviousState alloc] init]; InputStateEmptyIgnoringPreviousState *empty = [[InputStateEmptyIgnoringPreviousState alloc] init];
stateCallback(empty); stateCallback(empty);
} }
else if (Preferences.useSCPCTypingMode) { else if (mgrPrefs.useSCPCTypingMode) {
[self clear]; [self clear];
InputStateEmptyIgnoringPreviousState *empty = [[InputStateEmptyIgnoringPreviousState alloc] init]; InputStateEmptyIgnoringPreviousState *empty = [[InputStateEmptyIgnoringPreviousState alloc] init];
stateCallback(empty); stateCallback(empty);
@ -1040,7 +1040,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
if ([input isTab]) { if ([input isTab]) {
BOOL updated = BOOL updated =
Preferences.specifyTabKeyBehavior? mgrPrefs.specifyTabKeyBehavior?
([input isShiftHold] ? [gCurrentCandidateController showPreviousPage] : [gCurrentCandidateController showNextPage]) ([input isShiftHold] ? [gCurrentCandidateController showPreviousPage] : [gCurrentCandidateController showNextPage])
: :
([input isShiftHold] ? [gCurrentCandidateController highlightPreviousCandidate] : [gCurrentCandidateController highlightNextCandidate]) ([input isShiftHold] ? [gCurrentCandidateController highlightPreviousCandidate] : [gCurrentCandidateController highlightNextCandidate])
@ -1054,7 +1054,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
if ([input isSpace]) { if ([input isSpace]) {
BOOL updated = BOOL updated =
Preferences.specifySpaceKeyBehavior? mgrPrefs.specifySpaceKeyBehavior?
([input isShiftHold] ? [gCurrentCandidateController highlightNextCandidate] : [gCurrentCandidateController showNextPage]) ([input isShiftHold] ? [gCurrentCandidateController highlightNextCandidate] : [gCurrentCandidateController showNextPage])
: :
([input isShiftHold] ? [gCurrentCandidateController showNextPage] : [gCurrentCandidateController highlightNextCandidate]) ([input isShiftHold] ? [gCurrentCandidateController showNextPage] : [gCurrentCandidateController highlightNextCandidate])
@ -1237,12 +1237,12 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
return NO; return NO;
} }
if (Preferences.useSCPCTypingMode) { if (mgrPrefs.useSCPCTypingMode) {
std::string layout = [self _currentLayout]; std::string layout = [self _currentLayout];
std::string punctuationNamePrefix; std::string punctuationNamePrefix;
if ([input isControlHold]) { if ([input isControlHold]) {
punctuationNamePrefix = std::string("_ctrl_punctuation_"); punctuationNamePrefix = std::string("_ctrl_punctuation_");
} else if (Preferences.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_");
@ -1392,7 +1392,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
// be popped out // be popped out
NSString *poppedText = @""; NSString *poppedText = @"";
NSInteger composingBufferSize = Preferences.composingBufferSize; NSInteger composingBufferSize = mgrPrefs.composingBufferSize;
if (_builder->grid().width() > (size_t) composingBufferSize) { if (_builder->grid().width() > (size_t) composingBufferSize) {
if (_walkedNodes.size() > 0) { if (_walkedNodes.size() > 0) {
@ -1432,7 +1432,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 ((Preferences.selectPhraseAfterCursorAsCandidate && (cursorIndex < _builder->length())) if ((mgrPrefs.selectPhraseAfterCursorAsCandidate && (cursorIndex < _builder->length()))
|| !cursorIndex) { || !cursorIndex) {
++cursorIndex; ++cursorIndex;
} }

View File

@ -73,36 +73,36 @@ class ctlInputMethod: IMKInputController {
let useSCPCTypingModeItem = menu.addItem(withTitle: NSLocalizedString("Per-Char Select Mode", comment: ""), action: #selector(toggleSCPCTypingMode(_:)), keyEquivalent: "P") let useSCPCTypingModeItem = menu.addItem(withTitle: NSLocalizedString("Per-Char Select Mode", comment: ""), action: #selector(toggleSCPCTypingMode(_:)), keyEquivalent: "P")
useSCPCTypingModeItem.keyEquivalentModifierMask = [.command, .control] useSCPCTypingModeItem.keyEquivalentModifierMask = [.command, .control]
useSCPCTypingModeItem.state = Preferences.useSCPCTypingMode.state useSCPCTypingModeItem.state = mgrPrefs.useSCPCTypingMode.state
let useCNS11643SupportItem = menu.addItem(withTitle: NSLocalizedString("CNS11643 Mode", comment: ""), action: #selector(toggleCNS11643Enabled(_:)), keyEquivalent: "L") let useCNS11643SupportItem = menu.addItem(withTitle: NSLocalizedString("CNS11643 Mode", comment: ""), action: #selector(toggleCNS11643Enabled(_:)), keyEquivalent: "L")
useCNS11643SupportItem.keyEquivalentModifierMask = [.command, .control] useCNS11643SupportItem.keyEquivalentModifierMask = [.command, .control]
useCNS11643SupportItem.state = Preferences.cns11643Enabled.state useCNS11643SupportItem.state = mgrPrefs.cns11643Enabled.state
if keyHandler.inputMode == InputMode.imeModeCHT { if keyHandler.inputMode == InputMode.imeModeCHT {
let chineseConversionItem = menu.addItem(withTitle: NSLocalizedString("Force KangXi Writing", comment: ""), action: #selector(toggleChineseConverter(_:)), keyEquivalent: "K") let chineseConversionItem = menu.addItem(withTitle: NSLocalizedString("Force KangXi Writing", comment: ""), action: #selector(toggleChineseConverter(_:)), keyEquivalent: "K")
chineseConversionItem.keyEquivalentModifierMask = [.command, .control] chineseConversionItem.keyEquivalentModifierMask = [.command, .control]
chineseConversionItem.state = Preferences.chineseConversionEnabled.state chineseConversionItem.state = mgrPrefs.chineseConversionEnabled.state
let shiftJISConversionItem = menu.addItem(withTitle: NSLocalizedString("JIS Shinjitai Output", comment: ""), action: #selector(toggleShiftJISShinjitaiOutput(_:)), keyEquivalent: "J") let shiftJISConversionItem = menu.addItem(withTitle: NSLocalizedString("JIS Shinjitai Output", comment: ""), action: #selector(toggleShiftJISShinjitaiOutput(_:)), keyEquivalent: "J")
shiftJISConversionItem.keyEquivalentModifierMask = [.command, .control] shiftJISConversionItem.keyEquivalentModifierMask = [.command, .control]
shiftJISConversionItem.state = Preferences.shiftJISShinjitaiOutputEnabled.state shiftJISConversionItem.state = mgrPrefs.shiftJISShinjitaiOutputEnabled.state
} }
let halfWidthPunctuationItem = menu.addItem(withTitle: NSLocalizedString("Half-Width Punctuation Mode", comment: ""), action: #selector(toggleHalfWidthPunctuation(_:)), keyEquivalent: "H") let halfWidthPunctuationItem = menu.addItem(withTitle: NSLocalizedString("Half-Width Punctuation Mode", comment: ""), action: #selector(toggleHalfWidthPunctuation(_:)), keyEquivalent: "H")
halfWidthPunctuationItem.keyEquivalentModifierMask = [.command, .control] halfWidthPunctuationItem.keyEquivalentModifierMask = [.command, .control]
halfWidthPunctuationItem.state = Preferences.halfWidthPunctuationEnabled.state halfWidthPunctuationItem.state = mgrPrefs.halfWidthPunctuationEnabled.state
let userAssociatedPhrasesItem = menu.addItem(withTitle: NSLocalizedString("Per-Char Associated Phrases", comment: ""), action: #selector(toggleAssociatedPhrasesEnabled(_:)), keyEquivalent: "O") let userAssociatedPhrasesItem = menu.addItem(withTitle: NSLocalizedString("Per-Char Associated Phrases", comment: ""), action: #selector(toggleAssociatedPhrasesEnabled(_:)), keyEquivalent: "O")
userAssociatedPhrasesItem.keyEquivalentModifierMask = [.command, .control] userAssociatedPhrasesItem.keyEquivalentModifierMask = [.command, .control]
userAssociatedPhrasesItem.state = Preferences.associatedPhrasesEnabled.state userAssociatedPhrasesItem.state = mgrPrefs.associatedPhrasesEnabled.state
if optionKeyPressed { if optionKeyPressed {
let phaseReplacementItem = menu.addItem(withTitle: NSLocalizedString("Use Phrase Replacement", comment: ""), action: #selector(togglePhraseReplacement(_:)), keyEquivalent: "") let phaseReplacementItem = menu.addItem(withTitle: NSLocalizedString("Use Phrase Replacement", comment: ""), action: #selector(togglePhraseReplacement(_:)), keyEquivalent: "")
phaseReplacementItem.state = Preferences.phraseReplacementEnabled.state phaseReplacementItem.state = mgrPrefs.phraseReplacementEnabled.state
let toggleSymbolInputItem = menu.addItem(withTitle: NSLocalizedString("Symbol & Emoji Input", comment: ""), action: #selector(toggleSymbolEnabled(_:)), keyEquivalent: "") let toggleSymbolInputItem = menu.addItem(withTitle: NSLocalizedString("Symbol & Emoji Input", comment: ""), action: #selector(toggleSymbolEnabled(_:)), keyEquivalent: "")
toggleSymbolInputItem.state = Preferences.symbolInputEnabled.state toggleSymbolInputItem.state = mgrPrefs.symbolInputEnabled.state
} }
menu.addItem(NSMenuItem.separator()) // --------------------- menu.addItem(NSMenuItem.separator()) // ---------------------
@ -117,7 +117,7 @@ class ctlInputMethod: IMKInputController {
menu.addItem(withTitle: NSLocalizedString("Edit User Symbol & Emoji Data…", comment: ""), action: #selector(openUserSymbols(_:)), keyEquivalent: "") menu.addItem(withTitle: NSLocalizedString("Edit User Symbol & Emoji Data…", comment: ""), action: #selector(openUserSymbols(_:)), keyEquivalent: "")
} }
if (optionKeyPressed || !Preferences.shouldAutoReloadUserDataFiles) { if (optionKeyPressed || !mgrPrefs.shouldAutoReloadUserDataFiles) {
menu.addItem(withTitle: NSLocalizedString("Reload User Phrases", comment: ""), action: #selector(reloadUserPhrases(_:)), keyEquivalent: "") menu.addItem(withTitle: NSLocalizedString("Reload User Phrases", comment: ""), action: #selector(reloadUserPhrases(_:)), keyEquivalent: "")
} }
@ -140,7 +140,7 @@ class ctlInputMethod: IMKInputController {
UserDefaults.standard.synchronize() UserDefaults.standard.synchronize()
// Override the keyboard layout. Use US if not set. // Override the keyboard layout. Use US if not set.
(client as? IMKTextInput)?.overrideKeyboard(withKeyboardNamed: Preferences.basisKeyboardLayout) (client as? IMKTextInput)?.overrideKeyboard(withKeyboardNamed: mgrPrefs.basisKeyboardLayout)
// reset the state // reset the state
currentCandidateClient = nil currentCandidateClient = nil
@ -170,7 +170,7 @@ class ctlInputMethod: IMKInputController {
if keyHandler.inputMode != newInputMode { if keyHandler.inputMode != newInputMode {
UserDefaults.standard.synchronize() UserDefaults.standard.synchronize()
// Remember to override the keyboard layout again -- treat this as an activate event. // Remember to override the keyboard layout again -- treat this as an activate event.
(client as? IMKTextInput)?.overrideKeyboard(withKeyboardNamed: Preferences.basisKeyboardLayout) (client as? IMKTextInput)?.overrideKeyboard(withKeyboardNamed: mgrPrefs.basisKeyboardLayout)
keyHandler.clear() keyHandler.clear()
keyHandler.inputMode = newInputMode keyHandler.inputMode = newInputMode
self.handle(state: .Empty(), client: client) self.handle(state: .Empty(), client: client)
@ -189,14 +189,14 @@ class ctlInputMethod: IMKInputController {
override func handle(_ event: NSEvent!, client: Any!) -> Bool { override func handle(_ event: NSEvent!, client: Any!) -> Bool {
if event.type == .flagsChanged { if event.type == .flagsChanged {
let functionKeyKeyboardLayoutID = Preferences.functionKeyboardLayout let functionKeyKeyboardLayoutID = mgrPrefs.functionKeyboardLayout
let basisKeyboardLayoutID = Preferences.basisKeyboardLayout let basisKeyboardLayoutID = mgrPrefs.basisKeyboardLayout
if functionKeyKeyboardLayoutID == basisKeyboardLayoutID { if functionKeyKeyboardLayoutID == basisKeyboardLayoutID {
return false return false
} }
let includeShift = Preferences.functionKeyKeyboardLayoutOverrideIncludeShiftKey let includeShift = mgrPrefs.functionKeyKeyboardLayoutOverrideIncludeShiftKey
if event.modifierFlags.contains(.capsLock) || if event.modifierFlags.contains(.capsLock) ||
event.modifierFlags.contains(.option) || event.modifierFlags.contains(.option) ||
@ -238,35 +238,35 @@ class ctlInputMethod: IMKInputController {
} }
@objc func toggleSCPCTypingMode(_ sender: Any?) { @objc func toggleSCPCTypingMode(_ sender: Any?) {
NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("Per-Char Select Mode", comment: ""), "\n", Preferences.toggleSCPCTypingModeEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: ""))) NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("Per-Char Select Mode", comment: ""), "\n", mgrPrefs.toggleSCPCTypingModeEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: "")))
} }
@objc func toggleChineseConverter(_ sender: Any?) { @objc func toggleChineseConverter(_ sender: Any?) {
NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("Force KangXi Writing", comment: ""), "\n", Preferences.toggleChineseConversionEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: ""))) NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("Force KangXi Writing", comment: ""), "\n", mgrPrefs.toggleChineseConversionEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: "")))
} }
@objc func toggleShiftJISShinjitaiOutput(_ sender: Any?) { @objc func toggleShiftJISShinjitaiOutput(_ sender: Any?) {
NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("JIS Shinjitai Output", comment: ""), "\n", Preferences.toggleShiftJISShinjitaiOutputEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: ""))) NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("JIS Shinjitai Output", comment: ""), "\n", mgrPrefs.toggleShiftJISShinjitaiOutputEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: "")))
} }
@objc func toggleHalfWidthPunctuation(_ sender: Any?) { @objc func toggleHalfWidthPunctuation(_ sender: Any?) {
NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("Half-Width Punctuation Mode", comment: ""), "\n", Preferences.toggleHalfWidthPunctuationEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: ""))) NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("Half-Width Punctuation Mode", comment: ""), "\n", mgrPrefs.toggleHalfWidthPunctuationEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: "")))
} }
@objc func toggleCNS11643Enabled(_ sender: Any?) { @objc func toggleCNS11643Enabled(_ sender: Any?) {
NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("CNS11643 Mode", comment: ""), "\n", Preferences.toggleCNS11643Enabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: ""))) NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("CNS11643 Mode", comment: ""), "\n", mgrPrefs.toggleCNS11643Enabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: "")))
} }
@objc func toggleSymbolEnabled(_ sender: Any?) { @objc func toggleSymbolEnabled(_ sender: Any?) {
NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("Symbol & Emoji Input", comment: ""), "\n", Preferences.toggleSymbolInputEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: ""))) NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("Symbol & Emoji Input", comment: ""), "\n", mgrPrefs.toggleSymbolInputEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: "")))
} }
@objc func toggleAssociatedPhrasesEnabled(_ sender: Any?) { @objc func toggleAssociatedPhrasesEnabled(_ sender: Any?) {
NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("Per-Char Associated Phrases", comment: ""), "\n", Preferences.toggleAssociatedPhrasesEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: ""))) NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("Per-Char Associated Phrases", comment: ""), "\n", mgrPrefs.toggleAssociatedPhrasesEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: "")))
} }
@objc func togglePhraseReplacement(_ sender: Any?) { @objc func togglePhraseReplacement(_ sender: Any?) {
NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("Use Phrase Replacement", comment: ""), "\n", Preferences.togglePhraseReplacementEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: ""))) NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("Use Phrase Replacement", comment: ""), "\n", mgrPrefs.togglePhraseReplacementEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: "")))
} }
@objc func selfTerminate(_ sender: Any?) { @objc func selfTerminate(_ sender: Any?) {
@ -363,17 +363,17 @@ extension ctlInputMethod {
func kanjiConversionIfRequired(_ text: String) -> String { func kanjiConversionIfRequired(_ text: String) -> String {
if keyHandler.inputMode == InputMode.imeModeCHT { if keyHandler.inputMode == InputMode.imeModeCHT {
if !Preferences.chineseConversionEnabled && Preferences.shiftJISShinjitaiOutputEnabled { if !mgrPrefs.chineseConversionEnabled && mgrPrefs.shiftJISShinjitaiOutputEnabled {
return vChewingKanjiConverter.cnvTradToJIS(text) return vChewingKanjiConverter.cnvTradToJIS(text)
} }
if Preferences.chineseConversionEnabled && !Preferences.shiftJISShinjitaiOutputEnabled { if mgrPrefs.chineseConversionEnabled && !mgrPrefs.shiftJISShinjitaiOutputEnabled {
return vChewingKanjiConverter.cnvTradToKangXi(text) return vChewingKanjiConverter.cnvTradToKangXi(text)
} }
// //
if Preferences.chineseConversionEnabled && Preferences.shiftJISShinjitaiOutputEnabled { if mgrPrefs.chineseConversionEnabled && mgrPrefs.shiftJISShinjitaiOutputEnabled {
return vChewingKanjiConverter.cnvTradToJIS(text) return vChewingKanjiConverter.cnvTradToJIS(text)
} }
// if (!Preferences.chineseConversionEnabled && !Preferences.shiftJISShinjitaiOutputEnabled) || (keyHandler.inputMode != InputMode.imeModeCHT); // if (!mgrPrefs.chineseConversionEnabled && !mgrPrefs.shiftJISShinjitaiOutputEnabled) || (keyHandler.inputMode != InputMode.imeModeCHT);
return text return text
} }
return text return text
@ -535,14 +535,14 @@ extension ctlInputMethod {
if useVerticalMode { if useVerticalMode {
gCurrentCandidateController = .vertical gCurrentCandidateController = .vertical
} else if Preferences.useHorizontalCandidateList { } else if mgrPrefs.useHorizontalCandidateList {
gCurrentCandidateController = .horizontal gCurrentCandidateController = .horizontal
} else { } else {
gCurrentCandidateController = .vertical gCurrentCandidateController = .vertical
} }
// set the attributes for the candidate panel (which uses NSAttributedString) // set the attributes for the candidate panel (which uses NSAttributedString)
let textSize = Preferences.candidateListTextSize let textSize = mgrPrefs.candidateListTextSize
let keyLabelSize = max(textSize / 2, kMinKeyLabelSize) let keyLabelSize = max(textSize / 2, kMinKeyLabelSize)
func labelFont(name: String?, size: CGFloat) -> NSFont { func labelFont(name: String?, size: CGFloat) -> NSFont {
@ -563,11 +563,11 @@ extension ctlInputMethod {
return finalReturnFont return finalReturnFont
} }
gCurrentCandidateController?.keyLabelFont = labelFont(name: Preferences.candidateKeyLabelFontName, size: keyLabelSize) gCurrentCandidateController?.keyLabelFont = labelFont(name: mgrPrefs.candidateKeyLabelFontName, size: keyLabelSize)
gCurrentCandidateController?.candidateFont = candidateFont(name: Preferences.candidateTextFontName, size: textSize) gCurrentCandidateController?.candidateFont = candidateFont(name: mgrPrefs.candidateTextFontName, size: textSize)
let candidateKeys = Preferences.candidateKeys let candidateKeys = mgrPrefs.candidateKeys
let keyLabels = candidateKeys.count > 4 ? Array(candidateKeys) : Array(Preferences.defaultCandidateKeys) let keyLabels = candidateKeys.count > 4 ? Array(candidateKeys) : Array(mgrPrefs.defaultCandidateKeys)
let keyLabelSuffix = state is InputState.AssociatedPhrases ? "^" : "" let keyLabelSuffix = state is InputState.AssociatedPhrases ? "^" : ""
gCurrentCandidateController?.keyLabels = keyLabels.map { gCurrentCandidateController?.keyLabels = keyLabels.map {
CandidateKeyLabel(key: String($0), displayedText: String($0) + keyLabelSuffix) CandidateKeyLabel(key: String($0), displayedText: String($0) + keyLabelSuffix)
@ -695,11 +695,11 @@ extension ctlInputMethod: CandidateControllerDelegate {
return return
} }
if Preferences.useSCPCTypingMode { if mgrPrefs.useSCPCTypingMode {
keyHandler.clear() keyHandler.clear()
let composingBuffer = inputting.composingBuffer let composingBuffer = inputting.composingBuffer
handle(state: .Committing(poppedText: composingBuffer), client: client) handle(state: .Committing(poppedText: composingBuffer), client: client)
if Preferences.associatedPhrasesEnabled, if mgrPrefs.associatedPhrasesEnabled,
let associatePhrases = keyHandler.buildAssociatePhraseState(withKey: composingBuffer, useVerticalMode: state.useVerticalMode) as? InputState.AssociatedPhrases { let associatePhrases = keyHandler.buildAssociatePhraseState(withKey: composingBuffer, useVerticalMode: state.useVerticalMode) as? InputState.AssociatedPhrases {
self.handle(state: associatePhrases, client: client) self.handle(state: associatePhrases, client: client)
} else { } else {
@ -714,7 +714,7 @@ extension ctlInputMethod: CandidateControllerDelegate {
if let state = state as? InputState.AssociatedPhrases { if let state = state as? InputState.AssociatedPhrases {
let selectedValue = state.candidates[Int(index)] let selectedValue = state.candidates[Int(index)]
handle(state: .Committing(poppedText: selectedValue), client: currentCandidateClient) handle(state: .Committing(poppedText: selectedValue), client: currentCandidateClient)
if Preferences.associatedPhrasesEnabled, if mgrPrefs.associatedPhrasesEnabled,
let associatePhrases = keyHandler.buildAssociatePhraseState(withKey: selectedValue, useVerticalMode: state.useVerticalMode) as? InputState.AssociatedPhrases { let associatePhrases = keyHandler.buildAssociatePhraseState(withKey: selectedValue, useVerticalMode: state.useVerticalMode) as? InputState.AssociatedPhrases {
self.handle(state: associatePhrases, client: client) self.handle(state: associatePhrases, client: client)
} else { } else {

View File

@ -212,7 +212,7 @@ struct ComposingBufferSize {
} }
// MARK: - // MARK: -
@objc public class Preferences: NSObject { @objc public class mgrPrefs: NSObject {
static var allKeys:[String] { static var allKeys:[String] {
[kIsDebugModeEnabled, [kIsDebugModeEnabled,
kKeyboardLayoutPreference, kKeyboardLayoutPreference,
@ -253,7 +253,7 @@ struct ComposingBufferSize {
// //
if UserDefaults.standard.object(forKey: kIsDebugModeEnabled) == nil { if UserDefaults.standard.object(forKey: kIsDebugModeEnabled) == nil {
UserDefaults.standard.set(Preferences.isDebugModeEnabled, forKey: kIsDebugModeEnabled) UserDefaults.standard.set(mgrPrefs.isDebugModeEnabled, forKey: kIsDebugModeEnabled)
} }
// //
@ -263,87 +263,87 @@ struct ComposingBufferSize {
// //
if UserDefaults.standard.object(forKey: kShowPageButtonsInCandidateWindow) == nil { if UserDefaults.standard.object(forKey: kShowPageButtonsInCandidateWindow) == nil {
UserDefaults.standard.set(Preferences.showPageButtonsInCandidateWindow, forKey: kShowPageButtonsInCandidateWindow) UserDefaults.standard.set(mgrPrefs.showPageButtonsInCandidateWindow, forKey: kShowPageButtonsInCandidateWindow)
} }
// //
if UserDefaults.standard.object(forKey: kSymbolInputEnabled) == nil { if UserDefaults.standard.object(forKey: kSymbolInputEnabled) == nil {
UserDefaults.standard.set(Preferences.symbolInputEnabled, forKey: kSymbolInputEnabled) UserDefaults.standard.set(mgrPrefs.symbolInputEnabled, forKey: kSymbolInputEnabled)
} }
// 18 // 18
if UserDefaults.standard.object(forKey: kCandidateListTextSize) == nil { if UserDefaults.standard.object(forKey: kCandidateListTextSize) == nil {
UserDefaults.standard.set(Preferences.candidateListTextSize, forKey: kCandidateListTextSize) UserDefaults.standard.set(mgrPrefs.candidateListTextSize, forKey: kCandidateListTextSize)
} }
// true // true
if UserDefaults.standard.object(forKey: kChooseCandidateUsingSpace) == nil { if UserDefaults.standard.object(forKey: kChooseCandidateUsingSpace) == nil {
UserDefaults.standard.set(Preferences.chooseCandidateUsingSpace, forKey: kChooseCandidateUsingSpace) UserDefaults.standard.set(mgrPrefs.chooseCandidateUsingSpace, forKey: kChooseCandidateUsingSpace)
} }
// 使 // 使
if UserDefaults.standard.object(forKey: kShouldAutoReloadUserDataFiles) == nil { if UserDefaults.standard.object(forKey: kShouldAutoReloadUserDataFiles) == nil {
UserDefaults.standard.set(Preferences.shouldAutoReloadUserDataFiles, forKey: kShouldAutoReloadUserDataFiles) UserDefaults.standard.set(mgrPrefs.shouldAutoReloadUserDataFiles, forKey: kShouldAutoReloadUserDataFiles)
} }
// Tab // Tab
if UserDefaults.standard.object(forKey: kSpecifyTabKeyBehavior) == nil { if UserDefaults.standard.object(forKey: kSpecifyTabKeyBehavior) == nil {
UserDefaults.standard.set(Preferences.specifyTabKeyBehavior, forKey: kSpecifyTabKeyBehavior) UserDefaults.standard.set(mgrPrefs.specifyTabKeyBehavior, forKey: kSpecifyTabKeyBehavior)
} }
// Space // Space
if UserDefaults.standard.object(forKey: kSpecifySpaceKeyBehavior) == nil { if UserDefaults.standard.object(forKey: kSpecifySpaceKeyBehavior) == nil {
UserDefaults.standard.set(Preferences.specifySpaceKeyBehavior, forKey: kSpecifySpaceKeyBehavior) UserDefaults.standard.set(mgrPrefs.specifySpaceKeyBehavior, forKey: kSpecifySpaceKeyBehavior)
} }
// false // false
if UserDefaults.standard.object(forKey: kUseSCPCTypingMode) == nil { if UserDefaults.standard.object(forKey: kUseSCPCTypingMode) == nil {
UserDefaults.standard.set(Preferences.useSCPCTypingMode, forKey: kUseSCPCTypingMode) UserDefaults.standard.set(mgrPrefs.useSCPCTypingMode, forKey: kUseSCPCTypingMode)
} }
// false // false
if UserDefaults.standard.object(forKey: kAssociatedPhrasesEnabled) == nil { if UserDefaults.standard.object(forKey: kAssociatedPhrasesEnabled) == nil {
UserDefaults.standard.set(Preferences.associatedPhrasesEnabled, forKey: kAssociatedPhrasesEnabled) UserDefaults.standard.set(mgrPrefs.associatedPhrasesEnabled, forKey: kAssociatedPhrasesEnabled)
} }
// 0 // 0
if UserDefaults.standard.object(forKey: kSelectPhraseAfterCursorAsCandidatePreference) == nil { if UserDefaults.standard.object(forKey: kSelectPhraseAfterCursorAsCandidatePreference) == nil {
UserDefaults.standard.set(Preferences.selectPhraseAfterCursorAsCandidate, forKey: kSelectPhraseAfterCursorAsCandidatePreference) UserDefaults.standard.set(mgrPrefs.selectPhraseAfterCursorAsCandidate, forKey: kSelectPhraseAfterCursorAsCandidatePreference)
} }
// //
if UserDefaults.standard.object(forKey: kMoveCursorAfterSelectingCandidate) == nil { if UserDefaults.standard.object(forKey: kMoveCursorAfterSelectingCandidate) == nil {
UserDefaults.standard.set(Preferences.moveCursorAfterSelectingCandidate, forKey: kMoveCursorAfterSelectingCandidate) UserDefaults.standard.set(mgrPrefs.moveCursorAfterSelectingCandidate, forKey: kMoveCursorAfterSelectingCandidate)
} }
// //
if UserDefaults.standard.object(forKey: kUseHorizontalCandidateListPreference) == nil { if UserDefaults.standard.object(forKey: kUseHorizontalCandidateListPreference) == nil {
UserDefaults.standard.set(Preferences.useHorizontalCandidateList, forKey: kUseHorizontalCandidateListPreference) UserDefaults.standard.set(mgrPrefs.useHorizontalCandidateList, forKey: kUseHorizontalCandidateListPreference)
} }
// //
if UserDefaults.standard.object(forKey: kCNS11643Enabled) == nil { if UserDefaults.standard.object(forKey: kCNS11643Enabled) == nil {
UserDefaults.standard.set(Preferences.cns11643Enabled, forKey: kCNS11643Enabled) UserDefaults.standard.set(mgrPrefs.cns11643Enabled, forKey: kCNS11643Enabled)
} }
// //
if UserDefaults.standard.object(forKey: kChineseConversionEnabled) == nil { if UserDefaults.standard.object(forKey: kChineseConversionEnabled) == nil {
UserDefaults.standard.set(Preferences.chineseConversionEnabled, forKey: kChineseConversionEnabled) UserDefaults.standard.set(mgrPrefs.chineseConversionEnabled, forKey: kChineseConversionEnabled)
} }
// JIS // JIS
if UserDefaults.standard.object(forKey: kShiftJISShinjitaiOutputEnabled) == nil { if UserDefaults.standard.object(forKey: kShiftJISShinjitaiOutputEnabled) == nil {
UserDefaults.standard.set(Preferences.shiftJISShinjitaiOutputEnabled, forKey: kShiftJISShinjitaiOutputEnabled) UserDefaults.standard.set(mgrPrefs.shiftJISShinjitaiOutputEnabled, forKey: kShiftJISShinjitaiOutputEnabled)
} }
// //
if UserDefaults.standard.object(forKey: kPhraseReplacementEnabled) == nil { if UserDefaults.standard.object(forKey: kPhraseReplacementEnabled) == nil {
UserDefaults.standard.set(Preferences.phraseReplacementEnabled, forKey: kPhraseReplacementEnabled) UserDefaults.standard.set(mgrPrefs.phraseReplacementEnabled, forKey: kPhraseReplacementEnabled)
} }
// //
if UserDefaults.standard.object(forKey: kShouldNotFartInLieuOfBeep) == nil { if UserDefaults.standard.object(forKey: kShouldNotFartInLieuOfBeep) == nil {
UserDefaults.standard.set(Preferences.shouldNotFartInLieuOfBeep, forKey: kShouldNotFartInLieuOfBeep) UserDefaults.standard.set(mgrPrefs.shouldNotFartInLieuOfBeep, forKey: kShouldNotFartInLieuOfBeep)
} }
UserDefaults.standard.synchronize() UserDefaults.standard.synchronize()

View File

@ -137,16 +137,16 @@ static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, vChewing
+ (void)setupDataModelValueConverter + (void)setupDataModelValueConverter
{ {
auto converter = [] (string input) { auto converter = [] (string input) {
// if (!Preferences.chineseConversionEnabled) { // if (!mgrPrefs.chineseConversionEnabled) {
// return input; // return input;
// } // }
// //
// if (Preferences.chineseConversionStyle == 0) { // if (mgrPrefs.chineseConversionStyle == 0) {
// return input; // return input;
// } // }
// //
// NSString *text = [NSString stringWithUTF8String:input.c_str()]; // NSString *text = [NSString stringWithUTF8String:input.c_str()];
// if (Preferences.chineseConversionEngine == 1) { // if (mgrPrefs.chineseConversionEngine == 1) {
// text = [VXHanConvert convertToKangXiFrom:text]; // text = [VXHanConvert convertToKangXiFrom:text];
// } // }
// else { // else {
@ -288,7 +288,7 @@ static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, vChewing
// We use FSEventStream to monitor the change of the user phrase folder, // We use FSEventStream to monitor the change of the user phrase folder,
// so we don't have to load data here unless FSEventStream is disabled by user. // so we don't have to load data here unless FSEventStream is disabled by user.
if (!Preferences.shouldAutoReloadUserDataFiles) { if (!mgrPrefs.shouldAutoReloadUserDataFiles) {
[self loadUserPhrases]; [self loadUserPhrases];
} }
return YES; return YES;

View File

@ -34,7 +34,7 @@ import Cocoa
} }
// Create a new beep sound if possible // Create a new beep sound if possible
var sndBeep:String var sndBeep:String
if Preferences.shouldNotFartInLieuOfBeep == false { if mgrPrefs.shouldNotFartInLieuOfBeep == false {
sndBeep = "Fart" sndBeep = "Fart"
} else { } else {
sndBeep = "Beep" sndBeep = "Beep"

View File

@ -363,7 +363,7 @@ extension HorizontalCandidateController {
frameRect.size = newSize frameRect.size = newSize
candidateView.frame = frameRect candidateView.frame = frameRect
if pageCount > 1 && Preferences.showPageButtonsInCandidateWindow { if pageCount > 1 && mgrPrefs.showPageButtonsInCandidateWindow {
var buttonRect = nextPageButton.frame var buttonRect = nextPageButton.frame
let spacing:CGFloat = 0.0 let spacing:CGFloat = 0.0

View File

@ -369,7 +369,7 @@ extension VerticalCandidateController {
frameRect.size = newSize frameRect.size = newSize
candidateView.frame = frameRect candidateView.frame = frameRect
if pageCount > 1 && Preferences.showPageButtonsInCandidateWindow { if pageCount > 1 && mgrPrefs.showPageButtonsInCandidateWindow {
var buttonRect = nextPageButton.frame var buttonRect = nextPageButton.frame
let spacing:CGFloat = 0.0 let spacing:CGFloat = 0.0

View File

@ -49,7 +49,7 @@ extension RangeReplaceableCollection where Element: Hashable {
var chosenLanguageItem: NSMenuItem? = nil var chosenLanguageItem: NSMenuItem? = nil
uiLanguageButton.menu?.removeAllItems() uiLanguageButton.menu?.removeAllItems()
let appleLanguages = Preferences.appleLanguages let appleLanguages = mgrPrefs.appleLanguages
for language in languages { for language in languages {
let menuItem = NSMenuItem() let menuItem = NSMenuItem()
menuItem.title = NSLocalizedString(language, comment: "") menuItem.title = NSLocalizedString(language, comment: "")
@ -86,7 +86,7 @@ extension RangeReplaceableCollection where Element: Hashable {
menuItem_AppleZhuyinEten.representedObject = String("com.apple.keylayout.ZhuyinEten") menuItem_AppleZhuyinEten.representedObject = String("com.apple.keylayout.ZhuyinEten")
basisKeyboardLayoutButton.menu?.addItem(menuItem_AppleZhuyinEten) basisKeyboardLayoutButton.menu?.addItem(menuItem_AppleZhuyinEten)
let basisKeyboardLayoutID = Preferences.basisKeyboardLayout let basisKeyboardLayoutID = mgrPrefs.basisKeyboardLayout
for source in list { for source in list {
if let categoryPtr = TISGetInputSourceProperty(source, kTISPropertyInputSourceCategory) { if let categoryPtr = TISGetInputSourceProperty(source, kTISPropertyInputSourceCategory) {
@ -150,11 +150,11 @@ extension RangeReplaceableCollection where Element: Hashable {
selectionKeyComboBox.usesDataSource = false selectionKeyComboBox.usesDataSource = false
selectionKeyComboBox.removeAllItems() selectionKeyComboBox.removeAllItems()
selectionKeyComboBox.addItems(withObjectValues: Preferences.suggestedCandidateKeys) selectionKeyComboBox.addItems(withObjectValues: mgrPrefs.suggestedCandidateKeys)
var candidateSelectionKeys = Preferences.candidateKeys var candidateSelectionKeys = mgrPrefs.candidateKeys
if candidateSelectionKeys.isEmpty { if candidateSelectionKeys.isEmpty {
candidateSelectionKeys = Preferences.defaultCandidateKeys candidateSelectionKeys = mgrPrefs.defaultCandidateKeys
} }
selectionKeyComboBox.stringValue = candidateSelectionKeys selectionKeyComboBox.stringValue = candidateSelectionKeys
@ -163,28 +163,28 @@ extension RangeReplaceableCollection where Element: Hashable {
// CNS // CNS
// //
@IBAction func toggleCNSSupport(_ sender: Any) { @IBAction func toggleCNSSupport(_ sender: Any) {
mgrLangModel.setCNSEnabled(Preferences.cns11643Enabled) mgrLangModel.setCNSEnabled(mgrPrefs.cns11643Enabled)
} }
@IBAction func toggleSymbolInputEnabled(_ sender: Any) { @IBAction func toggleSymbolInputEnabled(_ sender: Any) {
mgrLangModel.setSymbolEnabled(Preferences.symbolInputEnabled) mgrLangModel.setSymbolEnabled(mgrPrefs.symbolInputEnabled)
} }
@IBAction func toggleTrad2KangXiAction(_ sender: Any) { @IBAction func toggleTrad2KangXiAction(_ sender: Any) {
if chkTrad2KangXi.state == .on && chkTrad2JISShinjitai.state == .on { if chkTrad2KangXi.state == .on && chkTrad2JISShinjitai.state == .on {
Preferences.toggleShiftJISShinjitaiOutputEnabled() mgrPrefs.toggleShiftJISShinjitaiOutputEnabled()
} }
} }
@IBAction func toggleTrad2JISShinjitaiAction(_ sender: Any) { @IBAction func toggleTrad2JISShinjitaiAction(_ sender: Any) {
if chkTrad2KangXi.state == .on && chkTrad2JISShinjitai.state == .on { if chkTrad2KangXi.state == .on && chkTrad2JISShinjitai.state == .on {
Preferences.toggleChineseConversionEnabled() mgrPrefs.toggleChineseConversionEnabled()
} }
} }
@IBAction func updateBasisKeyboardLayoutAction(_ sender: Any) { @IBAction func updateBasisKeyboardLayoutAction(_ sender: Any) {
if let sourceID = basisKeyboardLayoutButton.selectedItem?.representedObject as? String { if let sourceID = basisKeyboardLayoutButton.selectedItem?.representedObject as? String {
Preferences.basisKeyboardLayout = sourceID mgrPrefs.basisKeyboardLayout = sourceID
} }
} }
@ -196,7 +196,7 @@ extension RangeReplaceableCollection where Element: Hashable {
} }
if let language = uiLanguageButton.selectedItem?.representedObject as? String { if let language = uiLanguageButton.selectedItem?.representedObject as? String {
if (language != "auto") { if (language != "auto") {
Preferences.appleLanguages = [language] mgrPrefs.appleLanguages = [language]
} }
else { else {
UserDefaults.standard.removeObject(forKey: "AppleLanguages") UserDefaults.standard.removeObject(forKey: "AppleLanguages")
@ -216,18 +216,18 @@ extension RangeReplaceableCollection where Element: Hashable {
return return
} }
do { do {
try Preferences.validate(candidateKeys: keys) try mgrPrefs.validate(candidateKeys: keys)
Preferences.candidateKeys = keys mgrPrefs.candidateKeys = keys
selectionKeyComboBox.stringValue = Preferences.candidateKeys selectionKeyComboBox.stringValue = mgrPrefs.candidateKeys
} }
catch Preferences.CandidateKeyError.empty { catch mgrPrefs.CandidateKeyError.empty {
selectionKeyComboBox.stringValue = Preferences.candidateKeys selectionKeyComboBox.stringValue = mgrPrefs.candidateKeys
} }
catch { catch {
if let window = window { if let window = window {
let alert = NSAlert(error: error) let alert = NSAlert(error: error)
alert.beginSheetModal(for: window) { response in alert.beginSheetModal(for: window) { response in
self.selectionKeyComboBox.stringValue = Preferences.candidateKeys self.selectionKeyComboBox.stringValue = mgrPrefs.candidateKeys
} }
clsSFX.beep() clsSFX.beep()
} }

View File

@ -22,7 +22,7 @@
5B62A32927AE77D100A19448 /* FSEventStreamHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A32827AE77D100A19448 /* FSEventStreamHelper.swift */; }; 5B62A32927AE77D100A19448 /* FSEventStreamHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A32827AE77D100A19448 /* FSEventStreamHelper.swift */; };
5B62A32F27AE78B000A19448 /* CoreLM.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A32D27AE78B000A19448 /* CoreLM.mm */; }; 5B62A32F27AE78B000A19448 /* CoreLM.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A32D27AE78B000A19448 /* CoreLM.mm */; };
5B62A33227AE792F00A19448 /* InputSourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33127AE792F00A19448 /* InputSourceHelper.swift */; }; 5B62A33227AE792F00A19448 /* InputSourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33127AE792F00A19448 /* InputSourceHelper.swift */; };
5B62A33627AE795800A19448 /* PreferencesModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33527AE795800A19448 /* PreferencesModule.swift */; }; 5B62A33627AE795800A19448 /* mgrPrefs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33527AE795800A19448 /* mgrPrefs.swift */; };
5B62A33827AE79CD00A19448 /* NSStringUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33727AE79CD00A19448 /* NSStringUtils.swift */; }; 5B62A33827AE79CD00A19448 /* NSStringUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33727AE79CD00A19448 /* NSStringUtils.swift */; };
5B62A33D27AE7CC100A19448 /* ctlAboutWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33C27AE7CC100A19448 /* ctlAboutWindow.swift */; }; 5B62A33D27AE7CC100A19448 /* ctlAboutWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33C27AE7CC100A19448 /* ctlAboutWindow.swift */; };
5B62A34627AE7CD900A19448 /* HorizontalCandidateController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33F27AE7CD900A19448 /* HorizontalCandidateController.swift */; }; 5B62A34627AE7CD900A19448 /* HorizontalCandidateController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33F27AE7CD900A19448 /* HorizontalCandidateController.swift */; };
@ -188,7 +188,7 @@
5B62A32C27AE78B000A19448 /* CoreLM.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreLM.h; sourceTree = "<group>"; }; 5B62A32C27AE78B000A19448 /* CoreLM.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreLM.h; sourceTree = "<group>"; };
5B62A32D27AE78B000A19448 /* CoreLM.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CoreLM.mm; sourceTree = "<group>"; }; 5B62A32D27AE78B000A19448 /* CoreLM.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CoreLM.mm; sourceTree = "<group>"; };
5B62A33127AE792F00A19448 /* InputSourceHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputSourceHelper.swift; sourceTree = "<group>"; }; 5B62A33127AE792F00A19448 /* InputSourceHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputSourceHelper.swift; sourceTree = "<group>"; };
5B62A33527AE795800A19448 /* PreferencesModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesModule.swift; sourceTree = "<group>"; }; 5B62A33527AE795800A19448 /* mgrPrefs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = mgrPrefs.swift; sourceTree = "<group>"; };
5B62A33727AE79CD00A19448 /* NSStringUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSStringUtils.swift; sourceTree = "<group>"; }; 5B62A33727AE79CD00A19448 /* NSStringUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSStringUtils.swift; sourceTree = "<group>"; };
5B62A33C27AE7CC100A19448 /* ctlAboutWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ctlAboutWindow.swift; sourceTree = "<group>"; }; 5B62A33C27AE7CC100A19448 /* ctlAboutWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ctlAboutWindow.swift; sourceTree = "<group>"; };
5B62A33F27AE7CD900A19448 /* HorizontalCandidateController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HorizontalCandidateController.swift; sourceTree = "<group>"; }; 5B62A33F27AE7CD900A19448 /* HorizontalCandidateController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HorizontalCandidateController.swift; sourceTree = "<group>"; };
@ -462,7 +462,7 @@
children = ( children = (
D4A13D5927A59D5C003BE359 /* ctlInputMethod.swift */, D4A13D5927A59D5C003BE359 /* ctlInputMethod.swift */,
5B62A33127AE792F00A19448 /* InputSourceHelper.swift */, 5B62A33127AE792F00A19448 /* InputSourceHelper.swift */,
5B62A33527AE795800A19448 /* PreferencesModule.swift */, 5B62A33527AE795800A19448 /* mgrPrefs.swift */,
); );
path = IMEModules; path = IMEModules;
sourceTree = "<group>"; sourceTree = "<group>";
@ -1031,7 +1031,7 @@
5B62A31A27AE73A700A19448 /* mztools.m in Sources */, 5B62A31A27AE73A700A19448 /* mztools.m in Sources */,
5B62A32927AE77D100A19448 /* FSEventStreamHelper.swift in Sources */, 5B62A32927AE77D100A19448 /* FSEventStreamHelper.swift in Sources */,
D47F7DD3278C1263002F9DD7 /* UserOverrideModel.cpp in Sources */, D47F7DD3278C1263002F9DD7 /* UserOverrideModel.cpp in Sources */,
5B62A33627AE795800A19448 /* PreferencesModule.swift in Sources */, 5B62A33627AE795800A19448 /* mgrPrefs.swift in Sources */,
5B62A33827AE79CD00A19448 /* NSStringUtils.swift in Sources */, 5B62A33827AE79CD00A19448 /* NSStringUtils.swift in Sources */,
5B62A33227AE792F00A19448 /* InputSourceHelper.swift in Sources */, 5B62A33227AE792F00A19448 /* InputSourceHelper.swift in Sources */,
5B62A34927AE7CD900A19448 /* TooltipController.swift in Sources */, 5B62A34927AE7CD900A19448 /* TooltipController.swift in Sources */,