From 1d593b490f6e3d02941431eb8c6279665b711b36 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Sun, 27 Nov 2022 19:42:25 +0800 Subject: [PATCH] SessionCtl // Add candidatePairRightClicked(). --- .../Protocols/CtlCandidateProtocol.swift | 7 +++ Source/Modules/SessionCtl_Delegates.swift | 51 +++++++++++++++++++ .../Resources/Base.lproj/Localizable.strings | 6 +++ Source/Resources/en.lproj/Localizable.strings | 6 +++ Source/Resources/ja.lproj/Localizable.strings | 6 +++ .../zh-Hans.lproj/Localizable.strings | 6 +++ .../zh-Hant.lproj/Localizable.strings | 6 +++ 7 files changed, 88 insertions(+) diff --git a/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift b/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift index 6c6500a0..5ad0602b 100644 --- a/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift +++ b/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift @@ -11,6 +11,7 @@ import Cocoa public protocol CtlCandidateDelegate { func candidatePairs(conv: Bool) -> [(String, String)] func candidatePairSelected(at index: Int) + func candidatePairRightClicked(at index: Int, action: CandidateContextMenuAction) func candidates(_ sender: Any!) -> [Any]! @discardableResult func reverseLookup(for value: String) -> [String] var selectionKeys: String { get } @@ -44,3 +45,9 @@ public protocol CtlCandidateProtocol { func candidateIndexAtKeyLabelIndex(_: Int) -> Int func set(windowTopLeftPoint: NSPoint, bottomOutOfScreenAdjustmentHeight height: Double, useGCD: Bool) } + +public enum CandidateContextMenuAction { + case toBoost + case toNerf + case toFilter +} diff --git a/Source/Modules/SessionCtl_Delegates.swift b/Source/Modules/SessionCtl_Delegates.swift index 1a3287a2..353f8167 100644 --- a/Source/Modules/SessionCtl_Delegates.swift +++ b/Source/Modules/SessionCtl_Delegates.swift @@ -154,4 +154,55 @@ extension SessionCtl: CtlCandidateDelegate { switchState(IMEState.ofEmpty()) } } + + public func candidatePairRightClicked(at index: Int, action: CandidateContextMenuAction) { + guard isCandidateContextMenuEnabled else { return } + var succeeded = true + + let rawPair = state.candidates[index] + let valueCurrent = rawPair.1 + let valueReversed = ChineseConverter.crossConvert(rawPair.1) + let nerfedScore = (action == .toNerf) ? " -114.514" : "" + let convertedMark = "#๐™ƒ๐™ช๐™ข๐™–๐™ฃ๐˜พ๐™๐™š๐™˜๐™ ๐™๐™š๐™ฆ๐™ช๐™ž๐™ง๐™š๐™™" + + let userPhraseDumped = "\(valueCurrent) \(rawPair.0)\(nerfedScore)" + let userPhraseDumpedConverted = "\(valueReversed) \(rawPair.0)\(nerfedScore)\t\(convertedMark)" + + if !LMMgr.writeUserPhrase( + userPhraseDumped, inputMode: inputMode, + areWeDuplicating: action != .toFilter, + areWeDeleting: action == .toFilter + ) + || !LMMgr.writeUserPhrase( + userPhraseDumpedConverted, inputMode: inputMode.reversed, + areWeDuplicating: action != .toFilter, + areWeDeleting: action == .toFilter + ) + { + succeeded = false + } + + // ้–‹ๅง‹้‡ๅฐไฝฟ็”จ่€…ๅŠ่กฐๆจก็ต„็š„ๆธ…่ฉž่™•็† + LMMgr.bleachSpecifiedSuggestions(targets: [valueCurrent], mode: IMEApp.currentInputMode) + LMMgr.bleachSpecifiedSuggestions(targets: [valueReversed], mode: IMEApp.currentInputMode.reversed) + // ๆธ…่ฉžๅฎŒ็•ข + + var newState = IMEState.ofCommitting(textToCommit: state.displayedText) + newState.tooltipDuration = 1.85 + var tooltipMessage = "" + switch action { + case .toBoost: + newState.data.tooltipColorState = .normal + tooltipMessage = succeeded ? "+ Succeeded in boosting a candidate." : "โš ๏ธŽ Failed from boosting a candidate." + case .toNerf: + newState.data.tooltipColorState = .succeeded + tooltipMessage = succeeded ? "- Succeeded in nerfing a candidate." : "โš ๏ธŽ Failed from nerfing a candidate." + case .toFilter: + newState.data.tooltipColorState = .warning + tooltipMessage = succeeded ? "! Succeeded in filtering a candidate." : "โš ๏ธŽ Failed from filtering a candidate." + } + if !succeeded { newState.data.tooltipColorState = .redAlert } + newState.tooltip = NSLocalizedString(tooltipMessage, comment: "") + "ใ€€ใ€€" + switchState(newState) + } } diff --git a/Source/Resources/Base.lproj/Localizable.strings b/Source/Resources/Base.lproj/Localizable.strings index d6cc012a..55662489 100644 --- a/Source/Resources/Base.lproj/Localizable.strings +++ b/Source/Resources/Base.lproj/Localizable.strings @@ -1,4 +1,10 @@ "vChewing" = "vChewing"; +"โš ๏ธŽ Failed from boosting a candidate." = "โš ๏ธŽ Failed from boosting a candidate."; +"โš ๏ธŽ Failed from nerfing a candidate." = "โš ๏ธŽ Failed from nerfing a candidate."; +"โš ๏ธŽ Failed from filtering a candidate." = "โš ๏ธŽ Failed from filtering a candidate."; +"+ Succeeded in boosting a candidate." = "+ Succeeded in boosting a candidate."; +"- Succeeded in nerfing a candidate." = "- Succeeded in nerfing a candidate."; +"! Succeeded in filtering a candidate." = "! Succeeded in filtering a candidate."; "! Succeeded in filtering a user phrase." = "! Succeeded in filtering a user phrase."; "- Succeeded in nerfing a user phrase." = "- Succeeded in nerfing a user phrase."; "+ Succeeded in adding / boosting a user phrase." = "+ Succeeded in adding / boosting a user phrase."; diff --git a/Source/Resources/en.lproj/Localizable.strings b/Source/Resources/en.lproj/Localizable.strings index d6cc012a..55662489 100644 --- a/Source/Resources/en.lproj/Localizable.strings +++ b/Source/Resources/en.lproj/Localizable.strings @@ -1,4 +1,10 @@ "vChewing" = "vChewing"; +"โš ๏ธŽ Failed from boosting a candidate." = "โš ๏ธŽ Failed from boosting a candidate."; +"โš ๏ธŽ Failed from nerfing a candidate." = "โš ๏ธŽ Failed from nerfing a candidate."; +"โš ๏ธŽ Failed from filtering a candidate." = "โš ๏ธŽ Failed from filtering a candidate."; +"+ Succeeded in boosting a candidate." = "+ Succeeded in boosting a candidate."; +"- Succeeded in nerfing a candidate." = "- Succeeded in nerfing a candidate."; +"! Succeeded in filtering a candidate." = "! Succeeded in filtering a candidate."; "! Succeeded in filtering a user phrase." = "! Succeeded in filtering a user phrase."; "- Succeeded in nerfing a user phrase." = "- Succeeded in nerfing a user phrase."; "+ Succeeded in adding / boosting a user phrase." = "+ Succeeded in adding / boosting a user phrase."; diff --git a/Source/Resources/ja.lproj/Localizable.strings b/Source/Resources/ja.lproj/Localizable.strings index 6428d3ee..244080ac 100644 --- a/Source/Resources/ja.lproj/Localizable.strings +++ b/Source/Resources/ja.lproj/Localizable.strings @@ -1,4 +1,10 @@ "vChewing" = "ๅจๆณจ้Ÿณๅ…ฅๅŠ›ใ‚ขใƒ—ใƒช"; +"โš ๏ธŽ Failed from boosting a candidate." = "โš ๏ธŽ ๆŒ‡ๅฎšใ•ใ‚ŒใŸๆ–‡ๅญ—ๅ€™่ฃœใฎ้ †ไฝใฏๆœ€ๅ„ชๅ…ˆใซใงใใพใ›ใ‚“ใงใ—ใŸใ€‚"; +"โš ๏ธŽ Failed from nerfing a candidate." = "โš ๏ธŽ ๆŒ‡ๅฎšใ•ใ‚ŒใŸๆ–‡ๅญ—ๅ€™่ฃœใฎๅ„ชๅ…ˆ้ †ไฝใ‚’ไธ‹ใ’ใ‚‹ใ“ใจใซๅคฑๆ•—ใ—ใ—ใพใ—ใŸใ€‚"; +"โš ๏ธŽ Failed from filtering a candidate." = "โš ๏ธŽ ๆŒ‡ๅฎšใ•ใ‚ŒใŸๆ–‡ๅญ—ๅ€™่ฃœใฏๆŽ’้™ค่กจใซ็™ป้Œฒใงใใพใ›ใ‚“ใงใ—ใŸใ€‚"; +"+ Succeeded in boosting a candidate." = "+ ๆŒ‡ๅฎšใ•ใ‚ŒใŸๆ–‡ๅญ—ๅ€™่ฃœใฎ้ †ไฝใฏๆœ€ๅ„ชๅ…ˆใซใ—ใพใ—ใŸใ€‚"; +"- Succeeded in nerfing a candidate." = "- ๆŒ‡ๅฎšใ•ใ‚ŒใŸๆ–‡ๅญ—ๅ€™่ฃœใฎๅ„ชๅ…ˆ้ †ไฝใ‚’ไธ‹ใ’ใพใ—ใŸใ€‚"; +"! Succeeded in filtering a candidate." = "! ๆŒ‡ๅฎšใ•ใ‚ŒใŸๆ–‡ๅญ—ๅ€™่ฃœใฏๆŽ’้™ค่กจใซ็™ป้Œฒใ—ใพใ—ใŸใ€‚"; "! Succeeded in filtering a user phrase." = "! ใ“ใฎ่ชžๅฝ™ใฏๆŽ’้™ค่กจใซ็™ป้ŒฒๅฎŒไบ†ใ€‚"; "- Succeeded in nerfing a user phrase." = "- ใ“ใฎ่ชžๅฝ™ใฎ๏ผˆๅ€™่ฃœใจใ—ใฆใฎ๏ผ‰ๅ„ชๅ…ˆ้ †ไฝใ‚’ไธ‹ใ’ใพใ—ใŸใ€‚"; "+ Succeeded in adding / boosting a user phrase." = "+ ๆ–ฐใ—ใ„ใƒฆใƒผใ‚ถใƒผๅ€™่ฃœใ‚’็™ป้ŒฒๅฎŒไบ†ใ€\nๆˆ–ใ„ใฏใใฎๆ—ขๅญ˜ๅ€™่ฃœใฎ้ †ไฝใ‚’ๆœ€ๅ„ชๅ…ˆใซใ—ใพใ—ใŸใ€‚"; diff --git a/Source/Resources/zh-Hans.lproj/Localizable.strings b/Source/Resources/zh-Hans.lproj/Localizable.strings index 1eec306a..d0d2f962 100644 --- a/Source/Resources/zh-Hans.lproj/Localizable.strings +++ b/Source/Resources/zh-Hans.lproj/Localizable.strings @@ -1,4 +1,10 @@ "vChewing" = "ๅจๆณจ้Ÿณ่พ“ๅ…ฅๆณ•"; +"โš ๏ธŽ Failed from boosting a candidate." = "โš ๏ธŽ ๅ€™้€‰ๅญ—่ฏๆๆƒๅคฑ่ดฅใ€‚"; +"โš ๏ธŽ Failed from nerfing a candidate." = "โš ๏ธŽ ๅ€™้€‰ๅญ—่ฏ้™ๆƒๅคฑ่ดฅใ€‚"; +"โš ๏ธŽ Failed from filtering a candidate." = "โš ๏ธŽ ๅ€™้€‰ๅญ—่ฏๆปค้™คๅคฑ่ดฅใ€‚"; +"+ Succeeded in boosting a candidate." = "+ ๅ€™้€‰ๅญ—่ฏๆๆƒๆˆๅŠŸใ€‚"; +"- Succeeded in nerfing a candidate." = "- ๅ€™้€‰ๅญ—่ฏ้™ๆƒๆˆๅŠŸใ€‚"; +"! Succeeded in filtering a candidate." = "! ๅ€™้€‰ๅญ—่ฏๆปค้™คๆˆๅŠŸใ€‚"; "! Succeeded in filtering a user phrase." = "! ๆˆๅŠŸๆปค้™ค่ฏฅ่ฏ้Ÿณ้…ๅฏนใ€‚"; "- Succeeded in nerfing a user phrase." = "- ๆˆๅŠŸๅฐ†่ฏฅ่ฏ้Ÿณ้…ๅฏน้™ๆƒๅค„็†ใ€‚"; "+ Succeeded in adding / boosting a user phrase." = "+ ๆˆๅŠŸๆทปๅ…ฅไฝฟ็”จ่€…่ฏญๆฑ‡๏ผˆๆˆ–ไฝฟๅ…ถๅ‡ๆƒ๏ผ‰ใ€‚"; diff --git a/Source/Resources/zh-Hant.lproj/Localizable.strings b/Source/Resources/zh-Hant.lproj/Localizable.strings index 357ebb14..47a169a5 100644 --- a/Source/Resources/zh-Hant.lproj/Localizable.strings +++ b/Source/Resources/zh-Hant.lproj/Localizable.strings @@ -1,4 +1,10 @@ "vChewing" = "ๅจๆณจ้Ÿณ่ผธๅ…ฅๆณ•"; +"โš ๏ธŽ Failed from boosting a candidate." = "โš ๏ธŽ ๅ€™้ธๅญ—่ฉžๆๆฌŠๅคฑๆ•—ใ€‚"; +"โš ๏ธŽ Failed from nerfing a candidate." = "โš ๏ธŽ ๅ€™้ธๅญ—่ฉž้™ๆฌŠๅคฑๆ•—ใ€‚"; +"โš ๏ธŽ Failed from filtering a candidate." = "โš ๏ธŽ ๅ€™้ธๅญ—่ฉžๆฟพ้™คๅคฑๆ•—ใ€‚"; +"+ Succeeded in boosting a candidate." = "+ ๅ€™้ธๅญ—่ฉžๆๆฌŠๆˆๅŠŸใ€‚"; +"- Succeeded in nerfing a candidate." = "- ๅ€™้ธๅญ—่ฉž้™ๆฌŠๆˆๅŠŸใ€‚"; +"! Succeeded in filtering a candidate." = "! ๅ€™้ธๅญ—่ฉžๆฟพ้™คๆˆๅŠŸใ€‚"; "! Succeeded in filtering a user phrase." = "! ๆˆๅŠŸๆฟพ้™ค่ฉฒ่ฉž้Ÿณ้…ๅฐใ€‚"; "- Succeeded in nerfing a user phrase." = "- ๆˆๅŠŸๅฐ‡่ฉฒ่ฉž้Ÿณ้…ๅฐ้™ๆฌŠ่™•็†ใ€‚"; "+ Succeeded in adding / boosting a user phrase." = "+ ๆˆๅŠŸๆทปๅ…ฅไฝฟ็”จ่€…่ชžๅฝ™๏ผˆๆˆ–ไฝฟๅ…ถๅ‡ๆฌŠ๏ผ‰ใ€‚";