ctlIME // Bind alphanumerical mode preferences.

This commit is contained in:
ShikiSuen 2022-03-01 18:11:04 +08:00
parent 7938f4bf95
commit 3c176086e0
1 changed files with 9 additions and 1 deletions

View File

@ -92,6 +92,10 @@ class ctlInputMethod: IMKInputController {
userAssociatedPhrasesItem.keyEquivalentModifierMask = [.command, .control] userAssociatedPhrasesItem.keyEquivalentModifierMask = [.command, .control]
userAssociatedPhrasesItem.state = Preferences.associatedPhrasesEnabled.state userAssociatedPhrasesItem.state = Preferences.associatedPhrasesEnabled.state
let alphaNumericalModeItem = menu.addItem(withTitle: NSLocalizedString("Alphanumerical Input Mode", comment: ""), action: #selector(toggleAlphanumericalModeEnabled(_:)), keyEquivalent: "I")
alphaNumericalModeItem.keyEquivalentModifierMask = [.command, .control]
alphaNumericalModeItem.state = Preferences.isAlphanumericalModeEnabled.state
if optionKeyPressed { if optionKeyPressed {
let phaseReplacementItem = menu.addItem(withTitle: NSLocalizedString("Use Phrase Replacement", comment: ""), action: #selector(togglePhraseReplacement(_:)), keyEquivalent: "") let phaseReplacementItem = menu.addItem(withTitle: NSLocalizedString("Use Phrase Replacement", comment: ""), action: #selector(togglePhraseReplacement(_:)), keyEquivalent: "")
phaseReplacementItem.state = Preferences.phraseReplacementEnabled.state phaseReplacementItem.state = Preferences.phraseReplacementEnabled.state
@ -200,7 +204,7 @@ class ctlInputMethod: IMKInputController {
var textFrame = NSRect.zero var textFrame = NSRect.zero
let attributes: [AnyHashable: Any]? = (client as? IMKTextInput)?.attributes(forCharacterIndex: 0, lineHeightRectangle: &textFrame) let attributes: [AnyHashable: Any]? = (client as? IMKTextInput)?.attributes(forCharacterIndex: 0, lineHeightRectangle: &textFrame)
let useVerticalMode = (attributes?["IMKTextOrientation"] as? NSNumber)?.intValue == 0 || false let useVerticalMode = (attributes?["IMKTextOrientation"] as? NSNumber)?.intValue == 0 || false
if (client as? IMKTextInput)?.bundleIdentifier() == "org.atelierInmu.vChewing.vChewingPhraseEditor" { if (client as? IMKTextInput)?.bundleIdentifier() == "org.atelierInmu.vChewing.vChewingPhraseEditor" {
ctlInputMethod.areWeUsingOurOwnPhraseEditor = true ctlInputMethod.areWeUsingOurOwnPhraseEditor = true
} else { } else {
@ -249,6 +253,10 @@ class ctlInputMethod: IMKInputController {
NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("Per-Char Associated Phrases", comment: ""), "\n", Preferences.toggleAssociatedPhrasesEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: ""))) NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("Per-Char Associated Phrases", comment: ""), "\n", Preferences.toggleAssociatedPhrasesEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: "")))
} }
@objc func toggleAlphanumericalModeEnabled(_ sender: Any?) {
Preferences.toggleAlphanumericalModeEnabled()
}
@objc func togglePhraseReplacement(_ sender: Any?) { @objc func togglePhraseReplacement(_ sender: Any?) {
mgrLangModel.setPhraseReplacementEnabled(Preferences.togglePhraseReplacementEnabled()) mgrLangModel.setPhraseReplacementEnabled(Preferences.togglePhraseReplacementEnabled())
} }