Repo // Remove useless symbols regarding candidate windows.
This commit is contained in:
parent
2f83ba7479
commit
1dfebd7b44
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -66,7 +66,6 @@ public enum UserDef: String, CaseIterable {
|
|||
case kShiftKeyAccommodationBehavior = "ShiftKeyAccommodationBehavior"
|
||||
|
||||
case kCandidateTextFontName = "CandidateTextFontName"
|
||||
case kCandidateKeyLabelFontName = "CandidateKeyLabelFontName"
|
||||
case kCandidateKeys = "CandidateKeys"
|
||||
|
||||
case kAssociatedPhrasesEnabled = "AssociatedPhrasesEnabled"
|
||||
|
|
|
@ -232,9 +232,9 @@ extension KeyHandler {
|
|||
let match: String =
|
||||
(state.type == .ofAssociates) ? input.inputTextIgnoringModifiers ?? "" : input.text
|
||||
|
||||
for j in 0..<ctlCandidate.keyLabels.count {
|
||||
let label: CandidateCellData = ctlCandidate.keyLabels[j]
|
||||
if match.compare(label.key, options: .caseInsensitive, range: nil, locale: .current) == .orderedSame {
|
||||
for j in 0..<PrefMgr.shared.candidateKeys.count {
|
||||
let label = PrefMgr.shared.candidateKeys.charComponents[j]
|
||||
if match.compare(label, options: .caseInsensitive, range: nil, locale: .current) == .orderedSame {
|
||||
index = j
|
||||
break
|
||||
}
|
||||
|
|
|
@ -234,9 +234,6 @@ public class PrefMgr: PrefMgrProtocol {
|
|||
@AppProperty(key: UserDef.kCandidateTextFontName.rawValue, defaultValue: "")
|
||||
public var candidateTextFontName: String
|
||||
|
||||
@AppProperty(key: UserDef.kCandidateKeyLabelFontName.rawValue, defaultValue: "")
|
||||
public var candidateKeyLabelFontName: String
|
||||
|
||||
@AppProperty(key: UserDef.kCandidateKeys.rawValue, defaultValue: kDefaultCandidateKeys)
|
||||
public var candidateKeys: String {
|
||||
didSet {
|
||||
|
|
|
@ -111,35 +111,12 @@ extension SessionCtl {
|
|||
Self.ctlCandidateCurrent = CtlCandidateIMK(candidateLayout)
|
||||
}
|
||||
|
||||
// set the attributes for the candidate panel (which uses NSAttributedString)
|
||||
let textSize = PrefMgr.shared.candidateListTextSize
|
||||
let minimumKeyLabelSize: Double = 10
|
||||
let keyLabelSize = max(textSize / 2, minimumKeyLabelSize)
|
||||
|
||||
func labelFont(name: String?, size: Double) -> 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
|
||||
|
|
|
@ -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() }
|
||||
|
|
Loading…
Reference in New Issue