diff --git a/Packages/vChewing_CocoaExtension/Sources/CocoaExtension/CocoaExtension_NSWindowController.swift b/Packages/vChewing_CocoaExtension/Sources/CocoaExtension/CocoaExtension_NSWindowController.swift index 262320df..7f2d38cf 100644 --- a/Packages/vChewing_CocoaExtension/Sources/CocoaExtension/CocoaExtension_NSWindowController.swift +++ b/Packages/vChewing_CocoaExtension/Sources/CocoaExtension/CocoaExtension_NSWindowController.swift @@ -48,6 +48,16 @@ extension NSWindowController { } } +extension NSWindow { + public func callAlert(title: String, text: String? = nil) { + let alert = NSAlert() + alert.messageText = title + if let text = text { alert.informativeText = text } + alert.addButton(withTitle: NSLocalizedString("OK", comment: "")) + alert.beginSheetModal(for: self) + } +} + extension IMKCandidates { /// 設定選字窗的顯示位置。 /// diff --git a/Source/Modules/WindowControllers/CtlClientListMgr.swift b/Source/Modules/WindowControllers/CtlClientListMgr.swift index 653ab150..c8ae4a97 100644 --- a/Source/Modules/WindowControllers/CtlClientListMgr.swift +++ b/Source/Modules/WindowControllers/CtlClientListMgr.swift @@ -43,16 +43,6 @@ extension CtlClientListMgr { PrefMgr.shared.clientsIMKTextInputIncapable.count } - func callAlert(_ window: NSWindow, title: String, text: String? = nil) { - let alert = NSAlert() - alert.messageText = title - if let text = text { - alert.informativeText = text - } - alert.addButton(withTitle: NSLocalizedString("OK", comment: "")) - alert.beginSheetModal(for: window) - } - @IBAction func btnAddClientClicked(_: Any) { guard let window = window else { return } let alert = NSAlert() @@ -119,18 +109,18 @@ extension CtlClientListMgr { ) let text = url.path + "\n\n" + NSLocalizedString("Please try again.", comment: "") guard let bundle = Bundle(url: url) else { - self.callAlert(window, title: title, text: text) + self.window?.callAlert(title: title, text: text) return } guard let identifier = bundle.bundleIdentifier else { - self.callAlert(window, title: title, text: text) + self.window?.callAlert(title: title, text: text) return } if PrefMgr.shared.clientsIMKTextInputIncapable.contains(identifier) { title = NSLocalizedString( "The selected item's identifier is already in the list.", comment: "" ) - self.callAlert(window, title: title, text: identifier + "\n\n" + url.path) + self.window?.callAlert(title: title, text: identifier + "\n\n" + url.path) return } self.applyNewValue(identifier)