KeyHandler // Use PrefMgrProtocol delegate to handle UserDefaults.

This commit is contained in:
ShikiSuen 2022-09-21 10:28:39 +08:00
parent 9d077a9d49
commit 03d4099894
27 changed files with 266 additions and 260 deletions

View File

@ -55,7 +55,7 @@ class ctlInputMethod: IMKInputController {
// MARK: - Extracted methods and functions (Tekkon). // MARK: - Extracted methods and functions (Tekkon).
func ensureParser() { func ensureParser() {
switch mgrPrefs.mandarinParser { switch PrefMgr.shared.mandarinParser {
case MandarinParser.ofStandard.rawValue: case MandarinParser.ofStandard.rawValue:
_composer.ensureParser(arrange: .ofDachen) // 大千 _composer.ensureParser(arrange: .ofDachen) // 大千
case MandarinParser.ofETen.rawValue: case MandarinParser.ofETen.rawValue:
@ -82,7 +82,7 @@ class ctlInputMethod: IMKInputController {
_composer.ensureParser(arrange: .ofUniversalPinyin) // 通用拼音 _composer.ensureParser(arrange: .ofUniversalPinyin) // 通用拼音
default: default:
_composer.ensureParser(arrange: .ofDachen) // 預設情況下按照 PrefMgr 內定義預設值來處理 _composer.ensureParser(arrange: .ofDachen) // 預設情況下按照 PrefMgr 內定義預設值來處理
mgrPrefs.mandarinParser = MandarinParser.ofStandard.rawValue PrefMgr.shared.mandarinParser = MandarinParser.ofStandard.rawValue
} }
_composer.clear() _composer.clear()
} }

View File

@ -17,7 +17,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
private func reloadOnFolderChangeHappens() { private func reloadOnFolderChangeHappens() {
// 100ms 使使 // 100ms 使使
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) {
if mgrPrefs.shouldAutoReloadUserDataFiles { if PrefMgr.shared.shouldAutoReloadUserDataFiles {
LMMgr.initUserLangModels() LMMgr.initUserLangModels()
} }
} }
@ -39,10 +39,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
func applicationDidFinishLaunching(_: Notification) { func applicationDidFinishLaunching(_: Notification) {
NSUserNotificationCenter.default.delegate = self NSUserNotificationCenter.default.delegate = self
// 使 // 使
if mgrPrefs.failureFlagForUOMObservation { if PrefMgr.shared.failureFlagForUOMObservation {
LMMgr.clearUserOverrideModelData(.imeModeCHS) LMMgr.clearUserOverrideModelData(.imeModeCHS)
LMMgr.clearUserOverrideModelData(.imeModeCHT) LMMgr.clearUserOverrideModelData(.imeModeCHT)
mgrPrefs.failureFlagForUOMObservation = false PrefMgr.shared.failureFlagForUOMObservation = false
let userNotification = NSUserNotification() let userNotification = NSUserNotification()
userNotification.title = NSLocalizedString("vChewing", comment: "") userNotification.title = NSLocalizedString("vChewing", comment: "")
userNotification.informativeText = userNotification.informativeText =
@ -61,7 +61,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
} }
} }
mgrPrefs.fixOddPreferences() PrefMgr.shared.fixOddPreferences()
// //
updateSputnik.varkUpdateInfoPageURLKey = "UpdateInfoSite" updateSputnik.varkUpdateInfoPageURLKey = "UpdateInfoSite"
@ -71,7 +71,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
updateSputnik.varCheckUpdateAutomatically = "ChecvarkUpdateAutomatically" updateSputnik.varCheckUpdateAutomatically = "ChecvarkUpdateAutomatically"
// 使 // 使
if mgrPrefs.checkUpdateAutomatically { if PrefMgr.shared.checkUpdateAutomatically {
updateSputnik.checkForUpdate(forced: false, url: kUpdateInfoSourceURL) updateSputnik.checkForUpdate(forced: false, url: kUpdateInfoSourceURL)
} }
} }

View File

@ -54,14 +54,14 @@ public enum ChineseConverter {
/// ///
/// - Parameter target: /// - Parameter target:
public static func ensureCurrencyNumerals(target: inout String) { public static func ensureCurrencyNumerals(target: inout String) {
if !mgrPrefs.currencyNumeralsEnabled { return } if !PrefMgr.shared.currencyNumeralsEnabled { return }
for key in currencyNumeralDictTable.keys { for key in currencyNumeralDictTable.keys {
guard let result = currencyNumeralDictTable[key] else { continue } guard let result = currencyNumeralDictTable[key] else { continue }
if IMEApp.currentInputMode == InputMode.imeModeCHS { if IMEApp.currentInputMode == InputMode.imeModeCHS {
target = target.replacingOccurrences(of: key, with: result.3) // Simplified Chinese target = target.replacingOccurrences(of: key, with: result.3) // Simplified Chinese
continue continue
} }
switch (mgrPrefs.chineseConversionEnabled, mgrPrefs.shiftJISShinjitaiOutputEnabled) { switch (PrefMgr.shared.chineseConversionEnabled, PrefMgr.shared.shiftJISShinjitaiOutputEnabled) {
case (false, true), (true, true): target = target.replacingOccurrences(of: key, with: result.2) // JIS case (false, true), (true, true): target = target.replacingOccurrences(of: key, with: result.2) // JIS
case (true, false): target = target.replacingOccurrences(of: key, with: result.0) // KangXi case (true, false): target = target.replacingOccurrences(of: key, with: result.0) // KangXi
default: target = target.replacingOccurrences(of: key, with: result.1) // Contemporary default: target = target.replacingOccurrences(of: key, with: result.1) // Contemporary
@ -98,7 +98,7 @@ public enum ChineseConverter {
static func kanjiConversionIfRequired(_ text: String) -> String { static func kanjiConversionIfRequired(_ text: String) -> String {
guard IMEApp.currentInputMode == InputMode.imeModeCHT else { return text } guard IMEApp.currentInputMode == InputMode.imeModeCHT else { return text }
switch (mgrPrefs.chineseConversionEnabled, mgrPrefs.shiftJISShinjitaiOutputEnabled) { switch (PrefMgr.shared.chineseConversionEnabled, PrefMgr.shared.shiftJISShinjitaiOutputEnabled) {
case (false, true): return ChineseConverter.cnvTradToJIS(text) case (false, true): return ChineseConverter.cnvTradToJIS(text)
case (true, false): return ChineseConverter.cnvTradToKangXi(text) case (true, false): return ChineseConverter.cnvTradToKangXi(text)
// //

View File

@ -121,7 +121,7 @@ extension IMEState {
// displayTextSegments // displayTextSegments
result.data.displayTextSegments = displayTextSegments.map { result.data.displayTextSegments = displayTextSegments.map {
if !ctlInputMethod.isVerticalTyping { return $0 } if !ctlInputMethod.isVerticalTyping { return $0 }
guard mgrPrefs.hardenVerticalPunctuations else { return $0 } guard PrefMgr.shared.hardenVerticalPunctuations else { return $0 }
var neta = $0 var neta = $0
ChineseConverter.hardenVerticalPunctuations(target: &neta, convert: ctlInputMethod.isVerticalTyping) ChineseConverter.hardenVerticalPunctuations(target: &neta, convert: ctlInputMethod.isVerticalTyping)
return neta return neta

View File

@ -10,11 +10,11 @@ import Tekkon
public struct StateData { public struct StateData {
private static var minCandidateLength: Int { private static var minCandidateLength: Int {
mgrPrefs.allowBoostingSingleKanjiAsUserPhrase ? 1 : 2 PrefMgr.shared.allowBoostingSingleKanjiAsUserPhrase ? 1 : 2
} }
static var allowedMarkLengthRange: ClosedRange<Int> { static var allowedMarkLengthRange: ClosedRange<Int> {
Self.minCandidateLength...mgrPrefs.maxCandidateLength Self.minCandidateLength...PrefMgr.shared.maxCandidateLength
} }
var displayedText: String = "" var displayedText: String = ""
@ -177,8 +177,8 @@ extension StateData {
arrOutput.append("??") arrOutput.append("??")
continue continue
} }
if mgrPrefs.showHanyuPinyinInCompositionBuffer, if PrefMgr.shared.showHanyuPinyinInCompositionBuffer,
mgrPrefs.alwaysShowTooltipTextsHorizontally || !isVerticalTyping PrefMgr.shared.alwaysShowTooltipTextsHorizontally || !isVerticalTyping
{ {
// ->->調 // ->->調
neta = Tekkon.restoreToneOneInZhuyinKey(target: neta) neta = Tekkon.restoreToneOneInZhuyinKey(target: neta)
@ -215,7 +215,7 @@ extension StateData {
mutating func updateTooltipForMarking() { mutating func updateTooltipForMarking() {
var tooltipForMarking: String { var tooltipForMarking: String {
let pair = userPhraseKVPair let pair = userPhraseKVPair
if mgrPrefs.phraseReplacementEnabled { if PrefMgr.shared.phraseReplacementEnabled {
tooltipColorState = .warning tooltipColorState = .warning
return NSLocalizedString( return NSLocalizedString(
"⚠︎ Phrase replacement mode enabled, interfering user phrase entry.", comment: "" "⚠︎ Phrase replacement mode enabled, interfering user phrase entry.", comment: ""

View File

@ -32,6 +32,7 @@ public protocol KeyHandlerDelegate {
public class KeyHandler { public class KeyHandler {
/// (ctlInputMethod)便 /// (ctlInputMethod)便
public var delegate: KeyHandlerDelegate? public var delegate: KeyHandlerDelegate?
public var prefs: PrefMgrProtocol
/// ///
let kEpsilon: Double = 0.000_001 let kEpsilon: Double = 0.000_001
@ -47,11 +48,12 @@ public class KeyHandler {
} }
/// ///
public init(lm: vChewingLM.LMInstantiator, uom: vChewingLM.LMUserOverride) { public init(lm: vChewingLM.LMInstantiator, uom: vChewingLM.LMUserOverride, pref: PrefMgrProtocol) {
prefs = pref
currentLM = lm currentLM = lm
currentUOM = uom currentUOM = uom
/// ///
Megrez.Compositor.maxSpanLength = mgrPrefs.maxCandidateLength Megrez.Compositor.maxSpanLength = prefs.maxCandidateLength
/// ensureCompositor() /// ensureCompositor()
compositor = Megrez.Compositor(with: currentLM, separator: "-") compositor = Megrez.Compositor(with: currentLM, separator: "-")
/// ///
@ -85,7 +87,7 @@ public class KeyHandler {
/// 使 Node Crossing /// 使 Node Crossing
var actualCandidateCursor: Int { var actualCandidateCursor: Int {
compositor.cursor compositor.cursor
- ((compositor.cursor == compositor.width || !mgrPrefs.useRearCursorMode) && compositor.cursor > 0 ? 1 : 0) - ((compositor.cursor == compositor.width || !prefs.useRearCursorMode) && compositor.cursor > 0 ? 1 : 0)
} }
/// ///
@ -97,7 +99,7 @@ public class KeyHandler {
compositor.walk() compositor.walk()
// GraphViz // GraphViz
if mgrPrefs.isDebugModeEnabled { if prefs.isDebugModeEnabled {
let result = compositor.dumpDOT let result = compositor.dumpDOT
let thePath = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0].path.appending( let thePath = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0].path.appending(
"/vChewing-visualization.dot") "/vChewing-visualization.dot")
@ -222,12 +224,12 @@ public class KeyHandler {
let currentNode = currentWalk.findNode(at: actualCandidateCursor, target: &accumulatedCursor) let currentNode = currentWalk.findNode(at: actualCandidateCursor, target: &accumulatedCursor)
guard let currentNode = currentNode else { return } guard let currentNode = currentNode else { return }
if currentNode.currentUnigram.score > -12, mgrPrefs.fetchSuggestionsFromUserOverrideModel { if currentNode.currentUnigram.score > -12, prefs.fetchSuggestionsFromUserOverrideModel {
vCLog("UOM: Start Observation.") vCLog("UOM: Start Observation.")
// 使 // 使
// //
// AppDelegate // AppDelegate
mgrPrefs.failureFlagForUOMObservation = true prefs.failureFlagForUOMObservation = true
// //
// //
currentUOM.performObservation( currentUOM.performObservation(
@ -235,11 +237,11 @@ public class KeyHandler {
timestamp: Date().timeIntervalSince1970, saveCallback: { self.currentUOM.saveData() } timestamp: Date().timeIntervalSince1970, saveCallback: { self.currentUOM.saveData() }
) )
// //
mgrPrefs.failureFlagForUOMObservation = false prefs.failureFlagForUOMObservation = false
} }
/// ///
if mgrPrefs.moveCursorAfterSelectingCandidate, respectCursorPushing { if prefs.moveCursorAfterSelectingCandidate, respectCursorPushing {
// compositor.cursor = accumulatedCursor // compositor.cursor = accumulatedCursor
compositor.jumpCursorBySpan(to: .front) compositor.jumpCursorBySpan(to: .front)
} }
@ -250,7 +252,7 @@ public class KeyHandler {
/// 使 nodesCrossing macOS /// 使 nodesCrossing macOS
/// nodeCrossing /// nodeCrossing
var arrCandidates: [Megrez.Compositor.KeyValuePaired] = { var arrCandidates: [Megrez.Compositor.KeyValuePaired] = {
switch mgrPrefs.useRearCursorMode { switch prefs.useRearCursorMode {
case false: case false:
return compositor.fetchCandidates(at: actualCandidateCursor, filter: .endAt) return compositor.fetchCandidates(at: actualCandidateCursor, filter: .endAt)
case true: case true:
@ -264,7 +266,7 @@ public class KeyHandler {
if arrCandidates.isEmpty { return .init() } if arrCandidates.isEmpty { return .init() }
// 調 // 調
if !mgrPrefs.fetchSuggestionsFromUserOverrideModel || mgrPrefs.useSCPCTypingMode || fixOrder { if !prefs.fetchSuggestionsFromUserOverrideModel || prefs.useSCPCTypingMode || fixOrder {
return arrCandidates.map { ($0.key, $0.value) } return arrCandidates.map { ($0.key, $0.value) }
} }
@ -282,9 +284,9 @@ public class KeyHandler {
@discardableResult func fetchSuggestionsFromUOM(apply: Bool) -> [(String, Megrez.Unigram)] { @discardableResult func fetchSuggestionsFromUOM(apply: Bool) -> [(String, Megrez.Unigram)] {
var arrResult = [(String, Megrez.Unigram)]() var arrResult = [(String, Megrez.Unigram)]()
/// ///
if mgrPrefs.useSCPCTypingMode { return arrResult } if prefs.useSCPCTypingMode { return arrResult }
/// ///
if !mgrPrefs.fetchSuggestionsFromUserOverrideModel { return arrResult } if !prefs.fetchSuggestionsFromUserOverrideModel { return arrResult }
/// ///
let suggestion = currentUOM.fetchSuggestion( let suggestion = currentUOM.fetchSuggestion(
currentWalk: compositor.walkedNodes, cursor: actualCandidateCursor, timestamp: Date().timeIntervalSince1970 currentWalk: compositor.walkedNodes, cursor: actualCandidateCursor, timestamp: Date().timeIntervalSince1970
@ -320,7 +322,7 @@ public class KeyHandler {
} }
var currentKeyboardParserType: KeyboardParser { var currentKeyboardParserType: KeyboardParser {
.init(rawValue: mgrPrefs.keyboardParser) ?? .ofStandard .init(rawValue: prefs.keyboardParser) ?? .ofStandard
} }
/// ///
@ -358,7 +360,7 @@ public class KeyHandler {
composer.ensureParser(arrange: .ofUniversalPinyin) composer.ensureParser(arrange: .ofUniversalPinyin)
} }
composer.clear() composer.clear()
composer.phonabetCombinationCorrectionEnabled = mgrPrefs.autoCorrectReadingCombination composer.phonabetCombinationCorrectionEnabled = prefs.autoCorrectReadingCombination
} }
/// ///
@ -394,7 +396,7 @@ public class KeyHandler {
/// - Parameter input: /// - Parameter input:
/// - Returns: /// - Returns:
func generatePunctuationNamePrefix(withKeyCondition input: InputSignalProtocol) -> String { func generatePunctuationNamePrefix(withKeyCondition input: InputSignalProtocol) -> String {
if mgrPrefs.halfWidthPunctuationEnabled { if prefs.halfWidthPunctuationEnabled {
return "_half_punctuation_" return "_half_punctuation_"
} }
switch (input.isControlHold, input.isOptionHold) { switch (input.isControlHold, input.isOptionHold) {
@ -423,7 +425,7 @@ extension KeyHandler {
guard !compositor.walkedNodes.isEmpty, guard !compositor.walkedNodes.isEmpty,
compositor.width > compositorWidthLimit, compositor.width > compositorWidthLimit,
let identifier = delegate?.clientBundleIdentifier, let identifier = delegate?.clientBundleIdentifier,
mgrPrefs.clientsIMKTextInputIncapable.contains(identifier) prefs.clientsIMKTextInputIncapable.contains(identifier)
else { else {
return "" return ""
} }

View File

@ -39,7 +39,7 @@ extension KeyHandler {
if cancelCandidateKey { if cancelCandidateKey {
if state.type == .ofAssociates if state.type == .ofAssociates
|| mgrPrefs.useSCPCTypingMode || prefs.useSCPCTypingMode
|| compositor.isEmpty || compositor.isEmpty
{ {
// //
@ -59,7 +59,7 @@ extension KeyHandler {
// MARK: Enter // MARK: Enter
if input.isEnter { if input.isEnter {
if state.type == .ofAssociates, !mgrPrefs.alsoConfirmAssociatedCandidatesByEnter { if state.type == .ofAssociates, !prefs.alsoConfirmAssociatedCandidatesByEnter {
stateCallback(IMEState.ofAbortion()) stateCallback(IMEState.ofAbortion())
return true return true
} }
@ -71,7 +71,7 @@ extension KeyHandler {
if input.isTab { if input.isTab {
let updated: Bool = let updated: Bool =
mgrPrefs.specifyShiftTabKeyBehavior prefs.specifyShiftTabKeyBehavior
? (input.isShiftHold ? (input.isShiftHold
? ctlCandidate.showPreviousPage() ? ctlCandidate.showPreviousPage()
: ctlCandidate.showNextPage()) : ctlCandidate.showNextPage())
@ -88,7 +88,7 @@ extension KeyHandler {
if input.isSpace { if input.isSpace {
let updated: Bool = let updated: Bool =
mgrPrefs.specifyShiftSpaceKeyBehavior prefs.specifyShiftSpaceKeyBehavior
? (input.isShiftHold ? (input.isShiftHold
? ctlCandidate.highlightNextCandidate() ? ctlCandidate.highlightNextCandidate()
: ctlCandidate.showNextPage()) : ctlCandidate.showNextPage())
@ -242,7 +242,7 @@ extension KeyHandler {
// MARK: (SCPC Mode Processing) // MARK: (SCPC Mode Processing)
if mgrPrefs.useSCPCTypingMode { if prefs.useSCPCTypingMode {
/// ///
/// - / /// - /
/// - /// -

View File

@ -36,7 +36,7 @@ extension KeyHandler {
if !skipPhoneticHandling && composer.inputValidityCheck(key: input.charCode) { if !skipPhoneticHandling && composer.inputValidityCheck(key: input.charCode) {
// macOS 調 // macOS 調
// //
proc: if [0, 1].contains(mgrPrefs.specifyIntonationKeyBehavior), composer.isEmpty, !input.isSpace { proc: if [0, 1].contains(prefs.specifyIntonationKeyBehavior), composer.isEmpty, !input.isSpace {
// prevReading 調調 // prevReading 調調
guard let prevReading = previousParsableReading, isIntonationKey(input) else { break proc } guard let prevReading = previousParsableReading, isIntonationKey(input) else { break proc }
var theComposer = composer var theComposer = composer
@ -44,7 +44,7 @@ extension KeyHandler {
// 調調 // 調調
let oldIntonation: Tekkon.Phonabet = theComposer.intonation let oldIntonation: Tekkon.Phonabet = theComposer.intonation
theComposer.receiveKey(fromString: input.text) theComposer.receiveKey(fromString: input.text)
if theComposer.intonation == oldIntonation, mgrPrefs.specifyIntonationKeyBehavior == 1 { break proc } if theComposer.intonation == oldIntonation, prefs.specifyIntonationKeyBehavior == 1 { break proc }
theComposer.intonation.clear() theComposer.intonation.clear()
// //
let temporaryReadingKey = theComposer.getComposition() let temporaryReadingKey = theComposer.getComposition()
@ -88,7 +88,7 @@ extension KeyHandler {
if !currentLM.hasUnigramsFor(key: readingKey) { if !currentLM.hasUnigramsFor(key: readingKey) {
errorCallback("B49C0979語彙庫內無「\(readingKey)」的匹配記錄。") errorCallback("B49C0979語彙庫內無「\(readingKey)」的匹配記錄。")
if mgrPrefs.keepReadingUponCompositionError { if prefs.keepReadingUponCompositionError {
composer.intonation.clear() // 調 composer.intonation.clear() // 調
stateCallback(buildInputtingState) stateCallback(buildInputtingState)
return true return true
@ -125,14 +125,14 @@ extension KeyHandler {
stateCallback(inputting) stateCallback(inputting)
/// ///
if mgrPrefs.useSCPCTypingMode { if prefs.useSCPCTypingMode {
let candidateState: IMEState = buildCandidate(state: inputting) let candidateState: IMEState = buildCandidate(state: inputting)
if candidateState.candidates.count == 1, let firstCandidate = candidateState.candidates.first { if candidateState.candidates.count == 1, let firstCandidate = candidateState.candidates.first {
let reading: String = firstCandidate.0 let reading: String = firstCandidate.0
let text: String = firstCandidate.1 let text: String = firstCandidate.1
stateCallback(IMEState.ofCommitting(textToCommit: text)) stateCallback(IMEState.ofCommitting(textToCommit: text))
if !mgrPrefs.associatedPhrasesEnabled { if !prefs.associatedPhrasesEnabled {
stateCallback(IMEState.ofEmpty()) stateCallback(IMEState.ofEmpty())
} else { } else {
let associatedPhrases = let associatedPhrases =

View File

@ -149,11 +149,11 @@ extension KeyHandler {
if state.hasComposition, composer.isEmpty, !input.isOptionHold, if state.hasComposition, composer.isEmpty, !input.isOptionHold,
input.isCursorClockLeft || input.isCursorClockRight || input.isSpace input.isCursorClockLeft || input.isCursorClockRight || input.isSpace
|| input.isPageDown || input.isPageUp || (input.isTab && mgrPrefs.specifyShiftTabKeyBehavior) || input.isPageDown || input.isPageUp || (input.isTab && prefs.specifyShiftTabKeyBehavior)
{ {
if input.isSpace { if input.isSpace {
/// Space /// Space
if !mgrPrefs.chooseCandidateUsingSpace { if !prefs.chooseCandidateUsingSpace {
if compositor.cursor >= compositor.length { if compositor.cursor >= compositor.length {
let displayedText = state.displayedText let displayedText = state.displayedText
if !displayedText.isEmpty { if !displayedText.isEmpty {
@ -317,7 +317,7 @@ extension KeyHandler {
let string = NSMutableString(string: stringRAW) let string = NSMutableString(string: stringRAW)
CFStringTransform(string, nil, kCFStringTransformFullwidthHalfwidth, true) CFStringTransform(string, nil, kCFStringTransformFullwidthHalfwidth, true)
stateCallback( stateCallback(
IMEState.ofCommitting(textToCommit: mgrPrefs.halfWidthPunctuationEnabled ? stringRAW : string as String) IMEState.ofCommitting(textToCommit: prefs.halfWidthPunctuationEnabled ? stringRAW : string as String)
) )
stateCallback(IMEState.ofEmpty()) stateCallback(IMEState.ofEmpty())
return true return true
@ -372,7 +372,7 @@ extension KeyHandler {
if input.isUpperCaseASCIILetterKey, !input.isCommandHold, !input.isControlHold { if input.isUpperCaseASCIILetterKey, !input.isCommandHold, !input.isControlHold {
if input.isShiftHold { // isOptionHold if input.isShiftHold { // isOptionHold
switch mgrPrefs.upperCaseLetterKeyBehavior { switch prefs.upperCaseLetterKeyBehavior {
case 1: case 1:
stateCallback(IMEState.ofEmpty()) stateCallback(IMEState.ofEmpty())
stateCallback(IMEState.ofCommitting(textToCommit: inputText.lowercased())) stateCallback(IMEState.ofCommitting(textToCommit: inputText.lowercased()))

View File

@ -23,7 +23,7 @@ extension KeyHandler {
/// NSAttributeString /// NSAttributeString
var displayTextSegments: [String] = compositor.walkedNodes.values var displayTextSegments: [String] = compositor.walkedNodes.values
var cursor = convertCursorForDisplay(compositor.cursor) var cursor = convertCursorForDisplay(compositor.cursor)
let reading = composer.getInlineCompositionForDisplay(isHanyuPinyin: mgrPrefs.showHanyuPinyinInCompositionBuffer) let reading = composer.getInlineCompositionForDisplay(isHanyuPinyin: prefs.showHanyuPinyinInCompositionBuffer)
if !reading.isEmpty { if !reading.isEmpty {
var newDisplayTextSegments = [String]() var newDisplayTextSegments = [String]()
var temporaryNode = "" var temporaryNode = ""
@ -91,7 +91,7 @@ extension KeyHandler {
state currentState: IMEStateProtocol state currentState: IMEStateProtocol
) -> IMEState { ) -> IMEState {
IMEState.ofCandidates( IMEState.ofCandidates(
candidates: getCandidatesArray(fixOrder: mgrPrefs.useFixecCandidateOrderOnSelection), candidates: getCandidatesArray(fixOrder: prefs.useFixecCandidateOrderOnSelection),
displayTextSegments: compositor.walkedNodes.values, displayTextSegments: compositor.walkedNodes.values,
cursor: currentState.cursor cursor: currentState.cursor
) )
@ -263,7 +263,7 @@ extension KeyHandler {
stateCallback(inputting) stateCallback(inputting)
// //
guard mgrPrefs.useSCPCTypingMode, composer.isEmpty else { return true } guard prefs.useSCPCTypingMode, composer.isEmpty else { return true }
let candidateState = buildCandidate(state: inputting) let candidateState = buildCandidate(state: inputting)
if candidateState.candidates.count == 1 { if candidateState.candidates.count == 1 {
@ -312,7 +312,7 @@ extension KeyHandler {
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
var displayedText = compositor.keys.joined(separator: "-") var displayedText = compositor.keys.joined(separator: "-")
if mgrPrefs.inlineDumpPinyinInLieuOfZhuyin { if prefs.inlineDumpPinyinInLieuOfZhuyin {
displayedText = Tekkon.restoreToneOneInZhuyinKey(target: displayedText) // displayedText = Tekkon.restoreToneOneInZhuyinKey(target: displayedText) //
displayedText = Tekkon.cnvPhonaToHanyuPinyin(target: displayedText) // displayedText = Tekkon.cnvPhonaToHanyuPinyin(target: displayedText) //
} }
@ -343,7 +343,7 @@ extension KeyHandler {
for node in compositor.walkedNodes { for node in compositor.walkedNodes {
var key = node.key var key = node.key
if mgrPrefs.inlineDumpPinyinInLieuOfZhuyin { if prefs.inlineDumpPinyinInLieuOfZhuyin {
key = Tekkon.restoreToneOneInZhuyinKey(target: key) // key = Tekkon.restoreToneOneInZhuyinKey(target: key) //
key = Tekkon.cnvPhonaToHanyuPinyin(target: key) // key = Tekkon.cnvPhonaToHanyuPinyin(target: key) //
key = Tekkon.cnvHanyuPinyinToTextbookStyle(target: key) // 調 key = Tekkon.cnvHanyuPinyinToTextbookStyle(target: key) // 調
@ -380,7 +380,7 @@ extension KeyHandler {
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
// macOS Shift+BackSpace // macOS Shift+BackSpace
switch mgrPrefs.specifyShiftBackSpaceKeyBehavior { switch prefs.specifyShiftBackSpaceKeyBehavior {
case 0: case 0:
guard input.isShiftHold, composer.isEmpty else { break } guard input.isShiftHold, composer.isEmpty else { break }
guard let prevReading = previousParsableReading else { break } guard let prevReading = previousParsableReading else { break }
@ -567,7 +567,7 @@ extension KeyHandler {
) -> Bool { ) -> Bool {
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
if mgrPrefs.escToCleanInputBuffer { if prefs.escToCleanInputBuffer {
/// ///
/// macOS Windows 使 /// macOS Windows 使
stateCallback(IMEState.ofAbortion()) stateCallback(IMEState.ofAbortion())

View File

@ -57,9 +57,9 @@ public enum LMMgr {
// LMMgr loadUserPhrases dataFolderPath // LMMgr loadUserPhrases dataFolderPath
// //
// //
if mgrPrefs.associatedPhrasesEnabled { Self.loadUserAssociatesData() } if PrefMgr.shared.associatedPhrasesEnabled { Self.loadUserAssociatesData() }
if mgrPrefs.phraseReplacementEnabled { Self.loadUserPhraseReplacement() } if PrefMgr.shared.phraseReplacementEnabled { Self.loadUserPhraseReplacement() }
if mgrPrefs.useSCPCTypingMode { Self.loadUserSCPCSequencesData() } if PrefMgr.shared.useSCPCTypingMode { Self.loadUserSCPCSequencesData() }
Self.loadUserPhrasesData() Self.loadUserPhrasesData()
} }
@ -445,7 +445,7 @@ public enum LMMgr {
public static let appSupportURL = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0] public static let appSupportURL = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
public static func dataFolderPath(isDefaultFolder: Bool) -> String { public static func dataFolderPath(isDefaultFolder: Bool) -> String {
var userDictPathSpecified = mgrPrefs.userDataFolderSpecified.expandingTildeInPath var userDictPathSpecified = PrefMgr.shared.userDataFolderSpecified.expandingTildeInPath
var userDictPathDefault = var userDictPathDefault =
Self.appSupportURL.appendingPathComponent("vChewing").path.expandingTildeInPath Self.appSupportURL.appendingPathComponent("vChewing").path.expandingTildeInPath
@ -516,7 +516,7 @@ public enum LMMgr {
// The new FolderMonitor module does NOT monitor cases that files are modified // The new FolderMonitor module does NOT monitor cases that files are modified
// by the current application itself, requiring additional manual loading process here. // by the current application itself, requiring additional manual loading process here.
// if !mgrPrefs.shouldAutoReloadUserDataFiles {} // if !PrefMgr.shared.shouldAutoReloadUserDataFiles {}
loadUserPhrasesData() loadUserPhrasesData()
return true return true
} }

View File

@ -15,11 +15,11 @@ private let kDefaultKeys = "123456789"
private let kDefaultBasicKeyboardLayout = "com.apple.keylayout.ZhuyinBopomofo" private let kDefaultBasicKeyboardLayout = "com.apple.keylayout.ZhuyinBopomofo"
private let kDefaultAlphanumericalKeyboardLayout = "com.apple.keylayout.ABC" private let kDefaultAlphanumericalKeyboardLayout = "com.apple.keylayout.ABC"
public let mgrPrefs = PrefMgr()
// MARK: - // MARK: -
public class PrefMgr: PrefMgrProtocol { public class PrefMgr: PrefMgrProtocol {
public static let shared = PrefMgr()
// MARK: - Settings (Tier 1) // MARK: - Settings (Tier 1)
@AppProperty(key: UserDef.kIsDebugModeEnabled.rawValue, defaultValue: false) @AppProperty(key: UserDef.kIsDebugModeEnabled.rawValue, defaultValue: false)

View File

@ -40,13 +40,13 @@ public class ctlCandidateIMK: IMKCandidates, ctlCandidateProtocol {
ofSize: 14, weight: .medium ofSize: 14, weight: .medium
) )
public var candidateFont = NSFont.systemFont(ofSize: mgrPrefs.candidateListTextSize) { public var candidateFont = NSFont.systemFont(ofSize: PrefMgr.shared.candidateListTextSize) {
didSet { didSet {
if #available(macOS 10.14, *) { setFontSize(candidateFont.pointSize) } if #available(macOS 10.14, *) { setFontSize(candidateFont.pointSize) }
var attributes = attributes() var attributes = attributes()
// FB11300759: Set "NSAttributedString.Key.font" doesn't work. // FB11300759: Set "NSAttributedString.Key.font" doesn't work.
attributes?[NSAttributedString.Key.font] = candidateFont attributes?[NSAttributedString.Key.font] = candidateFont
if mgrPrefs.handleDefaultCandidateFontsByLangIdentifier { if PrefMgr.shared.handleDefaultCandidateFontsByLangIdentifier {
switch IMEApp.currentInputMode { switch IMEApp.currentInputMode {
case InputMode.imeModeCHS: case InputMode.imeModeCHS:
if #available(macOS 12.0, *) { if #available(macOS 12.0, *) {
@ -55,7 +55,7 @@ public class ctlCandidateIMK: IMKCandidates, ctlCandidateProtocol {
case InputMode.imeModeCHT: case InputMode.imeModeCHT:
if #available(macOS 12.0, *) { if #available(macOS 12.0, *) {
attributes?[NSAttributedString.Key.languageIdentifier] = attributes?[NSAttributedString.Key.languageIdentifier] =
(mgrPrefs.shiftJISShinjitaiOutputEnabled || mgrPrefs.chineseConversionEnabled) (PrefMgr.shared.shiftJISShinjitaiOutputEnabled || PrefMgr.shared.chineseConversionEnabled)
? "ja" as AnyObject : "zh-Hant" as AnyObject ? "ja" as AnyObject : "zh-Hant" as AnyObject
} }
default: default:
@ -201,12 +201,12 @@ public class ctlCandidateIMK: IMKCandidates, ctlCandidateProtocol {
case .vertical: event.isShiftHold ? moveLeft(self) : moveRight(self) case .vertical: event.isShiftHold ? moveLeft(self) : moveRight(self)
} }
} else if event.isSpace { } else if event.isSpace {
switch mgrPrefs.specifyShiftSpaceKeyBehavior { switch PrefMgr.shared.specifyShiftSpaceKeyBehavior {
case true: _ = event.isShiftHold ? highlightNextCandidate() : showNextPage() case true: _ = event.isShiftHold ? highlightNextCandidate() : showNextPage()
case false: _ = event.isShiftHold ? showNextPage() : highlightNextCandidate() case false: _ = event.isShiftHold ? showNextPage() : highlightNextCandidate()
} }
} else if event.isTab { } else if event.isTab {
switch mgrPrefs.specifyShiftTabKeyBehavior { switch PrefMgr.shared.specifyShiftTabKeyBehavior {
case true: _ = event.isShiftHold ? showPreviousPage() : showNextPage() case true: _ = event.isShiftHold ? showPreviousPage() : showNextPage()
case false: _ = event.isShiftHold ? highlightPreviousCandidate() : highlightNextCandidate() case false: _ = event.isShiftHold ? highlightPreviousCandidate() : highlightNextCandidate()
} }
@ -216,7 +216,7 @@ public class ctlCandidateIMK: IMKCandidates, ctlCandidateProtocol {
/// IMK /// IMK
let newEvent = event.reinitiate(characters: newChar) let newEvent = event.reinitiate(characters: newChar)
if let newEvent = newEvent { if let newEvent = newEvent {
if mgrPrefs.useSCPCTypingMode, delegate.isAssociatedPhrasesState { if PrefMgr.shared.useSCPCTypingMode, delegate.isAssociatedPhrasesState {
// input.isShiftHold ctlInputMethod.handle() // input.isShiftHold ctlInputMethod.handle()
if !event.isShiftHold { if !event.isShiftHold {
_ = delegate.sharedEventHandler(event) _ = delegate.sharedEventHandler(event)
@ -233,7 +233,7 @@ public class ctlCandidateIMK: IMKCandidates, ctlCandidateProtocol {
} }
} }
if mgrPrefs.useSCPCTypingMode, !event.isReservedKey { if PrefMgr.shared.useSCPCTypingMode, !event.isReservedKey {
_ = delegate.sharedEventHandler(event) _ = delegate.sharedEventHandler(event)
return return
} }
@ -241,7 +241,7 @@ public class ctlCandidateIMK: IMKCandidates, ctlCandidateProtocol {
if delegate.isAssociatedPhrasesState, if delegate.isAssociatedPhrasesState,
!event.isPageUp, !event.isPageDown, !event.isCursorForward, !event.isCursorBackward, !event.isPageUp, !event.isPageDown, !event.isCursorForward, !event.isCursorBackward,
!event.isCursorClockLeft, !event.isCursorClockRight, !event.isSpace, !event.isCursorClockLeft, !event.isCursorClockRight, !event.isSpace,
!event.isEnter || !mgrPrefs.alsoConfirmAssociatedCandidatesByEnter !event.isEnter || !PrefMgr.shared.alsoConfirmAssociatedCandidatesByEnter
{ {
_ = delegate.sharedEventHandler(event) _ = delegate.sharedEventHandler(event)
return return

View File

@ -134,7 +134,7 @@ private class vwrCandidateUniversal: NSView {
} }
func ensureLangIdentifier(for attr: inout [NSAttributedString.Key: AnyObject]) { func ensureLangIdentifier(for attr: inout [NSAttributedString.Key: AnyObject]) {
if mgrPrefs.handleDefaultCandidateFontsByLangIdentifier { if PrefMgr.shared.handleDefaultCandidateFontsByLangIdentifier {
switch IMEApp.currentInputMode { switch IMEApp.currentInputMode {
case InputMode.imeModeCHS: case InputMode.imeModeCHS:
if #available(macOS 12.0, *) { if #available(macOS 12.0, *) {
@ -143,7 +143,7 @@ private class vwrCandidateUniversal: NSView {
case InputMode.imeModeCHT: case InputMode.imeModeCHT:
if #available(macOS 12.0, *) { if #available(macOS 12.0, *) {
attr[.languageIdentifier] = attr[.languageIdentifier] =
(mgrPrefs.shiftJISShinjitaiOutputEnabled || mgrPrefs.chineseConversionEnabled) (PrefMgr.shared.shiftJISShinjitaiOutputEnabled || PrefMgr.shared.chineseConversionEnabled)
? "ja" as AnyObject : "zh-Hant" as AnyObject ? "ja" as AnyObject : "zh-Hant" as AnyObject
} }
default: default:
@ -542,7 +542,7 @@ extension ctlCandidateUniversal {
candidateView.frame = frameRect candidateView.frame = frameRect
let counterHeight: CGFloat = newSize.height - 24 let counterHeight: CGFloat = newSize.height - 24
if pageCount > 1, mgrPrefs.showPageButtonsInCandidateWindow { if pageCount > 1, PrefMgr.shared.showPageButtonsInCandidateWindow {
var buttonRect = nextPageButton.frame var buttonRect = nextPageButton.frame
let spacing: CGFloat = 0.0 let spacing: CGFloat = 0.0
@ -587,7 +587,7 @@ extension ctlCandidateUniversal {
? (newSize.height - rect.height) / 2 ? (newSize.height - rect.height) / 2
: counterHeight : counterHeight
let rectOriginX: CGFloat = let rectOriginX: CGFloat =
mgrPrefs.showPageButtonsInCandidateWindow PrefMgr.shared.showPageButtonsInCandidateWindow
? newSize.width ? newSize.width
: newSize.width + 4 : newSize.width + 4
rect.origin = NSPoint(x: rectOriginX, y: rectOriginY) rect.origin = NSPoint(x: rectOriginX, y: rectOriginY)

View File

@ -21,11 +21,11 @@ struct suiPrefPaneDevZone: View {
private let contentMaxHeight: Double = 432 private let contentMaxHeight: Double = 432
private let contentWidth: Double = { private let contentWidth: Double = {
switch mgrPrefs.appleLanguages[0] { switch PrefMgr.shared.appleLanguages[0] {
case "ja": case "ja":
return 520 return 520
default: default:
if mgrPrefs.appleLanguages[0].contains("zh-Han") { if PrefMgr.shared.appleLanguages[0].contains("zh-Han") {
return 480 return 480
} else { } else {
return 580 return 580
@ -53,7 +53,7 @@ struct suiPrefPaneDevZone: View {
Toggle( Toggle(
LocalizedStringKey("Use IMK Candidate Window instead (will reboot the IME)"), LocalizedStringKey("Use IMK Candidate Window instead (will reboot the IME)"),
isOn: $selUseIMKCandidateWindow.onChange { isOn: $selUseIMKCandidateWindow.onChange {
mgrPrefs.useIMKCandidateWindow = selUseIMKCandidateWindow PrefMgr.shared.useIMKCandidateWindow = selUseIMKCandidateWindow
NSLog("vChewing App self-terminated due to enabling / disabling IMK candidate window.") NSLog("vChewing App self-terminated due to enabling / disabling IMK candidate window.")
NSApplication.shared.terminate(nil) NSApplication.shared.terminate(nil)
} }
@ -67,7 +67,8 @@ struct suiPrefPaneDevZone: View {
Toggle( Toggle(
LocalizedStringKey("Use .langIdentifier to handle UI fonts in candidate window"), LocalizedStringKey("Use .langIdentifier to handle UI fonts in candidate window"),
isOn: $selHandleDefaultCandidateFontsByLangIdentifier.onChange { isOn: $selHandleDefaultCandidateFontsByLangIdentifier.onChange {
mgrPrefs.handleDefaultCandidateFontsByLangIdentifier = selHandleDefaultCandidateFontsByLangIdentifier PrefMgr.shared.handleDefaultCandidateFontsByLangIdentifier =
selHandleDefaultCandidateFontsByLangIdentifier
} }
) )
.disabled(!isMontereyOrAbove) .disabled(!isMontereyOrAbove)
@ -80,7 +81,7 @@ struct suiPrefPaneDevZone: View {
Picker( Picker(
"", "",
selection: $selShiftKeyAccommodationBehavior.onChange { selection: $selShiftKeyAccommodationBehavior.onChange {
mgrPrefs.shiftKeyAccommodationBehavior = selShiftKeyAccommodationBehavior PrefMgr.shared.shiftKeyAccommodationBehavior = selShiftKeyAccommodationBehavior
} }
) { ) {
Text(LocalizedStringKey("Disable Shift key accomodation in all cases")).tag(0) Text(LocalizedStringKey("Disable Shift key accomodation in all cases")).tag(0)

View File

@ -37,11 +37,11 @@ struct suiPrefPaneDictionary: View {
private let contentMaxHeight: Double = 432 private let contentMaxHeight: Double = 432
private let contentWidth: Double = { private let contentWidth: Double = {
switch mgrPrefs.appleLanguages[0] { switch PrefMgr.shared.appleLanguages[0] {
case "ja": case "ja":
return 520 return 520
default: default:
if mgrPrefs.appleLanguages[0].contains("zh-Han") { if PrefMgr.shared.appleLanguages[0].contains("zh-Han") {
return 480 return 480
} else { } else {
return 580 return 580
@ -72,7 +72,7 @@ struct suiPrefPaneDictionary: View {
Self.dlgOpenPath.canChooseDirectories = true Self.dlgOpenPath.canChooseDirectories = true
let bolPreviousFolderValidity = LMMgr.checkIfSpecifiedUserDataFolderValid( let bolPreviousFolderValidity = LMMgr.checkIfSpecifiedUserDataFolderValid(
mgrPrefs.userDataFolderSpecified.expandingTildeInPath) PrefMgr.shared.userDataFolderSpecified.expandingTildeInPath)
if let window = ctlPrefUI.shared.controller.window { if let window = ctlPrefUI.shared.controller.window {
Self.dlgOpenPath.beginSheetModal(for: window) { result in Self.dlgOpenPath.beginSheetModal(for: window) { result in
@ -83,8 +83,8 @@ struct suiPrefPaneDictionary: View {
var newPath = url.path var newPath = url.path
newPath.ensureTrailingSlash() newPath.ensureTrailingSlash()
if LMMgr.checkIfSpecifiedUserDataFolderValid(newPath) { if LMMgr.checkIfSpecifiedUserDataFolderValid(newPath) {
mgrPrefs.userDataFolderSpecified = newPath PrefMgr.shared.userDataFolderSpecified = newPath
tbxUserDataPathSpecified = mgrPrefs.userDataFolderSpecified tbxUserDataPathSpecified = PrefMgr.shared.userDataFolderSpecified
BookmarkManager.shared.saveBookmark(for: url) BookmarkManager.shared.saveBookmark(for: url)
(NSApplication.shared.delegate as! AppDelegate).updateDirectoryMonitorPath() (NSApplication.shared.delegate as! AppDelegate).updateDirectoryMonitorPath()
} else { } else {
@ -115,7 +115,7 @@ struct suiPrefPaneDictionary: View {
Toggle( Toggle(
LocalizedStringKey("Automatically reload user data files if changes detected"), LocalizedStringKey("Automatically reload user data files if changes detected"),
isOn: $selAutoReloadUserData.onChange { isOn: $selAutoReloadUserData.onChange {
mgrPrefs.shouldAutoReloadUserDataFiles = selAutoReloadUserData PrefMgr.shared.shouldAutoReloadUserDataFiles = selAutoReloadUserData
} }
).controlSize(.small) ).controlSize(.small)
} }
@ -123,39 +123,39 @@ struct suiPrefPaneDictionary: View {
Toggle( Toggle(
LocalizedStringKey("Enable CNS11643 Support (2022-08-02)"), LocalizedStringKey("Enable CNS11643 Support (2022-08-02)"),
isOn: $selEnableCNS11643.onChange { isOn: $selEnableCNS11643.onChange {
mgrPrefs.cns11643Enabled = selEnableCNS11643 PrefMgr.shared.cns11643Enabled = selEnableCNS11643
LMMgr.setCNSEnabled(mgrPrefs.cns11643Enabled) LMMgr.setCNSEnabled(PrefMgr.shared.cns11643Enabled)
} }
) )
Toggle( Toggle(
LocalizedStringKey("Enable symbol input support (incl. certain emoji symbols)"), LocalizedStringKey("Enable symbol input support (incl. certain emoji symbols)"),
isOn: $selEnableSymbolInputSupport.onChange { isOn: $selEnableSymbolInputSupport.onChange {
mgrPrefs.symbolInputEnabled = selEnableSymbolInputSupport PrefMgr.shared.symbolInputEnabled = selEnableSymbolInputSupport
LMMgr.setSymbolEnabled(mgrPrefs.symbolInputEnabled) LMMgr.setSymbolEnabled(PrefMgr.shared.symbolInputEnabled)
} }
) )
Toggle( Toggle(
LocalizedStringKey("Allow boosting / excluding a candidate of single kanji"), LocalizedStringKey("Allow boosting / excluding a candidate of single kanji"),
isOn: $selAllowBoostingSingleKanjiAsUserPhrase.onChange { isOn: $selAllowBoostingSingleKanjiAsUserPhrase.onChange {
mgrPrefs.allowBoostingSingleKanjiAsUserPhrase = selAllowBoostingSingleKanjiAsUserPhrase PrefMgr.shared.allowBoostingSingleKanjiAsUserPhrase = selAllowBoostingSingleKanjiAsUserPhrase
} }
) )
Toggle( Toggle(
LocalizedStringKey("Applying typing suggestions from half-life user override model"), LocalizedStringKey("Applying typing suggestions from half-life user override model"),
isOn: $selFetchSuggestionsFromUserOverrideModel.onChange { isOn: $selFetchSuggestionsFromUserOverrideModel.onChange {
mgrPrefs.fetchSuggestionsFromUserOverrideModel = selFetchSuggestionsFromUserOverrideModel PrefMgr.shared.fetchSuggestionsFromUserOverrideModel = selFetchSuggestionsFromUserOverrideModel
} }
) )
Toggle( Toggle(
LocalizedStringKey("Always use fixed listing order in candidate window"), LocalizedStringKey("Always use fixed listing order in candidate window"),
isOn: $selUseFixecCandidateOrderOnSelection.onChange { isOn: $selUseFixecCandidateOrderOnSelection.onChange {
mgrPrefs.useFixecCandidateOrderOnSelection = selUseFixecCandidateOrderOnSelection PrefMgr.shared.useFixecCandidateOrderOnSelection = selUseFixecCandidateOrderOnSelection
} }
) )
Toggle( Toggle(
LocalizedStringKey("Consolidate the context on confirming candidate selection"), LocalizedStringKey("Consolidate the context on confirming candidate selection"),
isOn: $selConsolidateContextOnCandidateSelection.onChange { isOn: $selConsolidateContextOnCandidateSelection.onChange {
mgrPrefs.consolidateContextOnCandidateSelection = selConsolidateContextOnCandidateSelection PrefMgr.shared.consolidateContextOnCandidateSelection = selConsolidateContextOnCandidateSelection
} }
) )
Text( Text(
@ -167,7 +167,7 @@ struct suiPrefPaneDictionary: View {
Toggle( Toggle(
LocalizedStringKey("Harden vertical punctuations during vertical typing (not recommended)"), LocalizedStringKey("Harden vertical punctuations during vertical typing (not recommended)"),
isOn: $selHardenVerticalPunctuations.onChange { isOn: $selHardenVerticalPunctuations.onChange {
mgrPrefs.hardenVerticalPunctuations = selHardenVerticalPunctuations PrefMgr.shared.hardenVerticalPunctuations = selHardenVerticalPunctuations
} }
) )
Text( Text(

View File

@ -50,11 +50,11 @@ struct suiPrefPaneExperience: View {
private let contentMaxHeight: Double = 432 private let contentMaxHeight: Double = 432
private let contentWidth: Double = { private let contentWidth: Double = {
switch mgrPrefs.appleLanguages[0] { switch PrefMgr.shared.appleLanguages[0] {
case "ja": case "ja":
return 520 return 520
default: default:
if mgrPrefs.appleLanguages[0].contains("zh-Han") { if PrefMgr.shared.appleLanguages[0].contains("zh-Han") {
return 480 return 480
} else { } else {
return 580 return 580
@ -85,7 +85,7 @@ struct suiPrefPaneExperience: View {
Picker( Picker(
"", "",
selection: $selCursorPosition.onChange { selection: $selCursorPosition.onChange {
mgrPrefs.useRearCursorMode = (selCursorPosition == 1) ? true : false PrefMgr.shared.useRearCursorMode = (selCursorPosition == 1) ? true : false
} }
) { ) {
Text(LocalizedStringKey("in front of the phrase (like macOS built-in Zhuyin IME)")).tag(0) Text(LocalizedStringKey("in front of the phrase (like macOS built-in Zhuyin IME)")).tag(0)
@ -98,7 +98,7 @@ struct suiPrefPaneExperience: View {
Toggle( Toggle(
LocalizedStringKey("Push the cursor in front of the phrase after selection"), LocalizedStringKey("Push the cursor in front of the phrase after selection"),
isOn: $selPushCursorAfterSelection.onChange { isOn: $selPushCursorAfterSelection.onChange {
mgrPrefs.moveCursorAfterSelectingCandidate = selPushCursorAfterSelection PrefMgr.shared.moveCursorAfterSelectingCandidate = selPushCursorAfterSelection
} }
).controlSize(.small) ).controlSize(.small)
} }
@ -106,7 +106,7 @@ struct suiPrefPaneExperience: View {
Picker( Picker(
"", "",
selection: $selSpecifyShiftBackSpaceKeyBehavior.onChange { selection: $selSpecifyShiftBackSpaceKeyBehavior.onChange {
mgrPrefs.specifyShiftBackSpaceKeyBehavior = selSpecifyShiftBackSpaceKeyBehavior PrefMgr.shared.specifyShiftBackSpaceKeyBehavior = selSpecifyShiftBackSpaceKeyBehavior
} }
) { ) {
Text(LocalizedStringKey("Disassemble the previous reading, dropping its intonation")).tag(0) Text(LocalizedStringKey("Disassemble the previous reading, dropping its intonation")).tag(0)
@ -122,7 +122,7 @@ struct suiPrefPaneExperience: View {
Picker( Picker(
"", "",
selection: $selKeyBehaviorShiftTab.onChange { selection: $selKeyBehaviorShiftTab.onChange {
mgrPrefs.specifyShiftTabKeyBehavior = (selKeyBehaviorShiftTab == 1) ? true : false PrefMgr.shared.specifyShiftTabKeyBehavior = (selKeyBehaviorShiftTab == 1) ? true : false
} }
) { ) {
Text(LocalizedStringKey("for cycling candidates")).tag(0) Text(LocalizedStringKey("for cycling candidates")).tag(0)
@ -138,7 +138,7 @@ struct suiPrefPaneExperience: View {
Picker( Picker(
"", "",
selection: $selKeyBehaviorShiftSpace.onChange { selection: $selKeyBehaviorShiftSpace.onChange {
mgrPrefs.specifyShiftSpaceKeyBehavior = (selKeyBehaviorShiftSpace == 1) ? true : false PrefMgr.shared.specifyShiftSpaceKeyBehavior = (selKeyBehaviorShiftSpace == 1) ? true : false
} }
) { ) {
Text(LocalizedStringKey("Space to +cycle candidates, Shift+Space to +cycle pages")).tag(0) Text(LocalizedStringKey("Space to +cycle candidates, Shift+Space to +cycle pages")).tag(0)
@ -153,7 +153,7 @@ struct suiPrefPaneExperience: View {
Picker( Picker(
"", "",
selection: $selUpperCaseLetterKeyBehavior.onChange { selection: $selUpperCaseLetterKeyBehavior.onChange {
mgrPrefs.upperCaseLetterKeyBehavior = selUpperCaseLetterKeyBehavior PrefMgr.shared.upperCaseLetterKeyBehavior = selUpperCaseLetterKeyBehavior
} }
) { ) {
Text(LocalizedStringKey("Type them into inline composition buffer")).tag(0) Text(LocalizedStringKey("Type them into inline composition buffer")).tag(0)
@ -169,7 +169,7 @@ struct suiPrefPaneExperience: View {
Picker( Picker(
"", "",
selection: $selSpecifyIntonationKeyBehavior.onChange { selection: $selSpecifyIntonationKeyBehavior.onChange {
mgrPrefs.specifyIntonationKeyBehavior = selSpecifyIntonationKeyBehavior PrefMgr.shared.specifyIntonationKeyBehavior = selSpecifyIntonationKeyBehavior
} }
) { ) {
Text(LocalizedStringKey("Override the previous reading's intonation with candidate-reset")).tag(0) Text(LocalizedStringKey("Override the previous reading's intonation with candidate-reset")).tag(0)
@ -185,57 +185,57 @@ struct suiPrefPaneExperience: View {
Toggle( Toggle(
LocalizedStringKey("Completely disable using Shift key to toggle alphanumerical mode"), LocalizedStringKey("Completely disable using Shift key to toggle alphanumerical mode"),
isOn: $selDisableShiftTogglingAlphanumericalMode.onChange { isOn: $selDisableShiftTogglingAlphanumericalMode.onChange {
mgrPrefs.disableShiftTogglingAlphanumericalMode = selDisableShiftTogglingAlphanumericalMode PrefMgr.shared.disableShiftTogglingAlphanumericalMode = selDisableShiftTogglingAlphanumericalMode
} }
) )
Toggle( Toggle(
LocalizedStringKey("Also toggle alphanumerical mode with Left-Shift"), LocalizedStringKey("Also toggle alphanumerical mode with Left-Shift"),
isOn: $selTogglingAlphanumericalModeWithLShift.onChange { isOn: $selTogglingAlphanumericalModeWithLShift.onChange {
mgrPrefs.togglingAlphanumericalModeWithLShift = selTogglingAlphanumericalModeWithLShift PrefMgr.shared.togglingAlphanumericalModeWithLShift = selTogglingAlphanumericalModeWithLShift
} }
).disabled(mgrPrefs.disableShiftTogglingAlphanumericalMode == true) ).disabled(PrefMgr.shared.disableShiftTogglingAlphanumericalMode == true)
} }
Preferences.Section(label: { Text(LocalizedStringKey("Misc Settings:")) }) { Preferences.Section(label: { Text(LocalizedStringKey("Misc Settings:")) }) {
Toggle( Toggle(
LocalizedStringKey("Enable Space key for calling candidate window"), LocalizedStringKey("Enable Space key for calling candidate window"),
isOn: $selKeyBehaviorSpaceForCallingCandidate.onChange { isOn: $selKeyBehaviorSpaceForCallingCandidate.onChange {
mgrPrefs.chooseCandidateUsingSpace = selKeyBehaviorSpaceForCallingCandidate PrefMgr.shared.chooseCandidateUsingSpace = selKeyBehaviorSpaceForCallingCandidate
} }
) )
Toggle( Toggle(
LocalizedStringKey("Use ESC key to clear the entire input buffer"), LocalizedStringKey("Use ESC key to clear the entire input buffer"),
isOn: $selKeyBehaviorESCForClearingTheBuffer.onChange { isOn: $selKeyBehaviorESCForClearingTheBuffer.onChange {
mgrPrefs.escToCleanInputBuffer = selKeyBehaviorESCForClearingTheBuffer PrefMgr.shared.escToCleanInputBuffer = selKeyBehaviorESCForClearingTheBuffer
} }
) )
Toggle( Toggle(
LocalizedStringKey("Automatically correct reading combinations when typing"), LocalizedStringKey("Automatically correct reading combinations when typing"),
isOn: $selAutoCorrectReadingCombination.onChange { isOn: $selAutoCorrectReadingCombination.onChange {
mgrPrefs.autoCorrectReadingCombination = selAutoCorrectReadingCombination PrefMgr.shared.autoCorrectReadingCombination = selAutoCorrectReadingCombination
} }
) )
Toggle( Toggle(
LocalizedStringKey("Allow using Enter key to confirm associated candidate selection"), LocalizedStringKey("Allow using Enter key to confirm associated candidate selection"),
isOn: $selAlsoConfirmAssociatedCandidatesByEnter.onChange { isOn: $selAlsoConfirmAssociatedCandidatesByEnter.onChange {
mgrPrefs.alsoConfirmAssociatedCandidatesByEnter = selAlsoConfirmAssociatedCandidatesByEnter PrefMgr.shared.alsoConfirmAssociatedCandidatesByEnter = selAlsoConfirmAssociatedCandidatesByEnter
} }
) )
Toggle( Toggle(
LocalizedStringKey("Allow backspace-editing miscomposed readings"), LocalizedStringKey("Allow backspace-editing miscomposed readings"),
isOn: $selKeepReadingUponCompositionError.onChange { isOn: $selKeepReadingUponCompositionError.onChange {
mgrPrefs.keepReadingUponCompositionError = selKeepReadingUponCompositionError PrefMgr.shared.keepReadingUponCompositionError = selKeepReadingUponCompositionError
} }
) )
Toggle( Toggle(
LocalizedStringKey("Trim unfinished readings on commit"), LocalizedStringKey("Trim unfinished readings on commit"),
isOn: $selTrimUnfinishedReadingsOnCommit.onChange { isOn: $selTrimUnfinishedReadingsOnCommit.onChange {
mgrPrefs.trimUnfinishedReadingsOnCommit = selTrimUnfinishedReadingsOnCommit PrefMgr.shared.trimUnfinishedReadingsOnCommit = selTrimUnfinishedReadingsOnCommit
} }
) )
Toggle( Toggle(
LocalizedStringKey("Emulating select-candidate-per-character mode"), LocalizedStringKey("Emulating select-candidate-per-character mode"),
isOn: $selEnableSCPCTypingMode.onChange { isOn: $selEnableSCPCTypingMode.onChange {
mgrPrefs.useSCPCTypingMode = selEnableSCPCTypingMode PrefMgr.shared.useSCPCTypingMode = selEnableSCPCTypingMode
} }
) )
Text(LocalizedStringKey("An accommodation for elder computer users.")) Text(LocalizedStringKey("An accommodation for elder computer users."))
@ -243,7 +243,7 @@ struct suiPrefPaneExperience: View {
Toggle( Toggle(
LocalizedStringKey("Always show tooltip texts horizontally"), LocalizedStringKey("Always show tooltip texts horizontally"),
isOn: $selAlwaysShowTooltipTextsHorizontally.onChange { isOn: $selAlwaysShowTooltipTextsHorizontally.onChange {
mgrPrefs.alwaysShowTooltipTextsHorizontally = selAlwaysShowTooltipTextsHorizontally PrefMgr.shared.alwaysShowTooltipTextsHorizontally = selAlwaysShowTooltipTextsHorizontally
} }
).disabled(Bundle.main.preferredLocalizations[0] == "en") ).disabled(Bundle.main.preferredLocalizations[0] == "en")
Text( Text(

View File

@ -41,11 +41,11 @@ struct suiPrefPaneGeneral: View {
private let contentMaxHeight: Double = 432 private let contentMaxHeight: Double = 432
private let contentWidth: Double = { private let contentWidth: Double = {
switch mgrPrefs.appleLanguages[0] { switch PrefMgr.shared.appleLanguages[0] {
case "ja": case "ja":
return 520 return 520
default: default:
if mgrPrefs.appleLanguages[0].contains("zh-Han") { if PrefMgr.shared.appleLanguages[0].contains("zh-Han") {
return 480 return 480
} else { } else {
return 580 return 580
@ -60,7 +60,7 @@ struct suiPrefPaneGeneral: View {
Picker( Picker(
"", "",
selection: $selCandidateUIFontSize.onChange { selection: $selCandidateUIFontSize.onChange {
mgrPrefs.candidateListTextSize = CGFloat(selCandidateUIFontSize) PrefMgr.shared.candidateListTextSize = CGFloat(selCandidateUIFontSize)
} }
) { ) {
Group { Group {
@ -89,14 +89,14 @@ struct suiPrefPaneGeneral: View {
LocalizedStringKey("Follow OS settings"), LocalizedStringKey("Follow OS settings"),
selection: $selUILanguage.onChange { selection: $selUILanguage.onChange {
vCLog(selUILanguage[0]) vCLog(selUILanguage[0])
if selUILanguage == mgrPrefs.appleLanguages if selUILanguage == PrefMgr.shared.appleLanguages
|| (selUILanguage[0] == "auto" || (selUILanguage[0] == "auto"
&& UserDefaults.standard.object(forKey: UserDef.kAppleLanguages.rawValue) == nil) && UserDefaults.standard.object(forKey: UserDef.kAppleLanguages.rawValue) == nil)
{ {
return return
} }
if selUILanguage[0] != "auto" { if selUILanguage[0] != "auto" {
mgrPrefs.appleLanguages = selUILanguage PrefMgr.shared.appleLanguages = selUILanguage
} else { } else {
UserDefaults.standard.removeObject(forKey: UserDef.kAppleLanguages.rawValue) UserDefaults.standard.removeObject(forKey: UserDef.kAppleLanguages.rawValue)
} }
@ -120,7 +120,7 @@ struct suiPrefPaneGeneral: View {
Picker( Picker(
"", "",
selection: $selEnableHorizontalCandidateLayout.onChange { selection: $selEnableHorizontalCandidateLayout.onChange {
mgrPrefs.useHorizontalCandidateList = selEnableHorizontalCandidateLayout PrefMgr.shared.useHorizontalCandidateList = selEnableHorizontalCandidateLayout
} }
) { ) {
Text(LocalizedStringKey("Vertical")).tag(false) Text(LocalizedStringKey("Vertical")).tag(false)
@ -134,43 +134,43 @@ struct suiPrefPaneGeneral: View {
Toggle( Toggle(
LocalizedStringKey("Show page buttons in candidate window"), LocalizedStringKey("Show page buttons in candidate window"),
isOn: $selShowPageButtonsInCandidateUI.onChange { isOn: $selShowPageButtonsInCandidateUI.onChange {
mgrPrefs.showPageButtonsInCandidateWindow = selShowPageButtonsInCandidateUI PrefMgr.shared.showPageButtonsInCandidateWindow = selShowPageButtonsInCandidateUI
} }
) )
.controlSize(.small) .controlSize(.small)
.disabled(mgrPrefs.useIMKCandidateWindow) .disabled(PrefMgr.shared.useIMKCandidateWindow)
} }
Preferences.Section(label: { Text(LocalizedStringKey("Output Settings:")) }) { Preferences.Section(label: { Text(LocalizedStringKey("Output Settings:")) }) {
Toggle( Toggle(
LocalizedStringKey("Auto-convert traditional Chinese glyphs to KangXi characters"), LocalizedStringKey("Auto-convert traditional Chinese glyphs to KangXi characters"),
isOn: $selEnableKanjiConvToKangXi.onChange { isOn: $selEnableKanjiConvToKangXi.onChange {
mgrPrefs.chineseConversionEnabled = selEnableKanjiConvToKangXi PrefMgr.shared.chineseConversionEnabled = selEnableKanjiConvToKangXi
selEnableKanjiConvToJIS = mgrPrefs.shiftJISShinjitaiOutputEnabled selEnableKanjiConvToJIS = PrefMgr.shared.shiftJISShinjitaiOutputEnabled
} }
) )
Toggle( Toggle(
LocalizedStringKey("Auto-convert traditional Chinese glyphs to JIS Shinjitai characters"), LocalizedStringKey("Auto-convert traditional Chinese glyphs to JIS Shinjitai characters"),
isOn: $selEnableKanjiConvToJIS.onChange { isOn: $selEnableKanjiConvToJIS.onChange {
mgrPrefs.shiftJISShinjitaiOutputEnabled = selEnableKanjiConvToJIS PrefMgr.shared.shiftJISShinjitaiOutputEnabled = selEnableKanjiConvToJIS
selEnableKanjiConvToKangXi = mgrPrefs.chineseConversionEnabled selEnableKanjiConvToKangXi = PrefMgr.shared.chineseConversionEnabled
} }
) )
Toggle( Toggle(
LocalizedStringKey("Show Hanyu-Pinyin in the inline composition buffer"), LocalizedStringKey("Show Hanyu-Pinyin in the inline composition buffer"),
isOn: $selShowHanyuPinyinInCompositionBuffer.onChange { isOn: $selShowHanyuPinyinInCompositionBuffer.onChange {
mgrPrefs.showHanyuPinyinInCompositionBuffer = selShowHanyuPinyinInCompositionBuffer PrefMgr.shared.showHanyuPinyinInCompositionBuffer = selShowHanyuPinyinInCompositionBuffer
} }
) )
Toggle( Toggle(
LocalizedStringKey("Commit Hanyu-Pinyin instead on Ctrl(+Option)+Command+Enter"), LocalizedStringKey("Commit Hanyu-Pinyin instead on Ctrl(+Option)+Command+Enter"),
isOn: $selInlineDumpPinyinInLieuOfZhuyin.onChange { isOn: $selInlineDumpPinyinInLieuOfZhuyin.onChange {
mgrPrefs.inlineDumpPinyinInLieuOfZhuyin = selInlineDumpPinyinInLieuOfZhuyin PrefMgr.shared.inlineDumpPinyinInLieuOfZhuyin = selInlineDumpPinyinInLieuOfZhuyin
} }
) )
Toggle( Toggle(
LocalizedStringKey("Stop farting (when typed phonetic combination is invalid, etc.)"), LocalizedStringKey("Stop farting (when typed phonetic combination is invalid, etc.)"),
isOn: $selEnableFartSuppressor.onChange { isOn: $selEnableFartSuppressor.onChange {
mgrPrefs.shouldNotFartInLieuOfBeep = selEnableFartSuppressor PrefMgr.shared.shouldNotFartInLieuOfBeep = selEnableFartSuppressor
IMEApp.buzz() IMEApp.buzz()
} }
) )
@ -179,14 +179,14 @@ struct suiPrefPaneGeneral: View {
Toggle( Toggle(
LocalizedStringKey("Check for updates automatically"), LocalizedStringKey("Check for updates automatically"),
isOn: $selEnableAutoUpdateCheck.onChange { isOn: $selEnableAutoUpdateCheck.onChange {
mgrPrefs.checkUpdateAutomatically = selEnableAutoUpdateCheck PrefMgr.shared.checkUpdateAutomatically = selEnableAutoUpdateCheck
} }
) )
.controlSize(.small) .controlSize(.small)
Toggle( Toggle(
LocalizedStringKey("Debug Mode"), LocalizedStringKey("Debug Mode"),
isOn: $selEnableDebugMode.onChange { isOn: $selEnableDebugMode.onChange {
mgrPrefs.isDebugModeEnabled = selEnableDebugMode PrefMgr.shared.isDebugModeEnabled = selEnableDebugMode
} }
) )
.controlSize(.small) .controlSize(.small)

View File

@ -18,10 +18,10 @@ struct suiPrefPaneKeyboard: View {
UserDefaults.standard.string(forKey: UserDef.kCandidateKeys.rawValue) ?? CandidateKey.defaultKeys UserDefaults.standard.string(forKey: UserDef.kCandidateKeys.rawValue) ?? CandidateKey.defaultKeys
@State private var selKeyboardParser = UserDefaults.standard.integer(forKey: UserDef.kKeyboardParser.rawValue) @State private var selKeyboardParser = UserDefaults.standard.integer(forKey: UserDef.kKeyboardParser.rawValue)
@State private var selBasicKeyboardLayout: String = @State private var selBasicKeyboardLayout: String =
UserDefaults.standard.string(forKey: UserDef.kBasicKeyboardLayout.rawValue) ?? mgrPrefs.basicKeyboardLayout UserDefaults.standard.string(forKey: UserDef.kBasicKeyboardLayout.rawValue) ?? PrefMgr.shared.basicKeyboardLayout
@State private var selAlphanumericalKeyboardLayout: String = @State private var selAlphanumericalKeyboardLayout: String =
UserDefaults.standard.string(forKey: UserDef.kAlphanumericalKeyboardLayout.rawValue) UserDefaults.standard.string(forKey: UserDef.kAlphanumericalKeyboardLayout.rawValue)
?? mgrPrefs.alphanumericalKeyboardLayout ?? PrefMgr.shared.alphanumericalKeyboardLayout
@State private var selUsingHotKeySCPC = UserDefaults.standard.bool(forKey: UserDef.kUsingHotKeySCPC.rawValue) @State private var selUsingHotKeySCPC = UserDefaults.standard.bool(forKey: UserDef.kUsingHotKeySCPC.rawValue)
@State private var selUsingHotKeyAssociates = UserDefaults.standard.bool( @State private var selUsingHotKeyAssociates = UserDefaults.standard.bool(
@ -36,11 +36,11 @@ struct suiPrefPaneKeyboard: View {
private let contentMaxHeight: Double = 432 private let contentMaxHeight: Double = 432
private let contentWidth: Double = { private let contentWidth: Double = {
switch mgrPrefs.appleLanguages[0] { switch PrefMgr.shared.appleLanguages[0] {
case "ja": case "ja":
return 520 return 520
default: default:
if mgrPrefs.appleLanguages[0].contains("zh-Han") { if PrefMgr.shared.appleLanguages[0].contains("zh-Han") {
return 480 return 480
} else { } else {
return 580 return 580
@ -59,22 +59,22 @@ struct suiPrefPaneKeyboard: View {
let keys: String = value.trimmingCharacters(in: .whitespacesAndNewlines).deduplicate let keys: String = value.trimmingCharacters(in: .whitespacesAndNewlines).deduplicate
do { do {
try CandidateKey.validate(keys: keys) try CandidateKey.validate(keys: keys)
mgrPrefs.candidateKeys = keys PrefMgr.shared.candidateKeys = keys
selSelectionKeys = mgrPrefs.candidateKeys selSelectionKeys = PrefMgr.shared.candidateKeys
} catch CandidateKey.ErrorType.empty { } catch CandidateKey.ErrorType.empty {
selSelectionKeys = mgrPrefs.candidateKeys selSelectionKeys = PrefMgr.shared.candidateKeys
} catch { } catch {
if let window = ctlPrefUI.shared.controller.window { if let window = ctlPrefUI.shared.controller.window {
let alert = NSAlert(error: error) let alert = NSAlert(error: error)
alert.beginSheetModal(for: window) { _ in alert.beginSheetModal(for: window) { _ in
selSelectionKeys = mgrPrefs.candidateKeys selSelectionKeys = PrefMgr.shared.candidateKeys
} }
IMEApp.buzz() IMEApp.buzz()
} }
} }
} }
).frame(width: 180).disabled(mgrPrefs.useIMKCandidateWindow) ).frame(width: 180).disabled(PrefMgr.shared.useIMKCandidateWindow)
if mgrPrefs.useIMKCandidateWindow { if PrefMgr.shared.useIMKCandidateWindow {
Text( Text(
LocalizedStringKey( LocalizedStringKey(
"⚠︎ This feature in IMK Candidate Window defects. Please consult Apple Developer Relations\nand tell them the related Radar ID: #FB11300759." "⚠︎ This feature in IMK Candidate Window defects. Please consult Apple Developer Relations\nand tell them the related Radar ID: #FB11300759."
@ -96,17 +96,17 @@ struct suiPrefPaneKeyboard: View {
"", "",
selection: $selKeyboardParser.onChange { selection: $selKeyboardParser.onChange {
let value = selKeyboardParser let value = selKeyboardParser
mgrPrefs.keyboardParser = value PrefMgr.shared.keyboardParser = value
switch value { switch value {
case 0: case 0:
if !IMKHelper.arrDynamicBasicKeyLayouts.contains(mgrPrefs.basicKeyboardLayout) { if !IMKHelper.arrDynamicBasicKeyLayouts.contains(PrefMgr.shared.basicKeyboardLayout) {
mgrPrefs.basicKeyboardLayout = "com.apple.keylayout.ZhuyinBopomofo" PrefMgr.shared.basicKeyboardLayout = "com.apple.keylayout.ZhuyinBopomofo"
selBasicKeyboardLayout = mgrPrefs.basicKeyboardLayout selBasicKeyboardLayout = PrefMgr.shared.basicKeyboardLayout
} }
default: default:
if IMKHelper.arrDynamicBasicKeyLayouts.contains(mgrPrefs.basicKeyboardLayout) { if IMKHelper.arrDynamicBasicKeyLayouts.contains(PrefMgr.shared.basicKeyboardLayout) {
mgrPrefs.basicKeyboardLayout = "com.apple.keylayout.ABC" PrefMgr.shared.basicKeyboardLayout = "com.apple.keylayout.ABC"
selBasicKeyboardLayout = mgrPrefs.basicKeyboardLayout selBasicKeyboardLayout = PrefMgr.shared.basicKeyboardLayout
} }
} }
} }
@ -137,18 +137,18 @@ struct suiPrefPaneKeyboard: View {
} }
.labelsHidden() .labelsHidden()
Button { Button {
mgrPrefs.keyboardParser = 0 PrefMgr.shared.keyboardParser = 0
selKeyboardParser = mgrPrefs.keyboardParser selKeyboardParser = PrefMgr.shared.keyboardParser
mgrPrefs.basicKeyboardLayout = "com.apple.keylayout.ZhuyinBopomofo" PrefMgr.shared.basicKeyboardLayout = "com.apple.keylayout.ZhuyinBopomofo"
selBasicKeyboardLayout = mgrPrefs.basicKeyboardLayout selBasicKeyboardLayout = PrefMgr.shared.basicKeyboardLayout
} label: { } label: {
Text("↻ㄅ") Text("↻ㄅ")
} }
Button { Button {
mgrPrefs.keyboardParser = 10 PrefMgr.shared.keyboardParser = 10
selKeyboardParser = mgrPrefs.keyboardParser selKeyboardParser = PrefMgr.shared.keyboardParser
mgrPrefs.basicKeyboardLayout = "com.apple.keylayout.ABC" PrefMgr.shared.basicKeyboardLayout = "com.apple.keylayout.ABC"
selBasicKeyboardLayout = mgrPrefs.basicKeyboardLayout selBasicKeyboardLayout = PrefMgr.shared.basicKeyboardLayout
} label: { } label: {
Text("↻A") Text("↻A")
} }
@ -159,7 +159,7 @@ struct suiPrefPaneKeyboard: View {
NSLocalizedString( NSLocalizedString(
"Choose the phonetic layout for Mandarin parser.", "Choose the phonetic layout for Mandarin parser.",
comment: "" comment: ""
) + (mgrPrefs.appleLanguages[0].contains("en") ? " " : "") ) + (PrefMgr.shared.appleLanguages[0].contains("en") ? " " : "")
+ NSLocalizedString( + NSLocalizedString(
"Apple Dynamic Bopomofo Basic Keyboard Layouts (Dachen & Eten Traditional) must match the Dachen parser in order to be functional.", "Apple Dynamic Bopomofo Basic Keyboard Layouts (Dachen & Eten Traditional) must match the Dachen parser in order to be functional.",
comment: "" comment: ""
@ -175,10 +175,10 @@ struct suiPrefPaneKeyboard: View {
"", "",
selection: $selBasicKeyboardLayout.onChange { selection: $selBasicKeyboardLayout.onChange {
let value = selBasicKeyboardLayout let value = selBasicKeyboardLayout
mgrPrefs.basicKeyboardLayout = value PrefMgr.shared.basicKeyboardLayout = value
if IMKHelper.arrDynamicBasicKeyLayouts.contains(value) { if IMKHelper.arrDynamicBasicKeyLayouts.contains(value) {
mgrPrefs.keyboardParser = 0 PrefMgr.shared.keyboardParser = 0
selKeyboardParser = mgrPrefs.keyboardParser selKeyboardParser = PrefMgr.shared.keyboardParser
} }
} }
) { ) {
@ -210,7 +210,7 @@ struct suiPrefPaneKeyboard: View {
Picker( Picker(
"", "",
selection: $selAlphanumericalKeyboardLayout.onChange { selection: $selAlphanumericalKeyboardLayout.onChange {
mgrPrefs.alphanumericalKeyboardLayout = selAlphanumericalKeyboardLayout PrefMgr.shared.alphanumericalKeyboardLayout = selAlphanumericalKeyboardLayout
} }
) { ) {
ForEach(0...(IMKHelper.allowedAlphanumericalTISInputSources.count - 1), id: \.self) { id in ForEach(0...(IMKHelper.allowedAlphanumericalTISInputSources.count - 1), id: \.self) { id in
@ -239,25 +239,25 @@ struct suiPrefPaneKeyboard: View {
Toggle( Toggle(
LocalizedStringKey("Per-Char Select Mode"), LocalizedStringKey("Per-Char Select Mode"),
isOn: $selUsingHotKeySCPC.onChange { isOn: $selUsingHotKeySCPC.onChange {
mgrPrefs.usingHotKeySCPC = selUsingHotKeySCPC PrefMgr.shared.usingHotKeySCPC = selUsingHotKeySCPC
} }
) )
Toggle( Toggle(
LocalizedStringKey("Per-Char Associated Phrases"), LocalizedStringKey("Per-Char Associated Phrases"),
isOn: $selUsingHotKeyAssociates.onChange { isOn: $selUsingHotKeyAssociates.onChange {
mgrPrefs.usingHotKeyAssociates = selUsingHotKeyAssociates PrefMgr.shared.usingHotKeyAssociates = selUsingHotKeyAssociates
} }
) )
Toggle( Toggle(
LocalizedStringKey("CNS11643 Mode"), LocalizedStringKey("CNS11643 Mode"),
isOn: $selUsingHotKeyCNS.onChange { isOn: $selUsingHotKeyCNS.onChange {
mgrPrefs.usingHotKeyCNS = selUsingHotKeyCNS PrefMgr.shared.usingHotKeyCNS = selUsingHotKeyCNS
} }
) )
Toggle( Toggle(
LocalizedStringKey("Force KangXi Writing"), LocalizedStringKey("Force KangXi Writing"),
isOn: $selUsingHotKeyKangXi.onChange { isOn: $selUsingHotKeyKangXi.onChange {
mgrPrefs.usingHotKeyKangXi = selUsingHotKeyKangXi PrefMgr.shared.usingHotKeyKangXi = selUsingHotKeyKangXi
} }
) )
} }
@ -265,19 +265,19 @@ struct suiPrefPaneKeyboard: View {
Toggle( Toggle(
LocalizedStringKey("JIS Shinjitai Output"), LocalizedStringKey("JIS Shinjitai Output"),
isOn: $selUsingHotKeyJIS.onChange { isOn: $selUsingHotKeyJIS.onChange {
mgrPrefs.usingHotKeyJIS = selUsingHotKeyJIS PrefMgr.shared.usingHotKeyJIS = selUsingHotKeyJIS
} }
) )
Toggle( Toggle(
LocalizedStringKey("Half-Width Punctuation Mode"), LocalizedStringKey("Half-Width Punctuation Mode"),
isOn: $selUsingHotKeyHalfWidthASCII.onChange { isOn: $selUsingHotKeyHalfWidthASCII.onChange {
mgrPrefs.usingHotKeyHalfWidthASCII = selUsingHotKeyHalfWidthASCII PrefMgr.shared.usingHotKeyHalfWidthASCII = selUsingHotKeyHalfWidthASCII
} }
) )
Toggle( Toggle(
LocalizedStringKey("Currency Numeral Output"), LocalizedStringKey("Currency Numeral Output"),
isOn: $selUsingHotKeyCurrencyNumerals.onChange { isOn: $selUsingHotKeyCurrencyNumerals.onChange {
mgrPrefs.usingHotKeyCurrencyNumerals = selUsingHotKeyCurrencyNumerals PrefMgr.shared.usingHotKeyCurrencyNumerals = selUsingHotKeyCurrencyNumerals
} }
) )
} }

View File

@ -27,7 +27,7 @@ class ctlClientListMgr: NSWindowController, NSTableViewDelegate, NSTableViewData
extension ctlClientListMgr { extension ctlClientListMgr {
func numberOfRows(in _: NSTableView) -> Int { func numberOfRows(in _: NSTableView) -> Int {
mgrPrefs.clientsIMKTextInputIncapable.count PrefMgr.shared.clientsIMKTextInputIncapable.count
} }
func callAlert(_ window: NSWindow, title: String, text: String? = nil) { func callAlert(_ window: NSWindow, title: String, text: String? = nil) {
@ -107,7 +107,7 @@ extension ctlClientListMgr {
self.callAlert(window, title: title, text: text) self.callAlert(window, title: title, text: text)
return return
} }
if mgrPrefs.clientsIMKTextInputIncapable.contains(identifier) { if PrefMgr.shared.clientsIMKTextInputIncapable.contains(identifier) {
title = NSLocalizedString( title = NSLocalizedString(
"The selected item's identifier is already in the list.", comment: "" "The selected item's identifier is already in the list.", comment: ""
) )
@ -125,41 +125,41 @@ extension ctlClientListMgr {
private func applyNewValue(_ newValue: String) { private func applyNewValue(_ newValue: String) {
guard !newValue.isEmpty else { return } guard !newValue.isEmpty else { return }
var arrResult = mgrPrefs.clientsIMKTextInputIncapable var arrResult = PrefMgr.shared.clientsIMKTextInputIncapable
arrResult.append(newValue) arrResult.append(newValue)
mgrPrefs.clientsIMKTextInputIncapable = arrResult.sorted() PrefMgr.shared.clientsIMKTextInputIncapable = arrResult.sorted()
tblClients.reloadData() tblClients.reloadData()
btnRemoveClient.isEnabled = (0..<mgrPrefs.clientsIMKTextInputIncapable.count).contains( btnRemoveClient.isEnabled = (0..<PrefMgr.shared.clientsIMKTextInputIncapable.count).contains(
tblClients.selectedRow) tblClients.selectedRow)
} }
@IBAction func btnRemoveClientClicked(_: Any) { @IBAction func btnRemoveClientClicked(_: Any) {
guard let minIndexSelected = tblClients.selectedRowIndexes.min() else { return } guard let minIndexSelected = tblClients.selectedRowIndexes.min() else { return }
if minIndexSelected >= mgrPrefs.clientsIMKTextInputIncapable.count { return } if minIndexSelected >= PrefMgr.shared.clientsIMKTextInputIncapable.count { return }
if minIndexSelected < 0 { return } if minIndexSelected < 0 { return }
var isLastRow = false var isLastRow = false
tblClients.selectedRowIndexes.sorted().reversed().forEach { index in tblClients.selectedRowIndexes.sorted().reversed().forEach { index in
isLastRow = { isLastRow = {
if mgrPrefs.clientsIMKTextInputIncapable.count < 2 { return false } if PrefMgr.shared.clientsIMKTextInputIncapable.count < 2 { return false }
return minIndexSelected == mgrPrefs.clientsIMKTextInputIncapable.count - 1 return minIndexSelected == PrefMgr.shared.clientsIMKTextInputIncapable.count - 1
}() }()
if index < mgrPrefs.clientsIMKTextInputIncapable.count { if index < PrefMgr.shared.clientsIMKTextInputIncapable.count {
mgrPrefs.clientsIMKTextInputIncapable.remove(at: index) PrefMgr.shared.clientsIMKTextInputIncapable.remove(at: index)
} }
} }
if isLastRow { if isLastRow {
tblClients.selectRowIndexes(.init(arrayLiteral: minIndexSelected - 1), byExtendingSelection: false) tblClients.selectRowIndexes(.init(arrayLiteral: minIndexSelected - 1), byExtendingSelection: false)
} }
tblClients.reloadData() tblClients.reloadData()
btnRemoveClient.isEnabled = (0..<mgrPrefs.clientsIMKTextInputIncapable.count).contains(minIndexSelected) btnRemoveClient.isEnabled = (0..<PrefMgr.shared.clientsIMKTextInputIncapable.count).contains(minIndexSelected)
} }
func tableView(_: NSTableView, objectValueFor _: NSTableColumn?, row: Int) -> Any? { func tableView(_: NSTableView, objectValueFor _: NSTableColumn?, row: Int) -> Any? {
defer { defer {
self.btnRemoveClient.isEnabled = (0..<mgrPrefs.clientsIMKTextInputIncapable.count).contains( self.btnRemoveClient.isEnabled = (0..<PrefMgr.shared.clientsIMKTextInputIncapable.count).contains(
self.tblClients.selectedRow) self.tblClients.selectedRow)
} }
return mgrPrefs.clientsIMKTextInputIncapable[row] return PrefMgr.shared.clientsIMKTextInputIncapable[row]
} }
private func localize() { private func localize() {

View File

@ -51,7 +51,7 @@ class ctlPrefWindow: NSWindowController {
cmbCandidateFontSize.isEnabled = true cmbCandidateFontSize.isEnabled = true
if #unavailable(macOS 10.14) { if #unavailable(macOS 10.14) {
if mgrPrefs.useIMKCandidateWindow { if PrefMgr.shared.useIMKCandidateWindow {
cmbCandidateFontSize.isEnabled = false cmbCandidateFontSize.isEnabled = false
} }
} }
@ -82,7 +82,7 @@ class ctlPrefWindow: NSWindowController {
var chosenLanguageItem: NSMenuItem? var chosenLanguageItem: NSMenuItem?
uiLanguageButton.menu?.removeAllItems() uiLanguageButton.menu?.removeAllItems()
let appleLanguages = mgrPrefs.appleLanguages let appleLanguages = PrefMgr.shared.appleLanguages
for language in languages { for language in languages {
let menuItem = NSMenuItem() let menuItem = NSMenuItem()
menuItem.title = NSLocalizedString(language, comment: language) menuItem.title = NSLocalizedString(language, comment: language)
@ -108,7 +108,7 @@ class ctlPrefWindow: NSWindowController {
basicKeyboardLayoutButton.menu?.removeAllItems() basicKeyboardLayoutButton.menu?.removeAllItems()
let basicKeyboardLayoutID = mgrPrefs.basicKeyboardLayout let basicKeyboardLayoutID = PrefMgr.shared.basicKeyboardLayout
for source in IMKHelper.allowedBasicLayoutsAsTISInputSources { for source in IMKHelper.allowedBasicLayoutsAsTISInputSources {
guard let source = source else { guard let source = source else {
@ -129,7 +129,7 @@ class ctlPrefWindow: NSWindowController {
selectionKeyComboBox.removeAllItems() selectionKeyComboBox.removeAllItems()
selectionKeyComboBox.addItems(withObjectValues: CandidateKey.suggestions) selectionKeyComboBox.addItems(withObjectValues: CandidateKey.suggestions)
var candidateSelectionKeys = mgrPrefs.candidateKeys var candidateSelectionKeys = PrefMgr.shared.candidateKeys
if candidateSelectionKeys.isEmpty { if candidateSelectionKeys.isEmpty {
candidateSelectionKeys = CandidateKey.defaultKeys candidateSelectionKeys = CandidateKey.defaultKeys
} }
@ -140,28 +140,28 @@ class ctlPrefWindow: NSWindowController {
// CNS // CNS
// //
@IBAction func toggleCNSSupport(_: Any) { @IBAction func toggleCNSSupport(_: Any) {
LMMgr.setCNSEnabled(mgrPrefs.cns11643Enabled) LMMgr.setCNSEnabled(PrefMgr.shared.cns11643Enabled)
} }
@IBAction func toggleSymbolInputEnabled(_: Any) { @IBAction func toggleSymbolInputEnabled(_: Any) {
LMMgr.setSymbolEnabled(mgrPrefs.symbolInputEnabled) LMMgr.setSymbolEnabled(PrefMgr.shared.symbolInputEnabled)
} }
@IBAction func toggleTrad2KangXiAction(_: Any) { @IBAction func toggleTrad2KangXiAction(_: Any) {
if chkTrad2KangXi.state == .on, chkTrad2JISShinjitai.state == .on { if chkTrad2KangXi.state == .on, chkTrad2JISShinjitai.state == .on {
mgrPrefs.shiftJISShinjitaiOutputEnabled.toggle() PrefMgr.shared.shiftJISShinjitaiOutputEnabled.toggle()
} }
} }
@IBAction func toggleTrad2JISShinjitaiAction(_: Any) { @IBAction func toggleTrad2JISShinjitaiAction(_: Any) {
if chkTrad2KangXi.state == .on, chkTrad2JISShinjitai.state == .on { if chkTrad2KangXi.state == .on, chkTrad2JISShinjitai.state == .on {
mgrPrefs.chineseConversionEnabled.toggle() PrefMgr.shared.chineseConversionEnabled.toggle()
} }
} }
@IBAction func updateBasicKeyboardLayoutAction(_: Any) { @IBAction func updateBasicKeyboardLayoutAction(_: Any) {
if let sourceID = basicKeyboardLayoutButton.selectedItem?.representedObject as? String { if let sourceID = basicKeyboardLayoutButton.selectedItem?.representedObject as? String {
mgrPrefs.basicKeyboardLayout = sourceID PrefMgr.shared.basicKeyboardLayout = sourceID
} }
} }
@ -173,7 +173,7 @@ class ctlPrefWindow: NSWindowController {
} }
if let language = uiLanguageButton.selectedItem?.representedObject as? String { if let language = uiLanguageButton.selectedItem?.representedObject as? String {
if language != "auto" { if language != "auto" {
mgrPrefs.appleLanguages = [language] PrefMgr.shared.appleLanguages = [language]
} else { } else {
UserDefaults.standard.removeObject(forKey: "AppleLanguages") UserDefaults.standard.removeObject(forKey: "AppleLanguages")
} }
@ -203,15 +203,15 @@ class ctlPrefWindow: NSWindowController {
} }
do { do {
try CandidateKey.validate(keys: keys) try CandidateKey.validate(keys: keys)
mgrPrefs.candidateKeys = keys PrefMgr.shared.candidateKeys = keys
selectionKeyComboBox.stringValue = mgrPrefs.candidateKeys selectionKeyComboBox.stringValue = PrefMgr.shared.candidateKeys
} catch CandidateKey.ErrorType.empty { } catch CandidateKey.ErrorType.empty {
selectionKeyComboBox.stringValue = mgrPrefs.candidateKeys selectionKeyComboBox.stringValue = PrefMgr.shared.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) { _ in alert.beginSheetModal(for: window) { _ in
self.selectionKeyComboBox.stringValue = mgrPrefs.candidateKeys self.selectionKeyComboBox.stringValue = PrefMgr.shared.candidateKeys
} }
IMEApp.buzz() IMEApp.buzz()
} }
@ -234,7 +234,7 @@ class ctlPrefWindow: NSWindowController {
dlgOpenPath.canChooseDirectories = true dlgOpenPath.canChooseDirectories = true
let bolPreviousFolderValidity = LMMgr.checkIfSpecifiedUserDataFolderValid( let bolPreviousFolderValidity = LMMgr.checkIfSpecifiedUserDataFolderValid(
mgrPrefs.userDataFolderSpecified.expandingTildeInPath) PrefMgr.shared.userDataFolderSpecified.expandingTildeInPath)
dlgOpenPath.beginSheetModal(for: window) { result in dlgOpenPath.beginSheetModal(for: window) { result in
if result == NSApplication.ModalResponse.OK { if result == NSApplication.ModalResponse.OK {
@ -244,7 +244,7 @@ class ctlPrefWindow: NSWindowController {
var newPath = url.path var newPath = url.path
newPath.ensureTrailingSlash() newPath.ensureTrailingSlash()
if LMMgr.checkIfSpecifiedUserDataFolderValid(newPath) { if LMMgr.checkIfSpecifiedUserDataFolderValid(newPath) {
mgrPrefs.userDataFolderSpecified = newPath PrefMgr.shared.userDataFolderSpecified = newPath
BookmarkManager.shared.saveBookmark(for: url) BookmarkManager.shared.saveBookmark(for: url)
(NSApplication.shared.delegate as! AppDelegate).updateDirectoryMonitorPath() (NSApplication.shared.delegate as! AppDelegate).updateDirectoryMonitorPath()
} else { } else {

View File

@ -28,7 +28,7 @@ class ctlInputMethod: IMKInputController {
/// ///
static var ctlCandidateCurrent: ctlCandidateProtocol = static var ctlCandidateCurrent: ctlCandidateProtocol =
mgrPrefs.useIMKCandidateWindow ? ctlCandidateIMK.init(.horizontal) : ctlCandidateUniversal.init(.horizontal) PrefMgr.shared.useIMKCandidateWindow ? ctlCandidateIMK.init(.horizontal) : ctlCandidateUniversal.init(.horizontal)
/// ///
static var tooltipInstance = ctlTooltip() static var tooltipInstance = ctlTooltip()
@ -41,7 +41,7 @@ class ctlInputMethod: IMKInputController {
/// ctlInputMethod /// ctlInputMethod
var isASCIIMode = false { didSet { setKeyLayout() } } var isASCIIMode = false { didSet { setKeyLayout() } }
/// 調 /// 調
var keyHandler: KeyHandler = .init(lm: LMMgr.currentLM(), uom: LMMgr.currentUOM()) var keyHandler = KeyHandler(lm: LMMgr.currentLM(), uom: LMMgr.currentUOM(), pref: PrefMgr.shared)
/// ///
var state: IMEStateProtocol = IMEState.ofEmpty() { var state: IMEStateProtocol = IMEState.ofEmpty() {
didSet { didSet {
@ -51,7 +51,7 @@ class ctlInputMethod: IMKInputController {
/// Shift /// Shift
/// - Remark: Struct CapsLock Shift /// - Remark: Struct CapsLock Shift
static var theShiftKeyDetector = ShiftKeyUpChecker(useLShift: mgrPrefs.togglingAlphanumericalModeWithLShift) static var theShiftKeyDetector = ShiftKeyUpChecker(useLShift: PrefMgr.shared.togglingAlphanumericalModeWithLShift)
/// ctlInputMethod /// ctlInputMethod
func toggleASCIIMode() -> Bool { func toggleASCIIMode() -> Bool {
@ -82,20 +82,20 @@ class ctlInputMethod: IMKInputController {
func setKeyLayout() { func setKeyLayout() {
guard let client = client() else { return } guard let client = client() else { return }
if isASCIIMode, IMKHelper.isDynamicBasicKeyboardLayoutEnabled { if isASCIIMode, IMKHelper.isDynamicBasicKeyboardLayoutEnabled {
client.overrideKeyboard(withKeyboardNamed: mgrPrefs.alphanumericalKeyboardLayout) client.overrideKeyboard(withKeyboardNamed: PrefMgr.shared.alphanumericalKeyboardLayout)
return return
} }
client.overrideKeyboard(withKeyboardNamed: mgrPrefs.basicKeyboardLayout) client.overrideKeyboard(withKeyboardNamed: PrefMgr.shared.basicKeyboardLayout)
} }
/// 調 /// 調
func resetKeyHandler() { func resetKeyHandler() {
// //
if state.type == .ofInputting, mgrPrefs.trimUnfinishedReadingsOnCommit { if state.type == .ofInputting, PrefMgr.shared.trimUnfinishedReadingsOnCommit {
keyHandler.composer.clear() keyHandler.composer.clear()
handle(state: keyHandler.buildInputtingState) handle(state: keyHandler.buildInputtingState)
} }
let isSecureMode = mgrPrefs.clientsIMKTextInputIncapable.contains(clientBundleIdentifier) let isSecureMode = PrefMgr.shared.clientsIMKTextInputIncapable.contains(clientBundleIdentifier)
if state.hasComposition, !isSecureMode { if state.hasComposition, !isSecureMode {
/// 調 /// 調
handle(state: IMEState.ofCommitting(textToCommit: state.displayedText)) handle(state: IMEState.ofCommitting(textToCommit: state.displayedText))
@ -137,7 +137,7 @@ class ctlInputMethod: IMKInputController {
keyHandler.clear() // handle State.Empty() keyHandler.clear() // handle State.Empty()
keyHandler.ensureKeyboardParser() keyHandler.ensureKeyboardParser()
if isASCIIMode, mgrPrefs.disableShiftTogglingAlphanumericalMode { isASCIIMode = false } if isASCIIMode, PrefMgr.shared.disableShiftTogglingAlphanumericalMode { isASCIIMode = false }
/// ///
/// macOS /// macOS
@ -199,7 +199,7 @@ class ctlInputMethod: IMKInputController {
willSet { willSet {
/// Prefs IME /// Prefs IME
IMEApp.currentInputMode = newValue IMEApp.currentInputMode = newValue
mgrPrefs.mostRecentInputMode = IMEApp.currentInputMode.rawValue PrefMgr.shared.mostRecentInputMode = IMEApp.currentInputMode.rawValue
} }
didSet { didSet {
/// ///
@ -214,11 +214,11 @@ class ctlInputMethod: IMKInputController {
/// ///
func syncBaseLMPrefs() { func syncBaseLMPrefs() {
LMMgr.currentLM().isPhraseReplacementEnabled = mgrPrefs.phraseReplacementEnabled LMMgr.currentLM().isPhraseReplacementEnabled = PrefMgr.shared.phraseReplacementEnabled
LMMgr.currentLM().isCNSEnabled = mgrPrefs.cns11643Enabled LMMgr.currentLM().isCNSEnabled = PrefMgr.shared.cns11643Enabled
LMMgr.currentLM().isSymbolEnabled = mgrPrefs.symbolInputEnabled LMMgr.currentLM().isSymbolEnabled = PrefMgr.shared.symbolInputEnabled
LMMgr.currentLM().isSCPCEnabled = mgrPrefs.useSCPCTypingMode LMMgr.currentLM().isSCPCEnabled = PrefMgr.shared.useSCPCTypingMode
LMMgr.currentLM().deltaOfCalendarYears = mgrPrefs.deltaOfCalendarYears LMMgr.currentLM().deltaOfCalendarYears = PrefMgr.shared.deltaOfCalendarYears
} }
// MARK: - IMKServerInput // MARK: - IMKServerInput
@ -261,7 +261,7 @@ class ctlInputMethod: IMKInputController {
// Shift macOS 10.15 macOS // Shift macOS 10.15 macOS
let shouldUseShiftToggleHandle: Bool = { let shouldUseShiftToggleHandle: Bool = {
switch mgrPrefs.shiftKeyAccommodationBehavior { switch PrefMgr.shared.shiftKeyAccommodationBehavior {
case 0: return false case 0: return false
case 1: return Shared.arrClientShiftHandlingExceptionList.contains(clientBundleIdentifier) case 1: return Shared.arrClientShiftHandlingExceptionList.contains(clientBundleIdentifier)
case 2: return true case 2: return true
@ -271,7 +271,7 @@ class ctlInputMethod: IMKInputController {
/// event event var Shift /// event event var Shift
if #available(macOS 10.15, *) { if #available(macOS 10.15, *) {
if Self.theShiftKeyDetector.check(event), !mgrPrefs.disableShiftTogglingAlphanumericalMode { if Self.theShiftKeyDetector.check(event), !PrefMgr.shared.disableShiftTogglingAlphanumericalMode {
if !shouldUseShiftToggleHandle || (!rencentKeyHandledByKeyHandlerEtc && shouldUseShiftToggleHandle) { if !shouldUseShiftToggleHandle || (!rencentKeyHandledByKeyHandlerEtc && shouldUseShiftToggleHandle) {
NotifierController.notify( NotifierController.notify(
message: toggleASCIIMode() message: toggleASCIIMode()
@ -375,7 +375,7 @@ class ctlInputMethod: IMKInputController {
var result = (theCandidate.1 == theConverted) ? theCandidate.1 : "\(theConverted)\u{1A}(\(theCandidate.1))" var result = (theCandidate.1 == theConverted) ? theCandidate.1 : "\(theConverted)\u{1A}(\(theCandidate.1))"
if arrResult.contains(result) { if arrResult.contains(result) {
let reading: String = let reading: String =
mgrPrefs.showHanyuPinyinInCompositionBuffer PrefMgr.shared.showHanyuPinyinInCompositionBuffer
? Tekkon.cnvPhonaToHanyuPinyin(target: Tekkon.restoreToneOneInZhuyinKey(target: theCandidate.0)) ? Tekkon.cnvPhonaToHanyuPinyin(target: Tekkon.restoreToneOneInZhuyinKey(target: theCandidate.0))
: theCandidate.0 : theCandidate.0
result = "\(result)\u{17}(\(reading))" result = "\(result)\u{17}(\(reading))"
@ -423,7 +423,7 @@ class ctlInputMethod: IMKInputController {
override open func candidateSelected(_ candidateString: NSAttributedString!) { override open func candidateSelected(_ candidateString: NSAttributedString!) {
let candidateString: String = candidateString?.string ?? "" let candidateString: String = candidateString?.string ?? ""
if state.type == .ofAssociates { if state.type == .ofAssociates {
if !mgrPrefs.alsoConfirmAssociatedCandidatesByEnter { if !PrefMgr.shared.alsoConfirmAssociatedCandidatesByEnter {
handle(state: IMEState.ofAbortion()) handle(state: IMEState.ofAbortion())
return return
} }
@ -437,7 +437,7 @@ class ctlInputMethod: IMKInputController {
let theConverted = ChineseConverter.kanjiConversionIfRequired(neta.1) let theConverted = ChineseConverter.kanjiConversionIfRequired(neta.1)
let netaShown = (neta.1 == theConverted) ? neta.1 : "\(theConverted)\u{1A}(\(neta.1))" let netaShown = (neta.1 == theConverted) ? neta.1 : "\(theConverted)\u{1A}(\(neta.1))"
let reading: String = let reading: String =
mgrPrefs.showHanyuPinyinInCompositionBuffer PrefMgr.shared.showHanyuPinyinInCompositionBuffer
? Tekkon.cnvPhonaToHanyuPinyin(target: Tekkon.restoreToneOneInZhuyinKey(target: neta.0)) : neta.0 ? Tekkon.cnvPhonaToHanyuPinyin(target: Tekkon.restoreToneOneInZhuyinKey(target: neta.0)) : neta.0
let netaShownWithPronunciation = "\(netaShown)\u{17}(\(reading))" let netaShownWithPronunciation = "\(netaShown)\u{17}(\(reading))"
if candidateString == prefix + netaShownWithPronunciation { if candidateString == prefix + netaShownWithPronunciation {

View File

@ -106,15 +106,15 @@ extension ctlInputMethod: ctlCandidateDelegate {
let selectedValue = state.candidates[index] let selectedValue = state.candidates[index]
keyHandler.fixNode( keyHandler.fixNode(
candidate: selectedValue, respectCursorPushing: true, candidate: selectedValue, respectCursorPushing: true,
preConsolidate: mgrPrefs.consolidateContextOnCandidateSelection preConsolidate: PrefMgr.shared.consolidateContextOnCandidateSelection
) )
let inputting = keyHandler.buildInputtingState let inputting = keyHandler.buildInputtingState
if mgrPrefs.useSCPCTypingMode { if PrefMgr.shared.useSCPCTypingMode {
handle(state: IMEState.ofCommitting(textToCommit: inputting.displayedText)) handle(state: IMEState.ofCommitting(textToCommit: inputting.displayedText))
// selectedValue.1 // selectedValue.1
if mgrPrefs.associatedPhrasesEnabled { if PrefMgr.shared.associatedPhrasesEnabled {
let associates = keyHandler.buildAssociatePhraseState( let associates = keyHandler.buildAssociatePhraseState(
withPair: .init(key: selectedValue.0, value: selectedValue.1) withPair: .init(key: selectedValue.0, value: selectedValue.1)
) )
@ -137,7 +137,7 @@ extension ctlInputMethod: ctlCandidateDelegate {
handle(state: IMEState.ofEmpty()) handle(state: IMEState.ofEmpty())
return return
} }
if mgrPrefs.associatedPhrasesEnabled { if PrefMgr.shared.associatedPhrasesEnabled {
let associates = keyHandler.buildAssociatePhraseState( let associates = keyHandler.buildAssociatePhraseState(
withPair: .init(key: selectedValue.0, value: String(valueKept)) withPair: .init(key: selectedValue.0, value: String(valueKept))
) )

View File

@ -18,7 +18,7 @@ extension ctlInputMethod {
// App App // App App
// 使 20 // 使 20
var attributedStringSecured: (NSAttributedString, NSRange) { var attributedStringSecured: (NSAttributedString, NSRange) {
mgrPrefs.clientsIMKTextInputIncapable.contains(clientBundleIdentifier) PrefMgr.shared.clientsIMKTextInputIncapable.contains(clientBundleIdentifier)
? (state.data.attributedStringPlaceholder, NSRange(location: 0, length: 0)) ? (state.data.attributedStringPlaceholder, NSRange(location: 0, length: 0))
: (state.attributedString, NSRange(state.data.u16MarkedRange)) : (state.attributedString, NSRange(state.data.u16MarkedRange))
} }
@ -56,7 +56,7 @@ extension ctlInputMethod {
) )
} }
let tooltipContentDirection: NSAttributedTextView.writingDirection = { let tooltipContentDirection: NSAttributedTextView.writingDirection = {
if mgrPrefs.alwaysShowTooltipTextsHorizontally { return .horizontal } if PrefMgr.shared.alwaysShowTooltipTextsHorizontally { return .horizontal }
return isVerticalTyping ? .vertical : .horizontal return isVerticalTyping ? .vertical : .horizontal
}() }()
// NSAttributedTextView // NSAttributedTextView
@ -88,13 +88,13 @@ extension ctlInputMethod {
// //
// 使 // 使
// Beer emoji // Beer emoji
let maxCandidatesPerPage = mgrPrefs.candidateKeys.count let maxCandidatesPerPage = PrefMgr.shared.candidateKeys.count
let firstPageCandidates = candidates[0..<min(maxCandidatesPerPage, candidates.count)].map(\.1) let firstPageCandidates = candidates[0..<min(maxCandidatesPerPage, candidates.count)].map(\.1)
return firstPageCandidates.joined().count > Int(round(Double(maxCandidatesPerPage) * 1.8)) return firstPageCandidates.joined().count > Int(round(Double(maxCandidatesPerPage) * 1.8))
// true // true
} }
state.isVerticalCandidateWindow = (isCandidateWindowVertical || !mgrPrefs.useHorizontalCandidateList) state.isVerticalCandidateWindow = (isCandidateWindowVertical || !PrefMgr.shared.useHorizontalCandidateList)
ctlInputMethod.ctlCandidateCurrent.delegate = nil ctlInputMethod.ctlCandidateCurrent.delegate = nil
@ -105,16 +105,16 @@ extension ctlInputMethod {
/// macOS 10.x SwiftUI /// macOS 10.x SwiftUI
let candidateLayout: CandidateLayout = let candidateLayout: CandidateLayout =
((isCandidateWindowVertical || !mgrPrefs.useHorizontalCandidateList) ((isCandidateWindowVertical || !PrefMgr.shared.useHorizontalCandidateList)
? CandidateLayout.vertical ? CandidateLayout.vertical
: CandidateLayout.horizontal) : CandidateLayout.horizontal)
ctlInputMethod.ctlCandidateCurrent = ctlInputMethod.ctlCandidateCurrent =
mgrPrefs.useIMKCandidateWindow PrefMgr.shared.useIMKCandidateWindow
? ctlCandidateIMK.init(candidateLayout) : ctlCandidateUniversal.init(candidateLayout) ? ctlCandidateIMK.init(candidateLayout) : ctlCandidateUniversal.init(candidateLayout)
// set the attributes for the candidate panel (which uses NSAttributedString) // set the attributes for the candidate panel (which uses NSAttributedString)
let textSize = mgrPrefs.candidateListTextSize let textSize = PrefMgr.shared.candidateListTextSize
let minimumKeyLabelSize: Double = 10 let minimumKeyLabelSize: Double = 10
let keyLabelSize = max(textSize / 2, minimumKeyLabelSize) let keyLabelSize = max(textSize / 2, minimumKeyLabelSize)
@ -126,13 +126,13 @@ extension ctlInputMethod {
} }
ctlInputMethod.ctlCandidateCurrent.keyLabelFont = labelFont( ctlInputMethod.ctlCandidateCurrent.keyLabelFont = labelFont(
name: mgrPrefs.candidateKeyLabelFontName, size: keyLabelSize name: PrefMgr.shared.candidateKeyLabelFontName, size: keyLabelSize
) )
ctlInputMethod.ctlCandidateCurrent.candidateFont = ctlInputMethod.candidateFont( ctlInputMethod.ctlCandidateCurrent.candidateFont = ctlInputMethod.candidateFont(
name: mgrPrefs.candidateTextFontName, size: textSize name: PrefMgr.shared.candidateTextFontName, size: textSize
) )
let candidateKeys = mgrPrefs.candidateKeys let candidateKeys = PrefMgr.shared.candidateKeys
let keyLabels = let keyLabels =
candidateKeys.count > 4 ? Array(candidateKeys) : Array(CandidateKey.defaultKeys) candidateKeys.count > 4 ? Array(candidateKeys) : Array(CandidateKey.defaultKeys)
let keyLabelSuffix = state.type == .ofAssociates ? "^" : "" let keyLabelSuffix = state.type == .ofAssociates ? "^" : ""
@ -195,7 +195,7 @@ extension ctlInputMethod {
case InputMode.imeModeCHS: case InputMode.imeModeCHS:
return CTFontCreateUIFontForLanguage(.system, size, "zh-Hans" as CFString) return CTFontCreateUIFontForLanguage(.system, size, "zh-Hans" as CFString)
case InputMode.imeModeCHT: case InputMode.imeModeCHT:
return (mgrPrefs.shiftJISShinjitaiOutputEnabled || mgrPrefs.chineseConversionEnabled) return (PrefMgr.shared.shiftJISShinjitaiOutputEnabled || PrefMgr.shared.chineseConversionEnabled)
? CTFontCreateUIFontForLanguage(.system, size, "ja" as CFString) ? CTFontCreateUIFontForLanguage(.system, size, "ja" as CFString)
: CTFontCreateUIFontForLanguage(.system, size, "zh-Hant" as CFString) : CTFontCreateUIFontForLanguage(.system, size, "zh-Hant" as CFString)
default: default:

View File

@ -80,7 +80,7 @@ extension ctlInputMethod {
default: break default: break
} }
// //
if state.hasComposition, mgrPrefs.clientsIMKTextInputIncapable.contains(clientBundleIdentifier) { if state.hasComposition, PrefMgr.shared.clientsIMKTextInputIncapable.contains(clientBundleIdentifier) {
ctlInputMethod.popupCompositionBuffer.isTypingDirectionVertical = isVerticalTyping ctlInputMethod.popupCompositionBuffer.isTypingDirectionVertical = isVerticalTyping
ctlInputMethod.popupCompositionBuffer.show( ctlInputMethod.popupCompositionBuffer.show(
state: state, at: lineHeightRect(zeroCursor: true).origin state: state, at: lineHeightRect(zeroCursor: true).origin

View File

@ -28,61 +28,64 @@ extension ctlInputMethod {
let useSCPCTypingModeItem = menu.addItem( let useSCPCTypingModeItem = menu.addItem(
withTitle: NSLocalizedString("Per-Char Select Mode", comment: ""), withTitle: NSLocalizedString("Per-Char Select Mode", comment: ""),
action: #selector(toggleSCPCTypingMode(_:)), keyEquivalent: mgrPrefs.usingHotKeySCPC ? "P" : "" action: #selector(toggleSCPCTypingMode(_:)), keyEquivalent: PrefMgr.shared.usingHotKeySCPC ? "P" : ""
) )
useSCPCTypingModeItem.keyEquivalentModifierMask = [.command, .control] useSCPCTypingModeItem.keyEquivalentModifierMask = [.command, .control]
useSCPCTypingModeItem.state = mgrPrefs.useSCPCTypingMode.state useSCPCTypingModeItem.state = PrefMgr.shared.useSCPCTypingMode.state
let userAssociatedPhrasesItem = menu.addItem( let userAssociatedPhrasesItem = menu.addItem(
withTitle: NSLocalizedString("Per-Char Associated Phrases", comment: ""), withTitle: NSLocalizedString("Per-Char Associated Phrases", comment: ""),
action: #selector(toggleAssociatedPhrasesEnabled(_:)), keyEquivalent: mgrPrefs.usingHotKeyAssociates ? "O" : "" action: #selector(toggleAssociatedPhrasesEnabled(_:)),
keyEquivalent: PrefMgr.shared.usingHotKeyAssociates ? "O" : ""
) )
userAssociatedPhrasesItem.keyEquivalentModifierMask = [.command, .control] userAssociatedPhrasesItem.keyEquivalentModifierMask = [.command, .control]
userAssociatedPhrasesItem.state = mgrPrefs.associatedPhrasesEnabled.state userAssociatedPhrasesItem.state = PrefMgr.shared.associatedPhrasesEnabled.state
let useCNS11643SupportItem = menu.addItem( let useCNS11643SupportItem = menu.addItem(
withTitle: NSLocalizedString("CNS11643 Mode", comment: ""), withTitle: NSLocalizedString("CNS11643 Mode", comment: ""),
action: #selector(toggleCNS11643Enabled(_:)), keyEquivalent: mgrPrefs.usingHotKeyCNS ? "L" : "" action: #selector(toggleCNS11643Enabled(_:)), keyEquivalent: PrefMgr.shared.usingHotKeyCNS ? "L" : ""
) )
useCNS11643SupportItem.keyEquivalentModifierMask = [.command, .control] useCNS11643SupportItem.keyEquivalentModifierMask = [.command, .control]
useCNS11643SupportItem.state = mgrPrefs.cns11643Enabled.state useCNS11643SupportItem.state = PrefMgr.shared.cns11643Enabled.state
if IMEApp.currentInputMode == InputMode.imeModeCHT { if IMEApp.currentInputMode == InputMode.imeModeCHT {
let chineseConversionItem = menu.addItem( let chineseConversionItem = menu.addItem(
withTitle: NSLocalizedString("Force KangXi Writing", comment: ""), withTitle: NSLocalizedString("Force KangXi Writing", comment: ""),
action: #selector(toggleChineseConverter(_:)), keyEquivalent: mgrPrefs.usingHotKeyKangXi ? "K" : "" action: #selector(toggleChineseConverter(_:)), keyEquivalent: PrefMgr.shared.usingHotKeyKangXi ? "K" : ""
) )
chineseConversionItem.keyEquivalentModifierMask = [.command, .control] chineseConversionItem.keyEquivalentModifierMask = [.command, .control]
chineseConversionItem.state = mgrPrefs.chineseConversionEnabled.state chineseConversionItem.state = PrefMgr.shared.chineseConversionEnabled.state
let shiftJISConversionItem = menu.addItem( let shiftJISConversionItem = menu.addItem(
withTitle: NSLocalizedString("JIS Shinjitai Output", comment: ""), withTitle: NSLocalizedString("JIS Shinjitai Output", comment: ""),
action: #selector(toggleShiftJISShinjitaiOutput(_:)), keyEquivalent: mgrPrefs.usingHotKeyJIS ? "J" : "" action: #selector(toggleShiftJISShinjitaiOutput(_:)), keyEquivalent: PrefMgr.shared.usingHotKeyJIS ? "J" : ""
) )
shiftJISConversionItem.keyEquivalentModifierMask = [.command, .control] shiftJISConversionItem.keyEquivalentModifierMask = [.command, .control]
shiftJISConversionItem.state = mgrPrefs.shiftJISShinjitaiOutputEnabled.state shiftJISConversionItem.state = PrefMgr.shared.shiftJISShinjitaiOutputEnabled.state
} }
let currencyNumeralsItem = menu.addItem( let currencyNumeralsItem = menu.addItem(
withTitle: NSLocalizedString("Currency Numeral Output", comment: ""), withTitle: NSLocalizedString("Currency Numeral Output", comment: ""),
action: #selector(toggleCurrencyNumerals(_:)), keyEquivalent: mgrPrefs.usingHotKeyCurrencyNumerals ? "M" : "" action: #selector(toggleCurrencyNumerals(_:)),
keyEquivalent: PrefMgr.shared.usingHotKeyCurrencyNumerals ? "M" : ""
) )
currencyNumeralsItem.keyEquivalentModifierMask = [.command, .control] currencyNumeralsItem.keyEquivalentModifierMask = [.command, .control]
currencyNumeralsItem.state = mgrPrefs.currencyNumeralsEnabled.state currencyNumeralsItem.state = PrefMgr.shared.currencyNumeralsEnabled.state
let halfWidthPunctuationItem = menu.addItem( let halfWidthPunctuationItem = menu.addItem(
withTitle: NSLocalizedString("Half-Width Punctuation Mode", comment: ""), withTitle: NSLocalizedString("Half-Width Punctuation Mode", comment: ""),
action: #selector(toggleHalfWidthPunctuation(_:)), keyEquivalent: mgrPrefs.usingHotKeyHalfWidthASCII ? "H" : "" action: #selector(toggleHalfWidthPunctuation(_:)),
keyEquivalent: PrefMgr.shared.usingHotKeyHalfWidthASCII ? "H" : ""
) )
halfWidthPunctuationItem.keyEquivalentModifierMask = [.command, .control] halfWidthPunctuationItem.keyEquivalentModifierMask = [.command, .control]
halfWidthPunctuationItem.state = mgrPrefs.halfWidthPunctuationEnabled.state halfWidthPunctuationItem.state = PrefMgr.shared.halfWidthPunctuationEnabled.state
if optionKeyPressed || mgrPrefs.phraseReplacementEnabled { if optionKeyPressed || PrefMgr.shared.phraseReplacementEnabled {
let phaseReplacementItem = menu.addItem( let phaseReplacementItem = menu.addItem(
withTitle: NSLocalizedString("Use Phrase Replacement", comment: ""), withTitle: NSLocalizedString("Use Phrase Replacement", comment: ""),
action: #selector(togglePhraseReplacement(_:)), keyEquivalent: "" action: #selector(togglePhraseReplacement(_:)), keyEquivalent: ""
) )
phaseReplacementItem.state = mgrPrefs.phraseReplacementEnabled.state phaseReplacementItem.state = PrefMgr.shared.phraseReplacementEnabled.state
} }
if optionKeyPressed { if optionKeyPressed {
@ -90,7 +93,7 @@ extension ctlInputMethod {
withTitle: NSLocalizedString("Symbol & Emoji Input", comment: ""), withTitle: NSLocalizedString("Symbol & Emoji Input", comment: ""),
action: #selector(toggleSymbolEnabled(_:)), keyEquivalent: "" action: #selector(toggleSymbolEnabled(_:)), keyEquivalent: ""
) )
toggleSymbolInputItem.state = mgrPrefs.symbolInputEnabled.state toggleSymbolInputItem.state = PrefMgr.shared.symbolInputEnabled.state
} }
menu.addItem(NSMenuItem.separator()) // --------------------- menu.addItem(NSMenuItem.separator()) // ---------------------
@ -108,7 +111,7 @@ extension ctlInputMethod {
action: #selector(openExcludedPhrases(_:)), keyEquivalent: "" action: #selector(openExcludedPhrases(_:)), keyEquivalent: ""
) )
if optionKeyPressed || mgrPrefs.associatedPhrasesEnabled { if optionKeyPressed || PrefMgr.shared.associatedPhrasesEnabled {
menu.addItem( menu.addItem(
withTitle: NSLocalizedString("Edit Associated Phrases…", comment: ""), withTitle: NSLocalizedString("Edit Associated Phrases…", comment: ""),
action: #selector(openAssociatedPhrases(_:)), keyEquivalent: "" action: #selector(openAssociatedPhrases(_:)), keyEquivalent: ""
@ -126,7 +129,7 @@ extension ctlInputMethod {
) )
} }
if optionKeyPressed || !mgrPrefs.shouldAutoReloadUserDataFiles { if optionKeyPressed || !PrefMgr.shared.shouldAutoReloadUserDataFiles {
menu.addItem( menu.addItem(
withTitle: NSLocalizedString("Reload User Phrases", comment: ""), withTitle: NSLocalizedString("Reload User Phrases", comment: ""),
action: #selector(reloadUserPhrasesData(_:)), keyEquivalent: "" action: #selector(reloadUserPhrasesData(_:)), keyEquivalent: ""
@ -222,7 +225,7 @@ extension ctlInputMethod {
resetKeyHandler() resetKeyHandler()
NotifierController.notify( NotifierController.notify(
message: NSLocalizedString("Per-Char Select Mode", comment: "") + "\n" message: NSLocalizedString("Per-Char Select Mode", comment: "") + "\n"
+ (mgrPrefs.useSCPCTypingMode.toggled() + (PrefMgr.shared.useSCPCTypingMode.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : NSLocalizedString("NotificationSwitchOFF", comment: ""))
) )
@ -232,7 +235,7 @@ extension ctlInputMethod {
resetKeyHandler() resetKeyHandler()
NotifierController.notify( NotifierController.notify(
message: NSLocalizedString("Force KangXi Writing", comment: "") + "\n" message: NSLocalizedString("Force KangXi Writing", comment: "") + "\n"
+ (mgrPrefs.chineseConversionEnabled.toggled() + (PrefMgr.shared.chineseConversionEnabled.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : NSLocalizedString("NotificationSwitchOFF", comment: ""))
) )
@ -242,7 +245,7 @@ extension ctlInputMethod {
resetKeyHandler() resetKeyHandler()
NotifierController.notify( NotifierController.notify(
message: NSLocalizedString("JIS Shinjitai Output", comment: "") + "\n" message: NSLocalizedString("JIS Shinjitai Output", comment: "") + "\n"
+ (mgrPrefs.shiftJISShinjitaiOutputEnabled.toggled() + (PrefMgr.shared.shiftJISShinjitaiOutputEnabled.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : NSLocalizedString("NotificationSwitchOFF", comment: ""))
) )
@ -252,7 +255,7 @@ extension ctlInputMethod {
resetKeyHandler() resetKeyHandler()
NotifierController.notify( NotifierController.notify(
message: NSLocalizedString("Currency Numeral Output", comment: "") + "\n" message: NSLocalizedString("Currency Numeral Output", comment: "") + "\n"
+ (mgrPrefs.currencyNumeralsEnabled.toggled() + (PrefMgr.shared.currencyNumeralsEnabled.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : NSLocalizedString("NotificationSwitchOFF", comment: ""))
) )
@ -262,7 +265,7 @@ extension ctlInputMethod {
resetKeyHandler() resetKeyHandler()
NotifierController.notify( NotifierController.notify(
message: NSLocalizedString("Half-Width Punctuation Mode", comment: "") + "\n" message: NSLocalizedString("Half-Width Punctuation Mode", comment: "") + "\n"
+ (mgrPrefs.halfWidthPunctuationEnabled.toggled() + (PrefMgr.shared.halfWidthPunctuationEnabled.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : NSLocalizedString("NotificationSwitchOFF", comment: ""))
) )
@ -272,7 +275,7 @@ extension ctlInputMethod {
resetKeyHandler() resetKeyHandler()
NotifierController.notify( NotifierController.notify(
message: NSLocalizedString("CNS11643 Mode", comment: "") + "\n" message: NSLocalizedString("CNS11643 Mode", comment: "") + "\n"
+ (mgrPrefs.cns11643Enabled.toggled() + (PrefMgr.shared.cns11643Enabled.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : NSLocalizedString("NotificationSwitchOFF", comment: ""))
) )
@ -282,7 +285,7 @@ extension ctlInputMethod {
resetKeyHandler() resetKeyHandler()
NotifierController.notify( NotifierController.notify(
message: NSLocalizedString("Symbol & Emoji Input", comment: "") + "\n" message: NSLocalizedString("Symbol & Emoji Input", comment: "") + "\n"
+ (mgrPrefs.symbolInputEnabled.toggled() + (PrefMgr.shared.symbolInputEnabled.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : NSLocalizedString("NotificationSwitchOFF", comment: ""))
) )
@ -292,7 +295,7 @@ extension ctlInputMethod {
resetKeyHandler() resetKeyHandler()
NotifierController.notify( NotifierController.notify(
message: NSLocalizedString("Per-Char Associated Phrases", comment: "") + "\n" message: NSLocalizedString("Per-Char Associated Phrases", comment: "") + "\n"
+ (mgrPrefs.associatedPhrasesEnabled.toggled() + (PrefMgr.shared.associatedPhrasesEnabled.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : NSLocalizedString("NotificationSwitchOFF", comment: ""))
) )
@ -302,7 +305,7 @@ extension ctlInputMethod {
resetKeyHandler() resetKeyHandler()
NotifierController.notify( NotifierController.notify(
message: NSLocalizedString("Use Phrase Replacement", comment: "") + "\n" message: NSLocalizedString("Use Phrase Replacement", comment: "") + "\n"
+ (mgrPrefs.phraseReplacementEnabled.toggled() + (PrefMgr.shared.phraseReplacementEnabled.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : NSLocalizedString("NotificationSwitchOFF", comment: ""))
) )

View File

@ -94,10 +94,10 @@ public enum InputMode: String, CaseIterable {
public enum IMEApp { public enum IMEApp {
// MARK: - // MARK: -
public static var currentInputMode: InputMode = .init(rawValue: mgrPrefs.mostRecentInputMode) ?? .imeModeNULL public static var currentInputMode: InputMode = .init(rawValue: PrefMgr.shared.mostRecentInputMode) ?? .imeModeNULL
/// Fart or Beep? /// Fart or Beep?
static func buzz() { static func buzz() {
NSSound.buzz(fart: !mgrPrefs.shouldNotFartInLieuOfBeep) NSSound.buzz(fart: !PrefMgr.shared.shouldNotFartInLieuOfBeep)
} }
} }