From d2107f847a4dccc73880467e050d564e6075b313 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Fri, 9 Dec 2022 22:16:41 +0800 Subject: [PATCH] PhraseEditor // Release some memory when it gets disappeared. --- .../Sources/PhraseEditorUI/PhraseEditorUI.swift | 2 ++ Source/Modules/WindowControllers/CtlPrefWindow.swift | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Packages/vChewing_PhraseEditorUI/Sources/PhraseEditorUI/PhraseEditorUI.swift b/Packages/vChewing_PhraseEditorUI/Sources/PhraseEditorUI/PhraseEditorUI.swift index 0b8c80cf1..8ba5c239f 100644 --- a/Packages/vChewing_PhraseEditorUI/Sources/PhraseEditorUI/PhraseEditorUI.swift +++ b/Packages/vChewing_PhraseEditorUI/Sources/PhraseEditorUI/PhraseEditorUI.swift @@ -297,6 +297,8 @@ public struct VwrPhraseEditorUI: View { selInputMode = .imeModeNULL selUserDataType = .thePhrases txtContent = NSLocalizedString("Please select Simplified / Traditional Chinese mode above.", comment: "") + isLoading = true + Self.txtContentStorage = "" }.onAppear { guard let delegate = delegate else { return } selInputMode = delegate.currentInputMode diff --git a/Source/Modules/WindowControllers/CtlPrefWindow.swift b/Source/Modules/WindowControllers/CtlPrefWindow.swift index 7d7749980..b3abd98f7 100644 --- a/Source/Modules/WindowControllers/CtlPrefWindow.swift +++ b/Source/Modules/WindowControllers/CtlPrefWindow.swift @@ -28,7 +28,7 @@ extension NSToolbarItem.Identifier { // only works with macOS System Preference pane (like macOS built-in input methods). // It should be set as "Preferences" which correspondes to the "Preference" pref pane // of this build target. -class CtlPrefWindow: NSWindowController { +class CtlPrefWindow: NSWindowController, NSWindowDelegate { @IBOutlet var fontSizePopUpButton: NSPopUpButton! @IBOutlet var uiLanguageButton: NSPopUpButton! @IBOutlet var basicKeyboardLayoutButton: NSPopUpButton! @@ -66,8 +66,9 @@ class CtlPrefWindow: NSWindowController { public static var shared: CtlPrefWindow? static func show() { - if shared == nil { shared = CtlPrefWindow(windowNibName: "frmPrefWindow") } + shared = CtlPrefWindow(windowNibName: "frmPrefWindow") guard let sharedWindow = shared?.window else { return } + sharedWindow.delegate = shared sharedWindow.center() sharedWindow.orderFrontRegardless() // 逼著視窗往最前方顯示 sharedWindow.level = .statusBar @@ -174,6 +175,10 @@ class CtlPrefWindow: NSWindowController { initPhraseEditor() } + func windowWillClose(_: Notification) { + tfdPETextEditor.string = "" + } + // 這裡有必要加上這段處理,用來確保藉由偏好設定介面動過的 CNS 開關能夠立刻生效。 // 所有涉及到語言模型開關的內容均需要這樣處理。 @IBAction func toggleCNSSupport(_: Any) {