Project // Reduce the usage of [at]objc.

This commit is contained in:
ShikiSuen 2022-05-02 14:36:26 +08:00
parent 25b3a1b766
commit b8bb5e18d6
18 changed files with 184 additions and 210 deletions

View File

@ -46,7 +46,7 @@ public class OpenCCBridge: NSObject {
/// ///
/// - Parameter string: Text in Original Script. /// - Parameter string: Text in Original Script.
/// - Returns: Text converted to Different Script. /// - Returns: Text converted to Different Script.
@objc public static func crossConvert(_ string: String) -> String? { public static func crossConvert(_ string: String) -> String? {
switch ctlInputMethod.currentKeyHandler.inputMode { switch ctlInputMethod.currentKeyHandler.inputMode {
case InputMode.imeModeCHS: case InputMode.imeModeCHS:
return shared.traditionalize?.convert(string) return shared.traditionalize?.convert(string)

View File

@ -76,7 +76,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega
} }
} }
@objc func showPreferences() { func showPreferences() {
if ctlPrefWindowInstance == nil { if ctlPrefWindowInstance == nil {
ctlPrefWindowInstance = ctlPrefWindow.init(windowNibName: "frmPrefWindow") ctlPrefWindowInstance = ctlPrefWindow.init(windowNibName: "frmPrefWindow")
} }
@ -88,7 +88,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega
} }
// New About Window // New About Window
@objc func showAbout() { func showAbout() {
if ctlAboutWindowInstance == nil { if ctlAboutWindowInstance == nil {
ctlAboutWindowInstance = ctlAboutWindow.init(windowNibName: "frmAboutWindow") ctlAboutWindowInstance = ctlAboutWindow.init(windowNibName: "frmAboutWindow")
} }
@ -98,12 +98,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega
NSApp.setActivationPolicy(.accessory) NSApp.setActivationPolicy(.accessory)
} }
@objc(checkForUpdate)
func checkForUpdate() { func checkForUpdate() {
checkForUpdate(forced: false) checkForUpdate(forced: false)
} }
@objc(checkForUpdateForced:)
func checkForUpdate(forced: Bool) { func checkForUpdate(forced: Bool) {
if checkTask != nil { if checkTask != nil {
// busy // busy

View File

@ -39,12 +39,12 @@ class AppleKeyboardConverter: NSObject {
"org.unknown.keylayout.vChewingIBM", "org.unknown.keylayout.vChewingIBM",
"org.unknown.keylayout.vChewingMiTAC", "org.unknown.keylayout.vChewingMiTAC",
] ]
@objc class func isDynamicBasicKeyboardLayoutEnabled() -> Bool { class func isDynamicBasicKeyboardLayoutEnabled() -> Bool {
AppleKeyboardConverter.arrDynamicBasicKeyLayout.contains(mgrPrefs.basicKeyboardLayout) AppleKeyboardConverter.arrDynamicBasicKeyLayout.contains(mgrPrefs.basicKeyboardLayout)
} }
// Apple // Apple
@objc class func cnvApple2ABC(_ charCode: UniChar) -> UniChar { class func cnvApple2ABC(_ charCode: UniChar) -> UniChar {
var charCode = charCode var charCode = charCode
// OVMandarin OVMandarin // OVMandarin OVMandarin
if isDynamicBasicKeyboardLayoutEnabled() { if isDynamicBasicKeyboardLayoutEnabled() {
@ -185,7 +185,7 @@ class AppleKeyboardConverter: NSObject {
return charCode return charCode
} }
@objc class func cnvStringApple2ABC(_ strProcessed: String) -> String { class func cnvStringApple2ABC(_ strProcessed: String) -> String {
var strProcessed = strProcessed var strProcessed = strProcessed
if isDynamicBasicKeyboardLayoutEnabled() { if isDynamicBasicKeyboardLayoutEnabled() {
// Apple // Apple

View File

@ -29,7 +29,7 @@ import Cocoa
// Use KeyCodes as much as possible since its recognition won't be affected by macOS Base Keyboard Layouts. // Use KeyCodes as much as possible since its recognition won't be affected by macOS Base Keyboard Layouts.
// KeyCodes: https://eastmanreference.com/complete-list-of-applescript-key-codes // KeyCodes: https://eastmanreference.com/complete-list-of-applescript-key-codes
// Also: HIToolbox.framework/Versions/A/Headers/Events.h // Also: HIToolbox.framework/Versions/A/Headers/Events.h
@objc enum KeyCode: UInt16 { enum KeyCode: UInt16 {
case kNone = 0 case kNone = 0
case kCarriageReturn = 36 // Renamed from "kReturn" to avoid nomenclatural confusions. case kCarriageReturn = 36 // Renamed from "kReturn" to avoid nomenclatural confusions.
case kTab = 48 case kTab = 48
@ -91,11 +91,11 @@ enum CharCode: UInt /* 16 */ {
} }
class InputHandler: NSObject { class InputHandler: NSObject {
@objc private(set) var useVerticalMode: Bool private(set) var useVerticalMode: Bool
@objc private(set) var inputText: String? private(set) var inputText: String?
@objc private(set) var inputTextIgnoringModifiers: String? private(set) var inputTextIgnoringModifiers: String?
@objc private(set) var charCode: UInt16 private(set) var charCode: UInt16
@objc private(set) var keyCode: UInt16 private(set) var keyCode: UInt16
private var isFlagChanged: Bool private var isFlagChanged: Bool
private var flags: NSEvent.ModifierFlags private var flags: NSEvent.ModifierFlags
private var cursorForwardKey: KeyCode private var cursorForwardKey: KeyCode
@ -104,9 +104,9 @@ class InputHandler: NSObject {
private var extraChooseCandidateKeyReverse: KeyCode private var extraChooseCandidateKeyReverse: KeyCode
private var absorbedArrowKey: KeyCode private var absorbedArrowKey: KeyCode
private var verticalModeOnlyChooseCandidateKey: KeyCode private var verticalModeOnlyChooseCandidateKey: KeyCode
@objc private(set) var emacsKey: vChewingEmacsKey private(set) var emacsKey: vChewingEmacsKey
@objc init( init(
inputText: String?, keyCode: UInt16, charCode: UInt16, flags: NSEvent.ModifierFlags, inputText: String?, keyCode: UInt16, charCode: UInt16, flags: NSEvent.ModifierFlags,
isVerticalMode: Bool, inputTextIgnoringModifiers: String? = nil isVerticalMode: Bool, inputTextIgnoringModifiers: String? = nil
) { ) {
@ -133,7 +133,7 @@ class InputHandler: NSObject {
super.init() super.init()
} }
@objc init(event: NSEvent, isVerticalMode: Bool) { init(event: NSEvent, isVerticalMode: Bool) {
inputText = AppleKeyboardConverter.cnvStringApple2ABC(event.characters ?? "") inputText = AppleKeyboardConverter.cnvStringApple2ABC(event.characters ?? "")
inputTextIgnoringModifiers = AppleKeyboardConverter.cnvStringApple2ABC( inputTextIgnoringModifiers = AppleKeyboardConverter.cnvStringApple2ABC(
event.charactersIgnoringModifiers ?? "") event.charactersIgnoringModifiers ?? "")
@ -172,143 +172,143 @@ class InputHandler: NSObject {
"<\(super.description) inputText:\(String(describing: inputText)), inputTextIgnoringModifiers:\(String(describing: inputTextIgnoringModifiers)) charCode:\(charCode), keyCode:\(keyCode), flags:\(flags), cursorForwardKey:\(cursorForwardKey), cursorBackwardKey:\(cursorBackwardKey), extraChooseCandidateKey:\(extraChooseCandidateKey), extraChooseCandidateKeyReverse:\(extraChooseCandidateKeyReverse), absorbedArrowKey:\(absorbedArrowKey), verticalModeOnlyChooseCandidateKey:\(verticalModeOnlyChooseCandidateKey), emacsKey:\(emacsKey), useVerticalMode:\(useVerticalMode)>" "<\(super.description) inputText:\(String(describing: inputText)), inputTextIgnoringModifiers:\(String(describing: inputTextIgnoringModifiers)) charCode:\(charCode), keyCode:\(keyCode), flags:\(flags), cursorForwardKey:\(cursorForwardKey), cursorBackwardKey:\(cursorBackwardKey), extraChooseCandidateKey:\(extraChooseCandidateKey), extraChooseCandidateKeyReverse:\(extraChooseCandidateKeyReverse), absorbedArrowKey:\(absorbedArrowKey), verticalModeOnlyChooseCandidateKey:\(verticalModeOnlyChooseCandidateKey), emacsKey:\(emacsKey), useVerticalMode:\(useVerticalMode)>"
} }
@objc var isShiftHold: Bool { var isShiftHold: Bool {
flags.contains([.shift]) flags.contains([.shift])
} }
@objc var isCommandHold: Bool { var isCommandHold: Bool {
flags.contains([.command]) flags.contains([.command])
} }
@objc var isControlHold: Bool { var isControlHold: Bool {
flags.contains([.control]) flags.contains([.control])
} }
@objc var isControlHotKey: Bool { var isControlHotKey: Bool {
flags.contains([.control]) && inputText?.first?.isLetter ?? false flags.contains([.control]) && inputText?.first?.isLetter ?? false
} }
@objc var isOptionHotKey: Bool { var isOptionHotKey: Bool {
flags.contains([.option]) && inputText?.first?.isLetter ?? false flags.contains([.option]) && inputText?.first?.isLetter ?? false
} }
@objc var isOptionHold: Bool { var isOptionHold: Bool {
flags.contains([.option]) flags.contains([.option])
} }
@objc var isCapsLockOn: Bool { var isCapsLockOn: Bool {
flags.contains([.capsLock]) flags.contains([.capsLock])
} }
@objc var isNumericPad: Bool { var isNumericPad: Bool {
flags.contains([.numericPad]) flags.contains([.numericPad])
} }
@objc var isFunctionKeyHold: Bool { var isFunctionKeyHold: Bool {
flags.contains([.function]) flags.contains([.function])
} }
@objc var isReservedKey: Bool { var isReservedKey: Bool {
guard let code = KeyCode(rawValue: keyCode) else { guard let code = KeyCode(rawValue: keyCode) else {
return false return false
} }
return code.rawValue != KeyCode.kNone.rawValue return code.rawValue != KeyCode.kNone.rawValue
} }
@objc var isTab: Bool { var isTab: Bool {
KeyCode(rawValue: keyCode) == KeyCode.kTab KeyCode(rawValue: keyCode) == KeyCode.kTab
} }
@objc var isEnter: Bool { var isEnter: Bool {
(KeyCode(rawValue: keyCode) == KeyCode.kCarriageReturn) (KeyCode(rawValue: keyCode) == KeyCode.kCarriageReturn)
|| (KeyCode(rawValue: keyCode) == KeyCode.kLineFeed) || (KeyCode(rawValue: keyCode) == KeyCode.kLineFeed)
} }
@objc var isUp: Bool { var isUp: Bool {
KeyCode(rawValue: keyCode) == KeyCode.kUpArrow KeyCode(rawValue: keyCode) == KeyCode.kUpArrow
} }
@objc var isDown: Bool { var isDown: Bool {
KeyCode(rawValue: keyCode) == KeyCode.kDownArrow KeyCode(rawValue: keyCode) == KeyCode.kDownArrow
} }
@objc var isLeft: Bool { var isLeft: Bool {
KeyCode(rawValue: keyCode) == KeyCode.kLeftArrow KeyCode(rawValue: keyCode) == KeyCode.kLeftArrow
} }
@objc var isRight: Bool { var isRight: Bool {
KeyCode(rawValue: keyCode) == KeyCode.kRightArrow KeyCode(rawValue: keyCode) == KeyCode.kRightArrow
} }
@objc var isPageUp: Bool { var isPageUp: Bool {
KeyCode(rawValue: keyCode) == KeyCode.kPageUp KeyCode(rawValue: keyCode) == KeyCode.kPageUp
} }
@objc var isPageDown: Bool { var isPageDown: Bool {
KeyCode(rawValue: keyCode) == KeyCode.kPageDown KeyCode(rawValue: keyCode) == KeyCode.kPageDown
} }
@objc var isSpace: Bool { var isSpace: Bool {
KeyCode(rawValue: keyCode) == KeyCode.kSpace KeyCode(rawValue: keyCode) == KeyCode.kSpace
} }
@objc var isBackSpace: Bool { var isBackSpace: Bool {
KeyCode(rawValue: keyCode) == KeyCode.kBackSpace KeyCode(rawValue: keyCode) == KeyCode.kBackSpace
} }
@objc var isESC: Bool { var isESC: Bool {
KeyCode(rawValue: keyCode) == KeyCode.kEscape KeyCode(rawValue: keyCode) == KeyCode.kEscape
} }
@objc var isHome: Bool { var isHome: Bool {
KeyCode(rawValue: keyCode) == KeyCode.kHome KeyCode(rawValue: keyCode) == KeyCode.kHome
} }
@objc var isEnd: Bool { var isEnd: Bool {
KeyCode(rawValue: keyCode) == KeyCode.kEnd KeyCode(rawValue: keyCode) == KeyCode.kEnd
} }
@objc var isDelete: Bool { var isDelete: Bool {
KeyCode(rawValue: keyCode) == KeyCode.kWindowDelete KeyCode(rawValue: keyCode) == KeyCode.kWindowDelete
} }
@objc var isCursorBackward: Bool { var isCursorBackward: Bool {
KeyCode(rawValue: keyCode) == cursorBackwardKey KeyCode(rawValue: keyCode) == cursorBackwardKey
} }
@objc var isCursorForward: Bool { var isCursorForward: Bool {
KeyCode(rawValue: keyCode) == cursorForwardKey KeyCode(rawValue: keyCode) == cursorForwardKey
} }
@objc var isAbsorbedArrowKey: Bool { var isAbsorbedArrowKey: Bool {
KeyCode(rawValue: keyCode) == absorbedArrowKey KeyCode(rawValue: keyCode) == absorbedArrowKey
} }
@objc var isExtraChooseCandidateKey: Bool { var isExtraChooseCandidateKey: Bool {
KeyCode(rawValue: keyCode) == extraChooseCandidateKey KeyCode(rawValue: keyCode) == extraChooseCandidateKey
} }
@objc var isExtraChooseCandidateKeyReverse: Bool { var isExtraChooseCandidateKeyReverse: Bool {
KeyCode(rawValue: keyCode) == extraChooseCandidateKeyReverse KeyCode(rawValue: keyCode) == extraChooseCandidateKeyReverse
} }
@objc var isVerticalModeOnlyChooseCandidateKey: Bool { var isVerticalModeOnlyChooseCandidateKey: Bool {
KeyCode(rawValue: keyCode) == verticalModeOnlyChooseCandidateKey KeyCode(rawValue: keyCode) == verticalModeOnlyChooseCandidateKey
} }
@objc var isUpperCaseASCIILetterKey: Bool { var isUpperCaseASCIILetterKey: Bool {
// flags == .shift Shift // flags == .shift Shift
charCode >= 65 && charCode <= 90 && flags == .shift charCode >= 65 && charCode <= 90 && flags == .shift
} }
@objc var isSymbolMenuPhysicalKey: Bool { var isSymbolMenuPhysicalKey: Bool {
// KeyCode macOS Apple // KeyCode macOS Apple
// ![input isShift] 使 Shift // ![input isShift] 使 Shift
KeyCode(rawValue: keyCode) == KeyCode.kSymbolMenuPhysicalKey KeyCode(rawValue: keyCode) == KeyCode.kSymbolMenuPhysicalKey
} }
} }
@objc enum vChewingEmacsKey: UInt16 { enum vChewingEmacsKey: UInt16 {
case none = 0 case none = 0
case forward = 6 // F case forward = 6 // F
case backward = 2 // B case backward = 2 // B
@ -319,7 +319,7 @@ class InputHandler: NSObject {
} }
class EmacsKeyHelper: NSObject { class EmacsKeyHelper: NSObject {
@objc static func detect(charCode: UniChar, flags: NSEvent.ModifierFlags) -> vChewingEmacsKey { static func detect(charCode: UniChar, flags: NSEvent.ModifierFlags) -> vChewingEmacsKey {
let charCode = AppleKeyboardConverter.cnvApple2ABC(charCode) let charCode = AppleKeyboardConverter.cnvApple2ABC(charCode)
if flags.contains(.control) { if flags.contains(.control) {
return vChewingEmacsKey(rawValue: charCode) ?? .none return vChewingEmacsKey(rawValue: charCode) ?? .none

View File

@ -59,7 +59,6 @@ import Cocoa
/// one among the candidates. /// one among the candidates.
class InputState: NSObject { class InputState: NSObject {
/// Represents that the input controller is deactivated. /// Represents that the input controller is deactivated.
@objc(InputStateDeactivated)
class Deactivated: InputState { class Deactivated: InputState {
override var description: String { override var description: String {
"<InputState.Deactivated>" "<InputState.Deactivated>"
@ -69,9 +68,8 @@ class InputState: NSObject {
// MARK: - // MARK: -
/// Represents that the composing buffer is empty. /// Represents that the composing buffer is empty.
@objc(InputStateEmpty)
class Empty: InputState { class Empty: InputState {
@objc var composingBuffer: String { var composingBuffer: String {
"" ""
} }
@ -83,9 +81,8 @@ class InputState: NSObject {
// MARK: - // MARK: -
/// Represents that the composing buffer is empty. /// Represents that the composing buffer is empty.
@objc(InputStateEmptyIgnoringPreviousState)
class EmptyIgnoringPreviousState: InputState { class EmptyIgnoringPreviousState: InputState {
@objc var composingBuffer: String { var composingBuffer: String {
"" ""
} }
@ -97,11 +94,10 @@ class InputState: NSObject {
// MARK: - // MARK: -
/// Represents that the input controller is committing text into client app. /// Represents that the input controller is committing text into client app.
@objc(InputStateCommitting)
class Committing: InputState { class Committing: InputState {
@objc private(set) var poppedText: String = "" private(set) var poppedText: String = ""
@objc convenience init(poppedText: String) { convenience init(poppedText: String) {
self.init() self.init()
self.poppedText = poppedText self.poppedText = poppedText
} }
@ -114,12 +110,11 @@ class InputState: NSObject {
// MARK: - // MARK: -
/// Represents that the composing buffer is not empty. /// Represents that the composing buffer is not empty.
@objc(InputStateNotEmpty)
class NotEmpty: InputState { class NotEmpty: InputState {
@objc private(set) var composingBuffer: String private(set) var composingBuffer: String
@objc private(set) var cursorIndex: UInt private(set) var cursorIndex: UInt
@objc init(composingBuffer: String, cursorIndex: UInt) { init(composingBuffer: String, cursorIndex: UInt) {
self.composingBuffer = composingBuffer self.composingBuffer = composingBuffer
self.cursorIndex = cursorIndex self.cursorIndex = cursorIndex
} }
@ -132,16 +127,15 @@ class InputState: NSObject {
// MARK: - // MARK: -
/// Represents that the user is inputting text. /// Represents that the user is inputting text.
@objc(InputStateInputting)
class Inputting: NotEmpty { class Inputting: NotEmpty {
@objc var poppedText: String = "" var poppedText: String = ""
@objc var tooltip: String = "" var tooltip: String = ""
@objc override init(composingBuffer: String, cursorIndex: UInt) { override init(composingBuffer: String, cursorIndex: UInt) {
super.init(composingBuffer: composingBuffer, cursorIndex: cursorIndex) super.init(composingBuffer: composingBuffer, cursorIndex: cursorIndex)
} }
@objc var attributedString: NSAttributedString { var attributedString: NSAttributedString {
let attributedSting = NSAttributedString( let attributedSting = NSAttributedString(
string: composingBuffer, string: composingBuffer,
attributes: [ attributes: [
@ -163,12 +157,11 @@ class InputState: NSObject {
private let kMaxMarkRangeLength = mgrPrefs.maxCandidateLength private let kMaxMarkRangeLength = mgrPrefs.maxCandidateLength
/// Represents that the user is marking a range in the composing buffer. /// Represents that the user is marking a range in the composing buffer.
@objc(InputStateMarking)
class Marking: NotEmpty { class Marking: NotEmpty {
@objc private(set) var markerIndex: UInt private(set) var markerIndex: UInt
@objc private(set) var markedRange: NSRange private(set) var markedRange: NSRange
@objc private var deleteTargetExists = false private var deleteTargetExists = false
@objc var tooltip: String { var tooltip: String {
if composingBuffer.count != readings.count { if composingBuffer.count != readings.count {
TooltipController.backgroundColor = NSColor( TooltipController.backgroundColor = NSColor(
red: 0.55, green: 0.00, blue: 0.00, alpha: 1.00 red: 0.55, green: 0.00, blue: 0.00, alpha: 1.00
@ -251,10 +244,10 @@ class InputState: NSObject {
) )
} }
@objc var tooltipForInputting: String = "" var tooltipForInputting: String = ""
@objc private(set) var readings: [String] private(set) var readings: [String]
@objc init(composingBuffer: String, cursorIndex: UInt, markerIndex: UInt, readings: [String]) { init(composingBuffer: String, cursorIndex: UInt, markerIndex: UInt, readings: [String]) {
self.markerIndex = markerIndex self.markerIndex = markerIndex
let begin = min(cursorIndex, markerIndex) let begin = min(cursorIndex, markerIndex)
let end = max(cursorIndex, markerIndex) let end = max(cursorIndex, markerIndex)
@ -263,7 +256,7 @@ class InputState: NSObject {
super.init(composingBuffer: composingBuffer, cursorIndex: cursorIndex) super.init(composingBuffer: composingBuffer, cursorIndex: cursorIndex)
} }
@objc var attributedString: NSAttributedString { var attributedString: NSAttributedString {
let attributedSting = NSMutableAttributedString(string: composingBuffer) let attributedSting = NSMutableAttributedString(string: composingBuffer)
let end = markedRange.location + markedRange.length let end = markedRange.location + markedRange.length
@ -296,13 +289,13 @@ class InputState: NSObject {
"<InputState.Marking, composingBuffer:\(composingBuffer), cursorIndex:\(cursorIndex), markedRange:\(markedRange)>" "<InputState.Marking, composingBuffer:\(composingBuffer), cursorIndex:\(cursorIndex), markedRange:\(markedRange)>"
} }
@objc func convertToInputting() -> Inputting { func convertToInputting() -> Inputting {
let state = Inputting(composingBuffer: composingBuffer, cursorIndex: cursorIndex) let state = Inputting(composingBuffer: composingBuffer, cursorIndex: cursorIndex)
state.tooltip = tooltipForInputting state.tooltip = tooltipForInputting
return state return state
} }
@objc var validToWrite: Bool { var validToWrite: Bool {
/// vChewing allows users to input a string whose length differs /// vChewing allows users to input a string whose length differs
/// from the amount of Bopomofo readings. In this case, the range /// from the amount of Bopomofo readings. In this case, the range
/// in the composing buffer and the readings could not match, so /// in the composing buffer and the readings could not match, so
@ -323,7 +316,7 @@ class InputState: NSObject {
&& markedRange.length <= kMaxMarkRangeLength && markedRange.length <= kMaxMarkRangeLength
} }
@objc var chkIfUserPhraseExists: Bool { var chkIfUserPhraseExists: Bool {
let text = (composingBuffer as NSString).substring(with: markedRange) let text = (composingBuffer as NSString).substring(with: markedRange)
let (exactBegin, _) = (composingBuffer as NSString).characterIndex( let (exactBegin, _) = (composingBuffer as NSString).characterIndex(
from: markedRange.location) from: markedRange.location)
@ -337,7 +330,7 @@ class InputState: NSObject {
== true == true
} }
@objc var userPhrase: String { var userPhrase: String {
let text = (composingBuffer as NSString).substring(with: markedRange) let text = (composingBuffer as NSString).substring(with: markedRange)
let (exactBegin, _) = (composingBuffer as NSString).characterIndex( let (exactBegin, _) = (composingBuffer as NSString).characterIndex(
from: markedRange.location) from: markedRange.location)
@ -348,7 +341,7 @@ class InputState: NSObject {
return "\(text) \(joined)" return "\(text) \(joined)"
} }
@objc var userPhraseConverted: String { var userPhraseConverted: String {
let text = let text =
OpenCCBridge.crossConvert( OpenCCBridge.crossConvert(
(composingBuffer as NSString).substring(with: markedRange)) ?? "" (composingBuffer as NSString).substring(with: markedRange)) ?? ""
@ -366,18 +359,17 @@ class InputState: NSObject {
// MARK: - // MARK: -
/// Represents that the user is choosing in a candidates list. /// Represents that the user is choosing in a candidates list.
@objc(InputStateChoosingCandidate)
class ChoosingCandidate: NotEmpty { class ChoosingCandidate: NotEmpty {
@objc private(set) var candidates: [String] private(set) var candidates: [String]
@objc private(set) var useVerticalMode: Bool private(set) var useVerticalMode: Bool
@objc init(composingBuffer: String, cursorIndex: UInt, candidates: [String], useVerticalMode: Bool) { init(composingBuffer: String, cursorIndex: UInt, candidates: [String], useVerticalMode: Bool) {
self.candidates = candidates self.candidates = candidates
self.useVerticalMode = useVerticalMode self.useVerticalMode = useVerticalMode
super.init(composingBuffer: composingBuffer, cursorIndex: cursorIndex) super.init(composingBuffer: composingBuffer, cursorIndex: cursorIndex)
} }
@objc var attributedString: NSAttributedString { var attributedString: NSAttributedString {
let attributedSting = NSAttributedString( let attributedSting = NSAttributedString(
string: composingBuffer, string: composingBuffer,
attributes: [ attributes: [
@ -397,11 +389,10 @@ class InputState: NSObject {
/// Represents that the user is choosing in a candidates list /// Represents that the user is choosing in a candidates list
/// in the associated phrases mode. /// in the associated phrases mode.
@objc(InputStateAssociatedPhrases)
class AssociatedPhrases: InputState { class AssociatedPhrases: InputState {
@objc private(set) var candidates: [String] = [] private(set) var candidates: [String] = []
@objc private(set) var useVerticalMode: Bool = false private(set) var useVerticalMode: Bool = false
@objc init(candidates: [String], useVerticalMode: Bool) { init(candidates: [String], useVerticalMode: Bool) {
self.candidates = candidates self.candidates = candidates
self.useVerticalMode = useVerticalMode self.useVerticalMode = useVerticalMode
super.init() super.init()
@ -412,11 +403,10 @@ class InputState: NSObject {
} }
} }
@objc(InputStateSymbolTable)
class SymbolTable: ChoosingCandidate { class SymbolTable: ChoosingCandidate {
@objc var node: SymbolNode var node: SymbolNode
@objc init(node: SymbolNode, useVerticalMode: Bool) { init(node: SymbolNode, useVerticalMode: Bool) {
self.node = node self.node = node
let candidates = node.children?.map(\.title) ?? [String]() let candidates = node.children?.map(\.title) ?? [String]()
super.init( super.init(
@ -432,53 +422,53 @@ class InputState: NSObject {
} }
class SymbolNode: NSObject { class SymbolNode: NSObject {
@objc var title: String var title: String
@objc var children: [SymbolNode]? var children: [SymbolNode]?
@objc init(_ title: String, _ children: [SymbolNode]? = nil) { init(_ title: String, _ children: [SymbolNode]? = nil) {
self.title = title self.title = title
self.children = children self.children = children
super.init() super.init()
} }
@objc init(_ title: String, symbols: String) { init(_ title: String, symbols: String) {
self.title = title self.title = title
children = Array(symbols).map { SymbolNode(String($0), nil) } children = Array(symbols).map { SymbolNode(String($0), nil) }
super.init() super.init()
} }
@objc static let catCommonSymbols = String( static let catCommonSymbols = String(
format: NSLocalizedString("catCommonSymbols", comment: "")) format: NSLocalizedString("catCommonSymbols", comment: ""))
@objc static let catHoriBrackets = String( static let catHoriBrackets = String(
format: NSLocalizedString("catHoriBrackets", comment: "")) format: NSLocalizedString("catHoriBrackets", comment: ""))
@objc static let catVertBrackets = String( static let catVertBrackets = String(
format: NSLocalizedString("catVertBrackets", comment: "")) format: NSLocalizedString("catVertBrackets", comment: ""))
@objc static let catGreekLetters = String( static let catGreekLetters = String(
format: NSLocalizedString("catGreekLetters", comment: "")) format: NSLocalizedString("catGreekLetters", comment: ""))
@objc static let catMathSymbols = String( static let catMathSymbols = String(
format: NSLocalizedString("catMathSymbols", comment: "")) format: NSLocalizedString("catMathSymbols", comment: ""))
@objc static let catCurrencyUnits = String( static let catCurrencyUnits = String(
format: NSLocalizedString("catCurrencyUnits", comment: "")) format: NSLocalizedString("catCurrencyUnits", comment: ""))
@objc static let catSpecialSymbols = String( static let catSpecialSymbols = String(
format: NSLocalizedString("catSpecialSymbols", comment: "")) format: NSLocalizedString("catSpecialSymbols", comment: ""))
@objc static let catUnicodeSymbols = String( static let catUnicodeSymbols = String(
format: NSLocalizedString("catUnicodeSymbols", comment: "")) format: NSLocalizedString("catUnicodeSymbols", comment: ""))
@objc static let catCircledKanjis = String( static let catCircledKanjis = String(
format: NSLocalizedString("catCircledKanjis", comment: "")) format: NSLocalizedString("catCircledKanjis", comment: ""))
@objc static let catCircledKataKana = String( static let catCircledKataKana = String(
format: NSLocalizedString("catCircledKataKana", comment: "")) format: NSLocalizedString("catCircledKataKana", comment: ""))
@objc static let catBracketKanjis = String( static let catBracketKanjis = String(
format: NSLocalizedString("catBracketKanjis", comment: "")) format: NSLocalizedString("catBracketKanjis", comment: ""))
@objc static let catSingleTableLines = String( static let catSingleTableLines = String(
format: NSLocalizedString("catSingleTableLines", comment: "")) format: NSLocalizedString("catSingleTableLines", comment: ""))
@objc static let catDoubleTableLines = String( static let catDoubleTableLines = String(
format: NSLocalizedString("catDoubleTableLines", comment: "")) format: NSLocalizedString("catDoubleTableLines", comment: ""))
@objc static let catFillingBlocks = String( static let catFillingBlocks = String(
format: NSLocalizedString("catFillingBlocks", comment: "")) format: NSLocalizedString("catFillingBlocks", comment: ""))
@objc static let catLineSegments = String( static let catLineSegments = String(
format: NSLocalizedString("catLineSegments", comment: "")) format: NSLocalizedString("catLineSegments", comment: ""))
@objc static let root: SymbolNode = .init( static let root: SymbolNode = .init(
"/", "/",
[ [
SymbolNode(""), SymbolNode(""),

View File

@ -84,7 +84,7 @@ class KeyHandler: NSObject {
} }
// ObjC 使 // ObjC 使
@objc func setInputMode(_ value: String) { func setInputMode(_ value: String) {
// isKindOfClass // isKindOfClass
// plist // plist
let isCHS: Bool = (value == InputMode.imeModeCHS.rawValue) let isCHS: Bool = (value == InputMode.imeModeCHS.rawValue)

View File

@ -47,7 +47,7 @@ extension NSString {
return (string.count, string) return (string.count, string)
} }
@objc public func nextUtf16Position(for index: Int) -> Int { public func nextUtf16Position(for index: Int) -> Int {
var (fixedIndex, string) = characterIndex(from: index) var (fixedIndex, string) = characterIndex(from: index)
if fixedIndex < string.count { if fixedIndex < string.count {
fixedIndex += 1 fixedIndex += 1
@ -55,7 +55,7 @@ extension NSString {
return string[..<string.index(string.startIndex, offsetBy: fixedIndex)].utf16.count return string[..<string.index(string.startIndex, offsetBy: fixedIndex)].utf16.count
} }
@objc public func previousUtf16Position(for index: Int) -> Int { public func previousUtf16Position(for index: Int) -> Int {
var (fixedIndex, string) = characterIndex(from: index) var (fixedIndex, string) = characterIndex(from: index)
if fixedIndex > 0 { if fixedIndex > 0 {
fixedIndex -= 1 fixedIndex -= 1
@ -63,11 +63,11 @@ extension NSString {
return string[..<string.index(string.startIndex, offsetBy: fixedIndex)].utf16.count return string[..<string.index(string.startIndex, offsetBy: fixedIndex)].utf16.count
} }
@objc public var count: Int { public var count: Int {
(self as String).count (self as String).count
} }
@objc public func split() -> [NSString] { public func split() -> [NSString] {
Array(self as String).map { Array(self as String).map {
NSString(string: String($0)) NSString(string: String($0))
} }

View File

@ -31,7 +31,7 @@ extension String {
} }
class vChewingKanjiConverter: NSObject { class vChewingKanjiConverter: NSObject {
@objc class func cnvTradToKangXi(_ strObj: String) -> String { class func cnvTradToKangXi(_ strObj: String) -> String {
var strObj = strObj var strObj = strObj
strObj.selfReplace("", "") strObj.selfReplace("", "")
strObj.selfReplace("", "") strObj.selfReplace("", "")
@ -217,7 +217,7 @@ class vChewingKanjiConverter: NSObject {
return strObj return strObj
} }
@objc class func cnvTradToJIS(_ strObj: String) -> String { class func cnvTradToJIS(_ strObj: String) -> String {
// //
var strObj = cnvTradToKangXi(strObj) var strObj = cnvTradToKangXi(strObj)
strObj.selfReplace("", "") strObj.selfReplace("", "")

View File

@ -34,7 +34,7 @@ public class IME: NSObject {
// MARK: - // MARK: -
@objc static var areWeUsingOurOwnPhraseEditor: Bool = false static var areWeUsingOurOwnPhraseEditor: Bool = false
// MARK: - ctlInputMethod // MARK: - ctlInputMethod
@ -49,7 +49,7 @@ public class IME: NSObject {
// MARK: - Print debug information to the console. // MARK: - Print debug information to the console.
@objc static func prtDebugIntel(_ strPrint: String) { static func prtDebugIntel(_ strPrint: String) {
if mgrPrefs.isDebugModeEnabled { if mgrPrefs.isDebugModeEnabled {
NSLog("vChewingErrorCallback: %@", strPrint) NSLog("vChewingErrorCallback: %@", strPrint)
} }
@ -57,13 +57,13 @@ public class IME: NSObject {
// MARK: - Tell whether this IME is running with Root privileges. // MARK: - Tell whether this IME is running with Root privileges.
@objc static var isSudoMode: Bool { static var isSudoMode: Bool {
NSUserName() == "root" NSUserName() == "root"
} }
// MARK: - Initializing Language Models. // MARK: - Initializing Language Models.
@objc static func initLangModels(userOnly: Bool) { static func initLangModels(userOnly: Bool) {
if !userOnly { if !userOnly {
mgrLangModel.loadDataModels() // mgrLangModel.loadDataModels() //
} }
@ -77,7 +77,7 @@ public class IME: NSObject {
// MARK: - System Dark Mode Status Detector. // MARK: - System Dark Mode Status Detector.
@objc static func isDarkMode() -> Bool { static func isDarkMode() -> Bool {
if #available(macOS 10.15, *) { if #available(macOS 10.15, *) {
let appearanceDescription = NSApplication.shared.effectiveAppearance.debugDescription let appearanceDescription = NSApplication.shared.effectiveAppearance.debugDescription
.lowercased() .lowercased()

View File

@ -37,7 +37,6 @@ public class InputSourceHelper: NSObject {
TISCreateInputSourceList(nil, true).takeRetainedValue() as! [TISInputSource] TISCreateInputSourceList(nil, true).takeRetainedValue() as! [TISInputSource]
} }
@objc(inputSourceForProperty:stringValue:)
public static func inputSource(for propertyKey: CFString, stringValue: String) public static func inputSource(for propertyKey: CFString, stringValue: String)
-> TISInputSource? -> TISInputSource?
{ {
@ -57,12 +56,10 @@ public class InputSourceHelper: NSObject {
return nil return nil
} }
@objc(inputSourceForInputSourceID:)
public static func inputSource(for sourceID: String) -> TISInputSource? { public static func inputSource(for sourceID: String) -> TISInputSource? {
inputSource(for: kTISPropertyInputSourceID, stringValue: sourceID) inputSource(for: kTISPropertyInputSourceID, stringValue: sourceID)
} }
@objc(inputSourceEnabled:)
public static func inputSourceEnabled(for source: TISInputSource) -> Bool { public static func inputSourceEnabled(for source: TISInputSource) -> Bool {
if let valuePts = TISGetInputSourceProperty(source, kTISPropertyInputSourceIsEnabled) { if let valuePts = TISGetInputSourceProperty(source, kTISPropertyInputSourceIsEnabled) {
let value = Unmanaged<CFBoolean>.fromOpaque(valuePts).takeUnretainedValue() let value = Unmanaged<CFBoolean>.fromOpaque(valuePts).takeUnretainedValue()
@ -71,13 +68,11 @@ public class InputSourceHelper: NSObject {
return false return false
} }
@objc(enableInputSource:)
public static func enable(inputSource: TISInputSource) -> Bool { public static func enable(inputSource: TISInputSource) -> Bool {
let status = TISEnableInputSource(inputSource) let status = TISEnableInputSource(inputSource)
return status == noErr return status == noErr
} }
@objc(enableAllInputModesForInputSourceBundleID:)
public static func enableAllInputMode(for inputSourceBundleD: String) -> Bool { public static func enableAllInputMode(for inputSourceBundleD: String) -> Bool {
var enabled = false var enabled = false
for source in allInstalledInputSources() { for source in allInstalledInputSources() {
@ -99,7 +94,6 @@ public class InputSourceHelper: NSObject {
return enabled return enabled
} }
@objc(enableInputMode:forInputSourceBundleID:)
public static func enable(inputMode modeID: String, for bundleID: String) -> Bool { public static func enable(inputMode modeID: String, for bundleID: String) -> Bool {
for source in allInstalledInputSources() { for source in allInstalledInputSources() {
guard let bundleIDPtr = TISGetInputSourceProperty(source, kTISPropertyBundleID), guard let bundleIDPtr = TISGetInputSourceProperty(source, kTISPropertyBundleID),
@ -122,13 +116,11 @@ public class InputSourceHelper: NSObject {
return false return false
} }
@objc(disableInputSource:)
public static func disable(inputSource: TISInputSource) -> Bool { public static func disable(inputSource: TISInputSource) -> Bool {
let status = TISDisableInputSource(inputSource) let status = TISDisableInputSource(inputSource)
return status == noErr return status == noErr
} }
@objc(registerInputSource:)
public static func registerTnputSource(at url: URL) -> Bool { public static func registerTnputSource(at url: URL) -> Bool {
let status = TISRegisterInputSource(url as CFURL) let status = TISRegisterInputSource(url as CFURL)
return status == noErr return status == noErr

View File

@ -80,7 +80,7 @@ private let kDefaultKeys = "123456789"
// MARK: - UserDefaults extension. // MARK: - UserDefaults extension.
@objc extension UserDefaults { extension UserDefaults {
func setDefault(_ value: Any?, forKey defaultName: String) { func setDefault(_ value: Any?, forKey defaultName: String) {
if object(forKey: defaultName) == nil { if object(forKey: defaultName) == nil {
set(value, forKey: defaultName) set(value, forKey: defaultName)
@ -236,7 +236,7 @@ public class mgrPrefs: NSObject {
// MARK: - Preferences Module plist // MARK: - Preferences Module plist
@objc public static func setMissingDefaults() { public static func setMissingDefaults() {
UserDefaults.standard.setDefault(mgrPrefs.isDebugModeEnabled, forKey: UserDef.kIsDebugModeEnabled) UserDefaults.standard.setDefault(mgrPrefs.isDebugModeEnabled, forKey: UserDef.kIsDebugModeEnabled)
UserDefaults.standard.setDefault(mgrPrefs.mostRecentInputMode, forKey: UserDef.kMostRecentInputMode) UserDefaults.standard.setDefault(mgrPrefs.mostRecentInputMode, forKey: UserDef.kMostRecentInputMode)
UserDefaults.standard.setDefault(mgrPrefs.checkUpdateAutomatically, forKey: UserDef.kCheckUpdateAutomatically) UserDefaults.standard.setDefault(mgrPrefs.checkUpdateAutomatically, forKey: UserDef.kCheckUpdateAutomatically)
@ -278,90 +278,90 @@ public class mgrPrefs: NSObject {
} }
@UserDefault(key: UserDef.kIsDebugModeEnabled, defaultValue: false) @UserDefault(key: UserDef.kIsDebugModeEnabled, defaultValue: false)
@objc static var isDebugModeEnabled: Bool static var isDebugModeEnabled: Bool
@UserDefault(key: UserDef.kMostRecentInputMode, defaultValue: "") @UserDefault(key: UserDef.kMostRecentInputMode, defaultValue: "")
@objc static var mostRecentInputMode: String static var mostRecentInputMode: String
@UserDefault(key: UserDef.kCheckUpdateAutomatically, defaultValue: false) @UserDefault(key: UserDef.kCheckUpdateAutomatically, defaultValue: false)
@objc static var checkUpdateAutomatically: Bool static var checkUpdateAutomatically: Bool
@UserDefault(key: UserDef.kUserDataFolderSpecified, defaultValue: "") @UserDefault(key: UserDef.kUserDataFolderSpecified, defaultValue: "")
@objc static var userDataFolderSpecified: String static var userDataFolderSpecified: String
@objc static func ifSpecifiedUserDataPathExistsInPlist() -> Bool { static func ifSpecifiedUserDataPathExistsInPlist() -> Bool {
UserDefaults.standard.object(forKey: UserDef.kUserDataFolderSpecified) != nil UserDefaults.standard.object(forKey: UserDef.kUserDataFolderSpecified) != nil
} }
@objc static func resetSpecifiedUserDataFolder() { static func resetSpecifiedUserDataFolder() {
UserDefaults.standard.removeObject(forKey: "UserDataFolderSpecified") UserDefaults.standard.removeObject(forKey: "UserDataFolderSpecified")
IME.initLangModels(userOnly: true) IME.initLangModels(userOnly: true)
} }
@UserDefault(key: UserDef.kAppleLanguages, defaultValue: []) @UserDefault(key: UserDef.kAppleLanguages, defaultValue: [])
@objc static var appleLanguages: [String] static var appleLanguages: [String]
@UserDefault(key: UserDef.kMandarinParser, defaultValue: 0) @UserDefault(key: UserDef.kMandarinParser, defaultValue: 0)
@objc static var mandarinParser: Int @objc static var mandarinParser: Int
@objc static var mandarinParserName: String { static var mandarinParserName: String {
(MandarinParser(rawValue: mandarinParser) ?? MandarinParser.ofStandard).name (MandarinParser(rawValue: mandarinParser) ?? MandarinParser.ofStandard).name
} }
@UserDefault( @UserDefault(
key: UserDef.kBasicKeyboardLayout, defaultValue: "com.apple.keylayout.ZhuyinBopomofo" key: UserDef.kBasicKeyboardLayout, defaultValue: "com.apple.keylayout.ZhuyinBopomofo"
) )
@objc static var basicKeyboardLayout: String static var basicKeyboardLayout: String
@UserDefault(key: UserDef.kShowPageButtonsInCandidateWindow, defaultValue: true) @UserDefault(key: UserDef.kShowPageButtonsInCandidateWindow, defaultValue: true)
@objc static var showPageButtonsInCandidateWindow: Bool static var showPageButtonsInCandidateWindow: Bool
@CandidateListTextSize(key: UserDef.kCandidateListTextSize) @CandidateListTextSize(key: UserDef.kCandidateListTextSize)
@objc static var candidateListTextSize: CGFloat static var candidateListTextSize: CGFloat
@UserDefault(key: UserDef.kShouldAutoReloadUserDataFiles, defaultValue: true) @UserDefault(key: UserDef.kShouldAutoReloadUserDataFiles, defaultValue: true)
@objc static var shouldAutoReloadUserDataFiles: Bool static var shouldAutoReloadUserDataFiles: Bool
@UserDefault(key: UserDef.kSetRearCursorMode, defaultValue: false) @UserDefault(key: UserDef.kSetRearCursorMode, defaultValue: false)
@objc static var setRearCursorMode: Bool static var setRearCursorMode: Bool
@UserDefault(key: UserDef.kMoveCursorAfterSelectingCandidate, defaultValue: true) @UserDefault(key: UserDef.kMoveCursorAfterSelectingCandidate, defaultValue: true)
@objc static var moveCursorAfterSelectingCandidate: Bool static var moveCursorAfterSelectingCandidate: Bool
@UserDefault(key: UserDef.kUseHorizontalCandidateList, defaultValue: true) @UserDefault(key: UserDef.kUseHorizontalCandidateList, defaultValue: true)
@objc static var useHorizontalCandidateList: Bool static var useHorizontalCandidateList: Bool
@ComposingBufferSize(key: UserDef.kComposingBufferSize) @ComposingBufferSize(key: UserDef.kComposingBufferSize)
@objc static var composingBufferSize: Int static var composingBufferSize: Int
@UserDefault(key: UserDef.kChooseCandidateUsingSpace, defaultValue: true) @UserDefault(key: UserDef.kChooseCandidateUsingSpace, defaultValue: true)
@objc static var chooseCandidateUsingSpace: Bool static var chooseCandidateUsingSpace: Bool
@UserDefault(key: UserDef.kUseSCPCTypingMode, defaultValue: false) @UserDefault(key: UserDef.kUseSCPCTypingMode, defaultValue: false)
@objc static var useSCPCTypingMode: Bool static var useSCPCTypingMode: Bool
@objc static func toggleSCPCTypingModeEnabled() -> Bool { static func toggleSCPCTypingModeEnabled() -> Bool {
useSCPCTypingMode = !useSCPCTypingMode useSCPCTypingMode = !useSCPCTypingMode
UserDefaults.standard.set(useSCPCTypingMode, forKey: UserDef.kUseSCPCTypingMode) UserDefaults.standard.set(useSCPCTypingMode, forKey: UserDef.kUseSCPCTypingMode)
return useSCPCTypingMode return useSCPCTypingMode
} }
@UserDefault(key: UserDef.kMaxCandidateLength, defaultValue: kDefaultComposingBufferSize * 2) @UserDefault(key: UserDef.kMaxCandidateLength, defaultValue: kDefaultComposingBufferSize * 2)
@objc static var maxCandidateLength: Int static var maxCandidateLength: Int
@UserDefault(key: UserDef.kShouldNotFartInLieuOfBeep, defaultValue: true) @UserDefault(key: UserDef.kShouldNotFartInLieuOfBeep, defaultValue: true)
@objc static var shouldNotFartInLieuOfBeep: Bool static var shouldNotFartInLieuOfBeep: Bool
@objc static func toggleShouldNotFartInLieuOfBeep() -> Bool { static func toggleShouldNotFartInLieuOfBeep() -> Bool {
shouldNotFartInLieuOfBeep = !shouldNotFartInLieuOfBeep shouldNotFartInLieuOfBeep = !shouldNotFartInLieuOfBeep
UserDefaults.standard.set(shouldNotFartInLieuOfBeep, forKey: UserDef.kShouldNotFartInLieuOfBeep) UserDefaults.standard.set(shouldNotFartInLieuOfBeep, forKey: UserDef.kShouldNotFartInLieuOfBeep)
return shouldNotFartInLieuOfBeep return shouldNotFartInLieuOfBeep
} }
@UserDefault(key: UserDef.kCNS11643Enabled, defaultValue: false) @UserDefault(key: UserDef.kCNS11643Enabled, defaultValue: false)
@objc static var cns11643Enabled: Bool static var cns11643Enabled: Bool
@objc static func toggleCNS11643Enabled() -> Bool { static func toggleCNS11643Enabled() -> Bool {
cns11643Enabled = !cns11643Enabled cns11643Enabled = !cns11643Enabled
mgrLangModel.setCNSEnabled(cns11643Enabled) // mgrLangModel.setCNSEnabled(cns11643Enabled) //
UserDefaults.standard.set(cns11643Enabled, forKey: UserDef.kCNS11643Enabled) UserDefaults.standard.set(cns11643Enabled, forKey: UserDef.kCNS11643Enabled)
@ -369,9 +369,9 @@ public class mgrPrefs: NSObject {
} }
@UserDefault(key: UserDef.kSymbolInputEnabled, defaultValue: true) @UserDefault(key: UserDef.kSymbolInputEnabled, defaultValue: true)
@objc static var symbolInputEnabled: Bool static var symbolInputEnabled: Bool
@objc static func toggleSymbolInputEnabled() -> Bool { static func toggleSymbolInputEnabled() -> Bool {
symbolInputEnabled = !symbolInputEnabled symbolInputEnabled = !symbolInputEnabled
mgrLangModel.setSymbolEnabled(symbolInputEnabled) // mgrLangModel.setSymbolEnabled(symbolInputEnabled) //
UserDefaults.standard.set(symbolInputEnabled, forKey: UserDef.kSymbolInputEnabled) UserDefaults.standard.set(symbolInputEnabled, forKey: UserDef.kSymbolInputEnabled)
@ -379,9 +379,9 @@ public class mgrPrefs: NSObject {
} }
@UserDefault(key: UserDef.kChineseConversionEnabled, defaultValue: false) @UserDefault(key: UserDef.kChineseConversionEnabled, defaultValue: false)
@objc static var chineseConversionEnabled: Bool static var chineseConversionEnabled: Bool
@objc @discardableResult static func toggleChineseConversionEnabled() -> Bool { @discardableResult static func toggleChineseConversionEnabled() -> Bool {
chineseConversionEnabled = !chineseConversionEnabled chineseConversionEnabled = !chineseConversionEnabled
// JIS // JIS
if chineseConversionEnabled, shiftJISShinjitaiOutputEnabled { if chineseConversionEnabled, shiftJISShinjitaiOutputEnabled {
@ -395,9 +395,9 @@ public class mgrPrefs: NSObject {
} }
@UserDefault(key: UserDef.kShiftJISShinjitaiOutputEnabled, defaultValue: false) @UserDefault(key: UserDef.kShiftJISShinjitaiOutputEnabled, defaultValue: false)
@objc static var shiftJISShinjitaiOutputEnabled: Bool static var shiftJISShinjitaiOutputEnabled: Bool
@objc @discardableResult static func toggleShiftJISShinjitaiOutputEnabled() -> Bool { @discardableResult static func toggleShiftJISShinjitaiOutputEnabled() -> Bool {
shiftJISShinjitaiOutputEnabled = !shiftJISShinjitaiOutputEnabled shiftJISShinjitaiOutputEnabled = !shiftJISShinjitaiOutputEnabled
// JIS // JIS
if shiftJISShinjitaiOutputEnabled, chineseConversionEnabled { if shiftJISShinjitaiOutputEnabled, chineseConversionEnabled {
@ -410,42 +410,42 @@ public class mgrPrefs: NSObject {
} }
@UserDefault(key: UserDef.kHalfWidthPunctuationEnabled, defaultValue: false) @UserDefault(key: UserDef.kHalfWidthPunctuationEnabled, defaultValue: false)
@objc static var halfWidthPunctuationEnabled: Bool static var halfWidthPunctuationEnabled: Bool
@objc static func toggleHalfWidthPunctuationEnabled() -> Bool { static func toggleHalfWidthPunctuationEnabled() -> Bool {
halfWidthPunctuationEnabled = !halfWidthPunctuationEnabled halfWidthPunctuationEnabled = !halfWidthPunctuationEnabled
return halfWidthPunctuationEnabled return halfWidthPunctuationEnabled
} }
@UserDefault(key: UserDef.kEscToCleanInputBuffer, defaultValue: true) @UserDefault(key: UserDef.kEscToCleanInputBuffer, defaultValue: true)
@objc static var escToCleanInputBuffer: Bool static var escToCleanInputBuffer: Bool
@UserDefault(key: UserDef.kSpecifyShiftTabKeyBehavior, defaultValue: false) @UserDefault(key: UserDef.kSpecifyShiftTabKeyBehavior, defaultValue: false)
@objc static var specifyShiftTabKeyBehavior: Bool static var specifyShiftTabKeyBehavior: Bool
@UserDefault(key: UserDef.kSpecifyShiftSpaceKeyBehavior, defaultValue: false) @UserDefault(key: UserDef.kSpecifyShiftSpaceKeyBehavior, defaultValue: false)
@objc static var specifyShiftSpaceKeyBehavior: Bool static var specifyShiftSpaceKeyBehavior: Bool
// MARK: - Optional settings // MARK: - Optional settings
@UserDefault(key: UserDef.kCandidateTextFontName, defaultValue: nil) @UserDefault(key: UserDef.kCandidateTextFontName, defaultValue: nil)
@objc static var candidateTextFontName: String? static var candidateTextFontName: String?
@UserDefault(key: UserDef.kCandidateKeyLabelFontName, defaultValue: nil) @UserDefault(key: UserDef.kCandidateKeyLabelFontName, defaultValue: nil)
@objc static var candidateKeyLabelFontName: String? static var candidateKeyLabelFontName: String?
@UserDefault(key: UserDef.kCandidateKeys, defaultValue: kDefaultKeys) @UserDefault(key: UserDef.kCandidateKeys, defaultValue: kDefaultKeys)
@objc static var candidateKeys: String static var candidateKeys: String
@objc static var defaultCandidateKeys: String { static var defaultCandidateKeys: String {
kDefaultKeys kDefaultKeys
} }
@objc static var suggestedCandidateKeys: [String] { static var suggestedCandidateKeys: [String] {
[kDefaultKeys, "234567890", "QWERTYUIO", "QWERTASDF", "ASDFGHJKL", "ASDFZXCVB"] [kDefaultKeys, "234567890", "QWERTYUIO", "QWERTASDF", "ASDFGHJKL", "ASDFZXCVB"]
} }
@objc static func validate(candidateKeys: String) throws { static func validate(candidateKeys: String) throws {
let trimmed = candidateKeys.trimmingCharacters(in: .whitespacesAndNewlines) let trimmed = candidateKeys.trimmingCharacters(in: .whitespacesAndNewlines)
if trimmed.isEmpty { if trimmed.isEmpty {
throw CandidateKeyError.empty throw CandidateKeyError.empty
@ -500,9 +500,9 @@ public class mgrPrefs: NSObject {
} }
@UserDefault(key: UserDef.kPhraseReplacementEnabled, defaultValue: false) @UserDefault(key: UserDef.kPhraseReplacementEnabled, defaultValue: false)
@objc static var phraseReplacementEnabled: Bool static var phraseReplacementEnabled: Bool
@objc static func togglePhraseReplacementEnabled() -> Bool { static func togglePhraseReplacementEnabled() -> Bool {
phraseReplacementEnabled = !phraseReplacementEnabled phraseReplacementEnabled = !phraseReplacementEnabled
mgrLangModel.setPhraseReplacementEnabled(phraseReplacementEnabled) mgrLangModel.setPhraseReplacementEnabled(phraseReplacementEnabled)
UserDefaults.standard.set(phraseReplacementEnabled, forKey: UserDef.kPhraseReplacementEnabled) UserDefaults.standard.set(phraseReplacementEnabled, forKey: UserDef.kPhraseReplacementEnabled)
@ -510,9 +510,9 @@ public class mgrPrefs: NSObject {
} }
@UserDefault(key: UserDef.kAssociatedPhrasesEnabled, defaultValue: false) @UserDefault(key: UserDef.kAssociatedPhrasesEnabled, defaultValue: false)
@objc static var associatedPhrasesEnabled: Bool static var associatedPhrasesEnabled: Bool
@objc static func toggleAssociatedPhrasesEnabled() -> Bool { static func toggleAssociatedPhrasesEnabled() -> Bool {
associatedPhrasesEnabled = !associatedPhrasesEnabled associatedPhrasesEnabled = !associatedPhrasesEnabled
UserDefaults.standard.set(associatedPhrasesEnabled, forKey: UserDef.kAssociatedPhrasesEnabled) UserDefaults.standard.set(associatedPhrasesEnabled, forKey: UserDef.kAssociatedPhrasesEnabled)
return associatedPhrasesEnabled return associatedPhrasesEnabled

View File

@ -59,11 +59,11 @@ public class clsSFX: NSObject, NSSoundDelegate {
currentBeep = beep currentBeep = beep
} }
@objc public func sound(_: NSSound, didFinishPlaying _: Bool) { public func sound(_: NSSound, didFinishPlaying _: Bool) {
currentBeep = nil currentBeep = nil
} }
@objc static func beep() { static func beep() {
shared.beep() shared.beep()
} }
} }

View File

@ -26,10 +26,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import Cocoa import Cocoa
@objc(VTCandidateKeyLabel)
public class CandidateKeyLabel: NSObject { public class CandidateKeyLabel: NSObject {
@objc public private(set) var key: String public private(set) var key: String
@objc public private(set) var displayedText: String public private(set) var displayedText: String
public init(key: String, displayedText: String) { public init(key: String, displayedText: String) {
self.key = key self.key = key
@ -38,7 +37,6 @@ public class CandidateKeyLabel: NSObject {
} }
} }
@objc(ctlCandidateDelegate)
public protocol ctlCandidateDelegate: AnyObject { public protocol ctlCandidateDelegate: AnyObject {
func candidateCountForController(_ controller: ctlCandidate) -> UInt func candidateCountForController(_ controller: ctlCandidate) -> UInt
func ctlCandidate(_ controller: ctlCandidate, candidateAtIndex index: UInt) func ctlCandidate(_ controller: ctlCandidate, candidateAtIndex index: UInt)
@ -48,16 +46,15 @@ public protocol ctlCandidateDelegate: AnyObject {
) )
} }
@objc(ctlCandidate)
public class ctlCandidate: NSWindowController { public class ctlCandidate: NSWindowController {
@objc public weak var delegate: ctlCandidateDelegate? { public weak var delegate: ctlCandidateDelegate? {
didSet { didSet {
reloadData() reloadData()
} }
} }
@objc public var selectedCandidateIndex: UInt = .max public var selectedCandidateIndex: UInt = .max
@objc public var visible: Bool = false { public var visible: Bool = false {
didSet { didSet {
NSObject.cancelPreviousPerformRequests(withTarget: self) NSObject.cancelPreviousPerformRequests(withTarget: self)
if visible { if visible {
@ -68,7 +65,7 @@ public class ctlCandidate: NSWindowController {
} }
} }
@objc public var windowTopLeftPoint: NSPoint { public var windowTopLeftPoint: NSPoint {
get { get {
guard let frameRect = window?.frame else { guard let frameRect = window?.frame else {
return NSPoint.zero return NSPoint.zero
@ -82,36 +79,36 @@ public class ctlCandidate: NSWindowController {
} }
} }
@objc public var keyLabels: [CandidateKeyLabel] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"] public var keyLabels: [CandidateKeyLabel] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
.map { .map {
CandidateKeyLabel(key: $0, displayedText: $0) CandidateKeyLabel(key: $0, displayedText: $0)
} }
@objc public var keyLabelFont: NSFont = NSFont.monospacedDigitSystemFont( public var keyLabelFont: NSFont = NSFont.monospacedDigitSystemFont(
ofSize: 14, weight: .medium ofSize: 14, weight: .medium
) )
@objc public var candidateFont: NSFont = NSFont.systemFont(ofSize: 18) public var candidateFont: NSFont = NSFont.systemFont(ofSize: 18)
@objc public var tooltip: String = "" public var tooltip: String = ""
@objc public func reloadData() {} public func reloadData() {}
@objc public func showNextPage() -> Bool { public func showNextPage() -> Bool {
false false
} }
@objc public func showPreviousPage() -> Bool { public func showPreviousPage() -> Bool {
false false
} }
@objc public func highlightNextCandidate() -> Bool { public func highlightNextCandidate() -> Bool {
false false
} }
@objc public func highlightPreviousCandidate() -> Bool { public func highlightPreviousCandidate() -> Bool {
false false
} }
@objc public func candidateIndexAtKeyLabelIndex(_: UInt) -> UInt { public func candidateIndexAtKeyLabelIndex(_: UInt) -> UInt {
UInt.max UInt.max
} }
@ -125,7 +122,6 @@ public class ctlCandidate: NSWindowController {
/// - windowTopLeftPoint: The given location. /// - windowTopLeftPoint: The given location.
/// - height: The height that helps the window not to be out of the bottom /// - height: The height that helps the window not to be out of the bottom
/// of a screen. /// of a screen.
@objc(setWindowTopLeftPoint:bottomOutOfScreenAdjustmentHeight:)
public func set(windowTopLeftPoint: NSPoint, bottomOutOfScreenAdjustmentHeight height: CGFloat) { public func set(windowTopLeftPoint: NSPoint, bottomOutOfScreenAdjustmentHeight height: CGFloat) {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()) { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()) {
self.doSet( self.doSet(

View File

@ -87,7 +87,7 @@ public class NotifierController: NSWindowController, NotifierWindowDelegate {
private static var instanceCount = 0 private static var instanceCount = 0
private static var lastLocation = NSPoint.zero private static var lastLocation = NSPoint.zero
@objc public static func notify(message: String, stay: Bool = false) { public static func notify(message: String, stay: Bool = false) {
let controller = NotifierController() let controller = NotifierController()
controller.message = message controller.message = message
controller.shouldStay = stay controller.shouldStay = stay

View File

@ -64,7 +64,6 @@ public class TooltipController: NSWindowController {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
@objc(showTooltip:atPoint:)
public func show(tooltip: String, at point: NSPoint) { public func show(tooltip: String, at point: NSPoint) {
messageTextField.textColor = TooltipController.textColor messageTextField.textColor = TooltipController.textColor
messageTextField.backgroundColor = TooltipController.backgroundColor messageTextField.backgroundColor = TooltipController.backgroundColor

View File

@ -26,7 +26,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import Cocoa import Cocoa
@objc(AboutWindow) class ctlAboutWindow: NSWindowController { class ctlAboutWindow: NSWindowController {
@IBOutlet var appVersionLabel: NSTextField! @IBOutlet var appVersionLabel: NSTextField!
@IBOutlet var appCopyrightLabel: NSTextField! @IBOutlet var appCopyrightLabel: NSTextField!
@IBOutlet var appEULAContent: NSTextView! @IBOutlet var appEULAContent: NSTextView!

View File

@ -26,13 +26,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import Cocoa import Cocoa
@objc protocol ctlNonModalAlertWindowDelegate: AnyObject { protocol ctlNonModalAlertWindowDelegate: AnyObject {
func ctlNonModalAlertWindowDidConfirm(_ controller: ctlNonModalAlertWindow) func ctlNonModalAlertWindowDidConfirm(_ controller: ctlNonModalAlertWindow)
func ctlNonModalAlertWindowDidCancel(_ controller: ctlNonModalAlertWindow) func ctlNonModalAlertWindowDidCancel(_ controller: ctlNonModalAlertWindow)
} }
class ctlNonModalAlertWindow: NSWindowController { class ctlNonModalAlertWindow: NSWindowController {
@objc(sharedInstance)
static let shared = ctlNonModalAlertWindow(windowNibName: "frmNonModalAlertWindow") static let shared = ctlNonModalAlertWindow(windowNibName: "frmNonModalAlertWindow")
@IBOutlet var titleTextField: NSTextField! @IBOutlet var titleTextField: NSTextField!
@ -41,7 +40,7 @@ class ctlNonModalAlertWindow: NSWindowController {
@IBOutlet var cancelButton: NSButton! @IBOutlet var cancelButton: NSButton!
weak var delegate: ctlNonModalAlertWindowDelegate? weak var delegate: ctlNonModalAlertWindowDelegate?
@objc func show( func show(
title: String, content: String, confirmButtonTitle: String, cancelButtonTitle: String?, title: String, content: String, confirmButtonTitle: String, cancelButtonTitle: String?,
cancelAsDefault: Bool, delegate: ctlNonModalAlertWindowDelegate? cancelAsDefault: Bool, delegate: ctlNonModalAlertWindowDelegate?
) { ) {

View File

@ -30,7 +30,7 @@ import Cocoa
// Please note that the class should be exposed using the same class name // Please note that the class should be exposed using the same class name
// in Objective-C in order to let IMK to see the same class name as // in Objective-C in order to let IMK to see the same class name as
// the "InputMethodServerPreferencesWindowControllerClass" in Info.plist. // the "InputMethodServerPreferencesWindowControllerClass" in Info.plist.
@objc(ctlPrefWindow) class ctlPrefWindow: NSWindowController { class ctlPrefWindow: NSWindowController {
@IBOutlet var fontSizePopUpButton: NSPopUpButton! @IBOutlet var fontSizePopUpButton: NSPopUpButton!
@IBOutlet var uiLanguageButton: NSPopUpButton! @IBOutlet var uiLanguageButton: NSPopUpButton!
@IBOutlet var basicKeyboardLayoutButton: NSPopUpButton! @IBOutlet var basicKeyboardLayoutButton: NSPopUpButton!