AssoPhrases // Bind Menu Commands and Preferences.

This commit is contained in:
ShikiSuen 2022-02-10 11:41:54 +08:00
parent ca0bd45f06
commit 5ea771f88a
2 changed files with 16 additions and 2 deletions

View File

@ -279,7 +279,12 @@ struct ComposingBufferSize {
if UserDefaults.standard.object(forKey: kUseSCPCTypingMode) == nil {
UserDefaults.standard.set(Preferences.useSCPCTypingMode, forKey: kUseSCPCTypingMode)
}
// false
if UserDefaults.standard.object(forKey: kAssociatedPhrasesEnabled) == nil {
UserDefaults.standard.set(Preferences.associatedPhrasesEnabled, forKey: kAssociatedPhrasesEnabled)
}
// 0
if UserDefaults.standard.object(forKey: kSelectPhraseAfterCursorAsCandidatePreference) == nil {
UserDefaults.standard.set(Preferences.selectPhraseAfterCursorAsCandidate, forKey: kSelectPhraseAfterCursorAsCandidatePreference)

View File

@ -73,6 +73,10 @@ class ctlInputMethod: IMKInputController {
halfWidthPunctuationItem.keyEquivalentModifierMask = [.command, .control]
halfWidthPunctuationItem.state = Preferences.halfWidthPunctuationEnabled.state
let userAssociatedPhrasesItem = menu.addItem(withTitle: NSLocalizedString("Per-Char Associated Phrases", comment: ""), action: #selector(toggleAssociatedPhrasesEnabled(_:)), keyEquivalent: "O")
userAssociatedPhrasesItem.keyEquivalentModifierMask = [.command, .control]
userAssociatedPhrasesItem.state = Preferences.associatedPhrasesEnabled.state
if optionKeyPressed {
let phaseReplacementItem = menu.addItem(withTitle: NSLocalizedString("Use Phrase Replacement", comment: ""), action: #selector(togglePhraseReplacement(_:)), keyEquivalent: "")
phaseReplacementItem.state = Preferences.phraseReplacementEnabled.state
@ -86,6 +90,7 @@ class ctlInputMethod: IMKInputController {
if optionKeyPressed {
menu.addItem(withTitle: NSLocalizedString("Edit Excluded Phrases", comment: ""), action: #selector(openExcludedPhrases(_:)), keyEquivalent: "")
menu.addItem(withTitle: NSLocalizedString("Edit Phrase Replacement Table", comment: ""), action: #selector(openPhraseReplacement(_:)), keyEquivalent: "")
menu.addItem(withTitle: NSLocalizedString("Edit Associated Phrases", comment: ""), action: #selector(openAssociatedPhrases(_:)), keyEquivalent: "")
}
if (optionKeyPressed || !Preferences.shouldAutoReloadUserDataFiles) {
@ -218,7 +223,7 @@ class ctlInputMethod: IMKInputController {
}
@objc func toggleAssociatedPhrasesEnabled(_ sender: Any?) {
_ = Preferences.toggleAssociatedPhrasesEnabled()
NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("Per-Char Associated Phrases", comment: ""), "\n", Preferences.toggleAssociatedPhrasesEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: "")))
}
@objc func togglePhraseReplacement(_ sender: Any?) {
@ -268,6 +273,10 @@ class ctlInputMethod: IMKInputController {
open(userFileAt: mgrLangModel.phraseReplacementDataPath(keyHandler.inputMode))
}
@objc func openAssociatedPhrases(_ sender: Any?) {
open(userFileAt: mgrLangModel.userAssociatedPhrasesDataPath(keyHandler.inputMode))
}
@objc func reloadUserPhrases(_ sender: Any?) {
mgrLangModel.loadUserPhrases()
mgrLangModel.loadUserPhraseReplacement()