diff --git a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CtlCandidate.swift b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CtlCandidate.swift index 6ad44b95..fd117a5f 100644 --- a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CtlCandidate.swift +++ b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CtlCandidate.swift @@ -10,7 +10,7 @@ import Cocoa import Shared open class CtlCandidate: NSWindowController, CtlCandidateProtocol { - open var hint: String = "" + open var tooltip: String = "" open var currentLayout: NSUserInterfaceLayoutOrientation = .horizontal open var locale: String = "" open var useLangIdentifier: Bool = false @@ -110,15 +110,7 @@ open class CtlCandidate: NSWindowController, CtlCandidateProtocol { fatalError("init(coder:) has not been implemented") } - open var keyLabels: [CandidateCellData] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"] - .map { - CandidateCellData(key: $0, displayedText: $0) - } - open var candidateFont = NSFont.systemFont(ofSize: 18) - open var keyLabelFont = NSFont.monospacedDigitSystemFont(ofSize: 14, weight: .medium) - - open var tooltip: String = "" @discardableResult open func showNextLine() -> Bool { false diff --git a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/CtlCandidateTDK.swift b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/CtlCandidateTDK.swift index 2087bb02..67ed6c63 100644 --- a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/CtlCandidateTDK.swift +++ b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/CtlCandidateTDK.swift @@ -18,20 +18,20 @@ public class CtlCandidateTDK: CtlCandidate { @available(macOS 12, *) public var theViewHorizontal: VwrCandidateHorizontal { - .init(controller: self, thePool: thePoolHorizontal, hint: hint) + .init(controller: self, thePool: thePoolHorizontal, tooltip: tooltip) } @available(macOS 12, *) public var theViewVertical: VwrCandidateVertical { - .init(controller: self, thePool: thePoolVertical, hint: hint) + .init(controller: self, thePool: thePoolVertical, tooltip: tooltip) } public var theViewHorizontalBackports: VwrCandidateHorizontalBackports { - .init(controller: self, thePool: thePoolHorizontal, hint: hint) + .init(controller: self, thePool: thePoolHorizontal, tooltip: tooltip) } public var theViewVerticalBackports: VwrCandidateVerticalBackports { - .init(controller: self, thePool: thePoolVertical, hint: hint) + .init(controller: self, thePool: thePoolVertical, tooltip: tooltip) } public var thePool: CandidatePool { diff --git a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateHorizontal.swift b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateHorizontal.swift index 19cb27ca..cfbdda1e 100644 --- a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateHorizontal.swift +++ b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateHorizontal.swift @@ -37,7 +37,7 @@ struct CandidatePoolViewUIHorizontal_Previews: PreviewProvider { public struct VwrCandidateHorizontal: View { public var controller: CtlCandidateTDK @State public var thePool: CandidatePool - @State public var hint: String = "" + @State public var tooltip: String = "" private var positionLabel: String { (thePool.highlightedIndex + 1).description + "/" + thePool.candidateDataAll.count.description @@ -91,16 +91,17 @@ public struct VwrCandidateHorizontal: View { .fixedSize(horizontal: false, vertical: true).padding(5) .background(Color(nsColor: NSColor.controlBackgroundColor).ignoresSafeArea()) ZStack(alignment: .leading) { - Color(nsColor: hint.isEmpty ? .windowBackgroundColor : CandidateCellData.highlightBackground).ignoresSafeArea() + Color(nsColor: tooltip.isEmpty ? .windowBackgroundColor : CandidateCellData.highlightBackground) + .ignoresSafeArea() HStack(alignment: .bottom) { - Text(hint).font(.system(size: max(CandidateCellData.unifiedSize * 0.7, 11), weight: .bold)).lineLimit(1) + Text(tooltip).font(.system(size: max(CandidateCellData.unifiedSize * 0.7, 11), weight: .bold)).lineLimit(1) Spacer() Text(positionLabel).font(.system(size: max(CandidateCellData.unifiedSize * 0.7, 11), weight: .bold)) .lineLimit( 1) } .padding(6).foregroundColor( - .init(nsColor: hint.isEmpty ? .controlTextColor : .selectedMenuItemTextColor.withAlphaComponent(0.9)) + .init(nsColor: tooltip.isEmpty ? .controlTextColor : .selectedMenuItemTextColor.withAlphaComponent(0.9)) ) } } diff --git a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateVertical.swift b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateVertical.swift index 6bdee970..46f6ec4b 100644 --- a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateVertical.swift +++ b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateVertical.swift @@ -36,7 +36,7 @@ struct CandidatePoolViewUIVertical_Previews: PreviewProvider { public struct VwrCandidateVertical: View { public var controller: CtlCandidateTDK @State public var thePool: CandidatePool - @State public var hint: String = "" + @State public var tooltip: String = "" private var positionLabel: String { (thePool.highlightedIndex + 1).description + "/" + thePool.candidateDataAll.count.description @@ -96,16 +96,17 @@ public struct VwrCandidateVertical: View { .fixedSize(horizontal: true, vertical: false).padding(5) .background(Color(nsColor: NSColor.controlBackgroundColor).ignoresSafeArea()) ZStack(alignment: .leading) { - Color(nsColor: hint.isEmpty ? .windowBackgroundColor : CandidateCellData.highlightBackground).ignoresSafeArea() + Color(nsColor: tooltip.isEmpty ? .windowBackgroundColor : CandidateCellData.highlightBackground) + .ignoresSafeArea() HStack(alignment: .bottom) { - Text(hint).font(.system(size: max(CandidateCellData.unifiedSize * 0.7, 11), weight: .bold)).lineLimit(1) + Text(tooltip).font(.system(size: max(CandidateCellData.unifiedSize * 0.7, 11), weight: .bold)).lineLimit(1) Spacer() Text(positionLabel).font(.system(size: max(CandidateCellData.unifiedSize * 0.7, 11), weight: .bold)) .lineLimit( 1) } .padding(6).foregroundColor( - .init(nsColor: hint.isEmpty ? .controlTextColor : .selectedMenuItemTextColor.withAlphaComponent(0.9)) + .init(nsColor: tooltip.isEmpty ? .controlTextColor : .selectedMenuItemTextColor.withAlphaComponent(0.9)) ) } } diff --git a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates_Backports/VwrCandidateHorizontalBackports.swift b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates_Backports/VwrCandidateHorizontalBackports.swift index 7abd13a9..efedab54 100644 --- a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates_Backports/VwrCandidateHorizontalBackports.swift +++ b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates_Backports/VwrCandidateHorizontalBackports.swift @@ -39,7 +39,7 @@ public struct VwrCandidateHorizontalBackports: View { @Environment(\.colorScheme) var colorScheme public var controller: CtlCandidateTDK @State public var thePool: CandidatePool - @State public var hint: String = "" + @State public var tooltip: String = "" private var positionLabel: String { (thePool.highlightedIndex + 1).description + "/" + thePool.candidateDataAll.count.description @@ -93,20 +93,20 @@ public struct VwrCandidateHorizontalBackports: View { .fixedSize(horizontal: false, vertical: true).padding(5) .background(Color(white: colorScheme == .dark ? 0.1 : 1)) ZStack(alignment: .leading) { - if hint.isEmpty { + if tooltip.isEmpty { Color(white: colorScheme == .dark ? 0.2 : 0.9) } else { controller.highlightedColorUIBackports } HStack(alignment: .bottom) { - Text(hint).font(.system(size: max(CandidateCellData.unifiedSize * 0.7, 11), weight: .bold)).lineLimit(1) + Text(tooltip).font(.system(size: max(CandidateCellData.unifiedSize * 0.7, 11), weight: .bold)).lineLimit(1) Spacer() Text(positionLabel).font(.system(size: max(CandidateCellData.unifiedSize * 0.7, 11), weight: .bold)) .lineLimit( 1) } .padding(6).foregroundColor( - hint.isEmpty && colorScheme == .light ? Color(white: 0.1) : Color(white: 0.9) + tooltip.isEmpty && colorScheme == .light ? Color(white: 0.1) : Color(white: 0.9) ) } } diff --git a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates_Backports/VwrCandidateVerticalBackports.swift b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates_Backports/VwrCandidateVerticalBackports.swift index 51137f2f..30ea03e7 100644 --- a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates_Backports/VwrCandidateVerticalBackports.swift +++ b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates_Backports/VwrCandidateVerticalBackports.swift @@ -38,7 +38,7 @@ public struct VwrCandidateVerticalBackports: View { @Environment(\.colorScheme) var colorScheme public var controller: CtlCandidateTDK @State public var thePool: CandidatePool - @State public var hint: String = "" + @State public var tooltip: String = "" private var positionLabel: String { (thePool.highlightedIndex + 1).description + "/" + thePool.candidateDataAll.count.description @@ -98,20 +98,20 @@ public struct VwrCandidateVerticalBackports: View { .fixedSize(horizontal: true, vertical: false).padding(5) .background(Color(white: colorScheme == .dark ? 0.1 : 1)) ZStack(alignment: .leading) { - if hint.isEmpty { + if tooltip.isEmpty { Color(white: colorScheme == .dark ? 0.2 : 0.9) } else { controller.highlightedColorUIBackports } HStack(alignment: .bottom) { - Text(hint).font(.system(size: max(CandidateCellData.unifiedSize * 0.7, 11), weight: .bold)).lineLimit(1) + Text(tooltip).font(.system(size: max(CandidateCellData.unifiedSize * 0.7, 11), weight: .bold)).lineLimit(1) Spacer() Text(positionLabel).font(.system(size: max(CandidateCellData.unifiedSize * 0.7, 11), weight: .bold)) .lineLimit( 1) } .padding(6).foregroundColor( - hint.isEmpty && colorScheme == .light ? Color(white: 0.1) : Color(white: 0.9) + tooltip.isEmpty && colorScheme == .light ? Color(white: 0.1) : Color(white: 0.9) ) } } diff --git a/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift b/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift index 01cc803b..ec9df4c8 100644 --- a/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift +++ b/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift @@ -18,17 +18,14 @@ public protocol CtlCandidateDelegate: AnyObject { } public protocol CtlCandidateProtocol { - var hint: String { get set } + var tooltip: String { get set } var locale: String { get set } var currentLayout: NSUserInterfaceLayoutOrientation { get set } var delegate: CtlCandidateDelegate? { get set } var selectedCandidateIndex: Int { get set } var visible: Bool { get set } var windowTopLeftPoint: NSPoint { get set } - var keyLabels: [CandidateCellData] { get set } - var keyLabelFont: NSFont { get set } var candidateFont: NSFont { get set } - var tooltip: String { get set } var useLangIdentifier: Bool { get set } init(_ layout: NSUserInterfaceLayoutOrientation) diff --git a/Packages/vChewing_Shared/Sources/Shared/Protocols/PrefMgrProtocol.swift b/Packages/vChewing_Shared/Sources/Shared/Protocols/PrefMgrProtocol.swift index b4261cdc..024a1fce 100644 --- a/Packages/vChewing_Shared/Sources/Shared/Protocols/PrefMgrProtocol.swift +++ b/Packages/vChewing_Shared/Sources/Shared/Protocols/PrefMgrProtocol.swift @@ -60,7 +60,6 @@ public protocol PrefMgrProtocol { var specifyShiftTabKeyBehavior: Bool { get set } var specifyShiftSpaceKeyBehavior: Bool { get set } var candidateTextFontName: String { get set } - var candidateKeyLabelFontName: String { get set } var candidateKeys: String { get set } var useSCPCTypingMode: Bool { get set } var phraseReplacementEnabled: Bool { get set } diff --git a/Packages/vChewing_Shared/Sources/Shared/Shared.swift b/Packages/vChewing_Shared/Sources/Shared/Shared.swift index 6e781926..f4c90d43 100644 --- a/Packages/vChewing_Shared/Sources/Shared/Shared.swift +++ b/Packages/vChewing_Shared/Sources/Shared/Shared.swift @@ -66,7 +66,6 @@ public enum UserDef: String, CaseIterable { case kShiftKeyAccommodationBehavior = "ShiftKeyAccommodationBehavior" case kCandidateTextFontName = "CandidateTextFontName" - case kCandidateKeyLabelFontName = "CandidateKeyLabelFontName" case kCandidateKeys = "CandidateKeys" case kAssociatedPhrasesEnabled = "AssociatedPhrasesEnabled" diff --git a/Source/Modules/KeyHandler_HandleCandidate.swift b/Source/Modules/KeyHandler_HandleCandidate.swift index 597f5550..b722e979 100644 --- a/Source/Modules/KeyHandler_HandleCandidate.swift +++ b/Source/Modules/KeyHandler_HandleCandidate.swift @@ -232,9 +232,9 @@ extension KeyHandler { let match: String = (state.type == .ofAssociates) ? input.inputTextIgnoringModifiers ?? "" : input.text - for j in 0.. NSFont { - if let name = name { - return NSFont(name: name, size: size) ?? NSFont.systemFont(ofSize: size) - } - return NSFont.systemFont(ofSize: size) - } - - Self.ctlCandidateCurrent.keyLabelFont = labelFont( - name: PrefMgr.shared.candidateKeyLabelFontName, size: keyLabelSize - ) Self.ctlCandidateCurrent.candidateFont = Self.candidateFont( - name: PrefMgr.shared.candidateTextFontName, size: textSize + name: PrefMgr.shared.candidateTextFontName, size: PrefMgr.shared.candidateListTextSize ) - let candidateKeys = PrefMgr.shared.candidateKeys - let keyLabels = - candidateKeys.count > 4 ? Array(candidateKeys) : Array(CandidateKey.defaultKeys) - let keyLabelSuffix = state.type == .ofAssociates ? "^" : "" - Self.ctlCandidateCurrent.keyLabels = keyLabels.map { - CandidateCellData(key: String($0), displayedText: String($0) + keyLabelSuffix) - } - if state.type == .ofAssociates { - Self.ctlCandidateCurrent.hint = NSLocalizedString("Hold ⇧ to choose associates.", comment: "") + Self.ctlCandidateCurrent.tooltip = NSLocalizedString("Hold ⇧ to choose associates.", comment: "") } Self.ctlCandidateCurrent.useLangIdentifier = PrefMgr.shared.handleDefaultCandidateFontsByLangIdentifier diff --git a/Source/Modules/UIModules/CandidateUI/IMKCandidatesImpl.swift b/Source/Modules/UIModules/CandidateUI/IMKCandidatesImpl.swift index 973fb49f..73ed646d 100644 --- a/Source/Modules/UIModules/CandidateUI/IMKCandidatesImpl.swift +++ b/Source/Modules/UIModules/CandidateUI/IMKCandidatesImpl.swift @@ -11,7 +11,7 @@ import Shared /// 威注音自用的 IMKCandidates 型別。因為有用到 bridging header,所以無法弄成 Swift Package。 public class CtlCandidateIMK: IMKCandidates, CtlCandidateProtocol { - public var hint: String = "" + public var tooltip: String = "" public var locale: String = "" public var useLangIdentifier: Bool = false public var currentLayout: NSUserInterfaceLayoutOrientation = .horizontal @@ -38,15 +38,6 @@ public class CtlCandidateIMK: IMKCandidates, CtlCandidateProtocol { } } - public var keyLabels: [CandidateCellData] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"] - .map { - CandidateCellData(key: $0, displayedText: $0) - } - - public var keyLabelFont = NSFont.monospacedDigitSystemFont( - ofSize: 14, weight: .medium - ) - public var candidateFont = NSFont.systemFont(ofSize: 16) { didSet { if #available(macOS 10.14, *) { setFontSize(candidateFont.pointSize) } @@ -63,11 +54,6 @@ public class CtlCandidateIMK: IMKCandidates, CtlCandidateProtocol { } } - public var tooltip: String = "" - - var keyCount = 0 - var displayedCandidates = [String]() - public func specifyLayout(_ layout: NSUserInterfaceLayoutOrientation = .horizontal) { currentLayout = layout switch currentLayout { @@ -107,7 +93,6 @@ public class CtlCandidateIMK: IMKCandidates, CtlCandidateProtocol { // guard let delegate = delegate else { return } // 下文無效,所以這句沒用。 // 既然下述函式無效,那中間這段沒用的也都砍了。 // setCandidateData(candidates) // 該函式無效。 - keyCount = selectionKeys().count selectedCandidateIndex = 0 update() } @@ -115,15 +100,6 @@ public class CtlCandidateIMK: IMKCandidates, CtlCandidateProtocol { /// 幹話:這裡很多函式內容亂寫也都無所謂了,因為都被 IMKCandidates 代管執行。 /// 對於所有 IMK 選字窗的選字判斷動作,不是在 keyHandler 中,而是在 `ctlIME_Core` 中。 - private var currentPageIndex: Int = 0 - - private var pageCount: Int { - guard let delegate = delegate else { return 0 } - let totalCount = delegate.candidatePairs(conv: false).count - let keyLabelCount = keyLabels.count - return totalCount / keyLabelCount + ((totalCount % keyLabelCount) != 0 ? 1 : 0) - } - // 該函式會影響 IMK 選字窗。 @discardableResult public func showNextPage() -> Bool { do { currentLayout == .vertical ? moveRight(self) : moveDown(self) } @@ -160,11 +136,8 @@ public class CtlCandidateIMK: IMKCandidates, CtlCandidateProtocol { return true } - public func candidateIndexAtKeyLabelIndex(_ index: Int) -> Int { - guard let delegate = delegate else { return Int.max } - let result = currentPageIndex * keyLabels.count + index - return result < delegate.candidatePairs(conv: false).count ? result : Int.max - } + // IMK 選字窗目前無法實作該函式。威注音 IMK 選字窗目前也不需要使用該函式。 + public func candidateIndexAtKeyLabelIndex(_: Int) -> Int { 0 } public var selectedCandidateIndex: Int { get { selectedCandidate() }