From f300305f856040168c77278d87ba8b7db1e3a9cc Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Wed, 31 Aug 2022 11:26:33 +0800 Subject: [PATCH] Repo // Ensure BookmarkMangager. --- .../LangModelRelated/mgrLangModel.swift | 3 +- .../PrefUI/suiPrefPaneDictionary.swift | 32 +++++++++---------- Source/WindowControllers/ctlPrefWindow.swift | 30 ++++++++--------- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/Source/Modules/LangModelRelated/mgrLangModel.swift b/Source/Modules/LangModelRelated/mgrLangModel.swift index 218c58e7..8697db08 100644 --- a/Source/Modules/LangModelRelated/mgrLangModel.swift +++ b/Source/Modules/LangModelRelated/mgrLangModel.swift @@ -354,7 +354,7 @@ enum mgrLangModel { folderPath?.ensureTrailingSlash() } let isFolderWritable = FileManager.default.isWritableFile(atPath: folderPath ?? "") - + // IME.prtDebugIntel("mgrLM: Exist: \(folderExist), IsFolder: \(isFolder.boolValue), isWritable: \(isFolderWritable)") if ((folderExist && !isFolder.boolValue) || !folderExist) || !isFolderWritable { return false } @@ -423,6 +423,7 @@ enum mgrLangModel { return userDictPathDefault } if mgrPrefs.ifSpecifiedUserDataPathExistsInPlist() { + BookmarkManager.shared.loadBookmarks() if mgrLangModel.checkIfSpecifiedUserDataFolderValid(userDictPathSpecified) { return userDictPathSpecified } else { diff --git a/Source/Modules/UIModules/PrefUI/suiPrefPaneDictionary.swift b/Source/Modules/UIModules/PrefUI/suiPrefPaneDictionary.swift index fe1855ec..612eadaa 100644 --- a/Source/Modules/UIModules/PrefUI/suiPrefPaneDictionary.swift +++ b/Source/Modules/UIModules/PrefUI/suiPrefPaneDictionary.swift @@ -72,23 +72,23 @@ struct suiPrefPaneDictionary: View { if let window = ctlPrefUI.shared.controller.window { IME.dlgOpenPath.beginSheetModal(for: window) { result in if result == NSApplication.ModalResponse.OK { - if IME.dlgOpenPath.url != nil { - // CommonDialog 讀入的路徑沒有結尾斜槓,這會導致檔案目錄合規性判定失準。 - // 所以要手動補回來。 - var newPath = IME.dlgOpenPath.url!.path - newPath.ensureTrailingSlash() - if mgrLangModel.checkIfSpecifiedUserDataFolderValid(newPath) { - mgrPrefs.userDataFolderSpecified = newPath - tbxUserDataPathSpecified = mgrPrefs.userDataFolderSpecified - IME.initLangModels(userOnly: true) - (NSApplication.shared.delegate as! AppDelegate).updateStreamHelperPath() - } else { - clsSFX.beep() - if !bolPreviousFolderValidity { - mgrPrefs.resetSpecifiedUserDataFolder() - } - return + guard let url = IME.dlgOpenPath.url else { return } + // CommonDialog 讀入的路徑沒有結尾斜槓,這會導致檔案目錄合規性判定失準。 + // 所以要手動補回來。 + var newPath = url.path + newPath.ensureTrailingSlash() + if mgrLangModel.checkIfSpecifiedUserDataFolderValid(newPath) { + mgrPrefs.userDataFolderSpecified = newPath + tbxUserDataPathSpecified = mgrPrefs.userDataFolderSpecified + BookmarkManager.shared.saveBookmark(for: url) + IME.initLangModels(userOnly: true) + (NSApplication.shared.delegate as! AppDelegate).updateStreamHelperPath() + } else { + clsSFX.beep() + if !bolPreviousFolderValidity { + mgrPrefs.resetSpecifiedUserDataFolder() } + return } } else { if !bolPreviousFolderValidity { diff --git a/Source/WindowControllers/ctlPrefWindow.swift b/Source/WindowControllers/ctlPrefWindow.swift index 161ed061..85c17d56 100644 --- a/Source/WindowControllers/ctlPrefWindow.swift +++ b/Source/WindowControllers/ctlPrefWindow.swift @@ -293,22 +293,22 @@ class ctlPrefWindow: NSWindowController { IME.dlgOpenPath.beginSheetModal(for: window) { result in if result == NSApplication.ModalResponse.OK { - if IME.dlgOpenPath.url != nil { - // CommonDialog 讀入的路徑沒有結尾斜槓,這會導致檔案目錄合規性判定失準。 - // 所以要手動補回來。 - var newPath = IME.dlgOpenPath.url!.path - newPath.ensureTrailingSlash() - if mgrLangModel.checkIfSpecifiedUserDataFolderValid(newPath) { - mgrPrefs.userDataFolderSpecified = newPath - IME.initLangModels(userOnly: true) - (NSApplication.shared.delegate as! AppDelegate).updateStreamHelperPath() - } else { - clsSFX.beep() - if !bolPreviousFolderValidity { - mgrPrefs.resetSpecifiedUserDataFolder() - } - return + guard let url = IME.dlgOpenPath.url else { return } + // CommonDialog 讀入的路徑沒有結尾斜槓,這會導致檔案目錄合規性判定失準。 + // 所以要手動補回來。 + var newPath = url.path + newPath.ensureTrailingSlash() + if mgrLangModel.checkIfSpecifiedUserDataFolderValid(newPath) { + mgrPrefs.userDataFolderSpecified = newPath + BookmarkManager.shared.saveBookmark(for: url) + IME.initLangModels(userOnly: true) + (NSApplication.shared.delegate as! AppDelegate).updateStreamHelperPath() + } else { + clsSFX.beep() + if !bolPreviousFolderValidity { + mgrPrefs.resetSpecifiedUserDataFolder() } + return } } else { if !bolPreviousFolderValidity {