SessionCtl // Update certain menu titles.

This commit is contained in:
ShikiSuen 2022-12-10 21:02:16 +08:00
parent 5e1ef36441
commit 16162cd9ca
1 changed files with 59 additions and 61 deletions

View File

@ -28,14 +28,14 @@ extension SessionCtl {
let menu = NSMenu(title: "Input Method Menu") let menu = NSMenu(title: "Input Method Menu")
let useSCPCTypingModeItem = menu.addItem( let useSCPCTypingModeItem = menu.addItem(
withTitle: NSLocalizedString("Per-Char Select Mode", comment: ""), withTitle: "Per-Char Select Mode".localized,
action: #selector(toggleSCPCTypingMode(_:)), keyEquivalent: PrefMgr.shared.usingHotKeySCPC ? "P" : "" action: #selector(toggleSCPCTypingMode(_:)), keyEquivalent: PrefMgr.shared.usingHotKeySCPC ? "P" : ""
) )
useSCPCTypingModeItem.keyEquivalentModifierMask = [.command, .control] useSCPCTypingModeItem.keyEquivalentModifierMask = [.command, .control]
useSCPCTypingModeItem.state = PrefMgr.shared.useSCPCTypingMode.state useSCPCTypingModeItem.state = PrefMgr.shared.useSCPCTypingMode.state
let userAssociatedPhrasesItem = menu.addItem( let userAssociatedPhrasesItem = menu.addItem(
withTitle: NSLocalizedString("Per-Char Associated Phrases", comment: ""), withTitle: "Per-Char Associated Phrases".localized,
action: #selector(toggleAssociatedPhrasesEnabled(_:)), action: #selector(toggleAssociatedPhrasesEnabled(_:)),
keyEquivalent: PrefMgr.shared.usingHotKeyAssociates ? "O" : "" keyEquivalent: PrefMgr.shared.usingHotKeyAssociates ? "O" : ""
) )
@ -43,7 +43,7 @@ extension SessionCtl {
userAssociatedPhrasesItem.state = PrefMgr.shared.associatedPhrasesEnabled.state userAssociatedPhrasesItem.state = PrefMgr.shared.associatedPhrasesEnabled.state
let cassetteModeItem = menu.addItem( let cassetteModeItem = menu.addItem(
withTitle: NSLocalizedString("CIN Cassette Mode", comment: ""), withTitle: "CIN Cassette Mode".localized,
action: #selector(toggleCassetteMode(_:)), action: #selector(toggleCassetteMode(_:)),
keyEquivalent: PrefMgr.shared.usingHotKeyCassette ? "I" : "" keyEquivalent: PrefMgr.shared.usingHotKeyCassette ? "I" : ""
) )
@ -51,7 +51,7 @@ extension SessionCtl {
cassetteModeItem.state = PrefMgr.shared.cassetteEnabled.state cassetteModeItem.state = PrefMgr.shared.cassetteEnabled.state
let useCNS11643SupportItem = menu.addItem( let useCNS11643SupportItem = menu.addItem(
withTitle: NSLocalizedString("CNS11643 Mode", comment: ""), withTitle: "CNS11643 Mode".localized,
action: #selector(toggleCNS11643Enabled(_:)), keyEquivalent: PrefMgr.shared.usingHotKeyCNS ? "L" : "" action: #selector(toggleCNS11643Enabled(_:)), keyEquivalent: PrefMgr.shared.usingHotKeyCNS ? "L" : ""
) )
useCNS11643SupportItem.keyEquivalentModifierMask = [.command, .control] useCNS11643SupportItem.keyEquivalentModifierMask = [.command, .control]
@ -59,14 +59,13 @@ extension SessionCtl {
if IMEApp.currentInputMode == .imeModeCHT { if IMEApp.currentInputMode == .imeModeCHT {
let chineseConversionItem = menu.addItem( let chineseConversionItem = menu.addItem(
withTitle: NSLocalizedString("Force KangXi Writing", comment: ""), withTitle: "Force KangXi Writing".localized,
action: #selector(toggleChineseConverter(_:)), keyEquivalent: PrefMgr.shared.usingHotKeyKangXi ? "K" : "" action: #selector(toggleChineseConverter(_:)), keyEquivalent: PrefMgr.shared.usingHotKeyKangXi ? "K" : ""
) )
chineseConversionItem.keyEquivalentModifierMask = [.command, .control] chineseConversionItem.keyEquivalentModifierMask = [.command, .control]
chineseConversionItem.state = PrefMgr.shared.chineseConversionEnabled.state chineseConversionItem.state = PrefMgr.shared.chineseConversionEnabled.state
let shiftJISConversionItem = menu.addItem( let shiftJISConversionItem = menu.addItem(
withTitle: NSLocalizedString("JIS Shinjitai Output", comment: ""), withTitle: "JIS Shinjitai Output".localized,
action: #selector(toggleShiftJISShinjitaiOutput(_:)), keyEquivalent: PrefMgr.shared.usingHotKeyJIS ? "J" : "" action: #selector(toggleShiftJISShinjitaiOutput(_:)), keyEquivalent: PrefMgr.shared.usingHotKeyJIS ? "J" : ""
) )
shiftJISConversionItem.keyEquivalentModifierMask = [.command, .control] shiftJISConversionItem.keyEquivalentModifierMask = [.command, .control]
@ -74,7 +73,7 @@ extension SessionCtl {
} }
let currencyNumeralsItem = menu.addItem( let currencyNumeralsItem = menu.addItem(
withTitle: NSLocalizedString("Currency Numeral Output", comment: ""), withTitle: "Currency Numeral Output".localized,
action: #selector(toggleCurrencyNumerals(_:)), action: #selector(toggleCurrencyNumerals(_:)),
keyEquivalent: PrefMgr.shared.usingHotKeyCurrencyNumerals ? "M" : "" keyEquivalent: PrefMgr.shared.usingHotKeyCurrencyNumerals ? "M" : ""
) )
@ -82,7 +81,7 @@ extension SessionCtl {
currencyNumeralsItem.state = PrefMgr.shared.currencyNumeralsEnabled.state currencyNumeralsItem.state = PrefMgr.shared.currencyNumeralsEnabled.state
let halfWidthPunctuationItem = menu.addItem( let halfWidthPunctuationItem = menu.addItem(
withTitle: NSLocalizedString("Half-Width Punctuation Mode", comment: ""), withTitle: "Half-Width Punctuation Mode".localized,
action: #selector(toggleHalfWidthPunctuation(_:)), action: #selector(toggleHalfWidthPunctuation(_:)),
keyEquivalent: PrefMgr.shared.usingHotKeyHalfWidthASCII ? "H" : "" keyEquivalent: PrefMgr.shared.usingHotKeyHalfWidthASCII ? "H" : ""
) )
@ -91,7 +90,7 @@ extension SessionCtl {
if optionKeyPressed || PrefMgr.shared.phraseReplacementEnabled { if optionKeyPressed || PrefMgr.shared.phraseReplacementEnabled {
let phaseReplacementItem = menu.addItem( let phaseReplacementItem = menu.addItem(
withTitle: NSLocalizedString("Use Phrase Replacement", comment: ""), withTitle: "Use Phrase Replacement".localized,
action: #selector(togglePhraseReplacement(_:)), keyEquivalent: "" action: #selector(togglePhraseReplacement(_:)), keyEquivalent: ""
) )
phaseReplacementItem.state = PrefMgr.shared.phraseReplacementEnabled.state phaseReplacementItem.state = PrefMgr.shared.phraseReplacementEnabled.state
@ -99,7 +98,7 @@ extension SessionCtl {
if optionKeyPressed { if optionKeyPressed {
let toggleSymbolInputItem = menu.addItem( let toggleSymbolInputItem = menu.addItem(
withTitle: NSLocalizedString("Symbol & Emoji Input", comment: ""), withTitle: "Symbol & Emoji Input".localized,
action: #selector(toggleSymbolEnabled(_:)), keyEquivalent: "" action: #selector(toggleSymbolEnabled(_:)), keyEquivalent: ""
) )
toggleSymbolInputItem.state = PrefMgr.shared.symbolInputEnabled.state toggleSymbolInputItem.state = PrefMgr.shared.symbolInputEnabled.state
@ -108,39 +107,39 @@ extension SessionCtl {
menu.addItem(NSMenuItem.separator()) // --------------------- menu.addItem(NSMenuItem.separator()) // ---------------------
menu.addItem( menu.addItem(
withTitle: NSLocalizedString("Open User Dictionary Folder", comment: ""), withTitle: "Open User Dictionary Folder".localized,
action: #selector(openUserDataFolder(_:)), keyEquivalent: "" action: #selector(openUserDataFolder(_:)), keyEquivalent: ""
) )
menu.addItem( menu.addItem(
withTitle: NSLocalizedString("Edit vChewing User Phrases…", comment: ""), withTitle: "Edit vChewing User Phrases…".localized,
action: #selector(openUserPhrases(_:)), keyEquivalent: "" action: #selector(openUserPhrases(_:)), keyEquivalent: ""
) )
menu.addItem( menu.addItem(
withTitle: NSLocalizedString("Edit Excluded Phrases…", comment: ""), withTitle: "Edit Excluded Phrases…".localized,
action: #selector(openExcludedPhrases(_:)), keyEquivalent: "" action: #selector(openExcludedPhrases(_:)), keyEquivalent: ""
) )
if optionKeyPressed || PrefMgr.shared.associatedPhrasesEnabled { if optionKeyPressed || PrefMgr.shared.associatedPhrasesEnabled {
menu.addItem( menu.addItem(
withTitle: NSLocalizedString("Edit Associated Phrases…", comment: ""), withTitle: "Edit Associated Phrases…".localized,
action: #selector(openAssociatedPhrases(_:)), keyEquivalent: "" action: #selector(openAssociatedPhrases(_:)), keyEquivalent: ""
) )
} }
if optionKeyPressed { if optionKeyPressed {
menu.addItem( menu.addItem(
withTitle: NSLocalizedString("Edit Phrase Replacement Table…", comment: ""), withTitle: "Edit Phrase Replacement Table…".localized,
action: #selector(openPhraseReplacement(_:)), keyEquivalent: "" action: #selector(openPhraseReplacement(_:)), keyEquivalent: ""
) )
menu.addItem( menu.addItem(
withTitle: NSLocalizedString("Edit User Symbol & Emoji Data…", comment: ""), withTitle: "Edit User Symbol & Emoji Data…".localized,
action: #selector(openUserSymbols(_:)), keyEquivalent: "" action: #selector(openUserSymbols(_:)), keyEquivalent: ""
) )
} }
if optionKeyPressed || !PrefMgr.shared.shouldAutoReloadUserDataFiles { if optionKeyPressed || !PrefMgr.shared.shouldAutoReloadUserDataFiles {
menu.addItem( menu.addItem(
withTitle: NSLocalizedString("Reload User Phrases", comment: ""), withTitle: "Reload User Phrases".localized,
action: #selector(reloadUserPhrasesData(_:)), keyEquivalent: "" action: #selector(reloadUserPhrasesData(_:)), keyEquivalent: ""
) )
} }
@ -148,45 +147,45 @@ extension SessionCtl {
menu.addItem(NSMenuItem.separator()) // --------------------- menu.addItem(NSMenuItem.separator()) // ---------------------
menu.addItem( menu.addItem(
withTitle: NSLocalizedString("Optimize Memorized Phrases", comment: ""), withTitle: "Optimize Memorized Phrases".localized,
action: #selector(removeUnigramsFromUOM(_:)), keyEquivalent: "" action: #selector(removeUnigramsFromUOM(_:)), keyEquivalent: ""
) )
menu.addItem( menu.addItem(
withTitle: NSLocalizedString("Clear Memorized Phrases", comment: ""), withTitle: "Clear Memorized Phrases".localized,
action: #selector(clearUOM(_:)), keyEquivalent: "" action: #selector(clearUOM(_:)), keyEquivalent: ""
) )
menu.addItem(NSMenuItem.separator()) // --------------------- menu.addItem(NSMenuItem.separator()) // ---------------------
menu.addItem( menu.addItem(
withTitle: NSLocalizedString("vChewing Preferences…", comment: ""), withTitle: "vChewing Preferences…".localized,
action: #selector(showPreferences(_:)), keyEquivalent: "" action: #selector(showPreferences(_:)), keyEquivalent: ""
) )
menu.addItem( menu.addItem(
withTitle: NSLocalizedString("Client Manager", comment: "") + "", withTitle: "Client Manager".localized.withEllipsis,
action: #selector(showClientListMgr(_:)), keyEquivalent: "" action: #selector(showClientListMgr(_:)), keyEquivalent: ""
) )
if !optionKeyPressed { if !optionKeyPressed {
menu.addItem( menu.addItem(
withTitle: NSLocalizedString("Check for Updates…", comment: ""), withTitle: "Check for Updates…".localized,
action: #selector(checkForUpdate(_:)), keyEquivalent: "" action: #selector(checkForUpdate(_:)), keyEquivalent: ""
) )
} }
menu.addItem( menu.addItem(
withTitle: NSLocalizedString("Reboot vChewing…", comment: ""), withTitle: "Reboot vChewing…".localized,
action: #selector(selfTerminate(_:)), keyEquivalent: "" action: #selector(selfTerminate(_:)), keyEquivalent: ""
) )
menu.addItem( menu.addItem(
withTitle: NSLocalizedString("About vChewing…", comment: ""), withTitle: "About vChewing…".localized,
action: #selector(showAbout(_:)), keyEquivalent: "" action: #selector(showAbout(_:)), keyEquivalent: ""
) )
menu.addItem( menu.addItem(
withTitle: NSLocalizedString("CheatSheet", comment: "") + "", withTitle: "CheatSheet".localized.withEllipsis,
action: #selector(showCheatSheet(_:)), keyEquivalent: "" action: #selector(showCheatSheet(_:)), keyEquivalent: ""
) )
if optionKeyPressed { if optionKeyPressed {
menu.addItem( menu.addItem(
withTitle: NSLocalizedString("Uninstall vChewing…", comment: ""), withTitle: "Uninstall vChewing…".localized,
action: #selector(selfUninstall(_:)), keyEquivalent: "" action: #selector(selfUninstall(_:)), keyEquivalent: ""
) )
} }
@ -227,10 +226,9 @@ extension SessionCtl {
if !PrefMgr.shared.cassetteEnabled, !LMMgr.checkCassettePathValidity(PrefMgr.shared.cassettePath) { if !PrefMgr.shared.cassetteEnabled, !LMMgr.checkCassettePathValidity(PrefMgr.shared.cassettePath) {
DispatchQueue.main.async { DispatchQueue.main.async {
IMEApp.buzz() IMEApp.buzz()
let alert = NSAlert(error: NSLocalizedString("Path invalid or file access error.", comment: "")) let alert = NSAlert(error: "Path invalid or file access error.".localized)
alert.informativeText = NSLocalizedString( let informativeText = "Please reconfigure the cassette path to a valid one before enabling this mode."
"Please reconfigure the cassette path to a valid one before enabling this mode.", comment: "" alert.informativeText = informativeText.localized
)
let result = alert.runModal() let result = alert.runModal()
NSApp.activate(ignoringOtherApps: true) NSApp.activate(ignoringOtherApps: true)
if result == NSApplication.ModalResponse.alertFirstButtonReturn { if result == NSApplication.ModalResponse.alertFirstButtonReturn {
@ -241,10 +239,10 @@ extension SessionCtl {
return return
} }
Notifier.notify( Notifier.notify(
message: NSLocalizedString("CIN Cassette Mode", comment: "") + "\n" message: "CIN Cassette Mode".localized + "\n"
+ (PrefMgr.shared.cassetteEnabled.toggled() + (PrefMgr.shared.cassetteEnabled.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? "NotificationSwitchON".localized
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : "NotificationSwitchOFF".localized)
) )
if !LMMgr.currentLM.isCassetteDataLoaded { if !LMMgr.currentLM.isCassetteDataLoaded {
LMMgr.loadCassetteData() LMMgr.loadCassetteData()
@ -254,90 +252,90 @@ extension SessionCtl {
@objc public func toggleSCPCTypingMode(_: Any? = nil) { @objc public func toggleSCPCTypingMode(_: Any? = nil) {
resetInputHandler(forceComposerCleanup: true) resetInputHandler(forceComposerCleanup: true)
Notifier.notify( Notifier.notify(
message: NSLocalizedString("Per-Char Select Mode", comment: "") + "\n" message: "Per-Char Select Mode".localized + "\n"
+ (PrefMgr.shared.useSCPCTypingMode.toggled() + (PrefMgr.shared.useSCPCTypingMode.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? "NotificationSwitchON".localized
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : "NotificationSwitchOFF".localized)
) )
} }
@objc public func toggleChineseConverter(_: Any? = nil) { @objc public func toggleChineseConverter(_: Any? = nil) {
resetInputHandler(forceComposerCleanup: true) resetInputHandler(forceComposerCleanup: true)
Notifier.notify( Notifier.notify(
message: NSLocalizedString("Force KangXi Writing", comment: "") + "\n" message: "Force KangXi Writing".localized + "\n"
+ (PrefMgr.shared.chineseConversionEnabled.toggled() + (PrefMgr.shared.chineseConversionEnabled.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? "NotificationSwitchON".localized
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : "NotificationSwitchOFF".localized)
) )
} }
@objc public func toggleShiftJISShinjitaiOutput(_: Any? = nil) { @objc public func toggleShiftJISShinjitaiOutput(_: Any? = nil) {
resetInputHandler(forceComposerCleanup: true) resetInputHandler(forceComposerCleanup: true)
Notifier.notify( Notifier.notify(
message: NSLocalizedString("JIS Shinjitai Output", comment: "") + "\n" message: "JIS Shinjitai Output".localized + "\n"
+ (PrefMgr.shared.shiftJISShinjitaiOutputEnabled.toggled() + (PrefMgr.shared.shiftJISShinjitaiOutputEnabled.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? "NotificationSwitchON".localized
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : "NotificationSwitchOFF".localized)
) )
} }
@objc public func toggleCurrencyNumerals(_: Any? = nil) { @objc public func toggleCurrencyNumerals(_: Any? = nil) {
resetInputHandler(forceComposerCleanup: true) resetInputHandler(forceComposerCleanup: true)
Notifier.notify( Notifier.notify(
message: NSLocalizedString("Currency Numeral Output", comment: "") + "\n" message: "Currency Numeral Output".localized + "\n"
+ (PrefMgr.shared.currencyNumeralsEnabled.toggled() + (PrefMgr.shared.currencyNumeralsEnabled.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? "NotificationSwitchON".localized
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : "NotificationSwitchOFF".localized)
) )
} }
@objc public func toggleHalfWidthPunctuation(_: Any? = nil) { @objc public func toggleHalfWidthPunctuation(_: Any? = nil) {
resetInputHandler(forceComposerCleanup: true) resetInputHandler(forceComposerCleanup: true)
Notifier.notify( Notifier.notify(
message: NSLocalizedString("Half-Width Punctuation Mode", comment: "") + "\n" message: "Half-Width Punctuation Mode".localized + "\n"
+ (PrefMgr.shared.halfWidthPunctuationEnabled.toggled() + (PrefMgr.shared.halfWidthPunctuationEnabled.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? "NotificationSwitchON".localized
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : "NotificationSwitchOFF".localized)
) )
} }
@objc public func toggleCNS11643Enabled(_: Any? = nil) { @objc public func toggleCNS11643Enabled(_: Any? = nil) {
resetInputHandler(forceComposerCleanup: true) resetInputHandler(forceComposerCleanup: true)
Notifier.notify( Notifier.notify(
message: NSLocalizedString("CNS11643 Mode", comment: "") + "\n" message: "CNS11643 Mode".localized + "\n"
+ (PrefMgr.shared.cns11643Enabled.toggled() + (PrefMgr.shared.cns11643Enabled.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? "NotificationSwitchON".localized
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : "NotificationSwitchOFF".localized)
) )
} }
@objc public func toggleSymbolEnabled(_: Any? = nil) { @objc public func toggleSymbolEnabled(_: Any? = nil) {
resetInputHandler(forceComposerCleanup: true) resetInputHandler(forceComposerCleanup: true)
Notifier.notify( Notifier.notify(
message: NSLocalizedString("Symbol & Emoji Input", comment: "") + "\n" message: "Symbol & Emoji Input".localized + "\n"
+ (PrefMgr.shared.symbolInputEnabled.toggled() + (PrefMgr.shared.symbolInputEnabled.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? "NotificationSwitchON".localized
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : "NotificationSwitchOFF".localized)
) )
} }
@objc public func toggleAssociatedPhrasesEnabled(_: Any? = nil) { @objc public func toggleAssociatedPhrasesEnabled(_: Any? = nil) {
resetInputHandler(forceComposerCleanup: true) resetInputHandler(forceComposerCleanup: true)
Notifier.notify( Notifier.notify(
message: NSLocalizedString("Per-Char Associated Phrases", comment: "") + "\n" message: "Per-Char Associated Phrases".localized + "\n"
+ (PrefMgr.shared.associatedPhrasesEnabled.toggled() + (PrefMgr.shared.associatedPhrasesEnabled.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? "NotificationSwitchON".localized
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : "NotificationSwitchOFF".localized)
) )
} }
@objc public func togglePhraseReplacement(_: Any? = nil) { @objc public func togglePhraseReplacement(_: Any? = nil) {
resetInputHandler(forceComposerCleanup: true) resetInputHandler(forceComposerCleanup: true)
Notifier.notify( Notifier.notify(
message: NSLocalizedString("Use Phrase Replacement", comment: "") + "\n" message: "Use Phrase Replacement".localized + "\n"
+ (PrefMgr.shared.phraseReplacementEnabled.toggled() + (PrefMgr.shared.phraseReplacementEnabled.toggled()
? NSLocalizedString("NotificationSwitchON", comment: "") ? "NotificationSwitchON".localized
: NSLocalizedString("NotificationSwitchOFF", comment: "")) : "NotificationSwitchOFF".localized)
) )
} }