Repo // Remove useless symbols regarding candidate windows.

This commit is contained in:
ShikiSuen 2022-10-08 17:06:50 +08:00
parent 2f83ba7479
commit 1dfebd7b44
13 changed files with 32 additions and 96 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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))
)
}
}

View File

@ -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))
)
}
}

View File

@ -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)
)
}
}

View File

@ -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)
)
}
}

View File

@ -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)

View File

@ -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 }

View File

@ -66,7 +66,6 @@ public enum UserDef: String, CaseIterable {
case kShiftKeyAccommodationBehavior = "ShiftKeyAccommodationBehavior"
case kCandidateTextFontName = "CandidateTextFontName"
case kCandidateKeyLabelFontName = "CandidateKeyLabelFontName"
case kCandidateKeys = "CandidateKeys"
case kAssociatedPhrasesEnabled = "AssociatedPhrasesEnabled"

View File

@ -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
}

View File

@ -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 {

View File

@ -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

View File

@ -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() }