SessionCtl // Remove useless delegate symbols, etc.
This commit is contained in:
parent
216fe6e1ba
commit
b8ddfcabbf
|
@ -433,7 +433,7 @@ public class CtlCandidateUniversal: CtlCandidate {
|
|||
@discardableResult override public func highlightNextCandidate() -> Bool {
|
||||
guard let delegate = delegate else { return false }
|
||||
selectedCandidateIndex =
|
||||
(selectedCandidateIndex + 1 >= delegate.candidateCountForController(self))
|
||||
(selectedCandidateIndex + 1 >= delegate.candidatePairs().count)
|
||||
? 0 : selectedCandidateIndex + 1
|
||||
return true
|
||||
}
|
||||
|
@ -442,7 +442,7 @@ public class CtlCandidateUniversal: CtlCandidate {
|
|||
guard let delegate = delegate else { return false }
|
||||
selectedCandidateIndex =
|
||||
(selectedCandidateIndex == 0)
|
||||
? delegate.candidateCountForController(self) - 1 : selectedCandidateIndex - 1
|
||||
? delegate.candidatePairs().count - 1 : selectedCandidateIndex - 1
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -452,7 +452,7 @@ public class CtlCandidateUniversal: CtlCandidate {
|
|||
}
|
||||
|
||||
let result = currentPageIndex * keyLabels.count + index
|
||||
return result < delegate.candidateCountForController(self) ? result : Int.max
|
||||
return result < delegate.candidatePairs().count ? result : Int.max
|
||||
}
|
||||
|
||||
override public var selectedCandidateIndex: Int {
|
||||
|
@ -464,7 +464,7 @@ public class CtlCandidateUniversal: CtlCandidate {
|
|||
return
|
||||
}
|
||||
let keyLabelCount = keyLabels.count
|
||||
if newValue < delegate.candidateCountForController(self) {
|
||||
if newValue < delegate.candidatePairs().count {
|
||||
currentPageIndex = newValue / keyLabelCount
|
||||
candidateView.highlightedIndex = newValue % keyLabelCount
|
||||
layoutCandidateView()
|
||||
|
@ -478,7 +478,7 @@ extension CtlCandidateUniversal {
|
|||
guard let delegate = delegate else {
|
||||
return 0
|
||||
}
|
||||
let totalCount = delegate.candidateCountForController(self)
|
||||
let totalCount = delegate.candidatePairs().count
|
||||
let keyLabelCount = keyLabels.count
|
||||
return totalCount / keyLabelCount + ((totalCount % keyLabelCount) != 0 ? 1 : 0)
|
||||
}
|
||||
|
@ -487,7 +487,7 @@ extension CtlCandidateUniversal {
|
|||
guard let delegate = delegate else {
|
||||
return 0
|
||||
}
|
||||
let totalCount = delegate.candidateCountForController(self)
|
||||
let totalCount = delegate.candidatePairs().count
|
||||
let keyLabelCount = keyLabels.count
|
||||
return totalCount % keyLabelCount
|
||||
}
|
||||
|
@ -497,12 +497,12 @@ extension CtlCandidateUniversal {
|
|||
|
||||
candidateView.set(keyLabelFont: keyLabelFont, candidateFont: candidateFont)
|
||||
var candidates = [(String, String)]()
|
||||
let count = delegate.candidateCountForController(self)
|
||||
let count = delegate.candidatePairs().count
|
||||
let keyLabelCount = keyLabels.count
|
||||
|
||||
let begin = currentPageIndex * keyLabelCount
|
||||
for index in begin..<min(begin + keyLabelCount, count) {
|
||||
let candidate = delegate.ctlCandidate(self, candidateAtIndex: index)
|
||||
let candidate = delegate.candidatePairAt(index)
|
||||
candidates.append(candidate)
|
||||
}
|
||||
candidateView.set(
|
||||
|
@ -591,6 +591,6 @@ extension CtlCandidateUniversal {
|
|||
}
|
||||
|
||||
@objc private func candidateViewMouseDidClick(_: Any) {
|
||||
delegate?.candidateSelected(at: selectedCandidateIndex)
|
||||
delegate?.candidatePairSelected(at: selectedCandidateIndex)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,9 @@
|
|||
import Cocoa
|
||||
|
||||
public protocol CtlCandidateDelegate: AnyObject {
|
||||
func candidateCountForController(_ controller: CtlCandidateProtocol) -> Int
|
||||
func candidatesForController(_ controller: CtlCandidateProtocol) -> [(String, String)]
|
||||
func ctlCandidate(_ controller: CtlCandidateProtocol, candidateAtIndex index: Int)
|
||||
-> (String, String)
|
||||
func candidateSelected(at index: Int)
|
||||
func candidatePairs() -> [(String, String)]
|
||||
func candidatePairAt(_ index: Int) -> (String, String)
|
||||
func candidatePairSelected(at index: Int)
|
||||
func buzz()
|
||||
func kanjiConversionIfRequired(_ target: String) -> String
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import Tekkon
|
|||
/// KeyHandler 委任協定
|
||||
public protocol KeyHandlerDelegate {
|
||||
var clientBundleIdentifier: String { get }
|
||||
func ctlCandidate() -> CtlCandidateProtocol
|
||||
func candidateController() -> CtlCandidateProtocol
|
||||
func candidateSelectionCalledByKeyHandler(at index: Int)
|
||||
func performUserPhraseOperation(with state: IMEStateProtocol, addToFilter: Bool)
|
||||
-> Bool
|
||||
|
|
|
@ -26,7 +26,7 @@ extension KeyHandler {
|
|||
stateCallback: @escaping (IMEStateProtocol) -> Void,
|
||||
errorCallback: @escaping (String) -> Void
|
||||
) -> Bool {
|
||||
guard var ctlCandidate = delegate?.ctlCandidate() else {
|
||||
guard var ctlCandidate = delegate?.candidateController() else {
|
||||
errorCallback("06661F6E")
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -18,25 +18,23 @@ extension SessionCtl: KeyHandlerDelegate {
|
|||
return client.bundleIdentifier() ?? ""
|
||||
}
|
||||
|
||||
func ctlCandidate() -> CtlCandidateProtocol { Self.ctlCandidateCurrent }
|
||||
func candidateController() -> CtlCandidateProtocol { Self.ctlCandidateCurrent }
|
||||
|
||||
func candidateSelectionCalledByKeyHandler(at index: Int) {
|
||||
candidateSelected(at: index)
|
||||
candidatePairSelected(at: index)
|
||||
}
|
||||
|
||||
func performUserPhraseOperation(with state: IMEStateProtocol, addToFilter: Bool)
|
||||
-> Bool
|
||||
{
|
||||
guard state.type == .ofMarking else { return false }
|
||||
let refInputModeReversed: Shared.InputMode =
|
||||
(inputMode == .imeModeCHT) ? .imeModeCHS : .imeModeCHT
|
||||
if !LMMgr.writeUserPhrase(
|
||||
state.data.userPhraseDumped, inputMode: inputMode,
|
||||
areWeDuplicating: state.data.doesUserPhraseExist,
|
||||
areWeDeleting: addToFilter
|
||||
)
|
||||
|| !LMMgr.writeUserPhrase(
|
||||
state.data.userPhraseDumpedConverted, inputMode: refInputModeReversed,
|
||||
state.data.userPhraseDumpedConverted, inputMode: inputMode.reversed,
|
||||
areWeDuplicating: false,
|
||||
areWeDeleting: addToFilter
|
||||
)
|
||||
|
@ -58,36 +56,18 @@ extension SessionCtl: CtlCandidateDelegate {
|
|||
ChineseConverter.kanjiConversionIfRequired(target)
|
||||
}
|
||||
|
||||
func candidateCountForController(_ controller: CtlCandidateProtocol) -> Int {
|
||||
_ = controller // 防止格式整理工具毀掉與此對應的參數。
|
||||
if state.isCandidateContainer {
|
||||
return state.candidates.count
|
||||
}
|
||||
return 0
|
||||
func candidatePairs() -> [(String, String)] {
|
||||
state.isCandidateContainer ? state.candidates : []
|
||||
}
|
||||
|
||||
/// 直接給出全部的候選字詞的字音配對陣列
|
||||
/// - Parameter controller: 對應的控制器。因為有唯一解,所以填錯了也不會有影響。
|
||||
/// - Returns: 候選字詞陣列(字音配對)。
|
||||
func candidatesForController(_ controller: CtlCandidateProtocol) -> [(String, String)] {
|
||||
_ = controller // 防止格式整理工具毀掉與此對應的參數。
|
||||
if state.isCandidateContainer {
|
||||
return state.candidates
|
||||
}
|
||||
return .init()
|
||||
}
|
||||
|
||||
func ctlCandidate(_ controller: CtlCandidateProtocol, candidateAtIndex index: Int)
|
||||
-> (String, String)
|
||||
{
|
||||
_ = controller // 防止格式整理工具毀掉與此對應的參數。
|
||||
if state.isCandidateContainer {
|
||||
func candidatePairAt(_ index: Int) -> (String, String) {
|
||||
if state.isCandidateContainer, state.candidates.count > index {
|
||||
return state.candidates[index]
|
||||
}
|
||||
return ("", "")
|
||||
}
|
||||
|
||||
func candidateSelected(at index: Int) {
|
||||
func candidatePairSelected(at index: Int) {
|
||||
if state.type == .ofSymbolTable, (0..<state.node.members.count).contains(index) {
|
||||
let node = state.node.members[index]
|
||||
if !node.members.isEmpty {
|
||||
|
|
|
@ -124,6 +124,6 @@ extension SessionCtl {
|
|||
handleIMKCandidatesSelected(state.candidates)
|
||||
}
|
||||
}
|
||||
candidateSelected(at: indexDeducted)
|
||||
candidatePairSelected(at: indexDeducted)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ public class CtlCandidateIMK: IMKCandidates, CtlCandidateProtocol {
|
|||
|
||||
private var pageCount: Int {
|
||||
guard let delegate = delegate else { return 0 }
|
||||
let totalCount = delegate.candidateCountForController(self)
|
||||
let totalCount = delegate.candidatePairs().count
|
||||
let keyLabelCount = keyLabels.count
|
||||
return totalCount / keyLabelCount + ((totalCount % keyLabelCount) != 0 ? 1 : 0)
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ public class CtlCandidateIMK: IMKCandidates, CtlCandidateProtocol {
|
|||
public func candidateIndexAtKeyLabelIndex(_ index: Int) -> Int {
|
||||
guard let delegate = delegate else { return Int.max }
|
||||
let result = currentPageIndex * keyLabels.count + index
|
||||
return result < delegate.candidateCountForController(self) ? result : Int.max
|
||||
return result < delegate.candidatePairs().count ? result : Int.max
|
||||
}
|
||||
|
||||
public var selectedCandidateIndex: Int {
|
||||
|
|
Loading…
Reference in New Issue