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