ctlPrefWindow // Refine nil handling.

This commit is contained in:
ShikiSuen 2022-07-25 13:58:24 +08:00
parent c4c30680aa
commit e6253f6cbc
1 changed files with 23 additions and 24 deletions

View File

@ -287,6 +287,7 @@ class ctlPrefWindow: NSWindowController {
}
@IBAction func chooseUserDataFolderToSpecify(_: Any) {
guard let window = window else { return }
IME.dlgOpenPath.title = NSLocalizedString(
"Choose your desired user data folder.", comment: ""
)
@ -298,34 +299,32 @@ class ctlPrefWindow: NSWindowController {
let bolPreviousFolderValidity = mgrLangModel.checkIfSpecifiedUserDataFolderValid(
mgrPrefs.userDataFolderSpecified.expandingTildeInPath)
if window != nil {
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
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
}
} else {
if !bolPreviousFolderValidity {
mgrPrefs.resetSpecifiedUserDataFolder()
}
return
}
} else {
if !bolPreviousFolderValidity {
mgrPrefs.resetSpecifiedUserDataFolder()
}
return
}
} // End If self.window != nil
}
} // End IBAction
}