SessionCtl // Publicization.

This commit is contained in:
ShikiSuen 2022-10-10 12:08:30 +08:00
parent b43d4b8993
commit c95a55dc60
7 changed files with 69 additions and 68 deletions

View File

@ -23,12 +23,12 @@ import TooltipUI
/// - Remark: IMKServer
/// IMKInputController
@objc(SessionCtl) // ObjC IMK ObjC
class SessionCtl: IMKInputController {
public class SessionCtl: IMKInputController {
///
static var areWeNerfing = false
public static var areWeNerfing = false
///
var ctlCandidateCurrent: CtlCandidateProtocol = {
public var ctlCandidateCurrent: CtlCandidateProtocol = {
let direction: NSUserInterfaceLayoutOrientation =
PrefMgr.shared.useHorizontalCandidateList ? .horizontal : .vertical
if #available(macOS 10.15, *) {
@ -40,18 +40,18 @@ class SessionCtl: IMKInputController {
}()
///
var tooltipInstance = TooltipUI()
public var tooltipInstance = TooltipUI()
///
var popupCompositionBuffer = PopupCompositionBuffer()
public var popupCompositionBuffer = PopupCompositionBuffer()
// MARK: -
/// Caps Lock
var isCapsLocked: Bool { NSEvent.modifierFlags.intersection(.deviceIndependentFlagsMask).contains(.capsLock) }
public var isCapsLocked: Bool { NSEvent.modifierFlags.intersection(.deviceIndependentFlagsMask).contains(.capsLock) }
/// SessionCtl
var isASCIIMode = false {
public var isASCIIMode = false {
didSet {
resetKeyHandler()
setKeyLayout()
@ -61,7 +61,7 @@ class SessionCtl: IMKInputController {
/// 調
var keyHandler = KeyHandler(lm: LMMgr.currentLM(), uom: LMMgr.currentUOM(), pref: PrefMgr.shared)
///
var state: IMEStateProtocol = IMEState.ofEmpty() {
public var state: IMEStateProtocol = IMEState.ofEmpty() {
didSet {
guard oldValue.type != state.type else { return }
vCLog("Current State: \(state.type.rawValue), client: \(clientBundleIdentifier)")
@ -73,10 +73,11 @@ class SessionCtl: IMKInputController {
/// Shift
/// - Remark: Struct Caps Lock Shift
static var theShiftKeyDetector = ShiftKeyUpChecker(useLShift: PrefMgr.shared.togglingAlphanumericalModeWithLShift)
public static var theShiftKeyDetector = ShiftKeyUpChecker(
useLShift: PrefMgr.shared.togglingAlphanumericalModeWithLShift)
/// `handle(event:)` Shift
var rencentKeyHandledByKeyHandlerEtc = false
public var rencentKeyHandledByKeyHandlerEtc = false
///
public static var isVerticalTyping: Bool = false
@ -93,7 +94,7 @@ class SessionCtl: IMKInputController {
/// InputMode
/// IME UserPrefs
var inputMode: Shared.InputMode = IMEApp.currentInputMode {
public var inputMode: Shared.InputMode = IMEApp.currentInputMode {
willSet {
/// Prefs IMEApp
PrefMgr.shared.mostRecentInputMode = newValue.rawValue
@ -126,7 +127,7 @@ class SessionCtl: IMKInputController {
/// - server: IMKServer
/// - delegate:
/// - inputClient:
override init!(server: IMKServer!, delegate: Any!, client inputClient: Any!) {
override public init!(server: IMKServer!, delegate: Any!, client inputClient: Any!) {
super.init(server: server, delegate: delegate, client: inputClient)
keyHandler.delegate = self
syncBaseLMPrefs()
@ -137,7 +138,7 @@ class SessionCtl: IMKInputController {
extension SessionCtl {
///
func setKeyLayout() {
public func setKeyLayout() {
guard let client = client() else { return }
func doSetKeyLayout() {
@ -154,7 +155,7 @@ extension SessionCtl {
}
/// 調
func resetKeyHandler() {
public func resetKeyHandler() {
//
if state.type == .ofInputting, PrefMgr.shared.trimUnfinishedReadingsOnCommit {
keyHandler.composer.clear()
@ -174,7 +175,7 @@ extension SessionCtl {
extension SessionCtl {
///
/// - Parameter sender: 使
override func activateServer(_ sender: Any!) {
public override func activateServer(_ sender: Any!) {
_ = sender //
UserDefaults.standard.synchronize()
@ -200,7 +201,7 @@ extension SessionCtl {
///
/// - Parameter sender: 使
override func deactivateServer(_ sender: Any!) {
public override func deactivateServer(_ sender: Any!) {
_ = sender //
resetKeyHandler() // Empty
handle(state: IMEState.ofDeactivated())
@ -211,7 +212,7 @@ extension SessionCtl {
/// - value: identifier bundle identifier info.plist
/// - tag: 使
/// - sender: 使
override func setValue(_ value: Any!, forTag tag: Int, client sender: Any!) {
public override func setValue(_ value: Any!, forTag tag: Int, client sender: Any!) {
_ = tag //
_ = sender //
let newInputMode = Shared.InputMode(rawValue: value as? String ?? "") ?? Shared.InputMode.imeModeNULL
@ -225,7 +226,7 @@ extension SessionCtl {
}
///
func syncBaseLMPrefs() {
public func syncBaseLMPrefs() {
LMMgr.currentLM().isPhraseReplacementEnabled = PrefMgr.shared.phraseReplacementEnabled
LMMgr.currentLM().isCNSEnabled = PrefMgr.shared.cns11643Enabled
LMMgr.currentLM().isSymbolEnabled = PrefMgr.shared.symbolInputEnabled
@ -248,7 +249,7 @@ extension SessionCtl {
/// `commitComposition(_ message)`
/// - Parameter sender: 使
/// - Returns: uint NSEvent NSEvent.h
override func recognizedEvents(_ sender: Any!) -> Int {
public override func recognizedEvents(_ sender: Any!) -> Int {
_ = sender //
let events: NSEvent.EventTypeMask = [.keyDown, .flagsChanged]
return Int(events.rawValue)
@ -258,7 +259,7 @@ extension SessionCtl {
/// handle(event:) Event
/// commitComposition
/// - Parameter sender: 使
override func commitComposition(_ sender: Any!) {
public override func commitComposition(_ sender: Any!) {
_ = sender //
resetKeyHandler()
// super.commitComposition(sender) //
@ -267,7 +268,7 @@ extension SessionCtl {
/// InputMethodKit
/// - Parameter sender: 使
/// - Returns: nil
override func composedString(_ sender: Any!) -> Any! {
public override func composedString(_ sender: Any!) -> Any! {
_ = sender //
guard state.hasComposition else { return "" }
return state.displayedTextConverted
@ -275,7 +276,7 @@ extension SessionCtl {
///
/// IMK Bug
override func inputControllerWillClose() {
public override func inputControllerWillClose() {
//
resetKeyHandler()
super.inputControllerWillClose()

View File

@ -11,18 +11,18 @@ import Shared
// MARK: - KeyHandler Delegate
extension SessionCtl: KeyHandlerDelegate {
var clientBundleIdentifier: String {
public var clientBundleIdentifier: String {
guard let client = client() else { return "" }
return client.bundleIdentifier() ?? ""
}
func candidateController() -> CtlCandidateProtocol { ctlCandidateCurrent }
public func candidateController() -> CtlCandidateProtocol { ctlCandidateCurrent }
func candidateSelectionCalledByKeyHandler(at index: Int) {
public func candidateSelectionCalledByKeyHandler(at index: Int) {
candidatePairSelected(at: index)
}
func performUserPhraseOperation(with state: IMEStateProtocol, addToFilter: Bool)
public func performUserPhraseOperation(with state: IMEStateProtocol, addToFilter: Bool)
-> Bool
{
guard state.type == .ofMarking else { return false }
@ -53,11 +53,11 @@ extension SessionCtl: KeyHandlerDelegate {
// MARK: - Candidate Controller Delegate
extension SessionCtl: CtlCandidateDelegate {
var selectionKeys: String {
public var selectionKeys: String {
PrefMgr.shared.useIMKCandidateWindow ? "123456789" : PrefMgr.shared.candidateKeys
}
func candidatePairs(conv: Bool = false) -> [(String, String)] {
public func candidatePairs(conv: Bool = false) -> [(String, String)] {
if !state.isCandidateContainer || state.candidates.isEmpty { return [] }
if !conv || PrefMgr.shared.cns11643Enabled || state.candidates[0].0.contains("_punctuation") {
return state.candidates
@ -71,7 +71,7 @@ extension SessionCtl: CtlCandidateDelegate {
return convertedCandidates
}
func candidatePairSelected(at index: Int) {
public func candidatePairSelected(at index: Int) {
if state.type == .ofSymbolTable, (0..<state.node.members.count).contains(index) {
let node = state.node.members[index]
if !node.members.isEmpty {

View File

@ -16,13 +16,13 @@ extension SessionCtl {
// App 使
// App App
// 使 20
var attributedStringSecured: (NSAttributedString, NSRange) {
public var attributedStringSecured: (NSAttributedString, NSRange) {
PrefMgr.shared.clientsIMKTextInputIncapable.contains(clientBundleIdentifier)
? (state.data.attributedStringPlaceholder, NSRange(location: 0, length: 0))
: (state.attributedString, NSRange(state.u16MarkedRange))
}
func lineHeightRect(zeroCursor: Bool = false) -> NSRect {
public func lineHeightRect(zeroCursor: Bool = false) -> NSRect {
var lineHeightRect = NSRect.seniorTheBeast
guard let client = client() else {
return lineHeightRect
@ -40,7 +40,7 @@ extension SessionCtl {
return lineHeightRect
}
func show(tooltip: String) {
public func show(tooltip: String) {
guard client() != nil else { return }
let lineHeightRect = lineHeightRect()
var finalOrigin: NSPoint = lineHeightRect.origin
@ -69,7 +69,7 @@ extension SessionCtl {
)
}
func showCandidates() {
public func showCandidates() {
guard let client = client() else { return }
state.isVerticalCandidateWindow = (isVerticalTyping || !PrefMgr.shared.useHorizontalCandidateList)
@ -159,7 +159,7 @@ extension SessionCtl {
/// 5) Do NOT enable either KangXi conversion mode nor JIS conversion mode. They are disabled by default.
/// 6) Expecting the glyph differences of the candidate "" between PingFang SC and PingFang TC when rendering
/// the candidate window in different "vChewing-CHS" and "vChewing-CHT" input modes.
static func candidateFont(name: String? = nil, size: Double) -> NSFont {
public static func candidateFont(name: String? = nil, size: Double) -> NSFont {
let finalReturnFont: NSFont =
{
switch IMEApp.currentInputMode {

View File

@ -20,7 +20,7 @@ extension SessionCtl {
/// - event: nil
/// - sender: 使
/// - Returns: `true` IMK`false`
@objc(handleEvent:client:) override func handle(_ event: NSEvent!, client sender: Any!) -> Bool {
@objc(handleEvent:client:) public override func handle(_ event: NSEvent!, client sender: Any!) -> Bool {
_ = sender //
// MARK:

View File

@ -21,7 +21,7 @@ extension SessionCtl {
/// 使 SessionCtl
///
/// - Parameter newState:
func handle(state newState: IMEStateProtocol) {
public func handle(state newState: IMEStateProtocol) {
let previous = state
state = newState
switch state.type {
@ -97,7 +97,7 @@ extension SessionCtl {
}
/// .NotEmpty()
func setInlineDisplayWithCursor() {
public func setInlineDisplayWithCursor() {
if state.type == .ofAssociates {
doSetMarkedText(
state.data.attributedStringPlaceholder, selectionRange: NSRange(location: 0, length: 0),
@ -152,7 +152,7 @@ extension SessionCtl {
}
/// setMarkedText GCD
func doSetMarkedText(_ string: Any!, selectionRange: NSRange, replacementRange: NSRange) {
public func doSetMarkedText(_ string: Any!, selectionRange: NSRange, replacementRange: NSRange) {
guard let client = client() else { return }
if let myID = Bundle.main.bundleIdentifier, let clientID = client.bundleIdentifier(), myID == clientID {
DispatchQueue.main.async {

View File

@ -15,7 +15,7 @@ extension SessionCtl {
/// IMK
/// - Parameter sender: 使
/// - Returns: IMK
override func candidates(_ sender: Any!) -> [Any]! {
public override func candidates(_ sender: Any!) -> [Any]! {
_ = sender //
var arrResult = [String]()
@ -54,7 +54,7 @@ extension SessionCtl {
/// IMK
/// - Parameter _:
override open func candidateSelectionChanged(_: NSAttributedString!) {
public override func candidateSelectionChanged(_: NSAttributedString!) {
//
// IMKServer.commitCompositionWithReply() commitComposition()
// keyHandler
@ -71,7 +71,7 @@ extension SessionCtl {
/// IMK
/// - Parameter candidateString:
override open func candidateSelected(_ candidateString: NSAttributedString!) {
public override func candidateSelected(_ candidateString: NSAttributedString!) {
let candidateString: String = candidateString?.string ?? ""
if state.type == .ofAssociates {
if !PrefMgr.shared.alsoConfirmAssociatedCandidatesByEnter {

View File

@ -20,7 +20,7 @@ extension Bool {
//
extension SessionCtl {
override func menu() -> NSMenu! {
public override func menu() -> NSMenu! {
let optionKeyPressed = NSEvent.modifierFlags.contains(.option)
let menu = NSMenu(title: "Input Method Menu")
@ -191,7 +191,7 @@ extension SessionCtl {
// MARK: - IME Menu Items
extension SessionCtl {
@objc override func showPreferences(_: Any?) {
@objc public override func showPreferences(_: Any?) {
if #unavailable(macOS 10.15) {
showLegacyPreferences()
} else if NSEvent.modifierFlags.contains(.option) {
@ -203,24 +203,24 @@ extension SessionCtl {
}
}
func showLegacyPreferences() {
public func showLegacyPreferences() {
(NSApp.delegate as? AppDelegate)?.showPreferences()
NSApp.activate(ignoringOtherApps: true)
}
@objc func showCheatSheet(_: Any?) {
@objc public func showCheatSheet(_: Any?) {
guard let url = Bundle.main.url(forResource: "shortcuts", withExtension: "html") else { return }
DispatchQueue.main.async {
NSWorkspace.shared.openFile(url.path, withApplication: "Safari")
}
}
@objc func showClientListMgr(_: Any?) {
@objc public func showClientListMgr(_: Any?) {
(NSApp.delegate as? AppDelegate)?.showClientListMgr()
NSApp.activate(ignoringOtherApps: true)
}
@objc func toggleSCPCTypingMode(_: Any? = nil) {
@objc public func toggleSCPCTypingMode(_: Any? = nil) {
resetKeyHandler()
Notifier.notify(
message: NSLocalizedString("Per-Char Select Mode", comment: "") + "\n"
@ -230,7 +230,7 @@ extension SessionCtl {
)
}
@objc func toggleChineseConverter(_: Any?) {
@objc public func toggleChineseConverter(_: Any?) {
resetKeyHandler()
Notifier.notify(
message: NSLocalizedString("Force KangXi Writing", comment: "") + "\n"
@ -240,7 +240,7 @@ extension SessionCtl {
)
}
@objc func toggleShiftJISShinjitaiOutput(_: Any?) {
@objc public func toggleShiftJISShinjitaiOutput(_: Any?) {
resetKeyHandler()
Notifier.notify(
message: NSLocalizedString("JIS Shinjitai Output", comment: "") + "\n"
@ -250,7 +250,7 @@ extension SessionCtl {
)
}
@objc func toggleCurrencyNumerals(_: Any?) {
@objc public func toggleCurrencyNumerals(_: Any?) {
resetKeyHandler()
Notifier.notify(
message: NSLocalizedString("Currency Numeral Output", comment: "") + "\n"
@ -260,7 +260,7 @@ extension SessionCtl {
)
}
@objc func toggleHalfWidthPunctuation(_: Any?) {
@objc public func toggleHalfWidthPunctuation(_: Any?) {
resetKeyHandler()
Notifier.notify(
message: NSLocalizedString("Half-Width Punctuation Mode", comment: "") + "\n"
@ -270,7 +270,7 @@ extension SessionCtl {
)
}
@objc func toggleCNS11643Enabled(_: Any?) {
@objc public func toggleCNS11643Enabled(_: Any?) {
resetKeyHandler()
Notifier.notify(
message: NSLocalizedString("CNS11643 Mode", comment: "") + "\n"
@ -280,7 +280,7 @@ extension SessionCtl {
)
}
@objc func toggleSymbolEnabled(_: Any?) {
@objc public func toggleSymbolEnabled(_: Any?) {
resetKeyHandler()
Notifier.notify(
message: NSLocalizedString("Symbol & Emoji Input", comment: "") + "\n"
@ -290,7 +290,7 @@ extension SessionCtl {
)
}
@objc func toggleAssociatedPhrasesEnabled(_: Any?) {
@objc public func toggleAssociatedPhrasesEnabled(_: Any?) {
resetKeyHandler()
Notifier.notify(
message: NSLocalizedString("Per-Char Associated Phrases", comment: "") + "\n"
@ -300,7 +300,7 @@ extension SessionCtl {
)
}
@objc func togglePhraseReplacement(_: Any?) {
@objc public func togglePhraseReplacement(_: Any?) {
resetKeyHandler()
Notifier.notify(
message: NSLocalizedString("Use Phrase Replacement", comment: "") + "\n"
@ -310,20 +310,20 @@ extension SessionCtl {
)
}
@objc func selfUninstall(_: Any?) {
@objc public func selfUninstall(_: Any?) {
(NSApp.delegate as? AppDelegate)?.selfUninstall()
}
@objc func selfTerminate(_: Any?) {
@objc public func selfTerminate(_: Any?) {
NSApp.activate(ignoringOtherApps: true)
NSApp.terminate(nil)
}
@objc func checkForUpdate(_: Any?) {
@objc public func checkForUpdate(_: Any?) {
(NSApp.delegate as? AppDelegate)?.updateSputnik.checkForUpdate(forced: true, url: kUpdateInfoSourceURL)
}
@objc func openUserDataFolder(_: Any?) {
@objc public func openUserDataFolder(_: Any?) {
if !LMMgr.userDataFolderExists {
return
}
@ -332,35 +332,35 @@ extension SessionCtl {
)
}
@objc func openUserPhrases(_: Any?) {
@objc public func openUserPhrases(_: Any?) {
LMMgr.openPhraseFile(fromURL: LMMgr.userPhrasesDataURL(IMEApp.currentInputMode))
if NSEvent.modifierFlags.contains(.option) {
LMMgr.openPhraseFile(fromURL: LMMgr.userPhrasesDataURL(IMEApp.currentInputMode.reversed))
}
}
@objc func openExcludedPhrases(_: Any?) {
@objc public func openExcludedPhrases(_: Any?) {
LMMgr.openPhraseFile(fromURL: LMMgr.userFilteredDataURL(IMEApp.currentInputMode))
if NSEvent.modifierFlags.contains(.option) {
LMMgr.openPhraseFile(fromURL: LMMgr.userFilteredDataURL(IMEApp.currentInputMode.reversed))
}
}
@objc func openUserSymbols(_: Any?) {
@objc public func openUserSymbols(_: Any?) {
LMMgr.openPhraseFile(fromURL: LMMgr.userSymbolDataURL(IMEApp.currentInputMode))
if NSEvent.modifierFlags.contains(.option) {
LMMgr.openPhraseFile(fromURL: LMMgr.userSymbolDataURL(IMEApp.currentInputMode.reversed))
}
}
@objc func openPhraseReplacement(_: Any?) {
@objc public func openPhraseReplacement(_: Any?) {
LMMgr.openPhraseFile(fromURL: LMMgr.userReplacementsDataURL(IMEApp.currentInputMode))
if NSEvent.modifierFlags.contains(.option) {
LMMgr.openPhraseFile(fromURL: LMMgr.userReplacementsDataURL(IMEApp.currentInputMode.reversed))
}
}
@objc func openAssociatedPhrases(_: Any?) {
@objc public func openAssociatedPhrases(_: Any?) {
LMMgr.openPhraseFile(fromURL: LMMgr.userAssociatesDataURL(IMEApp.currentInputMode))
if NSEvent.modifierFlags.contains(.option) {
LMMgr.openPhraseFile(
@ -368,25 +368,25 @@ extension SessionCtl {
}
}
@objc func reloadUserPhrasesData(_: Any?) {
@objc public func reloadUserPhrasesData(_: Any?) {
LMMgr.initUserLangModels()
}
@objc func removeUnigramsFromUOM(_: Any?) {
@objc public func removeUnigramsFromUOM(_: Any?) {
LMMgr.removeUnigramsFromUserOverrideModel(IMEApp.currentInputMode)
if NSEvent.modifierFlags.contains(.option) {
LMMgr.removeUnigramsFromUserOverrideModel(IMEApp.currentInputMode.reversed)
}
}
@objc func clearUOM(_: Any?) {
@objc public func clearUOM(_: Any?) {
LMMgr.clearUserOverrideModelData(IMEApp.currentInputMode)
if NSEvent.modifierFlags.contains(.option) {
LMMgr.clearUserOverrideModelData(IMEApp.currentInputMode.reversed)
}
}
@objc func showAbout(_: Any?) {
@objc public func showAbout(_: Any?) {
(NSApp.delegate as? AppDelegate)?.showAbout()
NSApp.activate(ignoringOtherApps: true)
}