Formats Swift code.
This commit is contained in:
parent
1e7d4fe2b0
commit
0d80d28e0e
|
@ -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() {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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..<count])
|
||||
|
@ -81,7 +81,7 @@ fileprivate class HorizontalCandidateView: NSView {
|
|||
elementWidths = newWidths
|
||||
}
|
||||
|
||||
@objc (setKeyLabelFont:candidateFont:)
|
||||
@objc(setKeyLabelFont:candidateFont:)
|
||||
func set(keyLabelFont labelFont: NSFont, candidateFont: NSFont) {
|
||||
let paraStyle = NSMutableParagraphStyle()
|
||||
paraStyle.setParagraphStyle(NSParagraphStyle.default)
|
||||
|
@ -192,7 +192,7 @@ fileprivate class HorizontalCandidateView: NSView {
|
|||
}
|
||||
}
|
||||
|
||||
@objc (VTHorizontalCandidateController)
|
||||
@objc(VTHorizontalCandidateController)
|
||||
public class HorizontalCandidateController: CandidateController {
|
||||
private var candidateView: HorizontalCandidateView
|
||||
private var prevPageButton: NSButton
|
||||
|
@ -364,7 +364,7 @@ extension HorizontalCandidateController {
|
|||
|
||||
if pageCount > 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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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<CFBoolean>.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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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<VersionUpdateApiResult, Error>)->()) -> URLSessionTask? {
|
||||
static func check(forced: Bool, callback: @escaping (Result<VersionUpdateApiResult, Error>) -> ()) -> 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
|
||||
|
|
|
@ -326,7 +326,7 @@ static double FindHighestScore(const vector<NodeAnchor>& nodes, double epsilon)
|
|||
return text;
|
||||
}
|
||||
|
||||
if (Preferences.chineneConversionEngine == 1) {
|
||||
if (Preferences.chineseConversionEngine == 1) {
|
||||
return [VXHanConvert convertToSimplifiedFrom:text];
|
||||
}
|
||||
return [OpenCCBridge convertToSimplified:text];
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -40,7 +40,7 @@ import Cocoa
|
|||
}
|
||||
|
||||
class NonModalAlertWindowController: NSWindowController {
|
||||
@objc (sharedInstance)
|
||||
@objc(sharedInstance)
|
||||
static let shared = NonModalAlertWindowController(windowNibName: "NonModalAlertWindowController")
|
||||
|
||||
@IBOutlet weak var titleTextField: NSTextField!
|
||||
|
|
|
@ -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<Value> {
|
|||
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue