From f339948219fed103e2b98c6a336b015248d53885 Mon Sep 17 00:00:00 2001 From: zonble Date: Tue, 11 Jan 2022 13:46:29 +0800 Subject: [PATCH] Fixes duplicated code and typos. --- .gitignore | 1 + .../CandidateUI/CandidateController.swift | 12 ++-- .../HorizontalCandidateController.swift | 24 +++---- .../VerticalCandidateController.swift | 18 +++--- Source/AppDelegate.swift | 20 +++--- Source/InputMethodController.h | 2 +- Source/InputMethodController.mm | 62 +++++++------------ Source/InputSourceHelper.swift | 28 ++++----- Source/NonModalAlertWindowController.swift | 43 ++++++------- Source/OpenCCBridge.swift | 8 +-- Source/PreferencesWindowController.swift | 10 +-- 11 files changed, 108 insertions(+), 120 deletions(-) diff --git a/.gitignore b/.gitignore index 1e054964..242ad78a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build +.build *.pbxuser *.mode1v3 *.tm_build_errors diff --git a/Packages/CandidateUI/Sources/CandidateUI/CandidateController.swift b/Packages/CandidateUI/Sources/CandidateUI/CandidateController.swift index dfa83d19..073eef4a 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? @objc public var selectedCandidateIndex: UInt = UInt.max @@ -95,7 +95,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) @@ -110,9 +110,9 @@ public class CandidateController: NSWindowController { for screen in NSScreen.screens { let frame = screen.visibleFrame if windowTopLeftPoint.x >= frame.minX && - windowTopLeftPoint.x <= frame.maxX && - windowTopLeftPoint.y >= frame.minY && - windowTopLeftPoint.y <= frame.maxY { + windowTopLeftPoint.x <= frame.maxX && + windowTopLeftPoint.y >= frame.minY && + windowTopLeftPoint.y <= frame.maxY { screenFrame = frame break } diff --git a/Packages/CandidateUI/Sources/CandidateUI/HorizontalCandidateController.swift b/Packages/CandidateUI/Sources/CandidateUI/HorizontalCandidateController.swift index 8f6b9b7a..c7d7d505 100644 --- a/Packages/CandidateUI/Sources/CandidateUI/HorizontalCandidateController.swift +++ b/Packages/CandidateUI/Sources/CandidateUI/HorizontalCandidateController.swift @@ -44,8 +44,8 @@ fileprivate class HorizontalCandidateView: NSView { private var keyLabelHeight: CGFloat = 0 private var candidateTextHeight: CGFloat = 0 private var cellPadding: CGFloat = 0 - private var keyLabelAttrDict: [NSAttributedString.Key:AnyObject] = [:] - private var candidateAttrDict: [NSAttributedString.Key:AnyObject] = [:] + private var keyLabelAttrDict: [NSAttributedString.Key: AnyObject] = [:] + private var candidateAttrDict: [NSAttributedString.Key: AnyObject] = [:] private var elementWidths: [CGFloat] = [] private var trackingHighlightedIndex: UInt = UInt.max @@ -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 { + if pageCount > 1 { var buttonRect = nextPageButton.frame var spacing = 0.0 @@ -397,7 +397,7 @@ extension HorizontalCandidateController { frameRect.size = newSize frameRect.origin = NSMakePoint(topLeftPoint.x, topLeftPoint.y - frameRect.size.height) self.window?.setFrame(frameRect, display: false) - self.candidateView.setNeedsDisplay(candidateView.bounds) + candidateView.setNeedsDisplay(candidateView.bounds) } @objc fileprivate func pageButtonAction(_ sender: Any) { @@ -407,12 +407,12 @@ extension HorizontalCandidateController { if sender == nextPageButton { _ = showNextPage() } else if sender == prevPageButton { - _ = showPreviousPage() + _ = showPreviousPage() } } @objc fileprivate func candidateViewMouseDidClick(_ sender: Any) { - delegate?.candidateController(self, didSelectCandidateAtIndex: self.selectedCandidateIndex) + delegate?.candidateController(self, didSelectCandidateAtIndex: selectedCandidateIndex) } } diff --git a/Packages/CandidateUI/Sources/CandidateUI/VerticalCandidateController.swift b/Packages/CandidateUI/Sources/CandidateUI/VerticalCandidateController.swift index 495da285..746b32d8 100644 --- a/Packages/CandidateUI/Sources/CandidateUI/VerticalCandidateController.swift +++ b/Packages/CandidateUI/Sources/CandidateUI/VerticalCandidateController.swift @@ -62,7 +62,7 @@ fileprivate class VerticalKeyLabelStripView: NSView { paraStyle.setParagraphStyle(NSParagraphStyle.default) paraStyle.alignment = .center - let textAttr: [NSAttributedString.Key:AnyObject] = [ + let textAttr: [NSAttributedString.Key: AnyObject] = [ .font: keyLabelFont, .foregroundColor: black, .paragraphStyle: paraStyle] @@ -97,7 +97,7 @@ private let kCandidateTextPaddingWithMandatedTableViewPadding = 18.0 private let kCandidateTextLeftMarginWithMandatedTableViewPadding = 0.0 -@objc(VTVerticalCandidateController) +@objc (VTVerticalCandidateController) public class VerticalCandidateController: CandidateController { private var keyLabelStripView: VerticalKeyLabelStripView private var scrollView: NSScrollView @@ -172,7 +172,7 @@ public class VerticalCandidateController: CandidateController { public override func reloadData() { maxCandidateAttrStringWidth = ceil(candidateFont.pointSize * 2.0 + candidateTextPadding) tableView.reloadData() - self.layoutCandidateView() + layoutCandidateView() if delegate?.candidateCountForController(self) ?? 0 > 0 { selectedCandidateIndex = 0 } @@ -210,7 +210,7 @@ public class VerticalCandidateController: CandidateController { return UInt.max } - @objc public override var selectedCandidateIndex: UInt { + public override var selectedCandidateIndex: UInt { get { let selectedRow = tableView.selectedRow return selectedRow == -1 ? UInt.max : UInt(selectedRow) @@ -272,7 +272,7 @@ extension VerticalCandidateController: NSTableViewDataSource, NSTableViewDelegat // we do more work than what this method is expected to; normally not a good practice, but for the amount of data (9 to 10 rows max), we can afford the overhead // expand the window width if text overflows - let boundingRect = attrString.boundingRect(with: NSSize(width: 10240.0, height: 10240.0) , options: .usesLineFragmentOrigin) + let boundingRect = attrString.boundingRect(with: NSSize(width: 10240.0, height: 10240.0), options: .usesLineFragmentOrigin) let textWidth = boundingRect.size.width + candidateTextPadding if textWidth > maxCandidateAttrStringWidth { maxCandidateAttrStringWidth = textWidth @@ -287,7 +287,7 @@ extension VerticalCandidateController: NSTableViewDataSource, NSTableViewDelegat var newHilightIndex = 0 if keyLabelStripView.highlightedIndex != -1 && - (row >= selectedRow + Int(count) || (selectedRow > count && row <= selectedRow - Int(count))) { + (row >= selectedRow + Int(count) || (selectedRow > count && row <= selectedRow - Int(count))) { newHilightIndex = -1 } else { let firstVisibleRow = tableView.row(at: scrollView.documentVisibleRect.origin) @@ -390,11 +390,11 @@ extension VerticalCandidateController: NSTableViewDataSource, NSTableViewDelegat private func layoutCandidateView() { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()) { [self] in - self.doLayoutCanaditeView() + doLayoutCandidateView() } } - private func doLayoutCanaditeView() { + private func doLayoutCandidateView() { guard let delegate = delegate else { return } @@ -430,7 +430,7 @@ extension VerticalCandidateController: NSTableViewDataSource, NSTableViewDelegat tableView.rowHeight = rowHeight var maxKeyLabelWidth = keyLabelFontSize - let textAttr: [NSAttributedString.Key:AnyObject] = [.font: keyLabelFont] + let textAttr: [NSAttributedString.Key: AnyObject] = [.font: keyLabelFont] let boundingBox = NSSize(width: 1600.0, height: 1600.0) for label in keyLabels { diff --git a/Source/AppDelegate.swift b/Source/AppDelegate.swift index 620fbbfe..ac58d0e8 100644 --- a/Source/AppDelegate.swift +++ b/Source/AppDelegate.swift @@ -42,7 +42,7 @@ private let kUpdateInfoSiteKey = "UpdateInfoSite" private let kNextCheckInterval: TimeInterval = 86400.0 private let kTimeoutInterval: TimeInterval = 60.0 -@objc(AppDelegate) +@objc (AppDelegate) class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControllerDelegate { @IBOutlet weak var window: NSWindow? @@ -69,12 +69,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 { @@ -98,15 +98,15 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle UserDefaults.standard.set(nextUpdateDate, forKey: kNextUpdateCheckDateKey) guard let infoDict = Bundle.main.infoDictionary, - let updateInfoURLString = infoDict[kUpdateInfoEndpointKey] as? String, - let updateInfoURL = URL(string: updateInfoURLString) else { + let updateInfoURLString = infoDict[kUpdateInfoEndpointKey] as? String, + let updateInfoURL = URL(string: updateInfoURLString) else { return } let request = URLRequest(url: updateInfoURL, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: kTimeoutInterval) func showNoUpdateAvailableAlert() { - NonModalAlertWindowController.shared.show(title: NSLocalizedString("Check for Update Completed", comment: ""), content: NSLocalizedString("You are already using the latest version of McBopomofo.", comment: ""), confirmButtonTitle: NSLocalizedString("OK", comment: "") , cancelButtonTitle: nil, cancelAsDefault: false, delegate: nil) + NonModalAlertWindowController.shared.show(title: NSLocalizedString("Check for Update Completed", comment: ""), content: NSLocalizedString("You are already using the latest version of McBopomofo.", comment: ""), confirmButtonTitle: NSLocalizedString("OK", comment: ""), cancelButtonTitle: nil, cancelAsDefault: false, delegate: nil) } let task = URLSession.shared.dataTask(with: request) { data, response, error in @@ -121,7 +121,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle let buttonTitle = NSLocalizedString("Dismiss", comment: "") DispatchQueue.main.async { - NonModalAlertWindowController.shared.show(title:title , content: content, confirmButtonTitle: buttonTitle, cancelButtonTitle: nil, cancelAsDefault: false, delegate: nil) + NonModalAlertWindowController.shared.show(title: title, content: content, confirmButtonTitle: buttonTitle, cancelButtonTitle: nil, cancelAsDefault: false, delegate: nil) } } return @@ -131,7 +131,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle 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 { if forced { DispatchQueue.main.async { showNoUpdateAvailableAlert() @@ -156,7 +156,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle } guard let siteInfoURLString = plist[kUpdateInfoSiteKey] as? String, - let siteInfoURL = URL(string: siteInfoURLString) else { + let siteInfoURL = URL(string: siteInfoURLString) else { if forced { DispatchQueue.main.async { showNoUpdateAvailableAlert() @@ -189,7 +189,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle remoteVersion, versionDescription) DispatchQueue.main.async { - 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) + 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) } } catch { diff --git a/Source/InputMethodController.h b/Source/InputMethodController.h index 3fe1fdcc..97b745e7 100644 --- a/Source/InputMethodController.h +++ b/Source/InputMethodController.h @@ -68,7 +68,7 @@ // a special deferred client for Terminal.app fix id _currentDeferredClient; - // currently available candidates + // current available candidates NSMutableArray *_candidates; // current input mode diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index 0b075cf9..3442c853 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -1140,50 +1140,14 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; } string layout = [self currentLayout]; string customPunctuation = string("_punctuation_") + layout + string(1, (char)charCode); if (_languageModel->hasUnigramsForKey(customPunctuation)) { - if (_bpmfReadingBuffer->isEmpty()) { - _builder->insertReadingAtCursor(customPunctuation); - [self popOverflowComposingTextAndWalk:client]; - } - else { // If there is still unfinished bpmf reading, ignore the punctuation - [self beep]; - } - [self updateClientComposingBuffer:client]; - - if (_inputMode == kPlainBopomofoModeIdentifier && _bpmfReadingBuffer->isEmpty()) { - [self collectCandidates]; - if ([_candidates count] == 1) { - [self commitComposition:client]; - } - else { - [self _showCandidateWindowUsingVerticalMode:useVerticalMode client:client]; - } - } - + [self handlePunctuation:customPunctuation usingVerticalMode:useVerticalMode client:client]; return YES; } // if nothing is matched, see if it's a punctuation key string punctuation = string("_punctuation_") + string(1, (char)charCode); if (_languageModel->hasUnigramsForKey(punctuation)) { - if (_bpmfReadingBuffer->isEmpty()) { - _builder->insertReadingAtCursor(punctuation); - [self popOverflowComposingTextAndWalk:client]; - } - else { // If there is still unfinished bpmf reading, ignore the punctuation - [self beep]; - } - [self updateClientComposingBuffer:client]; - - if (_inputMode == kPlainBopomofoModeIdentifier && _bpmfReadingBuffer->isEmpty()) { - [self collectCandidates]; - if ([_candidates count] == 1) { - [self commitComposition:client]; - } - else { - [self _showCandidateWindowUsingVerticalMode:useVerticalMode client:client]; - } - } - + [self handlePunctuation:punctuation usingVerticalMode:useVerticalMode client:client]; return YES; } @@ -1199,6 +1163,28 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; } return NO; } +- (void)handlePunctuation:(string)customPunctuation usingVerticalMode:(BOOL)useVerticalMode client:(id)client +{ + if (_bpmfReadingBuffer->isEmpty()) { + _builder->insertReadingAtCursor(customPunctuation); + [self popOverflowComposingTextAndWalk:client]; + } + else { // If there is still unfinished bpmf reading, ignore the punctuation + [self beep]; + } + [self updateClientComposingBuffer:client]; + + if (_inputMode == kPlainBopomofoModeIdentifier && _bpmfReadingBuffer->isEmpty()) { + [self collectCandidates]; + if ([_candidates count] == 1) { + [self commitComposition:client]; + } + else { + [self _showCandidateWindowUsingVerticalMode:useVerticalMode client:client]; + } + } +} + - (BOOL)handleCandidateEventWithInputText:(NSString *)inputText charCode:(UniChar)charCode keyCode:(NSUInteger)keyCode { BOOL cancelCandidateKey = diff --git a/Source/InputSourceHelper.swift b/Source/InputSourceHelper.swift index e5c1bf83..a9fc979b 100644 --- a/Source/InputSourceHelper.swift +++ b/Source/InputSourceHelper.swift @@ -46,12 +46,12 @@ 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() { - if let proprtyPtr = TISGetInputSourceProperty(source, propertyKey) { - let property = Unmanaged.fromOpaque(proprtyPtr).takeUnretainedValue() + if let propertyPtr = TISGetInputSourceProperty(source, propertyKey) { + let property = Unmanaged.fromOpaque(propertyPtr).takeUnretainedValue() let typeID = CFGetTypeID(property) if typeID != stringID { continue @@ -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,20 +78,20 @@ 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() { guard let bundleIDPtr = TISGetInputSourceProperty(source, kTISPropertyBundleID), let _ = TISGetInputSourceProperty(source, kTISPropertyInputModeID) else { - continue - } + continue + } let bundleID = Unmanaged.fromOpaque(bundleIDPtr).takeUnretainedValue() if String(bundleID) == inputSourceBundleD { let modeEnabled = self.enable(inputSource: source) @@ -105,13 +105,13 @@ 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), let modePtr = TISGetInputSourceProperty(source, kTISPropertyInputModeID) else { - continue - } + continue + } let inputsSourceBundleID = Unmanaged.fromOpaque(bundleIDPtr).takeUnretainedValue() let inputsSourceModeID = Unmanaged.fromOpaque(modePtr).takeUnretainedValue() if modeID == String(inputsSourceModeID) && bundleID == String(inputsSourceBundleID) { @@ -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/Source/NonModalAlertWindowController.swift b/Source/NonModalAlertWindowController.swift index 4f1b60eb..2a227bee 100644 --- a/Source/NonModalAlertWindowController.swift +++ b/Source/NonModalAlertWindowController.swift @@ -40,45 +40,46 @@ import Cocoa } class NonModalAlertWindowController: NSWindowController { - @objc(sharedInstance) static let shared = NonModalAlertWindowController(windowNibName: "NonModalAlertWindowController") - + @objc (sharedInstance) + static let shared = NonModalAlertWindowController(windowNibName: "NonModalAlertWindowController") + @IBOutlet weak var titleTextField: NSTextField! @IBOutlet weak var contentTextField: NSTextField! @IBOutlet weak var confirmButton: NSButton! @IBOutlet weak var cancelButton: NSButton! weak var delegate: NonModalAlertWindowControllerDelegate? - + @objc func show(title: String, content: String, confirmButtonTitle: String, cancelButtonTitle: String?, cancelAsDefault: Bool, delegate: NonModalAlertWindowControllerDelegate?) { if window?.isVisible == true { self.delegate?.nonModalAlertWindowControllerDidCancel(self) } - + self.delegate = delegate - + var oldFrame = confirmButton.frame confirmButton.title = confirmButtonTitle confirmButton.sizeToFit() - + var newFrame = confirmButton.frame newFrame.size.width = max(90, newFrame.size.width + 10) newFrame.origin.x += oldFrame.size.width - newFrame.size.width - self.confirmButton.frame = newFrame - + confirmButton.frame = newFrame + if let cancelButtonTitle = cancelButtonTitle { cancelButton.title = cancelButtonTitle cancelButton.sizeToFit() var adjustFrame = cancelButton.frame adjustFrame.size.width = max(90, adjustFrame.size.width + 10) adjustFrame.origin.x = newFrame.origin.x - adjustFrame.size.width - self.confirmButton.frame = adjustFrame - self.cancelButton.isHidden = false + confirmButton.frame = adjustFrame + cancelButton.isHidden = false } else { - self.cancelButton.isHidden = true + cancelButton.isHidden = true } - + cancelButton.nextKeyView = confirmButton confirmButton.nextKeyView = cancelButton - + if cancelButtonTitle != nil { if cancelAsDefault { window?.defaultButtonCell = cancelButton.cell as? NSButtonCell @@ -89,12 +90,12 @@ class NonModalAlertWindowController: NSWindowController { } else { window?.defaultButtonCell = confirmButton.cell as? NSButtonCell } - + titleTextField.stringValue = title - + oldFrame = contentTextField.frame contentTextField.stringValue = content - + var infiniteHeightFrame = oldFrame infiniteHeightFrame.size.width -= 4.0 infiniteHeightFrame.size.height = 10240 @@ -104,7 +105,7 @@ class NonModalAlertWindowController: NSWindowController { newFrame.origin = oldFrame.origin newFrame.origin.y -= (newFrame.size.height - oldFrame.size.height) contentTextField.frame = newFrame - + var windowFrame = window?.frame ?? NSRect.zero windowFrame.size.height += (newFrame.size.height - oldFrame.size.height) window?.level = NSWindow.Level(Int(CGShieldingWindowLevel()) + 1) @@ -113,20 +114,20 @@ class NonModalAlertWindowController: NSWindowController { window?.makeKeyAndOrderFront(self) NSApp.activate(ignoringOtherApps: true) } - + @IBAction func confirmButtonAction(_ sender: Any) { delegate?.nonModalAlertWindowControllerDidConfirm(self) window?.orderOut(self) } - + @IBAction func cancelButtonAction(_ sender: Any) { cancel(sender) } - + func cancel(_ sender: Any) { delegate?.nonModalAlertWindowControllerDidCancel(self) delegate = nil window?.orderOut(self) } - + } diff --git a/Source/OpenCCBridge.swift b/Source/OpenCCBridge.swift index 582ec8e0..f63a2726 100644 --- a/Source/OpenCCBridge.swift +++ b/Source/OpenCCBridge.swift @@ -12,11 +12,11 @@ class OpenCCBridge: NSObject { super.init() } - @objc static func convert(_ string:String) -> String? { - return shared.converter?.convert(string) + @objc static func convert(_ string: String) -> String? { + shared.converter?.convert(string) } - private func convert(_ string:String) -> String? { - return converter?.convert(string) + private func convert(_ string: String) -> String? { + converter?.convert(string) } } diff --git a/Source/PreferencesWindowController.swift b/Source/PreferencesWindowController.swift index 59d490dd..0282d02b 100644 --- a/Source/PreferencesWindowController.swift +++ b/Source/PreferencesWindowController.swift @@ -42,7 +42,7 @@ private let kDefaultKeys = "123456789" // 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! @@ -85,8 +85,8 @@ private let kDefaultKeys = "123456789" guard let sourceIDPtr = TISGetInputSourceProperty(source, kTISPropertyInputSourceID), let localizedNamePtr = TISGetInputSourceProperty(source, kTISPropertyLocalizedName) else { - continue - } + continue + } let sourceID = String(Unmanaged.fromOpaque(sourceIDPtr).takeUnretainedValue()) let localizedName = String(Unmanaged.fromOpaque(localizedNamePtr).takeUnretainedValue()) @@ -109,7 +109,7 @@ private let kDefaultKeys = "123456789" selectionKeyComboBox.addItems(withObjectValues: [kDefaultKeys, "asdfghjkl", "asdfzxcvb"]) var candidateSelectionKeys = (UserDefaults.standard.string(forKey: kCandidateKeys) ?? kDefaultKeys) - .trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) + .trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) if candidateSelectionKeys.isEmpty { candidateSelectionKeys = kDefaultKeys } @@ -117,7 +117,7 @@ private let kDefaultKeys = "123456789" selectionKeyComboBox.stringValue = candidateSelectionKeys } - @IBAction func updateBasisKeyboardLayoutAction(_ sender:Any) { + @IBAction func updateBasisKeyboardLayoutAction(_ sender: Any) { if let sourceID = basisKeyboardLayoutButton.selectedItem?.representedObject { UserDefaults.standard.set(sourceID, forKey: kBasisKeyboardLayoutPreferenceKey) }