Repo // Remove useless do{} wrappers.
This commit is contained in:
parent
09cf014dca
commit
66f37fbb43
|
@ -154,18 +154,14 @@ extension KeyHandler {
|
||||||
if input.isLeft {
|
if input.isLeft {
|
||||||
switch ctlCandidateCurrent.currentLayout {
|
switch ctlCandidateCurrent.currentLayout {
|
||||||
case .horizontal:
|
case .horizontal:
|
||||||
do {
|
if !ctlCandidateCurrent.highlightPreviousCandidate() {
|
||||||
if !ctlCandidateCurrent.highlightPreviousCandidate() {
|
IME.prtDebugIntel("1145148D")
|
||||||
IME.prtDebugIntel("1145148D")
|
errorCallback()
|
||||||
errorCallback()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case .vertical:
|
case .vertical:
|
||||||
do {
|
if !ctlCandidateCurrent.showPreviousPage() {
|
||||||
if !ctlCandidateCurrent.showPreviousPage() {
|
IME.prtDebugIntel("1919810D")
|
||||||
IME.prtDebugIntel("1919810D")
|
errorCallback()
|
||||||
errorCallback()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -187,18 +183,14 @@ extension KeyHandler {
|
||||||
if input.isRight {
|
if input.isRight {
|
||||||
switch ctlCandidateCurrent.currentLayout {
|
switch ctlCandidateCurrent.currentLayout {
|
||||||
case .horizontal:
|
case .horizontal:
|
||||||
do {
|
if !ctlCandidateCurrent.highlightNextCandidate() {
|
||||||
if !ctlCandidateCurrent.highlightNextCandidate() {
|
IME.prtDebugIntel("9B65138D")
|
||||||
IME.prtDebugIntel("9B65138D")
|
errorCallback()
|
||||||
errorCallback()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case .vertical:
|
case .vertical:
|
||||||
do {
|
if !ctlCandidateCurrent.showNextPage() {
|
||||||
if !ctlCandidateCurrent.showNextPage() {
|
IME.prtDebugIntel("9244908D")
|
||||||
IME.prtDebugIntel("9244908D")
|
errorCallback()
|
||||||
errorCallback()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -220,18 +212,14 @@ extension KeyHandler {
|
||||||
if input.isUp {
|
if input.isUp {
|
||||||
switch ctlCandidateCurrent.currentLayout {
|
switch ctlCandidateCurrent.currentLayout {
|
||||||
case .horizontal:
|
case .horizontal:
|
||||||
do {
|
if !ctlCandidateCurrent.showPreviousPage() {
|
||||||
if !ctlCandidateCurrent.showPreviousPage() {
|
IME.prtDebugIntel("9B614524")
|
||||||
IME.prtDebugIntel("9B614524")
|
errorCallback()
|
||||||
errorCallback()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case .vertical:
|
case .vertical:
|
||||||
do {
|
if !ctlCandidateCurrent.highlightPreviousCandidate() {
|
||||||
if !ctlCandidateCurrent.highlightPreviousCandidate() {
|
IME.prtDebugIntel("ASD9908D")
|
||||||
IME.prtDebugIntel("ASD9908D")
|
errorCallback()
|
||||||
errorCallback()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -242,18 +230,14 @@ extension KeyHandler {
|
||||||
if input.isDown {
|
if input.isDown {
|
||||||
switch ctlCandidateCurrent.currentLayout {
|
switch ctlCandidateCurrent.currentLayout {
|
||||||
case .horizontal:
|
case .horizontal:
|
||||||
do {
|
if !ctlCandidateCurrent.showNextPage() {
|
||||||
if !ctlCandidateCurrent.showNextPage() {
|
IME.prtDebugIntel("92B990DD")
|
||||||
IME.prtDebugIntel("92B990DD")
|
errorCallback()
|
||||||
errorCallback()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case .vertical:
|
case .vertical:
|
||||||
do {
|
if !ctlCandidateCurrent.highlightNextCandidate() {
|
||||||
if !ctlCandidateCurrent.highlightNextCandidate() {
|
IME.prtDebugIntel("6B99908D")
|
||||||
IME.prtDebugIntel("6B99908D")
|
errorCallback()
|
||||||
errorCallback()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -81,10 +81,8 @@ extension KeyHandler {
|
||||||
case 0:
|
case 0:
|
||||||
tooltipParameterRef[1] = compositor.readings[compositorCursorIndex]
|
tooltipParameterRef[1] = compositor.readings[compositorCursorIndex]
|
||||||
default:
|
default:
|
||||||
do {
|
tooltipParameterRef[0] = compositor.readings[compositorCursorIndex - 1]
|
||||||
tooltipParameterRef[0] = compositor.readings[compositorCursorIndex - 1]
|
tooltipParameterRef[1] = compositor.readings[compositorCursorIndex]
|
||||||
tooltipParameterRef[1] = compositor.readings[compositorCursorIndex]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// 注音轉拼音
|
/// 注音轉拼音
|
||||||
for (i, _) in tooltipParameterRef.enumerated() {
|
for (i, _) in tooltipParameterRef.enumerated() {
|
||||||
|
|
|
@ -32,24 +32,18 @@ let kConnectionName = "vChewing_1_Connection"
|
||||||
switch max(CommandLine.arguments.count - 1, 0) {
|
switch max(CommandLine.arguments.count - 1, 0) {
|
||||||
case 0: break
|
case 0: break
|
||||||
case 1, 2:
|
case 1, 2:
|
||||||
do {
|
switch CommandLine.arguments[1] {
|
||||||
switch CommandLine.arguments[1] {
|
case "install":
|
||||||
case "install":
|
if CommandLine.arguments[1] == "install" {
|
||||||
do {
|
let exitCode = IME.registerInputMethod()
|
||||||
if CommandLine.arguments[1] == "install" {
|
exit(exitCode)
|
||||||
let exitCode = IME.registerInputMethod()
|
}
|
||||||
exit(exitCode)
|
case "uninstall":
|
||||||
}
|
if CommandLine.arguments[1] == "uninstall" {
|
||||||
}
|
let exitCode = IME.uninstall(isSudo: IME.isSudoMode)
|
||||||
case "uninstall":
|
exit(exitCode)
|
||||||
do {
|
}
|
||||||
if CommandLine.arguments[1] == "uninstall" {
|
default: break
|
||||||
let exitCode = IME.uninstall(isSudo: IME.isSudoMode)
|
|
||||||
exit(exitCode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default: break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
exit(0)
|
exit(0)
|
||||||
default: exit(0)
|
default: exit(0)
|
||||||
|
|
|
@ -162,146 +162,142 @@ private class vwrCandidateUniversal: NSView {
|
||||||
|
|
||||||
switch isVerticalLayout {
|
switch isVerticalLayout {
|
||||||
case true:
|
case true:
|
||||||
do {
|
var accuHeight: CGFloat = 0
|
||||||
var accuHeight: CGFloat = 0
|
for (index, elementHeight) in elementHeights.enumerated() {
|
||||||
for (index, elementHeight) in elementHeights.enumerated() {
|
let currentHeight = elementHeight
|
||||||
let currentHeight = elementHeight
|
let rctCandidateArea = NSRect(
|
||||||
let rctCandidateArea = NSRect(
|
x: 0.0, y: accuHeight, width: windowWidth, height: candidateTextHeight + cellPadding
|
||||||
x: 0.0, y: accuHeight, width: windowWidth, height: candidateTextHeight + cellPadding
|
)
|
||||||
)
|
let rctLabel = NSRect(
|
||||||
let rctLabel = NSRect(
|
x: cellPadding / 2 - 1, y: accuHeight + cellPadding / 2, width: keyLabelWidth,
|
||||||
x: cellPadding / 2 - 1, y: accuHeight + cellPadding / 2, width: keyLabelWidth,
|
height: keyLabelHeight * 2.0
|
||||||
height: keyLabelHeight * 2.0
|
)
|
||||||
)
|
let rctCandidatePhrase = NSRect(
|
||||||
let rctCandidatePhrase = NSRect(
|
x: cellPadding / 2 - 1 + keyLabelWidth, y: accuHeight + cellPadding / 2 - 1,
|
||||||
x: cellPadding / 2 - 1 + keyLabelWidth, y: accuHeight + cellPadding / 2 - 1,
|
width: windowWidth - keyLabelWidth, height: candidateTextHeight
|
||||||
width: windowWidth - keyLabelWidth, height: candidateTextHeight
|
)
|
||||||
)
|
|
||||||
|
|
||||||
var activeCandidateIndexAttr = keyLabelAttrDict
|
var activeCandidateIndexAttr = keyLabelAttrDict
|
||||||
var activeCandidateAttr = candidateAttrDict
|
var activeCandidateAttr = candidateAttrDict
|
||||||
if index == highlightedIndex {
|
if index == highlightedIndex {
|
||||||
let colorBlendAmount: CGFloat = IME.isDarkMode() ? 0.25 : 0
|
let colorBlendAmount: CGFloat = IME.isDarkMode() ? 0.25 : 0
|
||||||
// The background color of the highlightened candidate
|
// The background color of the highlightened candidate
|
||||||
switch IME.currentInputMode {
|
|
||||||
case InputMode.imeModeCHS:
|
|
||||||
NSColor.systemRed.blended(
|
|
||||||
withFraction: colorBlendAmount,
|
|
||||||
of: NSColor.controlBackgroundColor
|
|
||||||
)!
|
|
||||||
.setFill()
|
|
||||||
case InputMode.imeModeCHT:
|
|
||||||
NSColor.systemBlue.blended(
|
|
||||||
withFraction: colorBlendAmount,
|
|
||||||
of: NSColor.controlBackgroundColor
|
|
||||||
)!
|
|
||||||
.setFill()
|
|
||||||
default:
|
|
||||||
NSColor.alternateSelectedControlColor.setFill()
|
|
||||||
}
|
|
||||||
// Highlightened index text color
|
|
||||||
activeCandidateIndexAttr[.foregroundColor] = NSColor.selectedMenuItemTextColor
|
|
||||||
.withAlphaComponent(0.84)
|
|
||||||
// Highlightened phrase text color
|
|
||||||
activeCandidateAttr[.foregroundColor] = NSColor.selectedMenuItemTextColor
|
|
||||||
} else {
|
|
||||||
NSColor.controlBackgroundColor.setFill()
|
|
||||||
}
|
|
||||||
switch IME.currentInputMode {
|
switch IME.currentInputMode {
|
||||||
case InputMode.imeModeCHS:
|
case InputMode.imeModeCHS:
|
||||||
if #available(macOS 12.0, *) {
|
NSColor.systemRed.blended(
|
||||||
activeCandidateAttr[.languageIdentifier] = "zh-Hans" as AnyObject
|
withFraction: colorBlendAmount,
|
||||||
}
|
of: NSColor.controlBackgroundColor
|
||||||
|
)!
|
||||||
|
.setFill()
|
||||||
case InputMode.imeModeCHT:
|
case InputMode.imeModeCHT:
|
||||||
if #available(macOS 12.0, *) {
|
NSColor.systemBlue.blended(
|
||||||
activeCandidateAttr[.languageIdentifier] =
|
withFraction: colorBlendAmount,
|
||||||
(mgrPrefs.shiftJISShinjitaiOutputEnabled || mgrPrefs.chineseConversionEnabled)
|
of: NSColor.controlBackgroundColor
|
||||||
? "ja" as AnyObject : "zh-Hant" as AnyObject
|
)!
|
||||||
}
|
.setFill()
|
||||||
default:
|
default:
|
||||||
break
|
NSColor.alternateSelectedControlColor.setFill()
|
||||||
}
|
}
|
||||||
NSBezierPath.fill(rctCandidateArea)
|
// Highlightened index text color
|
||||||
(keyLabels[index] as NSString).draw(
|
activeCandidateIndexAttr[.foregroundColor] = NSColor.selectedMenuItemTextColor
|
||||||
in: rctLabel, withAttributes: activeCandidateIndexAttr
|
.withAlphaComponent(0.84)
|
||||||
)
|
// Highlightened phrase text color
|
||||||
(displayedCandidates[index] as NSString).draw(
|
activeCandidateAttr[.foregroundColor] = NSColor.selectedMenuItemTextColor
|
||||||
in: rctCandidatePhrase, withAttributes: activeCandidateAttr
|
} else {
|
||||||
)
|
NSColor.controlBackgroundColor.setFill()
|
||||||
accuHeight += currentHeight
|
|
||||||
}
|
}
|
||||||
|
switch IME.currentInputMode {
|
||||||
|
case InputMode.imeModeCHS:
|
||||||
|
if #available(macOS 12.0, *) {
|
||||||
|
activeCandidateAttr[.languageIdentifier] = "zh-Hans" as AnyObject
|
||||||
|
}
|
||||||
|
case InputMode.imeModeCHT:
|
||||||
|
if #available(macOS 12.0, *) {
|
||||||
|
activeCandidateAttr[.languageIdentifier] =
|
||||||
|
(mgrPrefs.shiftJISShinjitaiOutputEnabled || mgrPrefs.chineseConversionEnabled)
|
||||||
|
? "ja" as AnyObject : "zh-Hant" as AnyObject
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
NSBezierPath.fill(rctCandidateArea)
|
||||||
|
(keyLabels[index] as NSString).draw(
|
||||||
|
in: rctLabel, withAttributes: activeCandidateIndexAttr
|
||||||
|
)
|
||||||
|
(displayedCandidates[index] as NSString).draw(
|
||||||
|
in: rctCandidatePhrase, withAttributes: activeCandidateAttr
|
||||||
|
)
|
||||||
|
accuHeight += currentHeight
|
||||||
}
|
}
|
||||||
case false:
|
case false:
|
||||||
do {
|
var accuWidth: CGFloat = 0
|
||||||
var accuWidth: CGFloat = 0
|
for (index, elementWidth) in elementWidths.enumerated() {
|
||||||
for (index, elementWidth) in elementWidths.enumerated() {
|
let currentWidth = elementWidth
|
||||||
let currentWidth = elementWidth
|
let rctCandidateArea = NSRect(
|
||||||
let rctCandidateArea = NSRect(
|
x: accuWidth, y: 0.0, width: currentWidth + 1.0,
|
||||||
x: accuWidth, y: 0.0, width: currentWidth + 1.0,
|
height: candidateTextHeight + cellPadding
|
||||||
height: candidateTextHeight + cellPadding
|
)
|
||||||
)
|
let rctLabel = NSRect(
|
||||||
let rctLabel = NSRect(
|
x: accuWidth + cellPadding / 2 - 1, y: cellPadding / 2, width: keyLabelWidth,
|
||||||
x: accuWidth + cellPadding / 2 - 1, y: cellPadding / 2, width: keyLabelWidth,
|
height: keyLabelHeight * 2.0
|
||||||
height: keyLabelHeight * 2.0
|
)
|
||||||
)
|
let rctCandidatePhrase = NSRect(
|
||||||
let rctCandidatePhrase = NSRect(
|
x: accuWidth + keyLabelWidth - 1, y: cellPadding / 2 - 1,
|
||||||
x: accuWidth + keyLabelWidth - 1, y: cellPadding / 2 - 1,
|
width: currentWidth - keyLabelWidth,
|
||||||
width: currentWidth - keyLabelWidth,
|
height: candidateTextHeight
|
||||||
height: candidateTextHeight
|
)
|
||||||
)
|
|
||||||
|
|
||||||
var activeCandidateIndexAttr = keyLabelAttrDict
|
var activeCandidateIndexAttr = keyLabelAttrDict
|
||||||
var activeCandidateAttr = candidateAttrDict
|
var activeCandidateAttr = candidateAttrDict
|
||||||
if index == highlightedIndex {
|
if index == highlightedIndex {
|
||||||
let colorBlendAmount: CGFloat = IME.isDarkMode() ? 0.25 : 0
|
let colorBlendAmount: CGFloat = IME.isDarkMode() ? 0.25 : 0
|
||||||
// The background color of the highlightened candidate
|
// The background color of the highlightened candidate
|
||||||
switch IME.currentInputMode {
|
|
||||||
case InputMode.imeModeCHS:
|
|
||||||
NSColor.systemRed.blended(
|
|
||||||
withFraction: colorBlendAmount,
|
|
||||||
of: NSColor.controlBackgroundColor
|
|
||||||
)!
|
|
||||||
.setFill()
|
|
||||||
case InputMode.imeModeCHT:
|
|
||||||
NSColor.systemBlue.blended(
|
|
||||||
withFraction: colorBlendAmount,
|
|
||||||
of: NSColor.controlBackgroundColor
|
|
||||||
)!
|
|
||||||
.setFill()
|
|
||||||
default:
|
|
||||||
NSColor.alternateSelectedControlColor.setFill()
|
|
||||||
}
|
|
||||||
// Highlightened index text color
|
|
||||||
activeCandidateIndexAttr[.foregroundColor] = NSColor.selectedMenuItemTextColor
|
|
||||||
.withAlphaComponent(0.84)
|
|
||||||
// Highlightened phrase text color
|
|
||||||
activeCandidateAttr[.foregroundColor] = NSColor.selectedMenuItemTextColor
|
|
||||||
} else {
|
|
||||||
NSColor.controlBackgroundColor.setFill()
|
|
||||||
}
|
|
||||||
switch IME.currentInputMode {
|
switch IME.currentInputMode {
|
||||||
case InputMode.imeModeCHS:
|
case InputMode.imeModeCHS:
|
||||||
if #available(macOS 12.0, *) {
|
NSColor.systemRed.blended(
|
||||||
activeCandidateAttr[.languageIdentifier] = "zh-Hans" as AnyObject
|
withFraction: colorBlendAmount,
|
||||||
}
|
of: NSColor.controlBackgroundColor
|
||||||
|
)!
|
||||||
|
.setFill()
|
||||||
case InputMode.imeModeCHT:
|
case InputMode.imeModeCHT:
|
||||||
if #available(macOS 12.0, *) {
|
NSColor.systemBlue.blended(
|
||||||
activeCandidateAttr[.languageIdentifier] =
|
withFraction: colorBlendAmount,
|
||||||
(mgrPrefs.shiftJISShinjitaiOutputEnabled || mgrPrefs.chineseConversionEnabled)
|
of: NSColor.controlBackgroundColor
|
||||||
? "ja" as AnyObject : "zh-Hant" as AnyObject
|
)!
|
||||||
}
|
.setFill()
|
||||||
default:
|
default:
|
||||||
break
|
NSColor.alternateSelectedControlColor.setFill()
|
||||||
}
|
}
|
||||||
NSBezierPath.fill(rctCandidateArea)
|
// Highlightened index text color
|
||||||
(keyLabels[index] as NSString).draw(
|
activeCandidateIndexAttr[.foregroundColor] = NSColor.selectedMenuItemTextColor
|
||||||
in: rctLabel, withAttributes: activeCandidateIndexAttr
|
.withAlphaComponent(0.84)
|
||||||
)
|
// Highlightened phrase text color
|
||||||
(displayedCandidates[index] as NSString).draw(
|
activeCandidateAttr[.foregroundColor] = NSColor.selectedMenuItemTextColor
|
||||||
in: rctCandidatePhrase, withAttributes: activeCandidateAttr
|
} else {
|
||||||
)
|
NSColor.controlBackgroundColor.setFill()
|
||||||
accuWidth += currentWidth + 1.0
|
|
||||||
}
|
}
|
||||||
|
switch IME.currentInputMode {
|
||||||
|
case InputMode.imeModeCHS:
|
||||||
|
if #available(macOS 12.0, *) {
|
||||||
|
activeCandidateAttr[.languageIdentifier] = "zh-Hans" as AnyObject
|
||||||
|
}
|
||||||
|
case InputMode.imeModeCHT:
|
||||||
|
if #available(macOS 12.0, *) {
|
||||||
|
activeCandidateAttr[.languageIdentifier] =
|
||||||
|
(mgrPrefs.shiftJISShinjitaiOutputEnabled || mgrPrefs.chineseConversionEnabled)
|
||||||
|
? "ja" as AnyObject : "zh-Hant" as AnyObject
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
NSBezierPath.fill(rctCandidateArea)
|
||||||
|
(keyLabels[index] as NSString).draw(
|
||||||
|
in: rctLabel, withAttributes: activeCandidateIndexAttr
|
||||||
|
)
|
||||||
|
(displayedCandidates[index] as NSString).draw(
|
||||||
|
in: rctCandidatePhrase, withAttributes: activeCandidateAttr
|
||||||
|
)
|
||||||
|
accuWidth += currentWidth + 1.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -313,28 +309,24 @@ private class vwrCandidateUniversal: NSView {
|
||||||
}
|
}
|
||||||
switch isVerticalLayout {
|
switch isVerticalLayout {
|
||||||
case true:
|
case true:
|
||||||
do {
|
var accuHeight: CGFloat = 0.0
|
||||||
var accuHeight: CGFloat = 0.0
|
for (index, elementHeight) in elementHeights.enumerated() {
|
||||||
for (index, elementHeight) in elementHeights.enumerated() {
|
let currentHeight = elementHeight
|
||||||
let currentHeight = elementHeight
|
|
||||||
|
|
||||||
if location.y >= accuHeight, location.y <= accuHeight + currentHeight {
|
if location.y >= accuHeight, location.y <= accuHeight + currentHeight {
|
||||||
return index
|
return index
|
||||||
}
|
|
||||||
accuHeight += currentHeight
|
|
||||||
}
|
}
|
||||||
|
accuHeight += currentHeight
|
||||||
}
|
}
|
||||||
case false:
|
case false:
|
||||||
do {
|
var accuWidth: CGFloat = 0.0
|
||||||
var accuWidth: CGFloat = 0.0
|
for (index, elementWidth) in elementWidths.enumerated() {
|
||||||
for (index, elementWidth) in elementWidths.enumerated() {
|
let currentWidth = elementWidth
|
||||||
let currentWidth = elementWidth
|
|
||||||
|
|
||||||
if location.x >= accuWidth, location.x <= accuWidth + currentWidth {
|
if location.x >= accuWidth, location.x <= accuWidth + currentWidth {
|
||||||
return index
|
return index
|
||||||
}
|
|
||||||
accuWidth += currentWidth + 1.0
|
|
||||||
}
|
}
|
||||||
|
accuWidth += currentWidth + 1.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NSNotFound
|
return NSNotFound
|
||||||
|
|
Loading…
Reference in New Issue