diff --git a/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift b/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift index 5c4ad2db..b3544270 100644 --- a/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift +++ b/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift @@ -154,18 +154,14 @@ extension KeyHandler { if input.isLeft { switch ctlCandidateCurrent.currentLayout { case .horizontal: - do { - if !ctlCandidateCurrent.highlightPreviousCandidate() { - IME.prtDebugIntel("1145148D") - errorCallback() - } + if !ctlCandidateCurrent.highlightPreviousCandidate() { + IME.prtDebugIntel("1145148D") + errorCallback() } case .vertical: - do { - if !ctlCandidateCurrent.showPreviousPage() { - IME.prtDebugIntel("1919810D") - errorCallback() - } + if !ctlCandidateCurrent.showPreviousPage() { + IME.prtDebugIntel("1919810D") + errorCallback() } } return true @@ -187,18 +183,14 @@ extension KeyHandler { if input.isRight { switch ctlCandidateCurrent.currentLayout { case .horizontal: - do { - if !ctlCandidateCurrent.highlightNextCandidate() { - IME.prtDebugIntel("9B65138D") - errorCallback() - } + if !ctlCandidateCurrent.highlightNextCandidate() { + IME.prtDebugIntel("9B65138D") + errorCallback() } case .vertical: - do { - if !ctlCandidateCurrent.showNextPage() { - IME.prtDebugIntel("9244908D") - errorCallback() - } + if !ctlCandidateCurrent.showNextPage() { + IME.prtDebugIntel("9244908D") + errorCallback() } } return true @@ -220,18 +212,14 @@ extension KeyHandler { if input.isUp { switch ctlCandidateCurrent.currentLayout { case .horizontal: - do { - if !ctlCandidateCurrent.showPreviousPage() { - IME.prtDebugIntel("9B614524") - errorCallback() - } + if !ctlCandidateCurrent.showPreviousPage() { + IME.prtDebugIntel("9B614524") + errorCallback() } case .vertical: - do { - if !ctlCandidateCurrent.highlightPreviousCandidate() { - IME.prtDebugIntel("ASD9908D") - errorCallback() - } + if !ctlCandidateCurrent.highlightPreviousCandidate() { + IME.prtDebugIntel("ASD9908D") + errorCallback() } } return true @@ -242,18 +230,14 @@ extension KeyHandler { if input.isDown { switch ctlCandidateCurrent.currentLayout { case .horizontal: - do { - if !ctlCandidateCurrent.showNextPage() { - IME.prtDebugIntel("92B990DD") - errorCallback() - } + if !ctlCandidateCurrent.showNextPage() { + IME.prtDebugIntel("92B990DD") + errorCallback() } case .vertical: - do { - if !ctlCandidateCurrent.highlightNextCandidate() { - IME.prtDebugIntel("6B99908D") - errorCallback() - } + if !ctlCandidateCurrent.highlightNextCandidate() { + IME.prtDebugIntel("6B99908D") + errorCallback() } } return true diff --git a/Source/Modules/ControllerModules/KeyHandler_States.swift b/Source/Modules/ControllerModules/KeyHandler_States.swift index 1c416d92..40e2a73d 100644 --- a/Source/Modules/ControllerModules/KeyHandler_States.swift +++ b/Source/Modules/ControllerModules/KeyHandler_States.swift @@ -81,10 +81,8 @@ extension KeyHandler { case 0: tooltipParameterRef[1] = compositor.readings[compositorCursorIndex] default: - do { - tooltipParameterRef[0] = compositor.readings[compositorCursorIndex - 1] - tooltipParameterRef[1] = compositor.readings[compositorCursorIndex] - } + tooltipParameterRef[0] = compositor.readings[compositorCursorIndex - 1] + tooltipParameterRef[1] = compositor.readings[compositorCursorIndex] } /// 注音轉拼音 for (i, _) in tooltipParameterRef.enumerated() { diff --git a/Source/Modules/main.swift b/Source/Modules/main.swift index e6a3a8b8..ec01b966 100644 --- a/Source/Modules/main.swift +++ b/Source/Modules/main.swift @@ -32,24 +32,18 @@ let kConnectionName = "vChewing_1_Connection" switch max(CommandLine.arguments.count - 1, 0) { case 0: break case 1, 2: - do { - switch CommandLine.arguments[1] { - case "install": - do { - if CommandLine.arguments[1] == "install" { - let exitCode = IME.registerInputMethod() - exit(exitCode) - } - } - case "uninstall": - do { - if CommandLine.arguments[1] == "uninstall" { - let exitCode = IME.uninstall(isSudo: IME.isSudoMode) - exit(exitCode) - } - } - default: break - } + switch CommandLine.arguments[1] { + case "install": + if CommandLine.arguments[1] == "install" { + let exitCode = IME.registerInputMethod() + exit(exitCode) + } + case "uninstall": + if CommandLine.arguments[1] == "uninstall" { + let exitCode = IME.uninstall(isSudo: IME.isSudoMode) + exit(exitCode) + } + default: break } exit(0) default: exit(0) diff --git a/Source/UI/CandidateUI/ctlCandidateUniversal.swift b/Source/UI/CandidateUI/ctlCandidateUniversal.swift index 2fc4dd31..5663fcc8 100644 --- a/Source/UI/CandidateUI/ctlCandidateUniversal.swift +++ b/Source/UI/CandidateUI/ctlCandidateUniversal.swift @@ -162,146 +162,142 @@ private class vwrCandidateUniversal: NSView { switch isVerticalLayout { case true: - do { - var accuHeight: CGFloat = 0 - for (index, elementHeight) in elementHeights.enumerated() { - let currentHeight = elementHeight - let rctCandidateArea = NSRect( - x: 0.0, y: accuHeight, width: windowWidth, height: candidateTextHeight + cellPadding - ) - let rctLabel = NSRect( - x: cellPadding / 2 - 1, y: accuHeight + cellPadding / 2, width: keyLabelWidth, - height: keyLabelHeight * 2.0 - ) - let rctCandidatePhrase = NSRect( - x: cellPadding / 2 - 1 + keyLabelWidth, y: accuHeight + cellPadding / 2 - 1, - width: windowWidth - keyLabelWidth, height: candidateTextHeight - ) + var accuHeight: CGFloat = 0 + for (index, elementHeight) in elementHeights.enumerated() { + let currentHeight = elementHeight + let rctCandidateArea = NSRect( + x: 0.0, y: accuHeight, width: windowWidth, height: candidateTextHeight + cellPadding + ) + let rctLabel = NSRect( + x: cellPadding / 2 - 1, y: accuHeight + cellPadding / 2, width: keyLabelWidth, + height: keyLabelHeight * 2.0 + ) + let rctCandidatePhrase = NSRect( + x: cellPadding / 2 - 1 + keyLabelWidth, y: accuHeight + cellPadding / 2 - 1, + width: windowWidth - keyLabelWidth, height: candidateTextHeight + ) - var activeCandidateIndexAttr = keyLabelAttrDict - var activeCandidateAttr = candidateAttrDict - if index == highlightedIndex { - let colorBlendAmount: CGFloat = IME.isDarkMode() ? 0.25 : 0 - // 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() - } + var activeCandidateIndexAttr = keyLabelAttrDict + var activeCandidateAttr = candidateAttrDict + if index == highlightedIndex { + let colorBlendAmount: CGFloat = IME.isDarkMode() ? 0.25 : 0 + // The background color of the highlightened candidate switch IME.currentInputMode { case InputMode.imeModeCHS: - if #available(macOS 12.0, *) { - activeCandidateAttr[.languageIdentifier] = "zh-Hans" as AnyObject - } + NSColor.systemRed.blended( + withFraction: colorBlendAmount, + of: NSColor.controlBackgroundColor + )! + .setFill() case InputMode.imeModeCHT: - if #available(macOS 12.0, *) { - activeCandidateAttr[.languageIdentifier] = - (mgrPrefs.shiftJISShinjitaiOutputEnabled || mgrPrefs.chineseConversionEnabled) - ? "ja" as AnyObject : "zh-Hant" as AnyObject - } + NSColor.systemBlue.blended( + withFraction: colorBlendAmount, + of: NSColor.controlBackgroundColor + )! + .setFill() default: - break + NSColor.alternateSelectedControlColor.setFill() } - NSBezierPath.fill(rctCandidateArea) - (keyLabels[index] as NSString).draw( - in: rctLabel, withAttributes: activeCandidateIndexAttr - ) - (displayedCandidates[index] as NSString).draw( - in: rctCandidatePhrase, withAttributes: activeCandidateAttr - ) - accuHeight += currentHeight + // 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 { + 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: - do { - var accuWidth: CGFloat = 0 - for (index, elementWidth) in elementWidths.enumerated() { - let currentWidth = elementWidth - let rctCandidateArea = NSRect( - x: accuWidth, y: 0.0, width: currentWidth + 1.0, - height: candidateTextHeight + cellPadding - ) - let rctLabel = NSRect( - x: accuWidth + cellPadding / 2 - 1, y: cellPadding / 2, width: keyLabelWidth, - height: keyLabelHeight * 2.0 - ) - let rctCandidatePhrase = NSRect( - x: accuWidth + keyLabelWidth - 1, y: cellPadding / 2 - 1, - width: currentWidth - keyLabelWidth, - height: candidateTextHeight - ) + var accuWidth: CGFloat = 0 + for (index, elementWidth) in elementWidths.enumerated() { + let currentWidth = elementWidth + let rctCandidateArea = NSRect( + x: accuWidth, y: 0.0, width: currentWidth + 1.0, + height: candidateTextHeight + cellPadding + ) + let rctLabel = NSRect( + x: accuWidth + cellPadding / 2 - 1, y: cellPadding / 2, width: keyLabelWidth, + height: keyLabelHeight * 2.0 + ) + let rctCandidatePhrase = NSRect( + x: accuWidth + keyLabelWidth - 1, y: cellPadding / 2 - 1, + width: currentWidth - keyLabelWidth, + height: candidateTextHeight + ) - var activeCandidateIndexAttr = keyLabelAttrDict - var activeCandidateAttr = candidateAttrDict - if index == highlightedIndex { - let colorBlendAmount: CGFloat = IME.isDarkMode() ? 0.25 : 0 - // 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() - } + var activeCandidateIndexAttr = keyLabelAttrDict + var activeCandidateAttr = candidateAttrDict + if index == highlightedIndex { + let colorBlendAmount: CGFloat = IME.isDarkMode() ? 0.25 : 0 + // The background color of the highlightened candidate switch IME.currentInputMode { case InputMode.imeModeCHS: - if #available(macOS 12.0, *) { - activeCandidateAttr[.languageIdentifier] = "zh-Hans" as AnyObject - } + NSColor.systemRed.blended( + withFraction: colorBlendAmount, + of: NSColor.controlBackgroundColor + )! + .setFill() case InputMode.imeModeCHT: - if #available(macOS 12.0, *) { - activeCandidateAttr[.languageIdentifier] = - (mgrPrefs.shiftJISShinjitaiOutputEnabled || mgrPrefs.chineseConversionEnabled) - ? "ja" as AnyObject : "zh-Hant" as AnyObject - } + NSColor.systemBlue.blended( + withFraction: colorBlendAmount, + of: NSColor.controlBackgroundColor + )! + .setFill() default: - break + NSColor.alternateSelectedControlColor.setFill() } - 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 + // 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 { + 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 { case true: - do { - var accuHeight: CGFloat = 0.0 - for (index, elementHeight) in elementHeights.enumerated() { - let currentHeight = elementHeight + var accuHeight: CGFloat = 0.0 + for (index, elementHeight) in elementHeights.enumerated() { + let currentHeight = elementHeight - if location.y >= accuHeight, location.y <= accuHeight + currentHeight { - return index - } - accuHeight += currentHeight + if location.y >= accuHeight, location.y <= accuHeight + currentHeight { + return index } + accuHeight += currentHeight } case false: - do { - var accuWidth: CGFloat = 0.0 - for (index, elementWidth) in elementWidths.enumerated() { - let currentWidth = elementWidth + var accuWidth: CGFloat = 0.0 + for (index, elementWidth) in elementWidths.enumerated() { + let currentWidth = elementWidth - if location.x >= accuWidth, location.x <= accuWidth + currentWidth { - return index - } - accuWidth += currentWidth + 1.0 + if location.x >= accuWidth, location.x <= accuWidth + currentWidth { + return index } + accuWidth += currentWidth + 1.0 } } return NSNotFound