From 0d80d28e0ea740ab8e1ba6f7d15ef99a61d77574 Mon Sep 17 00:00:00 2001 From: zonble Date: Tue, 18 Jan 2022 21:16:07 +0800 Subject: [PATCH] Formats Swift code. --- McBopomofoTests/PreferencesTests.swift | 6 +-- .../CandidateUI/CandidateController.swift | 6 +-- .../HorizontalCandidateController.swift | 8 ++-- .../VerticalCandidateController.swift | 10 ++--- .../HorizontalCandidateControllerTests.swift | 9 ++-- .../VerticalCandidateControllerTests.swift | 9 ++-- .../InputSourceHelper/InputSourceHelper.swift | 16 +++---- .../Sources/TooltipUI/TooltipController.swift | 4 +- Source/AppDelegate.swift | 43 +++++++++---------- Source/InputMethodController.mm | 2 +- Source/LanguageModelManager.mm | 2 +- Source/NonModalAlertWindowController.swift | 2 +- Source/Preferences.swift | 28 ++++++------ Source/PreferencesWindowController.swift | 11 +++-- 14 files changed, 79 insertions(+), 77 deletions(-) diff --git a/McBopomofoTests/PreferencesTests.swift b/McBopomofoTests/PreferencesTests.swift index 6c4ebc56..5310de85 100644 --- a/McBopomofoTests/PreferencesTests.swift +++ b/McBopomofoTests/PreferencesTests.swift @@ -144,9 +144,9 @@ class PreferencesTests: XCTestCase { } func testChineneConversionEngine() { - XCTAssert(Preferences.chineneConversionEngine == 0) - Preferences.chineneConversionEngine = 1 - XCTAssert(Preferences.chineneConversionEngine == 1) + XCTAssert(Preferences.chineseConversionEngine == 0) + Preferences.chineseConversionEngine = 1 + XCTAssert(Preferences.chineseConversionEngine == 1) } func testChineseConversionStyle() { diff --git a/Packages/CandidateUI/Sources/CandidateUI/CandidateController.swift b/Packages/CandidateUI/Sources/CandidateUI/CandidateController.swift index cc287ea6..0e63fc3c 100644 --- a/Packages/CandidateUI/Sources/CandidateUI/CandidateController.swift +++ b/Packages/CandidateUI/Sources/CandidateUI/CandidateController.swift @@ -34,14 +34,14 @@ import Cocoa -@objc (VTCandidateControllerDelegate) +@objc(VTCandidateControllerDelegate) public protocol CandidateControllerDelegate: AnyObject { func candidateCountForController(_ controller: CandidateController) -> UInt func candidateController(_ controller: CandidateController, candidateAtIndex index: UInt) -> String func candidateController(_ controller: CandidateController, didSelectCandidateAtIndex index: UInt) } -@objc (VTCandidateController) +@objc(VTCandidateController) public class CandidateController: NSWindowController { @objc public weak var delegate: CandidateControllerDelegate? { didSet { @@ -99,7 +99,7 @@ public class CandidateController: NSWindowController { UInt.max } - @objc (setWindowTopLeftPoint:bottomOutOfScreenAdjustmentHeight:) + @objc(setWindowTopLeftPoint:bottomOutOfScreenAdjustmentHeight:) public func set(windowTopLeftPoint: NSPoint, bottomOutOfScreenAdjustmentHeight height: CGFloat) { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()) { self.doSet(windowTopLeftPoint: windowTopLeftPoint, bottomOutOfScreenAdjustmentHeight: height) diff --git a/Packages/CandidateUI/Sources/CandidateUI/HorizontalCandidateController.swift b/Packages/CandidateUI/Sources/CandidateUI/HorizontalCandidateController.swift index c9cab45f..0239d7f9 100644 --- a/Packages/CandidateUI/Sources/CandidateUI/HorizontalCandidateController.swift +++ b/Packages/CandidateUI/Sources/CandidateUI/HorizontalCandidateController.swift @@ -64,7 +64,7 @@ fileprivate class HorizontalCandidateView: NSView { return result } - @objc (setKeyLabels:displayedCandidates:) + @objc(setKeyLabels:displayedCandidates:) func set(keyLabels labels: [String], displayedCandidates candidates: [String]) { let count = min(labels.count, candidates.count) keyLabels = Array(labels[0.. 1 { var buttonRect = nextPageButton.frame - var spacing:CGFloat = 0.0 + var spacing: CGFloat = 0.0 if newSize.height < 40.0 { buttonRect.size.height = floor(newSize.height / 2) diff --git a/Packages/CandidateUI/Sources/CandidateUI/VerticalCandidateController.swift b/Packages/CandidateUI/Sources/CandidateUI/VerticalCandidateController.swift index d12721bf..5be7cf02 100644 --- a/Packages/CandidateUI/Sources/CandidateUI/VerticalCandidateController.swift +++ b/Packages/CandidateUI/Sources/CandidateUI/VerticalCandidateController.swift @@ -91,13 +91,13 @@ fileprivate class VerticalCandidateTableView: NSTableView { } } -private let kCandidateTextPadding:CGFloat = 24.0 -private let kCandidateTextLeftMargin:CGFloat = 8.0 -private let kCandidateTextPaddingWithMandatedTableViewPadding:CGFloat = 18.0 -private let kCandidateTextLeftMarginWithMandatedTableViewPadding:CGFloat = 0.0 +private let kCandidateTextPadding: CGFloat = 24.0 +private let kCandidateTextLeftMargin: CGFloat = 8.0 +private let kCandidateTextPaddingWithMandatedTableViewPadding: CGFloat = 18.0 +private let kCandidateTextLeftMarginWithMandatedTableViewPadding: CGFloat = 0.0 -@objc (VTVerticalCandidateController) +@objc(VTVerticalCandidateController) public class VerticalCandidateController: CandidateController { private var keyLabelStripView: VerticalKeyLabelStripView private var scrollView: NSScrollView diff --git a/Packages/CandidateUI/Tests/CandidateUITests/HorizontalCandidateControllerTests.swift b/Packages/CandidateUI/Tests/CandidateUITests/HorizontalCandidateControllerTests.swift index 585355aa..62a2d816 100644 --- a/Packages/CandidateUI/Tests/CandidateUITests/HorizontalCandidateControllerTests.swift +++ b/Packages/CandidateUI/Tests/CandidateUITests/HorizontalCandidateControllerTests.swift @@ -6,6 +6,7 @@ class HorizontalCandidateControllerTests: XCTestCase { class Mock: CandidateControllerDelegate { let candidates = ["A", "B", "C", "D", "E", "F", "G", "H"] var selected: String? + func candidateCountForController(_ controller: CandidateController) -> UInt { UInt(candidates.count) } @@ -29,8 +30,8 @@ class HorizontalCandidateControllerTests: XCTestCase { controller.set(windowTopLeftPoint: NSPoint(x: -100, y: -100), bottomOutOfScreenAdjustmentHeight: 10) let exp = expectation(description: "wait") _ = XCTWaiter.wait(for: [exp], timeout: 0.2) - XCTAssert (controller.window?.frame.minX ?? -1 >= 0) - XCTAssert (controller.window?.frame.minY ?? -1 >= 0) + XCTAssert(controller.window?.frame.minX ?? -1 >= 0) + XCTAssert(controller.window?.frame.minY ?? -1 >= 0) } func testPositioning2() { @@ -44,8 +45,8 @@ class HorizontalCandidateControllerTests: XCTestCase { controller.set(windowTopLeftPoint: NSPoint(x: screenRect.maxX + 100, y: screenRect.maxY + 100), bottomOutOfScreenAdjustmentHeight: 10) let exp = expectation(description: "wait") _ = XCTWaiter.wait(for: [exp], timeout: 0.2) - XCTAssert (controller.window?.frame.maxX ?? CGFloat.greatestFiniteMagnitude <= screenRect.maxX) - XCTAssert (controller.window?.frame.maxY ?? CGFloat.greatestFiniteMagnitude <= screenRect.maxY ) + XCTAssert(controller.window?.frame.maxX ?? CGFloat.greatestFiniteMagnitude <= screenRect.maxX) + XCTAssert(controller.window?.frame.maxY ?? CGFloat.greatestFiniteMagnitude <= screenRect.maxY) } func testReloadData() { diff --git a/Packages/CandidateUI/Tests/CandidateUITests/VerticalCandidateControllerTests.swift b/Packages/CandidateUI/Tests/CandidateUITests/VerticalCandidateControllerTests.swift index 0f11378c..601da6de 100644 --- a/Packages/CandidateUI/Tests/CandidateUITests/VerticalCandidateControllerTests.swift +++ b/Packages/CandidateUI/Tests/CandidateUITests/VerticalCandidateControllerTests.swift @@ -6,6 +6,7 @@ class VerticalCandidateControllerTests: XCTestCase { class Mock: CandidateControllerDelegate { let candidates = ["A", "B", "C", "D", "E", "F", "G", "H"] var selected: String? + func candidateCountForController(_ controller: CandidateController) -> UInt { UInt(candidates.count) } @@ -29,8 +30,8 @@ class VerticalCandidateControllerTests: XCTestCase { controller.set(windowTopLeftPoint: NSPoint(x: -100, y: -100), bottomOutOfScreenAdjustmentHeight: 10) let exp = expectation(description: "wait") _ = XCTWaiter.wait(for: [exp], timeout: 0.2) - XCTAssert (controller.window?.frame.minX ?? -1 >= 0) - XCTAssert (controller.window?.frame.minY ?? -1 >= 0) + XCTAssert(controller.window?.frame.minX ?? -1 >= 0) + XCTAssert(controller.window?.frame.minY ?? -1 >= 0) } func testPositioning2() { @@ -44,8 +45,8 @@ class VerticalCandidateControllerTests: XCTestCase { controller.set(windowTopLeftPoint: NSPoint(x: screenRect.maxX + 100, y: screenRect.maxY + 100), bottomOutOfScreenAdjustmentHeight: 10) let exp = expectation(description: "wait") _ = XCTWaiter.wait(for: [exp], timeout: 0.2) - XCTAssert (controller.window?.frame.maxX ?? CGFloat.greatestFiniteMagnitude <= screenRect.maxX) - XCTAssert (controller.window?.frame.maxY ?? CGFloat.greatestFiniteMagnitude <= screenRect.maxY ) + XCTAssert(controller.window?.frame.maxX ?? CGFloat.greatestFiniteMagnitude <= screenRect.maxX) + XCTAssert(controller.window?.frame.maxY ?? CGFloat.greatestFiniteMagnitude <= screenRect.maxY) } func testReloadData() { diff --git a/Packages/InputSourceHelper/Sources/InputSourceHelper/InputSourceHelper.swift b/Packages/InputSourceHelper/Sources/InputSourceHelper/InputSourceHelper.swift index a9fc979b..c53d47fd 100644 --- a/Packages/InputSourceHelper/Sources/InputSourceHelper/InputSourceHelper.swift +++ b/Packages/InputSourceHelper/Sources/InputSourceHelper/InputSourceHelper.swift @@ -46,7 +46,7 @@ public class InputSourceHelper: NSObject { TISCreateInputSourceList(nil, true).takeRetainedValue() as! [TISInputSource] } - @objc (inputSourceForProperty:stringValue:) + @objc(inputSourceForProperty:stringValue:) public static func inputSource(for propertyKey: CFString, stringValue: String) -> TISInputSource? { let stringID = CFStringGetTypeID() for source in allInstalledInputSources() { @@ -64,12 +64,12 @@ public class InputSourceHelper: NSObject { return nil } - @objc (inputSourceForInputSourceID:) + @objc(inputSourceForInputSourceID:) public static func inputSource(for sourceID: String) -> TISInputSource? { inputSource(for: kTISPropertyInputSourceID, stringValue: sourceID) } - @objc (inputSourceEnabled:) + @objc(inputSourceEnabled:) public static func inputSourceEnabled(for source: TISInputSource) -> Bool { if let valuePts = TISGetInputSourceProperty(source, kTISPropertyInputSourceIsEnabled) { let value = Unmanaged.fromOpaque(valuePts).takeUnretainedValue() @@ -78,13 +78,13 @@ public class InputSourceHelper: NSObject { return false } - @objc (enableInputSource:) + @objc(enableInputSource:) public static func enable(inputSource: TISInputSource) -> Bool { let status = TISEnableInputSource(inputSource) return status == noErr } - @objc (enableAllInputModesForInputSourceBundleID:) + @objc(enableAllInputModesForInputSourceBundleID:) public static func enableAllInputMode(for inputSourceBundleD: String) -> Bool { var enabled = false for source in allInstalledInputSources() { @@ -105,7 +105,7 @@ public class InputSourceHelper: NSObject { return enabled } - @objc (enableInputMode:forInputSourceBundleID:) + @objc(enableInputMode:forInputSourceBundleID:) public static func enable(inputMode modeID: String, for bundleID: String) -> Bool { for source in allInstalledInputSources() { guard let bundleIDPtr = TISGetInputSourceProperty(source, kTISPropertyBundleID), @@ -126,13 +126,13 @@ public class InputSourceHelper: NSObject { } - @objc (disableInputSource:) + @objc(disableInputSource:) public static func disable(inputSource: TISInputSource) -> Bool { let status = TISDisableInputSource(inputSource) return status == noErr } - @objc (registerInputSource:) + @objc(registerInputSource:) public static func registerTnputSource(at url: URL) -> Bool { let status = TISRegisterInputSource(url as CFURL) return status == noErr diff --git a/Packages/TooltipUI/Sources/TooltipUI/TooltipController.swift b/Packages/TooltipUI/Sources/TooltipUI/TooltipController.swift index dbbbeb78..76ea5c40 100644 --- a/Packages/TooltipUI/Sources/TooltipUI/TooltipController.swift +++ b/Packages/TooltipUI/Sources/TooltipUI/TooltipController.swift @@ -1,9 +1,9 @@ import Cocoa public class TooltipController: NSWindowController { - private let backgroundColor = NSColor(calibratedHue: 0.16, saturation: 0.22, brightness: 0.97, alpha: 1.0) + private let backgroundColor = NSColor(calibratedHue: 0.16, saturation: 0.22, brightness: 0.97, alpha: 1.0) private var messageTextField: NSTextField - private var tooltip: String = "" { + private var tooltip: String = "" { didSet { messageTextField.stringValue = tooltip adjustSize() diff --git a/Source/AppDelegate.swift b/Source/AppDelegate.swift index 6fb8d9ae..eea90f07 100644 --- a/Source/AppDelegate.swift +++ b/Source/AppDelegate.swift @@ -51,15 +51,14 @@ struct VersionUpdateReport { var versionDescription: String = "" } -enum VersionUpdateApiResult -{ +enum VersionUpdateApiResult { case shouldUpdate(report: VersionUpdateReport) case noNeedToUpdate case ignored } enum VersionUpdateApiError: Error, LocalizedError { - case connectionError(message:String) + case connectionError(message: String) var errorDescription: String? { switch self { @@ -70,11 +69,11 @@ enum VersionUpdateApiError: Error, LocalizedError { } struct VersionUpdateApi { - static func check(forced: Bool, callback: @escaping (Result)->()) -> URLSessionTask? { + static func check(forced: Bool, callback: @escaping (Result) -> ()) -> URLSessionTask? { guard let infoDict = Bundle.main.infoDictionary, let updateInfoURLString = infoDict[kUpdateInfoEndpointKey] as? String, let updateInfoURL = URL(string: updateInfoURLString) else { - return nil + return nil } let request = URLRequest(url: updateInfoURL, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: kTimeoutInterval) @@ -82,8 +81,8 @@ struct VersionUpdateApi { if let error = error { DispatchQueue.main.async { forced ? - callback(.failure(VersionUpdateApiError.connectionError(message: error.localizedDescription))) : - callback(.success(.ignored)) + callback(.failure(VersionUpdateApiError.connectionError(message: error.localizedDescription))) : + callback(.success(.ignored)) } return } @@ -92,9 +91,9 @@ struct VersionUpdateApi { guard let plist = try PropertyListSerialization.propertyList(from: data ?? Data(), options: [], format: nil) as? [AnyHashable: Any], let remoteVersion = plist[kCFBundleVersionKey] as? String, let infoDict = Bundle.main.infoDictionary - else { + else { DispatchQueue.main.async { - forced ? callback(.success(.noNeedToUpdate)): callback(.success(.ignored)) + forced ? callback(.success(.noNeedToUpdate)) : callback(.success(.ignored)) } return } @@ -107,21 +106,21 @@ struct VersionUpdateApi { if result != .orderedAscending { DispatchQueue.main.async { - forced ? callback(.success(.noNeedToUpdate)): callback(.success(.ignored)) + forced ? callback(.success(.noNeedToUpdate)) : callback(.success(.ignored)) } return } guard let siteInfoURLString = plist[kUpdateInfoSiteKey] as? String, let siteInfoURL = URL(string: siteInfoURLString) - else { + else { DispatchQueue.main.async { - forced ? callback(.success(.noNeedToUpdate)): callback(.success(.ignored)) + forced ? callback(.success(.noNeedToUpdate)) : callback(.success(.ignored)) } return } - var report = VersionUpdateReport(siteUrl:siteInfoURL) + var report = VersionUpdateReport(siteUrl: siteInfoURL) var versionDescription = "" let versionDescriptions = plist["Description"] as? [AnyHashable: Any] if let versionDescriptions = versionDescriptions { @@ -146,7 +145,7 @@ struct VersionUpdateApi { } } catch { DispatchQueue.main.async { - forced ? callback(.success(.noNeedToUpdate)): callback(.success(.ignored)) + forced ? callback(.success(.noNeedToUpdate)) : callback(.success(.ignored)) } } } @@ -155,7 +154,7 @@ struct VersionUpdateApi { } } -@objc (AppDelegate) +@objc(AppDelegate) class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControllerDelegate { @IBOutlet weak var window: NSWindow? @@ -184,12 +183,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle preferencesWindowController?.window?.orderFront(self) } - @objc (checkForUpdate) + @objc(checkForUpdate) func checkForUpdate() { checkForUpdate(forced: false) } - @objc (checkForUpdateForced:) + @objc(checkForUpdateForced:) func checkForUpdate(forced: Bool) { if checkTask != nil { @@ -222,11 +221,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle case .shouldUpdate(let report): self.updateNextStepURL = report.siteUrl let content = String(format: NSLocalizedString("You're currently using McBopomofo %@ (%@), a new version %@ (%@) is now available. Do you want to visit McBopomofo's website to download the version?%@", comment: ""), - report.currentShortVersion, - report.currentVersion, - report.remoteShortVersion, - report.remoteVersion, - report.versionDescription) + report.currentShortVersion, + report.currentVersion, + report.remoteShortVersion, + report.remoteVersion, + report.versionDescription) NonModalAlertWindowController.shared.show(title: NSLocalizedString("New Version Available", comment: ""), content: content, confirmButtonTitle: NSLocalizedString("Visit Website", comment: ""), cancelButtonTitle: NSLocalizedString("Not Now", comment: ""), cancelAsDefault: false, delegate: self) case .noNeedToUpdate, .ignored: break diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index 7372b319..9ef30ee8 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -326,7 +326,7 @@ static double FindHighestScore(const vector& nodes, double epsilon) return text; } - if (Preferences.chineneConversionEngine == 1) { + if (Preferences.chineseConversionEngine == 1) { return [VXHanConvert convertToSimplifiedFrom:text]; } return [OpenCCBridge convertToSimplified:text]; diff --git a/Source/LanguageModelManager.mm b/Source/LanguageModelManager.mm index bdf0ac9f..6d9193f5 100644 --- a/Source/LanguageModelManager.mm +++ b/Source/LanguageModelManager.mm @@ -59,7 +59,7 @@ static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, McBopomo } NSString *text = [NSString stringWithUTF8String:input.c_str()]; - if (Preferences.chineneConversionEngine == 1) { + if (Preferences.chineseConversionEngine == 1) { text = [VXHanConvert convertToSimplifiedFrom:text]; } else { diff --git a/Source/NonModalAlertWindowController.swift b/Source/NonModalAlertWindowController.swift index 2a227bee..0b67d9c2 100644 --- a/Source/NonModalAlertWindowController.swift +++ b/Source/NonModalAlertWindowController.swift @@ -40,7 +40,7 @@ import Cocoa } class NonModalAlertWindowController: NSWindowController { - @objc (sharedInstance) + @objc(sharedInstance) static let shared = NonModalAlertWindowController(windowNibName: "NonModalAlertWindowController") @IBOutlet weak var titleTextField: NSTextField! diff --git a/Source/Preferences.swift b/Source/Preferences.swift index 6c0cc7a5..d0415873 100644 --- a/Source/Preferences.swift +++ b/Source/Preferences.swift @@ -35,9 +35,9 @@ import Cocoa private let kKeyboardLayoutPreferenceKey = "KeyboardLayout" -private let kBasisKeyboardLayoutPreferenceKey = "BasisKeyboardLayout"; // alphanumeric ("ASCII") input basi -private let kFunctionKeyKeyboardLayoutPreferenceKey = "FunctionKeyKeyboardLayout"; // alphanumeric ("ASCII") input basi -private let kFunctionKeyKeyboardLayoutOverrideIncludeShiftKey = "FunctionKeyKeyboardLayoutOverrideIncludeShift"; // whether include shif +private let kBasisKeyboardLayoutPreferenceKey = "BasisKeyboardLayout" // alphanumeric ("ASCII") input basi +private let kFunctionKeyKeyboardLayoutPreferenceKey = "FunctionKeyKeyboardLayout" // alphanumeric ("ASCII") input basi +private let kFunctionKeyKeyboardLayoutOverrideIncludeShiftKey = "FunctionKeyKeyboardLayoutOverrideIncludeShift" // whether include shif private let kCandidateListTextSizeKey = "CandidateListTextSize" private let kSelectPhraseAfterCursorAsCandidatePreferenceKey = "SelectPhraseAfterCursorAsCandidate" private let kUseHorizontalCandidateListPreferenceKey = "UseHorizontalCandidateList" @@ -79,7 +79,7 @@ struct UserDefault { var wrappedValue: Value { get { - return container.object(forKey: key) as? Value ?? defaultValue + container.object(forKey: key) as? Value ?? defaultValue } set { container.set(newValue, forKey: key) @@ -92,7 +92,8 @@ struct CandidateListTextSize { let key: String let defaultValue: CGFloat = kDefaultCandidateListTextSize lazy var container: UserDefault = { - UserDefault(key: key, defaultValue: defaultValue) }() + UserDefault(key: key, defaultValue: defaultValue) + }() var wrappedValue: CGFloat { mutating get { @@ -121,7 +122,8 @@ struct ComposingBufferSize { let key: String let defaultValue: Int = kDefaultComposingBufferSize lazy var container: UserDefault = { - UserDefault(key: key, defaultValue: defaultValue) }() + UserDefault(key: key, defaultValue: defaultValue) + }() var wrappedValue: Int { mutating get { @@ -230,7 +232,7 @@ class Preferences: NSObject { @objc static var keyboardLayout: Int @objc static var keyboardLayoutName: String { - (KeyboardLayout(rawValue: self.keyboardLayout) ?? KeyboardLayout.standard).name + (KeyboardLayout(rawValue: keyboardLayout) ?? KeyboardLayout.standard).name } @UserDefault(key: kBasisKeyboardLayoutPreferenceKey, defaultValue: "com.apple.keylayout.US") @@ -270,7 +272,7 @@ class Preferences: NSObject { @objc static func toggleHalfWidthPunctuationEnabled() -> Bool { halfWidthPunctuationEnabled = !halfWidthPunctuationEnabled - return halfWidthPunctuationEnabled; + return halfWidthPunctuationEnabled } @UserDefault(key: kEscToCleanInputBufferKey, defaultValue: false) @@ -349,7 +351,7 @@ class Preferences: NSObject { @objc static func togglePhraseReplacementEnabled() -> Bool { phraseReplacementEnabled = !phraseReplacementEnabled - return phraseReplacementEnabled; + return phraseReplacementEnabled } /// The conversion engine. @@ -357,10 +359,10 @@ class Preferences: NSObject { /// - 0: OpenCC /// - 1: VXHanConvert @UserDefault(key: kChineseConversionEngineKey, defaultValue: 0) - @objc static var chineneConversionEngine: Int + @objc static var chineseConversionEngine: Int - @objc static var chineneConversionEngineName: String? { - return ChineseConversionEngine(rawValue: chineneConversionEngine)?.name + @objc static var chineseConversionEngineName: String? { + ChineseConversionEngine(rawValue: chineseConversionEngine)?.name } /// The conversion style. @@ -371,7 +373,7 @@ class Preferences: NSObject { @objc static var chineseConversionStyle: Int @objc static var chineseConversionStyleName: String? { - return ChineseConversionStyle(rawValue: chineseConversionStyle)?.name + ChineseConversionStyle(rawValue: chineseConversionStyle)?.name } } diff --git a/Source/PreferencesWindowController.swift b/Source/PreferencesWindowController.swift index 4d756da8..6a3badb7 100644 --- a/Source/PreferencesWindowController.swift +++ b/Source/PreferencesWindowController.swift @@ -38,7 +38,7 @@ import Carbon // Please note that the class should be exposed as "PreferencesWindowController" // in Objective-C in order to let IMK to see the same class name as // the "InputMethodServerPreferencesWindowControllerClass" in Info.plist. -@objc (PreferencesWindowController) class PreferencesWindowController: NSWindowController { +@objc(PreferencesWindowController) class PreferencesWindowController: NSWindowController { @IBOutlet weak var fontSizePopUpButton: NSPopUpButton! @IBOutlet weak var basisKeyboardLayoutButton: NSPopUpButton! @IBOutlet weak var selectionKeyComboBox: NSComboBox! @@ -104,13 +104,14 @@ import Carbon let icon = IconRef(iconPtr) let image = NSImage(iconRef: icon) - func resize( _ image: NSImage) -> NSImage { + func resize(_ image: NSImage) -> NSImage { let newImage = NSImage(size: NSSize(width: 16, height: 16)) newImage.lockFocus() image.draw(in: NSRect(x: 0, y: 0, width: 16, height: 16)) newImage.unlockFocus() return newImage } + menuItem.image = resize(image) } @@ -149,11 +150,9 @@ import Carbon do { try Preferences.validate(candidateKeys: keys) Preferences.candidateKeys = keys - } - catch Preferences.CandidateKeyError.empty { + } catch Preferences.CandidateKeyError.empty { selectionKeyComboBox.stringValue = Preferences.candidateKeys - } - catch { + } catch { if let window = window { let alert = NSAlert(error: error) alert.beginSheetModal(for: window) { response in