From 49e8ec749862e5784bce44f9faa7267ada82bc87 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Wed, 10 Aug 2022 14:34:17 +0800 Subject: [PATCH] PrefUI // Move "Selection Keys" setup to Keyboard page. --- Source/UI/PrefUI/suiPrefPaneExperience.swift | 32 +------------------- Source/UI/PrefUI/suiPrefPaneKeyboard.swift | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/Source/UI/PrefUI/suiPrefPaneExperience.swift b/Source/UI/PrefUI/suiPrefPaneExperience.swift index a95c7b57..1c734b10 100644 --- a/Source/UI/PrefUI/suiPrefPaneExperience.swift +++ b/Source/UI/PrefUI/suiPrefPaneExperience.swift @@ -11,9 +11,7 @@ import SwiftUI @available(macOS 11.0, *) 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 = UserDefaults.standard.bool( forKey: UserDef.kUseRearCursorMode.rawValue) ? 1 : 0 @@ -54,34 +52,6 @@ struct suiPrefPaneExperience: View { var body: some View { 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:")) }) { Picker("", selection: $selCursorPosition) { Text(LocalizedStringKey("in front of the phrase (like macOS built-in Zhuyin IME)")).tag(0) diff --git a/Source/UI/PrefUI/suiPrefPaneKeyboard.swift b/Source/UI/PrefUI/suiPrefPaneKeyboard.swift index d3b6e4e9..190a71a7 100644 --- a/Source/UI/PrefUI/suiPrefPaneKeyboard.swift +++ b/Source/UI/PrefUI/suiPrefPaneKeyboard.swift @@ -10,6 +10,9 @@ import SwiftUI @available(macOS 11.0, *) 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 selBasicKeyboardLayout: String = UserDefaults.standard.string(forKey: UserDef.kBasicKeyboardLayout.rawValue) ?? mgrPrefs.basicKeyboardLayout @@ -40,6 +43,34 @@ struct suiPrefPaneKeyboard: View { var body: some View { 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:")) }) { HStack { Picker("", selection: $selMandarinParser) {