Repo // Unify modal window calling methods.

This commit is contained in:
ShikiSuen 2024-02-14 03:32:48 +08:00
parent 21dcb58748
commit 54f61a28b1
6 changed files with 10 additions and 10 deletions

View File

@ -196,7 +196,7 @@ extension VwrClientListMgr {
} }
@IBAction func btnAddClientClicked(_: Any) { @IBAction func btnAddClientClicked(_: Any) {
guard let window = NSApp.keyWindow else { return } guard let window = CtlClientListMgr.shared?.window else { return }
let alert = NSAlert() let alert = NSAlert()
alert.messageText = NSLocalizedString( alert.messageText = NSLocalizedString(
"Please enter the client app bundle identifier(s) you want to register.", comment: "" "Please enter the client app bundle identifier(s) you want to register.", comment: ""
@ -277,11 +277,11 @@ extension VwrClientListMgr {
) )
let text = url.path + "\n\n" + NSLocalizedString("Please try again.", comment: "") let text = url.path + "\n\n" + NSLocalizedString("Please try again.", comment: "")
guard let bundle = Bundle(url: url) else { guard let bundle = Bundle(url: url) else {
NSApp.keyWindow?.callAlert(title: title, text: text) CtlClientListMgr.shared?.window.callAlert(title: title, text: text)
return return
} }
guard let identifier = bundle.bundleIdentifier else { guard let identifier = bundle.bundleIdentifier else {
NSApp.keyWindow?.callAlert(title: title, text: text) CtlClientListMgr.shared?.window.callAlert(title: title, text: text)
return return
} }
let isIdentifierAlreadyRegistered = Self.clientsList.contains(identifier) let isIdentifierAlreadyRegistered = Self.clientsList.contains(identifier)

View File

@ -38,7 +38,7 @@ public extension SettingsPanesCocoa {
static func warnAboutComDlg32Inavailability() { static func warnAboutComDlg32Inavailability() {
let title = "Please drag the desired target from Finder to this place.".localized let title = "Please drag the desired target from Finder to this place.".localized
let message = "[Technical Reason] macOS releases earlier than 10.13 have an issue: If calling NSOpenPanel directly from an input method, both the input method and its current client app hang in a dead-loop. Furthermore, it makes other apps hang in the same way when you switch into another app. If you don't want to hard-reboot your computer, your last resort is to use SSH to connect to your current computer from another computer and kill the input method process by Terminal commands. That's why vChewing cannot offer access to NSOpenPanel for macOS 10.12 and earlier.".localized let message = "[Technical Reason] macOS releases earlier than 10.13 have an issue: If calling NSOpenPanel directly from an input method, both the input method and its current client app hang in a dead-loop. Furthermore, it makes other apps hang in the same way when you switch into another app. If you don't want to hard-reboot your computer, your last resort is to use SSH to connect to your current computer from another computer and kill the input method process by Terminal commands. That's why vChewing cannot offer access to NSOpenPanel for macOS 10.12 and earlier.".localized
NSApp.keyWindow.callAlert(title: title, text: message) CtlSettingsCocoa.shared?.window.callAlert(title: title, text: message)
} }
} }

View File

@ -118,7 +118,7 @@ public extension SettingsPanesCocoa {
} }
} }
alert.addButton(withTitle: NSLocalizedString("Leave it checked", comment: "")) alert.addButton(withTitle: NSLocalizedString("Leave it checked", comment: ""))
let window = NSApp.keyWindow let window = CtlSettingsCocoa.shared?.window
if !PrefMgr.shared.shouldNotFartInLieuOfBeep { if !PrefMgr.shared.shouldNotFartInLieuOfBeep {
PrefMgr.shared.shouldNotFartInLieuOfBeep = true PrefMgr.shared.shouldNotFartInLieuOfBeep = true
alert.beginSheetModal(at: window) { result in alert.beginSheetModal(at: window) { result in

View File

@ -82,7 +82,7 @@ public extension SettingsPanesCocoa {
} }
@IBAction func whereIsIMKCandidatesWindow(_: Any) { @IBAction func whereIsIMKCandidatesWindow(_: Any) {
let window = NSApp.keyWindow let window = CtlSettingsCocoa.shared?.window
let title = "The End of Support for IMK Candidate Window" let title = "The End of Support for IMK Candidate Window"
let explanation = "1) Only macOS has IMKCandidates. Since it relies on a dedicated ObjC Bridging Header to expose necessary internal APIs to work, it hinders vChewing from completely modularized for multi-platform support.\n\n2) IMKCandidates is buggy. It is not likely to be completely fixed by Apple, and its devs are not allowed to talk about it to non-Apple individuals. That's why we have had enough with IMKCandidates. It is likely the reason why Apple had never used IMKCandidates in their official InputMethodKit sample projects (as of August 2023)." let explanation = "1) Only macOS has IMKCandidates. Since it relies on a dedicated ObjC Bridging Header to expose necessary internal APIs to work, it hinders vChewing from completely modularized for multi-platform support.\n\n2) IMKCandidates is buggy. It is not likely to be completely fixed by Apple, and its devs are not allowed to talk about it to non-Apple individuals. That's why we have had enough with IMKCandidates. It is likely the reason why Apple had never used IMKCandidates in their official InputMethodKit sample projects (as of August 2023)."
window.callAlert(title: title.localized, text: explanation.localized) window.callAlert(title: title.localized, text: explanation.localized)
@ -105,7 +105,7 @@ public extension SettingsPanesCocoa {
let alert = NSAlert(error: NSLocalizedString("Invalid Selection Keys.", comment: "")) let alert = NSAlert(error: NSLocalizedString("Invalid Selection Keys.", comment: ""))
alert.informativeText = errorResult alert.informativeText = errorResult
IMEApp.buzz() IMEApp.buzz()
if let window = NSApp.keyWindow { if let window = CtlSettingsCocoa.shared?.window {
alert.beginSheetModal(for: window) { _ in alert.beginSheetModal(for: window) { _ in
sender.stringValue = CandidateKey.defaultKeys sender.stringValue = CandidateKey.defaultKeys
} }

View File

@ -139,7 +139,7 @@ extension SettingsPanesCocoa.Cassette: NSPathControlDelegate {
let bolPreviousPathValidity = LMMgr.checkCassettePathValidity( let bolPreviousPathValidity = LMMgr.checkCassettePathValidity(
PrefMgr.shared.cassettePath.expandingTildeInPath) PrefMgr.shared.cassettePath.expandingTildeInPath)
let window = NSApp.keyWindow let window = CtlSettingsCocoa.shared?.window
dlgOpenFile.beginSheetModal(at: window) { result in dlgOpenFile.beginSheetModal(at: window) { result in
if result == NSApplication.ModalResponse.OK { if result == NSApplication.ModalResponse.OK {
guard let url = dlgOpenFile.url else { return } guard let url = dlgOpenFile.url else { return }

View File

@ -138,7 +138,7 @@ public extension SettingsPanesCocoa {
dlgOpenFile.allowedContentTypes = [.init(filenameExtension: "txt")].compactMap { $0 } dlgOpenFile.allowedContentTypes = [.init(filenameExtension: "txt")].compactMap { $0 }
} }
let window = NSApp.keyWindow let window = CtlSettingsCocoa.shared?.window
dlgOpenFile.beginSheetModal(at: window) { result in dlgOpenFile.beginSheetModal(at: window) { result in
if result == NSApplication.ModalResponse.OK { if result == NSApplication.ModalResponse.OK {
guard let url = dlgOpenFile.url else { return } guard let url = dlgOpenFile.url else { return }
@ -209,7 +209,7 @@ extension SettingsPanesCocoa.Dictionary: NSPathControlDelegate {
let bolPreviousFolderValidity = LMMgr.checkIfSpecifiedUserDataFolderValid( let bolPreviousFolderValidity = LMMgr.checkIfSpecifiedUserDataFolderValid(
PrefMgr.shared.userDataFolderSpecified.expandingTildeInPath) PrefMgr.shared.userDataFolderSpecified.expandingTildeInPath)
let window = NSApp.keyWindow let window = CtlSettingsCocoa.shared?.window
dlgOpenPath.beginSheetModal(at: window) { result in dlgOpenPath.beginSheetModal(at: window) { result in
if result == NSApplication.ModalResponse.OK { if result == NSApplication.ModalResponse.OK {
guard let url = dlgOpenPath.url else { return } guard let url = dlgOpenPath.url else { return }