From 5f078d7c400c8c1eceb9eb1c8679eddb0a79b29c Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Wed, 18 May 2022 16:54:04 +0800 Subject: [PATCH] PrefUI_Keyboard // Add reset buttons and mistake-proofing. --- .../zh-Hans.lproj/Localizable.strings | 2 - Source/UI/PrefUI/suiPrefPaneKeyboard.swift | 76 ++++++++++++++----- 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/Source/Resources/zh-Hans.lproj/Localizable.strings b/Source/Resources/zh-Hans.lproj/Localizable.strings index 8928773e..ab0f3f6a 100644 --- a/Source/Resources/zh-Hans.lproj/Localizable.strings +++ b/Source/Resources/zh-Hans.lproj/Localizable.strings @@ -138,7 +138,6 @@ "Phonetic Parser:" = "注音排列:"; "Push the cursor in front of the phrase after selection" = "在选字后将游标置于该字词的前方"; "Secondary Pinyin with Numeral Intonation" = "国音二式+数字标调"; -"Secondary Pinyin with Numeral Intonation" = "國音二式+数字标调"; "Selection Keys:" = "选字键:"; "Show Hanyu-Pinyin in the inline composition buffer" = "拼音并击模式(组字区内看到的是汉语拼音)"; "Show page buttons in candidate window" = "在选字窗内显示翻页按钮"; @@ -155,4 +154,3 @@ "Use ESC key to clear the entire input buffer" = "敲 ESC 键以清空整个组字缓冲区"; "Vertical" = "纵向布局"; "Yale Pinyin with Numeral Intonation" = "耶鲁拼音+数字标调"; -"Yale Pinyin with Numeral Intonation" = "耶魯拼音+数字标调"; diff --git a/Source/UI/PrefUI/suiPrefPaneKeyboard.swift b/Source/UI/PrefUI/suiPrefPaneKeyboard.swift index 15e7e66f..edeed2b8 100644 --- a/Source/UI/PrefUI/suiPrefPaneKeyboard.swift +++ b/Source/UI/PrefUI/suiPrefPaneKeyboard.swift @@ -45,30 +45,60 @@ struct suiPrefPaneKeyboard: View { var body: some View { Preferences.Container(contentWidth: contentWidth) { Preferences.Section(label: { Text(LocalizedStringKey("Phonetic Parser:")) }) { - Picker("", selection: $selMandarinParser) { - Group { - Text(LocalizedStringKey("Dachen (Microsoft Standard / Wang / 01, etc.)")).tag(0) - Text(LocalizedStringKey("Dachen 26 (libChewing)")).tag(7) - Text(LocalizedStringKey("Eten Traditional")).tag(1) - Text(LocalizedStringKey("Eten 26")).tag(3) - Text(LocalizedStringKey("IBM")).tag(4) - Text(LocalizedStringKey("Hsu")).tag(2) - Text(LocalizedStringKey("MiTAC")).tag(5) - Text(LocalizedStringKey("Fake Seigyou")).tag(6) + HStack { + Picker("", selection: $selMandarinParser) { + Group { + Text(LocalizedStringKey("Dachen (Microsoft Standard / Wang / 01, etc.)")).tag(0) + Text(LocalizedStringKey("Dachen 26 (libChewing)")).tag(7) + Text(LocalizedStringKey("Eten Traditional")).tag(1) + Text(LocalizedStringKey("Eten 26")).tag(3) + Text(LocalizedStringKey("IBM")).tag(4) + Text(LocalizedStringKey("Hsu")).tag(2) + Text(LocalizedStringKey("MiTAC")).tag(5) + Text(LocalizedStringKey("Fake Seigyou")).tag(6) + } + Divider() + Group { + Text(LocalizedStringKey("Hanyu Pinyin with Numeral Intonation")).tag(10) + Text(LocalizedStringKey("Secondary Pinyin with Numeral Intonation")).tag(11) + Text(LocalizedStringKey("Yale Pinyin with Numeral Intonation")).tag(12) + Text(LocalizedStringKey("Hualuo Pinyin with Numeral Intonation")).tag(13) + Text(LocalizedStringKey("Universal Pinyin with Numeral Intonation")).tag(14) + } + }.onChange(of: selMandarinParser) { value in + mgrPrefs.mandarinParser = value + switch value { + case 0: + if !AppleKeyboardConverter.arrDynamicBasicKeyLayout.contains(mgrPrefs.basicKeyboardLayout) { + mgrPrefs.basicKeyboardLayout = "com.apple.keylayout.ZhuyinBopomofo" + selBasicKeyboardLayout = mgrPrefs.basicKeyboardLayout + } + default: + if AppleKeyboardConverter.arrDynamicBasicKeyLayout.contains(mgrPrefs.basicKeyboardLayout) { + mgrPrefs.basicKeyboardLayout = "com.apple.keylayout.ABC" + selBasicKeyboardLayout = mgrPrefs.basicKeyboardLayout + } + } } - Divider() - Group { - Text(LocalizedStringKey("Hanyu Pinyin with Numeral Intonation")).tag(10) - Text(LocalizedStringKey("Secondary Pinyin with Numeral Intonation")).tag(11) - Text(LocalizedStringKey("Yale Pinyin with Numeral Intonation")).tag(12) - Text(LocalizedStringKey("Hualuo Pinyin with Numeral Intonation")).tag(13) - Text(LocalizedStringKey("Universal Pinyin with Numeral Intonation")).tag(14) + .labelsHidden() + Button { + mgrPrefs.mandarinParser = 0 + selMandarinParser = mgrPrefs.mandarinParser + mgrPrefs.basicKeyboardLayout = "com.apple.keylayout.ZhuyinBopomofo" + selBasicKeyboardLayout = mgrPrefs.basicKeyboardLayout + } label: { + Text("↻ㄅ") + } + Button { + mgrPrefs.mandarinParser = 10 + selMandarinParser = mgrPrefs.mandarinParser + mgrPrefs.basicKeyboardLayout = "com.apple.keylayout.ABC" + selBasicKeyboardLayout = mgrPrefs.basicKeyboardLayout + } label: { + Text("↻A") } - }.onChange(of: selMandarinParser) { value in - mgrPrefs.mandarinParser = value } - .labelsHidden() - .frame(width: 320.0) + .frame(width: 380.0) Text(LocalizedStringKey("Choose the phonetic layout for Mandarin parser.")) .preferenceDescription() } @@ -81,6 +111,10 @@ struct suiPrefPaneKeyboard: View { }.id(UUID()) }.onChange(of: selBasicKeyboardLayout) { value in mgrPrefs.basicKeyboardLayout = value + if AppleKeyboardConverter.arrDynamicBasicKeyLayout.contains(value) { + mgrPrefs.mandarinParser = 0 + selMandarinParser = mgrPrefs.mandarinParser + } } .labelsHidden() .frame(width: 240.0)