PrefUI // Move "Selection Keys" setup to Keyboard page.

This commit is contained in:
ShikiSuen 2022-08-10 14:34:17 +08:00
parent 4e85c7b873
commit d1c0a77587
2 changed files with 32 additions and 31 deletions

View File

@ -11,9 +11,7 @@ import SwiftUI
@available(macOS 11.0, *) @available(macOS 11.0, *)
struct suiPrefPaneExperience: View { struct suiPrefPaneExperience: View {
@State private var selSelectionKeysList = mgrPrefs.suggestedCandidateKeys
@State private var selSelectionKeys =
(UserDefaults.standard.string(forKey: UserDef.kCandidateKeys.rawValue) ?? mgrPrefs.defaultCandidateKeys) as String
@State private var selCursorPosition = @State private var selCursorPosition =
UserDefaults.standard.bool( UserDefaults.standard.bool(
forKey: UserDef.kUseRearCursorMode.rawValue) ? 1 : 0 forKey: UserDef.kUseRearCursorMode.rawValue) ? 1 : 0
@ -54,34 +52,6 @@ struct suiPrefPaneExperience: View {
var body: some View { var body: some View {
Preferences.Container(contentWidth: contentWidth) { Preferences.Container(contentWidth: contentWidth) {
Preferences.Section(label: { Text(LocalizedStringKey("Selection Keys:")) }) {
ComboBox(items: mgrPrefs.suggestedCandidateKeys, text: $selSelectionKeys).frame(width: 180).onChange(
of: selSelectionKeys
) { value in
let keys: String = value.trimmingCharacters(in: .whitespacesAndNewlines).deduplicate
do {
try mgrPrefs.validate(candidateKeys: keys)
mgrPrefs.candidateKeys = keys
selSelectionKeys = mgrPrefs.candidateKeys
} catch mgrPrefs.CandidateKeyError.empty {
selSelectionKeys = mgrPrefs.candidateKeys
} catch {
if let window = ctlPrefUI.shared.controller.window {
let alert = NSAlert(error: error)
alert.beginSheetModal(for: window) { _ in
selSelectionKeys = mgrPrefs.candidateKeys
}
clsSFX.beep()
}
}
}
Text(
LocalizedStringKey(
"Choose or hit Enter to confim your prefered keys for selecting candidates."
)
)
.preferenceDescription()
}
Preferences.Section(label: { Text(LocalizedStringKey("Cursor Selection:")) }) { Preferences.Section(label: { Text(LocalizedStringKey("Cursor Selection:")) }) {
Picker("", selection: $selCursorPosition) { Picker("", selection: $selCursorPosition) {
Text(LocalizedStringKey("in front of the phrase (like macOS built-in Zhuyin IME)")).tag(0) Text(LocalizedStringKey("in front of the phrase (like macOS built-in Zhuyin IME)")).tag(0)

View File

@ -10,6 +10,9 @@ import SwiftUI
@available(macOS 11.0, *) @available(macOS 11.0, *)
struct suiPrefPaneKeyboard: View { struct suiPrefPaneKeyboard: View {
@State private var selSelectionKeysList = mgrPrefs.suggestedCandidateKeys
@State private var selSelectionKeys =
UserDefaults.standard.string(forKey: UserDef.kCandidateKeys.rawValue) ?? mgrPrefs.defaultCandidateKeys
@State private var selMandarinParser = UserDefaults.standard.integer(forKey: UserDef.kMandarinParser.rawValue) @State private var selMandarinParser = UserDefaults.standard.integer(forKey: UserDef.kMandarinParser.rawValue)
@State private var selBasicKeyboardLayout: String = @State private var selBasicKeyboardLayout: String =
UserDefaults.standard.string(forKey: UserDef.kBasicKeyboardLayout.rawValue) ?? mgrPrefs.basicKeyboardLayout UserDefaults.standard.string(forKey: UserDef.kBasicKeyboardLayout.rawValue) ?? mgrPrefs.basicKeyboardLayout
@ -40,6 +43,34 @@ struct suiPrefPaneKeyboard: View {
var body: some View { var body: some View {
Preferences.Container(contentWidth: contentWidth) { Preferences.Container(contentWidth: contentWidth) {
Preferences.Section(label: { Text(LocalizedStringKey("Selection Keys:")) }) {
ComboBox(items: mgrPrefs.suggestedCandidateKeys, text: $selSelectionKeys).frame(width: 180).onChange(
of: selSelectionKeys
) { value in
let keys: String = value.trimmingCharacters(in: .whitespacesAndNewlines).deduplicate
do {
try mgrPrefs.validate(candidateKeys: keys)
mgrPrefs.candidateKeys = keys
selSelectionKeys = mgrPrefs.candidateKeys
} catch mgrPrefs.CandidateKeyError.empty {
selSelectionKeys = mgrPrefs.candidateKeys
} catch {
if let window = ctlPrefUI.shared.controller.window {
let alert = NSAlert(error: error)
alert.beginSheetModal(for: window) { _ in
selSelectionKeys = mgrPrefs.candidateKeys
}
clsSFX.beep()
}
}
}
Text(
LocalizedStringKey(
"Choose or hit Enter to confim your prefered keys for selecting candidates."
)
)
.preferenceDescription()
}
Preferences.Section(label: { Text(LocalizedStringKey("Phonetic Parser:")) }) { Preferences.Section(label: { Text(LocalizedStringKey("Phonetic Parser:")) }) {
HStack { HStack {
Picker("", selection: $selMandarinParser) { Picker("", selection: $selMandarinParser) {