SessionCtl // ctlCandidateCurrent -> candidateUI.

This commit is contained in:
ShikiSuen 2022-11-25 11:58:03 +08:00
parent 06e984b6f9
commit 0b2a046885
5 changed files with 25 additions and 25 deletions

View File

@ -29,7 +29,7 @@ public class SessionCtl: IMKInputController {
public static var areWeNerfing = false public static var areWeNerfing = false
/// ///
public var ctlCandidateCurrent: CtlCandidateProtocol = { public var candidateUI: CtlCandidateProtocol = {
let direction: NSUserInterfaceLayoutOrientation = let direction: NSUserInterfaceLayoutOrientation =
PrefMgr.shared.useHorizontalCandidateList ? .horizontal : .vertical PrefMgr.shared.useHorizontalCandidateList ? .horizontal : .vertical
if #available(macOS 10.15, *) { if #available(macOS 10.15, *) {
@ -135,7 +135,7 @@ public class SessionCtl: IMKInputController {
// //
// IMKCandidates // IMKCandidates
if PrefMgr.shared.useIMKCandidateWindow { if PrefMgr.shared.useIMKCandidateWindow {
guard let imkC = ctlCandidateCurrent as? CtlCandidateIMK else { return } guard let imkC = candidateUI as? CtlCandidateIMK else { return }
if state.isCandidateContainer, !imkC.visible { if state.isCandidateContainer, !imkC.visible {
handle(state: state, replace: false) handle(state: state, replace: false)
} }
@ -209,7 +209,8 @@ extension SessionCtl {
// activateServer nil // activateServer nil
// //
if inputHandler.delegate == nil { inputHandler.delegate = self } inputHandler.delegate = self
candidateUI.delegate = self
// setValue() IMK activateServer() setValue() // setValue() IMK activateServer() setValue()
inputHandler.clear() // handle State.Empty() inputHandler.clear() // handle State.Empty()
inputHandler.ensureKeyboardParser() inputHandler.ensureKeyboardParser()

View File

@ -16,7 +16,7 @@ extension SessionCtl: InputHandlerDelegate {
return client.bundleIdentifier() ?? "" return client.bundleIdentifier() ?? ""
} }
public func candidateController() -> CtlCandidateProtocol { ctlCandidateCurrent } public func candidateController() -> CtlCandidateProtocol { candidateUI }
public func candidateSelectionCalledByInputHandler(at index: Int) { public func candidateSelectionCalledByInputHandler(at index: Int) {
candidatePairSelected(at: index) candidatePairSelected(at: index)

View File

@ -82,35 +82,35 @@ extension SessionCtl {
: .horizontal) : .horizontal)
/// NSWindow() /// NSWindow()
ctlCandidateCurrent.visible = false candidateUI.visible = false
/// ///
if #available(macOS 10.15, *) { if #available(macOS 10.15, *) {
ctlCandidateCurrent = candidateUI =
PrefMgr.shared.useIMKCandidateWindow PrefMgr.shared.useIMKCandidateWindow
? CtlCandidateIMK(candidateLayout) : CtlCandidateTDK(candidateLayout) ? CtlCandidateIMK(candidateLayout) : CtlCandidateTDK(candidateLayout)
if let candidateTDK = ctlCandidateCurrent as? CtlCandidateTDK { if let candidateTDK = candidateUI as? CtlCandidateTDK {
candidateTDK.maxLinesPerPage = isVerticalTyping ? 1 : 3 candidateTDK.maxLinesPerPage = isVerticalTyping ? 1 : 3
} }
} else { } else {
ctlCandidateCurrent = CtlCandidateIMK(candidateLayout) candidateUI = CtlCandidateIMK(candidateLayout)
} }
ctlCandidateCurrent.candidateFont = Self.candidateFont( candidateUI.candidateFont = Self.candidateFont(
name: PrefMgr.shared.candidateTextFontName, size: PrefMgr.shared.candidateListTextSize name: PrefMgr.shared.candidateTextFontName, size: PrefMgr.shared.candidateListTextSize
) )
if PrefMgr.shared.cassetteEnabled { if PrefMgr.shared.cassetteEnabled {
ctlCandidateCurrent.tooltip = candidateUI.tooltip =
isVerticalTyping ? "📼" : "📼 " + NSLocalizedString("CIN Cassette Mode", comment: "") isVerticalTyping ? "📼" : "📼 " + NSLocalizedString("CIN Cassette Mode", comment: "")
} }
if state.type == .ofAssociates { if state.type == .ofAssociates {
ctlCandidateCurrent.tooltip = candidateUI.tooltip =
isVerticalTyping ? "" : NSLocalizedString("Hold ⇧ to choose associates.", comment: "") isVerticalTyping ? "" : NSLocalizedString("Hold ⇧ to choose associates.", comment: "")
} }
ctlCandidateCurrent.useLangIdentifier = PrefMgr.shared.handleDefaultCandidateFontsByLangIdentifier candidateUI.useLangIdentifier = PrefMgr.shared.handleDefaultCandidateFontsByLangIdentifier
ctlCandidateCurrent.locale = { candidateUI.locale = {
switch inputMode { switch inputMode {
case .imeModeCHS: return "zh-Hans" case .imeModeCHS: return "zh-Hans"
case .imeModeCHT: case .imeModeCHT:
@ -124,18 +124,18 @@ extension SessionCtl {
if #available(macOS 10.14, *) { if #available(macOS 10.14, *) {
// Spotlight IMK // Spotlight IMK
if let ctlCandidateCurrent = ctlCandidateCurrent as? CtlCandidateIMK { if let ctlCandidateCurrent = candidateUI as? CtlCandidateIMK {
while ctlCandidateCurrent.windowLevel() <= client.windowLevel() { while ctlCandidateCurrent.windowLevel() <= client.windowLevel() {
ctlCandidateCurrent.setWindowLevel(UInt64(max(0, client.windowLevel() + 1000))) ctlCandidateCurrent.setWindowLevel(UInt64(max(0, client.windowLevel() + 1000)))
} }
} }
} }
ctlCandidateCurrent.delegate = self // candidateUI.delegate = self //
ctlCandidateCurrent.visible = true candidateUI.visible = true
if isVerticalTyping { if isVerticalTyping {
ctlCandidateCurrent.set( candidateUI.set(
windowTopLeftPoint: NSPoint( windowTopLeftPoint: NSPoint(
x: lineHeightRect().origin.x + lineHeightRect().size.width + 4.0, y: lineHeightRect().origin.y - 4.0 x: lineHeightRect().origin.x + lineHeightRect().size.width + 4.0, y: lineHeightRect().origin.y - 4.0
), ),
@ -143,7 +143,7 @@ extension SessionCtl {
useGCD: true useGCD: true
) )
} else { } else {
ctlCandidateCurrent.set( candidateUI.set(
windowTopLeftPoint: NSPoint(x: lineHeightRect().origin.x, y: lineHeightRect().origin.y - 4.0), windowTopLeftPoint: NSPoint(x: lineHeightRect().origin.x, y: lineHeightRect().origin.y - 4.0),
bottomOutOfScreenAdjustmentHeight: lineHeightRect().size.height + 4.0, bottomOutOfScreenAdjustmentHeight: lineHeightRect().size.height + 4.0,
useGCD: true useGCD: true

View File

@ -45,7 +45,7 @@ extension SessionCtl {
// commitComposition() // commitComposition()
// clearInlineDisplay() // clearInlineDisplay()
// IMK inputMode.didSet() // IMK inputMode.didSet()
ctlCandidateCurrent.visible = false candidateUI.visible = false
popupCompositionBuffer.hide() popupCompositionBuffer.hide()
tooltipInstance.hide() tooltipInstance.hide()
case .ofEmpty, .ofAbortion, .ofCommitting: case .ofEmpty, .ofAbortion, .ofCommitting:
@ -58,22 +58,21 @@ extension SessionCtl {
if replace { state = IMEState.ofEmpty() } if replace { state = IMEState.ofEmpty() }
default: break innerCircle default: break innerCircle
} }
ctlCandidateCurrent.visible = false candidateUI.visible = false
// .Abortion // .Abortion
if previous.hasComposition, ![.ofAbortion, .ofCommitting].contains(newState.type) { if previous.hasComposition, ![.ofAbortion, .ofCommitting].contains(newState.type) {
commit(text: previous.displayedText) commit(text: previous.displayedText)
} }
showTooltip(newState.tooltip, duration: 1) // showTooltip(newState.tooltip, duration: 1) //
clearInlineDisplay() clearInlineDisplay()
//
inputHandler.clear() inputHandler.clear()
case .ofInputting: case .ofInputting:
ctlCandidateCurrent.visible = false candidateUI.visible = false
commit(text: newState.textToCommit) commit(text: newState.textToCommit)
setInlineDisplayWithCursor() setInlineDisplayWithCursor()
showTooltip(newState.tooltip, duration: 1) // showTooltip(newState.tooltip, duration: 1) //
case .ofMarking: case .ofMarking:
ctlCandidateCurrent.visible = false candidateUI.visible = false
setInlineDisplayWithCursor() setInlineDisplayWithCursor()
showTooltip(newState.tooltip) showTooltip(newState.tooltip)
case .ofCandidates, .ofAssociates, .ofSymbolTable: case .ofCandidates, .ofAssociates, .ofSymbolTable:

View File

@ -62,8 +62,8 @@ extension SessionCtl {
let annotation = reverseLookup(for: currentCandidate).joined(separator: "\n") let annotation = reverseLookup(for: currentCandidate).joined(separator: "\n")
guard !annotation.isEmpty else { return } guard !annotation.isEmpty else { return }
vCLog("Current Annotation: \(annotation)") vCLog("Current Annotation: \(annotation)")
DispatchQueue.main.async { DispatchQueue.main.async { [self] in
guard let imkCandidates = self.ctlCandidateCurrent as? CtlCandidateIMK else { return } guard let imkCandidates = candidateUI as? CtlCandidateIMK else { return }
imkCandidates.showAnnotation(.init(string: annotation)) imkCandidates.showAnnotation(.init(string: annotation))
} }
} }