SessionCtl // Add candidatePairRightClicked().

This commit is contained in:
ShikiSuen 2022-11-27 19:42:25 +08:00
parent dd964b3c40
commit 1d593b490f
7 changed files with 88 additions and 0 deletions

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -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.";

View File

@ -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.";

View File

@ -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或いはその既存候補の順位を最優先にしました。";

View File

@ -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." = "+ 成功添入使用者语汇(或使其升权)。";

View File

@ -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." = "+ 成功添入使用者語彙(或使其升權)。";