CtlPrefWindow // Use PathControl instead.

This commit is contained in:
ShikiSuen 2023-07-29 00:09:25 +08:00
parent a4cd1fb69e
commit 689d80ddda
7 changed files with 338 additions and 234 deletions

View File

@ -23,14 +23,12 @@ class CtlPrefWindow: NSWindowController, NSWindowDelegate {
@IBOutlet var selectionKeyComboBox: NSComboBox! @IBOutlet var selectionKeyComboBox: NSComboBox!
@IBOutlet var chkTrad2KangXi: NSButton! @IBOutlet var chkTrad2KangXi: NSButton!
@IBOutlet var chkTrad2JISShinjitai: NSButton! @IBOutlet var chkTrad2JISShinjitai: NSButton!
@IBOutlet var lblCurrentlySpecifiedUserDataFolder: NSTextFieldCell!
@IBOutlet var tglControlDevZoneIMKCandidate: NSButton! @IBOutlet var tglControlDevZoneIMKCandidate: NSButton!
@IBOutlet var cmbCandidateFontSize: NSPopUpButton! @IBOutlet var cmbCandidateFontSize: NSPopUpButton!
@IBOutlet var chkFartSuppressor: NSButton! @IBOutlet var chkFartSuppressor: NSButton!
@IBOutlet var chkRevLookupInCandidateWindow: NSButton! @IBOutlet var chkRevLookupInCandidateWindow: NSButton!
@IBOutlet var btnBrowseFolderForUserPhrases: NSButton! @IBOutlet var btnBrowseFolderForUserPhrases: NSButton!
@IBOutlet var txtUserPhrasesFolderPath: NSTextField!
@IBOutlet var lblUserPhraseFolderChangeDescription: NSTextField! @IBOutlet var lblUserPhraseFolderChangeDescription: NSTextField!
@IBOutlet var cmbPEInputModeMenu: NSPopUpButton! @IBOutlet var cmbPEInputModeMenu: NSPopUpButton!
@ -45,6 +43,9 @@ class CtlPrefWindow: NSWindowController, NSWindowDelegate {
@IBOutlet var txtPEField1: NSTextField! @IBOutlet var txtPEField1: NSTextField!
@IBOutlet var txtPEField2: NSTextField! @IBOutlet var txtPEField2: NSTextField!
@IBOutlet var txtPEField3: NSTextField! @IBOutlet var txtPEField3: NSTextField!
@IBOutlet var pctUserDictionaryFolder: NSPathControl!
@IBOutlet var pctCassetteFilePath: NSPathControl!
var isLoading = false { var isLoading = false {
didSet { setPEUIControlAvailability() } didSet { setPEUIControlAvailability() }
} }
@ -85,6 +86,14 @@ class CtlPrefWindow: NSWindowController, NSWindowDelegate {
chkFartSuppressor.isHidden = !Date.isTodayTheDate(from: 0401) chkFartSuppressor.isHidden = !Date.isTodayTheDate(from: 0401)
chkFartSuppressor.isEnabled = !chkFartSuppressor.isHidden chkFartSuppressor.isEnabled = !chkFartSuppressor.isHidden
pctCassetteFilePath.delegate = self
pctCassetteFilePath.url = URL(fileURLWithPath: LMMgr.cassettePath())
pctCassetteFilePath.toolTip = "Please drag the desired target from Finder to this place.".localized
pctUserDictionaryFolder.delegate = self
pctUserDictionaryFolder.url = URL(fileURLWithPath: LMMgr.dataFolderPath(isDefaultFolder: false))
pctUserDictionaryFolder.toolTip = "Please drag the desired target from Finder to this place.".localized
cmbCandidateFontSize.isEnabled = true cmbCandidateFontSize.isEnabled = true
if #unavailable(macOS 10.14) { if #unavailable(macOS 10.14) {
@ -111,9 +120,6 @@ class CtlPrefWindow: NSWindowController, NSWindowDelegate {
window?.titlebarAppearsTransparent = false window?.titlebarAppearsTransparent = false
use(view: vwrGeneral, animate: false) use(view: vwrGeneral, animate: false)
lblCurrentlySpecifiedUserDataFolder.placeholderString = LMMgr.dataFolderPath(
isDefaultFolder: true)
// Credit: Hiraku Wang (for the implementation of the UI language select support in Cocoa PrefWindow. // Credit: Hiraku Wang (for the implementation of the UI language select support in Cocoa PrefWindow.
// Note: The SwiftUI PrefWindow has the same feature implemented by Shiki Suen. // Note: The SwiftUI PrefWindow has the same feature implemented by Shiki Suen.
do { do {
@ -207,6 +213,12 @@ class CtlPrefWindow: NSWindowController, NSWindowDelegate {
parserButton.select(chosenParserItem ?? defaultParserItem) parserButton.select(chosenParserItem ?? defaultParserItem)
} }
func warnAboutComDlg32Inavailability() {
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
window?.callAlert(title: title, text: message)
}
// CNS // CNS
// //
@IBAction func toggleCNSSupport(_: Any) { @IBAction func toggleCNSSupport(_: Any) {
@ -321,10 +333,19 @@ class CtlPrefWindow: NSWindowController, NSWindowDelegate {
@IBAction func resetSpecifiedUserDataFolder(_: Any) { @IBAction func resetSpecifiedUserDataFolder(_: Any) {
LMMgr.resetSpecifiedUserDataFolder() LMMgr.resetSpecifiedUserDataFolder()
pctUserDictionaryFolder.url = URL(fileURLWithPath: LMMgr.dataFolderPath(isDefaultFolder: true))
} }
@IBAction func chooseUserDataFolderToSpecify(_: Any) { @IBAction func chooseUserDataFolderToSpecify(_: Any) {
if NSEvent.modifierFlags == .option, let url = pctUserDictionaryFolder.url {
NSWorkspace.shared.activateFileViewerSelecting([url])
return
}
guard let window = window else { return } guard let window = window else { return }
guard #available(macOS 10.13, *) else {
warnAboutComDlg32Inavailability()
return
}
let dlgOpenPath = NSOpenPanel() let dlgOpenPath = NSOpenPanel()
dlgOpenPath.title = NSLocalizedString( dlgOpenPath.title = NSLocalizedString(
"Choose your desired user data folder.", comment: "" "Choose your desired user data folder.", comment: ""
@ -349,16 +370,19 @@ class CtlPrefWindow: NSWindowController, NSWindowDelegate {
PrefMgr.shared.userDataFolderSpecified = newPath PrefMgr.shared.userDataFolderSpecified = newPath
BookmarkManager.shared.saveBookmark(for: url) BookmarkManager.shared.saveBookmark(for: url)
AppDelegate.shared.updateDirectoryMonitorPath() AppDelegate.shared.updateDirectoryMonitorPath()
self.pctUserDictionaryFolder.url = url
} else { } else {
IMEApp.buzz() IMEApp.buzz()
if !bolPreviousFolderValidity { if !bolPreviousFolderValidity {
LMMgr.resetSpecifiedUserDataFolder() LMMgr.resetSpecifiedUserDataFolder()
self.pctUserDictionaryFolder.url = URL(fileURLWithPath: LMMgr.dataFolderPath(isDefaultFolder: true))
} }
return return
} }
} else { } else {
if !bolPreviousFolderValidity { if !bolPreviousFolderValidity {
LMMgr.resetSpecifiedUserDataFolder() LMMgr.resetSpecifiedUserDataFolder()
self.pctUserDictionaryFolder.url = URL(fileURLWithPath: LMMgr.dataFolderPath(isDefaultFolder: true))
} }
return return
} }
@ -388,7 +412,15 @@ class CtlPrefWindow: NSWindowController, NSWindowDelegate {
} }
@IBAction func chooseCassettePath(_: Any) { @IBAction func chooseCassettePath(_: Any) {
if NSEvent.modifierFlags == .option, let url = pctCassetteFilePath.url {
NSWorkspace.shared.activateFileViewerSelecting([url])
return
}
guard let window = window else { return } guard let window = window else { return }
guard #available(macOS 10.13, *) else {
warnAboutComDlg32Inavailability()
return
}
let dlgOpenFile = NSOpenPanel() let dlgOpenFile = NSOpenPanel()
dlgOpenFile.title = NSLocalizedString( dlgOpenFile.title = NSLocalizedString(
"Choose your desired cassette file path.", comment: "" "Choose your desired cassette file path.", comment: ""
@ -411,6 +443,7 @@ class CtlPrefWindow: NSWindowController, NSWindowDelegate {
PrefMgr.shared.cassettePath = url.path PrefMgr.shared.cassettePath = url.path
LMMgr.loadCassetteData() LMMgr.loadCassetteData()
BookmarkManager.shared.saveBookmark(for: url) BookmarkManager.shared.saveBookmark(for: url)
self.pctCassetteFilePath.url = url
} else { } else {
IMEApp.buzz() IMEApp.buzz()
if !bolPreviousPathValidity { if !bolPreviousPathValidity {
@ -490,3 +523,50 @@ extension CtlPrefWindow: NSToolbarDelegate {
return item return item
} }
} }
// MARK: - Path Control Delegate Methods
extension CtlPrefWindow: NSPathControlDelegate {
func pathControl(_ pathControl: NSPathControl, acceptDrop info: NSDraggingInfo) -> Bool {
let urls = info.draggingPasteboard.readObjects(forClasses: [NSURL.self])
guard let url = urls?.first as? URL else { return false }
switch pathControl {
case pctCassetteFilePath:
let bolPreviousPathValidity = LMMgr.checkCassettePathValidity(
PrefMgr.shared.cassettePath.expandingTildeInPath)
if LMMgr.checkCassettePathValidity(url.path) {
PrefMgr.shared.cassettePath = url.path
LMMgr.loadCassetteData()
BookmarkManager.shared.saveBookmark(for: url)
pathControl.url = url
return true
}
// On Error:
IMEApp.buzz()
if !bolPreviousPathValidity {
LMMgr.resetCassettePath()
}
return false
case pctUserDictionaryFolder:
let bolPreviousFolderValidity = LMMgr.checkIfSpecifiedUserDataFolderValid(
PrefMgr.shared.userDataFolderSpecified.expandingTildeInPath)
var newPath = url.path
newPath.ensureTrailingSlash()
if LMMgr.checkIfSpecifiedUserDataFolderValid(newPath) {
PrefMgr.shared.userDataFolderSpecified = newPath
BookmarkManager.shared.saveBookmark(for: url)
AppDelegate.shared.updateDirectoryMonitorPath()
pathControl.url = url
return true
}
// On Error:
IMEApp.buzz()
if !bolPreviousFolderValidity {
LMMgr.resetSpecifiedUserDataFolder()
pathControl.url = URL(fileURLWithPath: LMMgr.dataFolderPath(isDefaultFolder: true))
}
return false
default: return false
}
}
}

View File

@ -1,4 +1,6 @@
"vChewing" = "vChewing"; "vChewing" = "vChewing";
"Please drag the desired target from Finder to this place." = "Please drag the desired target from Finder to this place.";
"[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." = "[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.";
"Quick Candidates" = "Quick Candidates"; "Quick Candidates" = "Quick Candidates";
"Alvin Liu (Imitative)" = "Alvin Liu (Imitative)"; "Alvin Liu (Imitative)" = "Alvin Liu (Imitative)";
"Previous intonation has been overridden." = "Previous intonation has been overridden."; "Previous intonation has been overridden." = "Previous intonation has been overridden.";

View File

@ -1,4 +1,6 @@
"vChewing" = "vChewing"; "vChewing" = "vChewing";
"Please drag the desired target from Finder to this place." = "Please drag the desired target from Finder to this place.";
"[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." = "[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.";
"Quick Candidates" = "Quick Candidates"; "Quick Candidates" = "Quick Candidates";
"Alvin Liu (Imitative)" = "Alvin Liu (Imitative)"; "Alvin Liu (Imitative)" = "Alvin Liu (Imitative)";
"Previous intonation has been overridden." = "Previous intonation has been overridden."; "Previous intonation has been overridden." = "Previous intonation has been overridden.";

View File

@ -1,4 +1,8 @@
"vChewing" = "威注音入力アプリ"; "vChewing" = "威注音入力アプリ";
"Please drag the desired target from Finder to this place." = "ご指定したいものは直接に Finder からこの辺にお引
// MARK: - Porting NSPathControl to SwiftUI.
きずりを。";
"[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." = "【技術上の原因説明】macOS 10.12 とそれ以前の macOS には、入力アプリが自ら NSOpenPanel を呼ぶと、入力アプリ自身も、全ての触れ合った客体アプリも、全部固まってしまう状態になります。こうなると、強引的にパソコン再起動や・或いは SSH で他のパソコンからこの入力アプリの強制停止が必要です。従って、弊アプリは macOS 10.12 とその以前の macOS には NSOpenPanel のアクセスの提供はできません。";
"Quick Candidates" = "早速候補"; "Quick Candidates" = "早速候補";
"Alvin Liu (Imitative)" = "劉又銘擬音注音配列"; "Alvin Liu (Imitative)" = "劉又銘擬音注音配列";
"Previous intonation has been overridden." = "後ろ側の漢字の音調を書き直しました。"; "Previous intonation has been overridden." = "後ろ側の漢字の音調を書き直しました。";

View File

@ -1,4 +1,6 @@
"vChewing" = "威注音输入法"; "vChewing" = "威注音输入法";
"Please drag the desired target from Finder to this place." = "请将您想要的目标直接拽到此处。";
"[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." = "【技术原因】macOS 10.13 之前的版本的系统会在输入法自身呼叫 NSOpenPanel 的时候令自身与客体应用陷入无限停止响应的状态。更甚者,此时任何尝试切换到的其他客体应用也会陷入同样的状态。除了强制断电重新开机以外,就只能借由远端 SSH 连到目前的电脑上、以终端命令强行终止输入法执行绪。因此,威注音输入法不能对 macOS 10.12 及之前的系统开放对 NSOpenPanel 的存取。";
"Quick Candidates" = "快速候选"; "Quick Candidates" = "快速候选";
"Alvin Liu (Imitative)" = "刘又铭拟音注音排列"; "Alvin Liu (Imitative)" = "刘又铭拟音注音排列";
"Previous intonation has been overridden." = "已覆写游标身后的汉字的音调。"; "Previous intonation has been overridden." = "已覆写游标身后的汉字的音调。";

View File

@ -1,4 +1,6 @@
"vChewing" = "威注音輸入法"; "vChewing" = "威注音輸入法";
"Please drag the desired target from Finder to this place." = "請將您想要的目標直接拽到此處。";
"[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." = "【技術原因】macOS 10.13 之前的版本的系統會在輸入法自身呼叫 NSOpenPanel 的時候令自身與客體應用陷入無限停止響應的狀態。更甚者,此時任何嘗試切換到的其他客體應用也會陷入同樣的狀態。除了強制斷電重新開機以外,就只能藉由遠端 SSH 連到目前的電腦上、以終端命令強行終止輸入法執行緒。因此,威注音輸入法不能對 macOS 10.12 及之前的系統開放對 NSOpenPanel 的存取。";
"Quick Candidates" = "快速候選"; "Quick Candidates" = "快速候選";
"Alvin Liu (Imitative)" = "劉又銘擬音注音排列"; "Alvin Liu (Imitative)" = "劉又銘擬音注音排列";
"Previous intonation has been overridden." = "已覆寫游標身後的漢字的音調。"; "Previous intonation has been overridden." = "已覆寫游標身後的漢字的音調。";

File diff suppressed because it is too large Load Diff