diff --git a/Source/Modules/UIModules/PrefUI/CtlPrefUIShared.swift b/Source/Modules/UIModules/PrefUI/CtlPrefUIShared.swift index 729b3611..c3f2ad07 100644 --- a/Source/Modules/UIModules/PrefUI/CtlPrefUIShared.swift +++ b/Source/Modules/UIModules/PrefUI/CtlPrefUIShared.swift @@ -86,6 +86,19 @@ class CtlPrefUIShared { } }() + static let formWidth: Double = { + switch PrefMgr.shared.appleLanguages[0] { + case "ja": + return 520 + default: + if PrefMgr.shared.appleLanguages[0].contains("zh-Han") { + return 500 + } else { + return 580 + } + } + }() + static var isCJKInterface: Bool { PrefMgr.shared.appleLanguages[0].contains("zh-Han") || PrefMgr.shared.appleLanguages[0] == "ja" } @@ -93,3 +106,21 @@ class CtlPrefUIShared { static var containerWidth: Double { contentWidth + 60 } static var maxDescriptionWidth: Double { contentWidth * 0.8 } } + +@available(macOS 10.15, *) +public extension View { + func settingsDescription(maxWidth: CGFloat? = .infinity) -> some View { + controlSize(.small) + .frame(maxWidth: maxWidth, alignment: .leading) + // TODO: Use `.foregroundStyle` when targeting macOS 12. + .foregroundColor(.secondary) + } +} + +@available(macOS 10.15, *) +public extension View { + func formStyled() -> some View { + if #available(macOS 13, *) { return self.formStyle(.grouped) } + return self.padding() + } +} diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneBehavior.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneBehavior.swift index 6b36bb0a..643ad0e5 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneBehavior.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneBehavior.swift @@ -73,178 +73,186 @@ struct VwrPrefPaneBehavior: View { var body: some View { ScrollView { - SSPreferences.Settings.Container(contentWidth: CtlPrefUIShared.contentWidth) { - SSPreferences.Settings.Section(title: "Space:".localized, bottomDivider: true) { - Toggle( - LocalizedStringKey("Enable Space key for calling candidate window"), - isOn: $chooseCandidateUsingSpace - ) - Text( - LocalizedStringKey( - "If disabled, this will insert space instead." + Form { + Section { + VStack(alignment: .leading) { + Toggle( + LocalizedStringKey("Enable Space key for calling candidate window"), + isOn: $chooseCandidateUsingSpace ) - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - } - SSPreferences.Settings.Section(title: "ESC:".localized, bottomDivider: true) { - Toggle( - LocalizedStringKey("Use ESC key to clear the entire input buffer"), - isOn: $escToCleanInputBuffer - ) - Text( - LocalizedStringKey( - "If unchecked, the ESC key will try cleaning the unfinished readings / strokes first, and will commit the current composition buffer if there's no unfinished readings / strokes." + Text( + LocalizedStringKey( + "If disabled, this will insert space instead." + ) ) - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - } - SSPreferences.Settings.Section(title: "Enter:".localized, bottomDivider: true) { - Toggle( - LocalizedStringKey("Allow using Enter key to confirm associated candidate selection"), - isOn: $alsoConfirmAssociatedCandidatesByEnter - ) - Text( - LocalizedStringKey( - "Otherwise, only the candidate keys are allowed to confirm associates." + .settingsDescription() + } + + VStack(alignment: .leading) { + Toggle( + LocalizedStringKey("Use ESC key to clear the entire input buffer"), + isOn: $escToCleanInputBuffer ) - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - } - SSPreferences.Settings.Section(title: "Shift+BackSpace:".localized, bottomDivider: true) { - Picker( - "", - selection: $specifyShiftBackSpaceKeyBehavior - ) { - Text(LocalizedStringKey("Disassemble the previous reading, dropping its intonation")).tag(0) - Text(LocalizedStringKey("Clear the entire inline composition buffer like Shift+Delete")).tag(1) - Text(LocalizedStringKey("Always drop the previous reading")).tag(2) + Text( + LocalizedStringKey( + "If unchecked, the ESC key will try cleaning the unfinished readings / strokes first, and will commit the current composition buffer if there's no unfinished readings / strokes." + ) + ) + .settingsDescription() } - .labelsHidden() - .pickerStyle(RadioGroupPickerStyle()) - Text(LocalizedStringKey("Disassembling process does not work with non-phonetic reading keys.")) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - } - SSPreferences.Settings.Section(title: "(Shift+)Tab:", bottomDivider: true) { - Picker( - "", - selection: $specifyShiftTabKeyBehavior - ) { - Text(LocalizedStringKey("for revolving candidates")).tag(false) - Text(LocalizedStringKey("for revolving pages")).tag(true) + VStack(alignment: .leading) { + Toggle( + LocalizedStringKey("Allow using Enter key to confirm associated candidate selection"), + isOn: $alsoConfirmAssociatedCandidatesByEnter + ) + Text( + LocalizedStringKey( + "Otherwise, only the candidate keys are allowed to confirm associates." + ) + ) + .settingsDescription() } - .labelsHidden() - .horizontalRadioGroupLayout() - .pickerStyle(RadioGroupPickerStyle()) - Text(LocalizedStringKey("Choose the behavior of (Shift+)Tab key in the candidate window.")) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - } - SSPreferences.Settings.Section(title: "(Shift+)Space:".localized, bottomDivider: true) { - Picker( - "", - selection: $specifyShiftSpaceKeyBehavior - ) { - Text(LocalizedStringKey("Space to +revolve candidates, Shift+Space to +revolve pages")).tag(false) - Text(LocalizedStringKey("Space to +revolve pages, Shift+Space to +revolve candidates")).tag(true) - } - .labelsHidden() - .pickerStyle(RadioGroupPickerStyle()) - Text(LocalizedStringKey("Choose the behavior of (Shift+)Space key with candidates.")) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - Toggle( - LocalizedStringKey("Use Space to confirm highlighted candidate in Per-Char Select Mode"), - isOn: $useSpaceToCommitHighlightedSCPCCandidate - ).controlSize(.small) - } - SSPreferences.Settings.Section(title: "Shift+Letter:".localized, bottomDivider: true) { - Picker( - "", - selection: $upperCaseLetterKeyBehavior - ) { - Text(LocalizedStringKey("Type them into inline composition buffer")).tag(0) - Text(LocalizedStringKey("Always directly commit lowercased letters")).tag(1) - Text(LocalizedStringKey("Always directly commit uppercased letters")).tag(2) - Text(LocalizedStringKey("Directly commit lowercased letters only if the compositor is empty")).tag(3) - Text(LocalizedStringKey("Directly commit uppercased letters only if the compositor is empty")).tag(4) - } - .labelsHidden() - .pickerStyle(RadioGroupPickerStyle()) - Text(LocalizedStringKey("Choose the behavior of Shift+Letter key with letter inputs.")) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - } - SSPreferences.Settings.Section(title: "Intonation Key:".localized, bottomDivider: true) { - Picker( - "", - selection: $specifyIntonationKeyBehavior - ) { - Text(LocalizedStringKey("Override the previous reading's intonation with candidate-reset")).tag(0) - Text(LocalizedStringKey("Only override the intonation of the previous reading if different")).tag(1) - Text(LocalizedStringKey("Always type intonations to the inline composition buffer")).tag(2) - } - .labelsHidden() - .pickerStyle(RadioGroupPickerStyle()) - Text(LocalizedStringKey("Specify the behavior of intonation key when syllable composer is empty.")) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - Toggle( - LocalizedStringKey("Accept leading intonations in rare cases"), - isOn: $acceptLeadingIntonations - ).controlSize(.small) - Text(LocalizedStringKey("This feature accommodates certain typing mistakes that the intonation mark might be typed at first (which is sequentially wrong from a common sense that intonation marks are supposed to be used for confirming combinations). It won't work if the current parser is of (any) pinyin. Also, this feature won't work when an intonation override is possible (and enabled).")) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - } - SSPreferences.Settings.Section(title: "Shift:", bottomDivider: true) { - Toggle( - LocalizedStringKey("Toggle alphanumerical mode with Left-Shift"), - isOn: $togglingAlphanumericalModeWithLShift.onChange { - SessionCtl.theShiftKeyDetector.toggleWithLShift = togglingAlphanumericalModeWithLShift + VStack(alignment: .leading) { + Picker( + "Shift+BackSpace:", + selection: $specifyShiftBackSpaceKeyBehavior + ) { + Text(LocalizedStringKey("Disassemble the previous reading, dropping its intonation")).tag(0) + Text(LocalizedStringKey("Clear the entire inline composition buffer like Shift+Delete")).tag(1) + Text(LocalizedStringKey("Always drop the previous reading")).tag(2) } - ) - Toggle( - LocalizedStringKey("Toggle alphanumerical mode with Right-Shift"), - isOn: $togglingAlphanumericalModeWithRShift.onChange { - SessionCtl.theShiftKeyDetector.toggleWithRShift = togglingAlphanumericalModeWithRShift + Text(LocalizedStringKey("Disassembling process does not work with non-phonetic reading keys.")) + .settingsDescription() + } + VStack(alignment: .leading) { + Picker( + "(Shift+)Tab:", + selection: $specifyShiftTabKeyBehavior + ) { + Text(LocalizedStringKey("for revolving candidates")).tag(false) + Text(LocalizedStringKey("for revolving pages")).tag(true) } - ) - Text( - "This feature requires macOS 10.15 and above.".localized + CtlPrefUIShared.sentenceSeparator - + "This feature only needs to parse consecutive NSEvents passed by macOS built-in InputMethodKit framework, hence no necessity of asking end-users for extra privileges of monitoring global keyboard inputs. You are free to investigate our codebase or reverse-engineer this input method to see whether the above statement is trustable.".localized - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - Toggle( - LocalizedStringKey("Share alphanumerical mode status across all clients"), - isOn: $shareAlphanumericalModeStatusAcrossClients - ).controlSize(.small) - Text( - "This only works when being toggled by Shift key and JIS Eisu key.".localized - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) + .pickerStyle(RadioGroupPickerStyle()) + Text(LocalizedStringKey("Choose the behavior of (Shift+)Tab key in the candidate window.")) + .settingsDescription() + } + VStack(alignment: .leading) { + Picker( + "(Shift+)Space:", + selection: $specifyShiftSpaceKeyBehavior + ) { + Text(LocalizedStringKey("Space to +revolve candidates, Shift+Space to +revolve pages")).tag(false) + Text(LocalizedStringKey("Space to +revolve pages, Shift+Space to +revolve candidates")).tag(true) + } + Spacer() + Text(LocalizedStringKey("Choose the behavior of (Shift+)Space key with candidates.")) + .settingsDescription() + Toggle( + LocalizedStringKey("Use Space to confirm highlighted candidate in Per-Char Select Mode"), + isOn: $useSpaceToCommitHighlightedSCPCCandidate + ) + } } - SSPreferences.Settings.Section(title: "Caps Lock:", bottomDivider: true) { - Toggle( - LocalizedStringKey("Show notifications when toggling Caps Lock"), - isOn: $showNotificationsWhenTogglingCapsLock.onChange { - if !macOSMontereyOrLaterDetected, showNotificationsWhenTogglingCapsLock { - showNotificationsWhenTogglingCapsLock.toggle() + Section { + VStack(alignment: .leading) { + Picker( + "Shift+Letter:", + selection: $upperCaseLetterKeyBehavior + ) { + Text(LocalizedStringKey("Type them into inline composition buffer")).tag(0) + Text(LocalizedStringKey("Always directly commit lowercased letters")).tag(1) + Text(LocalizedStringKey("Always directly commit uppercased letters")).tag(2) + Text(LocalizedStringKey("Directly commit lowercased letters only if the compositor is empty")).tag(3) + Text(LocalizedStringKey("Directly commit uppercased letters only if the compositor is empty")).tag(4) + } + Text(LocalizedStringKey("Choose the behavior of Shift+Letter key with letter inputs.")) + .settingsDescription() + } + } + Section { + VStack(alignment: .leading) { + Picker( + "Intonation Key:", + selection: $specifyIntonationKeyBehavior + ) { + Text(LocalizedStringKey("Override the previous reading's intonation with candidate-reset")).tag(0) + Text(LocalizedStringKey("Only override the intonation of the previous reading if different")).tag(1) + Text(LocalizedStringKey("Always type intonations to the inline composition buffer")).tag(2) + } + Text(LocalizedStringKey("Specify the behavior of intonation key when syllable composer is empty.")) + .settingsDescription() + } + VStack(alignment: .leading) { + Toggle( + LocalizedStringKey("Accept leading intonations in rare cases"), + isOn: $acceptLeadingIntonations + ) + Spacer() + Text(LocalizedStringKey("This feature accommodates certain typing mistakes that the intonation mark might be typed at first (which is sequentially wrong from a common sense that intonation marks are supposed to be used for confirming combinations). It won't work if the current parser is of (any) pinyin. Also, this feature won't work when an intonation override is possible (and enabled).")) + .settingsDescription() + } + } + Section { + VStack(alignment: .leading) { + Toggle( + LocalizedStringKey("Share alphanumerical mode status across all clients"), + isOn: $shareAlphanumericalModeStatusAcrossClients + ) + Text( + "This only works when being toggled by Shift key and JIS Eisu key.".localized + ) + .settingsDescription() + } + VStack(alignment: .leading) { + Toggle( + LocalizedStringKey("Toggle alphanumerical mode with Left-Shift"), + isOn: $togglingAlphanumericalModeWithLShift.onChange { + SessionCtl.theShiftKeyDetector.toggleWithLShift = togglingAlphanumericalModeWithLShift } - } - ).disabled(!macOSMontereyOrLaterDetected) - Text( - "This feature requires macOS 12 and above.".localized - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - } - SSPreferences.Settings.Section(title: "Misc Settings:".localized) { - Toggle( - LocalizedStringKey("Always show tooltip texts horizontally"), - isOn: $alwaysShowTooltipTextsHorizontally - ).disabled(Bundle.main.preferredLocalizations[0] == "en") - Text( - LocalizedStringKey( - "Key names in tooltip will be shown as symbols when the tooltip is vertical. However, this option will be ignored since tooltip will always be horizontal if the UI language is English." ) - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) + Toggle( + LocalizedStringKey("Toggle alphanumerical mode with Right-Shift"), + isOn: $togglingAlphanumericalModeWithRShift.onChange { + SessionCtl.theShiftKeyDetector.toggleWithRShift = togglingAlphanumericalModeWithRShift + } + ) + Spacer() + Text( + "This feature requires macOS 10.15 and above.".localized + CtlPrefUIShared.sentenceSeparator + + "This feature only needs to parse consecutive NSEvents passed by macOS built-in InputMethodKit framework, hence no necessity of asking end-users for extra privileges of monitoring global keyboard inputs. You are free to investigate our codebase or reverse-engineer this input method to see whether the above statement is trustable.".localized + ) + .settingsDescription() + } } - } + Section { + VStack(alignment: .leading) { + Toggle( + LocalizedStringKey("Show notifications when toggling Caps Lock"), + isOn: $showNotificationsWhenTogglingCapsLock.onChange { + if !macOSMontereyOrLaterDetected, showNotificationsWhenTogglingCapsLock { + showNotificationsWhenTogglingCapsLock.toggle() + } + } + ).disabled(!macOSMontereyOrLaterDetected) + Text( + "This feature requires macOS 12 and above.".localized + ) + .settingsDescription() + } + VStack(alignment: .leading) { + Toggle( + LocalizedStringKey("Always show tooltip texts horizontally"), + isOn: $alwaysShowTooltipTextsHorizontally + ).disabled(Bundle.main.preferredLocalizations[0] == "en") + Text( + LocalizedStringKey( + "Key names in tooltip will be shown as symbols when the tooltip is vertical. However, this option will be ignored since tooltip will always be horizontal if the UI language is English." + ) + ) + .settingsDescription() + } + } + }.formStyled().frame(width: CtlPrefUIShared.formWidth) } .frame(maxHeight: CtlPrefUIShared.contentMaxHeight) } diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneCandidates.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneCandidates.swift index 227ad45c..520a027a 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneCandidates.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneCandidates.swift @@ -54,141 +54,144 @@ struct VwrPrefPaneCandidates: View { var body: some View { ScrollView { - SSPreferences.Settings.Container(contentWidth: CtlPrefUIShared.contentWidth) { - SSPreferences.Settings.Section(title: "Selection Keys:".localized, bottomDivider: true) { - VwrPrefPaneCandidates_SelectionKeys() - } - SSPreferences.Settings.Section(title: "Candidate Layout:".localized, bottomDivider: true) { - Picker( - "", - selection: $useHorizontalCandidateList - ) { - Text(LocalizedStringKey("Vertical")).tag(false) - Text(LocalizedStringKey("Horizontal")).tag(true) + Form { + Section { + VStack(alignment: .leading) { + Picker( + "Cursor Selection:", + selection: $useRearCursorMode + ) { + Text(LocalizedStringKey("in front of the phrase (like macOS built-in Zhuyin IME)")).tag(false) + Text(LocalizedStringKey("at the rear of the phrase (like Microsoft New Phonetic)")).tag(true) + } + Text(LocalizedStringKey("Choose the cursor position where you want to list possible candidates.")) + .settingsDescription() } - .labelsHidden() - .horizontalRadioGroupLayout() - .pickerStyle(RadioGroupPickerStyle()) - Text(LocalizedStringKey("Choose your preferred layout of the candidate window.")) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - let candidateLayoutSubOptions = Group { + Toggle( + LocalizedStringKey("Push the cursor in front of the phrase after selection"), + isOn: $moveCursorAfterSelectingCandidate + ) + if !useRearCursorMode { + Toggle( + LocalizedStringKey("Adjust candidate window location according to current node length"), + isOn: $useDynamicCandidateWindowOrigin + ).disabled(useRearCursorMode) + } + } + Section { + VStack(alignment: .leading) { VwrPrefPaneCandidates_SelectionKeys() } + VStack(alignment: .leading) { + Picker( + "Candidate Layout:", + selection: $useHorizontalCandidateList + ) { + Text(LocalizedStringKey("Vertical")).tag(false) + Text(LocalizedStringKey("Horizontal")).tag(true) + } + .pickerStyle(RadioGroupPickerStyle()) + Text(LocalizedStringKey("Choose your preferred layout of the candidate window.")) + .settingsDescription() + } + VStack(alignment: .leading) { + Picker( + "Candidate Size:", + selection: $candidateListTextSize.onChange { + guard !(12 ... 196).contains(candidateListTextSize) else { return } + candidateListTextSize = max(12, min(candidateListTextSize, 196)) + } + ) { + Group { + Text("12").tag(12.0) + Text("14").tag(14.0) + Text("16").tag(16.0) + Text("17").tag(17.0) + Text("18").tag(18.0) + Text("20").tag(20.0) + Text("22").tag(22.0) + Text("24").tag(24.0) + } + Group { + Text("32").tag(32.0) + Text("64").tag(64.0) + Text("96").tag(96.0) + } + } + Text(LocalizedStringKey("Choose candidate font size for better visual clarity.")) + .settingsDescription() + } + VStack(alignment: .leading) { Toggle( LocalizedStringKey("Use only one row / column in candidate window"), isOn: $candidateWindowShowOnlyOneLine ) - .controlSize(.small) + Text( + "Tadokoro candidate window shows 4 rows / columns by default, providing similar experiences from Microsoft New Phonetic IME and macOS bult-in Chinese IME (since macOS 10.9). However, for some users who have presbyopia, they prefer giant candidate font sizes, resulting a concern that multiple rows / columns of candidates can make the candidate window looks too big, hence this option. Note that this option will be dismissed if the typing context is vertical, forcing the candidates to be shown in only one row / column. Only one reverse-lookup result can be made available in single row / column mode due to reduced candidate window size.".localized + ) + .settingsDescription() + } + if !candidateWindowShowOnlyOneLine { Toggle( LocalizedStringKey("Always expand candidate window panel"), isOn: $alwaysExpandCandidateWindow ) - .controlSize(.small).disabled(candidateWindowShowOnlyOneLine) + .disabled(candidateWindowShowOnlyOneLine) } - if CtlPrefUIShared.isCJKInterface { - HStack { - candidateLayoutSubOptions - } - } else { - VStack(alignment: .leading) { - candidateLayoutSubOptions - } - } - Text( - "Tadokoro candidate window shows 4 rows / columns by default, providing similar experiences from Microsoft New Phonetic IME and macOS bult-in Chinese IME (since macOS 10.9). However, for some users who have presbyopia, they prefer giant candidate font sizes, resulting a concern that multiple rows / columns of candidates can make the candidate window looks too big, hence this option. Note that this option will be dismissed if the typing context is vertical, forcing the candidates to be shown in only one row / column. Only one reverse-lookup result can be made available in single row / column mode due to reduced candidate window size.".localized - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) } - SSPreferences.Settings.Section(title: "Candidate Size:".localized, bottomDivider: true) { - Picker( - "", - selection: $candidateListTextSize.onChange { - guard !(12 ... 196).contains(candidateListTextSize) else { return } - candidateListTextSize = max(12, min(candidateListTextSize, 196)) - } - ) { - Group { - Text("12").tag(12.0) - Text("14").tag(14.0) - Text("16").tag(16.0) - Text("17").tag(17.0) - Text("18").tag(18.0) - Text("20").tag(20.0) - Text("22").tag(22.0) - Text("24").tag(24.0) - } - Group { - Text("32").tag(32.0) - Text("64").tag(64.0) - Text("96").tag(96.0) - } - } - .labelsHidden() - .frame(width: 120.0) - Text(LocalizedStringKey("Choose candidate font size for better visual clarity.")) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - } - SSPreferences.Settings.Section(title: "Cursor Selection:".localized, bottomDivider: true) { - Picker( - "", - selection: $useRearCursorMode - ) { - Text(LocalizedStringKey("in front of the phrase (like macOS built-in Zhuyin IME)")).tag(false) - Text(LocalizedStringKey("at the rear of the phrase (like Microsoft New Phonetic)")).tag(true) - } - .labelsHidden() - .pickerStyle(RadioGroupPickerStyle()) - Text(LocalizedStringKey("Choose the cursor position where you want to list possible candidates.")) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - Toggle( - LocalizedStringKey("Push the cursor in front of the phrase after selection"), - isOn: $moveCursorAfterSelectingCandidate - ).controlSize(.small) - Toggle( - LocalizedStringKey("Adjust candidate window location according to current node length"), - isOn: $useDynamicCandidateWindowOrigin - ).controlSize(.small).disabled(useRearCursorMode) - } - SSPreferences.Settings.Section(title: "Misc Settings:".localized, bottomDivider: true) { - Toggle( - LocalizedStringKey("Show available reverse-lookup results in candidate window"), - isOn: $showReverseLookupInCandidateUI - ) - Text( - "The lookup results are supplied by the CIN cassette module.".localized - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - Toggle( - LocalizedStringKey("Always use fixed listing order in candidate window"), - isOn: $useFixedCandidateOrderOnSelection - ) - Text( - LocalizedStringKey( - "This will stop user override model from affecting how candidates get sorted." + + // MARK: (header: Text("Misc Settings:")) + + Section { + VStack(alignment: .leading) { + Toggle( + LocalizedStringKey("Show available reverse-lookup results in candidate window"), + isOn: $showReverseLookupInCandidateUI ) - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - Toggle( - LocalizedStringKey("Consolidate the context on confirming candidate selection"), - isOn: $consolidateContextOnCandidateSelection - ) - Text( - "For example: When typing “章太炎” and you want to override the “太” with “泰”, and the raw operation index range [1,2) which bounds are cutting the current node “章太炎” in range [0,3). If having lack of the pre-consolidation process, this word will become something like “張泰言” after the candidate selection. Only if we enable this consolidation, this word will become “章泰炎” which is the expected result that the context is kept as-is.".localized - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) + Text( + "The lookup results are supplied by the CIN cassette module.".localized + ) + .settingsDescription() + } + VStack(alignment: .leading) { + Toggle( + LocalizedStringKey("Always use fixed listing order in candidate window"), + isOn: $useFixedCandidateOrderOnSelection + ) + Text( + LocalizedStringKey( + "This will stop user override model from affecting how candidates get sorted." + ) + ) + .settingsDescription() + } + VStack(alignment: .leading) { + Toggle( + LocalizedStringKey("Consolidate the context on confirming candidate selection"), + isOn: $consolidateContextOnCandidateSelection + ) + Text( + "For example: When typing “章太炎” and you want to override the “太” with “泰”, and the raw operation index range [1,2) which bounds are cutting the current node “章太炎” in range [0,3). If having lack of the pre-consolidation process, this word will become something like “張泰言” after the candidate selection. Only if we enable this consolidation, this word will become “章泰炎” which is the expected result that the context is kept as-is.".localized + ) + .settingsDescription() + } } - SSPreferences.Settings.Section(title: "Experimental:".localized) { + + // MARK: (header: Text("Experimental:")) + + let imkEOSNoticeButton = Button("Where's IMK Candidate Window?") { + if let window = CtlPrefUIShared.sharedWindow { + let title = "The End of Support for IMK Candidate Window" + let explanation = "1) Only macOS has IMKCandidates. Since it relies on a dedicated ObjC Bridging Header to expose necessary internal APIs to work, it hinders vChewing from completely modularized for multi-platform support.\n\n2) IMKCandidates is buggy. It is not likely to be completely fixed by Apple, and its devs are not allowed to talk about it to non-Apple individuals. That's why we have had enough with IMKCandidates. It is likely the reason why Apple had never used IMKCandidates in their official InputMethodKit sample projects (as of August 2023)." + window.callAlert(title: title.localized, text: explanation.localized) + } + } + + Section(footer: imkEOSNoticeButton) { Toggle( LocalizedStringKey("Enable mouse wheel support for Tadokoro Candidate Window"), isOn: $enableMouseScrollingForTDKCandidatesCocoa ) - Button("Where's IMK Candidate Window?") { - if let window = CtlPrefUIShared.sharedWindow { - let title = "The End of Support for IMK Candidate Window" - let explanation = "1) Only macOS has IMKCandidates. Since it relies on a ObjC Bridging Header to expose necessary internal APIs to work, it hinders vChewing from completely modularized for multi-platform support.\n\n2) IMKCandidates is buggy. It is not likely to be completely fixed by Apple, and its devs are not allowed to talk about it to non-Apple individuals. That's why we have had enough with IMKCandidates. It is likely the reason why Apple had never used IMKCandidates in their official InputMethodKit sample projects (as of August 2023)." - window.callAlert(title: title.localized, text: explanation.localized) - } - } } - } + }.formStyled().frame(width: CtlPrefUIShared.formWidth) } .frame(maxHeight: CtlPrefUIShared.contentMaxHeight) } @@ -213,30 +216,100 @@ private struct VwrPrefPaneCandidates_SelectionKeys: View { // MARK: - Main View var body: some View { - ComboBox( - items: CandidateKey.suggestions, - text: $candidateKeys.onChange { - let value = candidateKeys - let keys = value.trimmingCharacters(in: .whitespacesAndNewlines).lowercased().deduplicated - // Start Error Handling. - if let errorResult = CandidateKey.validate(keys: keys) { - if let window = CtlPrefUIShared.sharedWindow, !keys.isEmpty { - IMEApp.buzz() - let alert = NSAlert(error: NSLocalizedString("Invalid Selection Keys.", comment: "")) - alert.informativeText = errorResult - alert.beginSheetModal(for: window) { _ in - candidateKeys = PrefMgr.kDefaultCandidateKeys + HStack { + Text("Selection Keys:") + Spacer() + ComboBox( + items: CandidateKey.suggestions, + text: $candidateKeys.onChange { + let value = candidateKeys + let keys = value.trimmingCharacters(in: .whitespacesAndNewlines).lowercased().deduplicated + // Start Error Handling. + if let errorResult = CandidateKey.validate(keys: keys) { + if let window = CtlPrefUIShared.sharedWindow, !keys.isEmpty { + IMEApp.buzz() + let alert = NSAlert(error: NSLocalizedString("Invalid Selection Keys.", comment: "")) + alert.informativeText = errorResult + alert.beginSheetModal(for: window) { _ in + candidateKeys = PrefMgr.kDefaultCandidateKeys + } } } } - } - ).frame(width: 180) + ).frame(width: 180) + } Text( "Choose or hit Enter to confim your prefered keys for selecting candidates.".localized + "\n" + "This will also affect the row / column capacity of the candidate window.".localized ) - - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) + .settingsDescription() + } +} + +// MARK: - NSComboBox + +// Ref: https://stackoverflow.com/a/71058587/4162914 +// License: https://creativecommons.org/licenses/by-sa/4.0/ + +@available(macOS 10.15, *) +public struct ComboBox: NSViewRepresentable { + // The items that will show up in the pop-up menu: + public var items: [String] = [] + + // The property on our parent view that gets synced to the current + // stringValue of the NSComboBox, whether the user typed it in or + // selected it from the list: + @Binding public var text: String + + public func makeCoordinator() -> Coordinator { + Coordinator(self) + } + + public func makeNSView(context: Context) -> NSComboBox { + let comboBox = NSComboBox() + comboBox.usesDataSource = false + comboBox.completes = false + comboBox.delegate = context.coordinator + comboBox.intercellSpacing = NSSize(width: 0.0, height: 10.0) + return comboBox + } + + public func updateNSView(_ nsView: NSComboBox, context: Context) { + nsView.removeAllItems() + nsView.addItems(withObjectValues: items) + + // ComboBox doesn't automatically select the item matching its text; + // we must do that manually. But we need the delegate to ignore that + // selection-change or we'll get a "state modified during view update; + // will cause undefined behavior" warning. + context.coordinator.ignoreSelectionChanges = true + nsView.stringValue = text + nsView.selectItem(withObjectValue: text) + context.coordinator.ignoreSelectionChanges = false + } + + public class Coordinator: NSObject, NSComboBoxDelegate { + public var parent: ComboBox + public var ignoreSelectionChanges = false + + public init(_ parent: ComboBox) { + self.parent = parent + } + + public func comboBoxSelectionDidChange(_ notification: Notification) { + if !ignoreSelectionChanges, + let box: NSComboBox = notification.object as? NSComboBox, + let newStringValue: String = box.objectValueOfSelectedItem as? String + { + parent.text = newStringValue + } + } + + public func controlTextDidEndEditing(_ obj: Notification) { + if let textField = obj.object as? NSTextField { + parent.text = textField.stringValue + } + } } } diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneCassette.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneCassette.swift index 9252a948..fe065f83 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneCassette.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneCassette.swift @@ -39,151 +39,154 @@ struct VwrPrefPaneCassette: View { var body: some View { ScrollView { - SSPreferences.Settings.Container(contentWidth: CtlPrefUIShared.contentWidth) { + Form { // MARK: - Cassette Data Path Management - SSPreferences.Settings.Section(bottomDivider: true) { - Text(LocalizedStringKey("Choose your desired cassette file path. Will be omitted if invalid.")) - HStack { - PathControl(pathDroppable: $cassettePath) { pathControl in - pathControl.allowedTypes = ["cin2", "cin", "vcin"] - pathControl.heightAnchor.constraint(equalToConstant: 20).isActive = true - pathControl.widthAnchor.constraint(equalToConstant: CtlPrefUIShared.maxDescriptionWidth).isActive = true - pathControl.placeholderString = "Please drag the desired target from Finder to this place.".localized - } acceptDrop: { pathControl, info in - let urls = info.draggingPasteboard.readObjects(forClasses: [NSURL.self]) - guard let url = urls?.first as? URL else { return false } - let bolPreviousPathValidity = LMMgr.checkCassettePathValidity( - PrefMgr.shared.cassettePath.expandingTildeInPath) - if LMMgr.checkCassettePathValidity(url.path) { - cassettePath = url.path - pathControl.url = url - LMMgr.loadCassetteData() - BookmarkManager.shared.saveBookmark(for: url) - return true + Section { + VStack(alignment: .leading) { + Text(LocalizedStringKey("Choose your desired cassette file path. Will be omitted if invalid.")) + HStack(spacing: 3) { + PathControl(pathDroppable: $cassettePath) { pathControl in + pathControl.allowedTypes = ["cin2", "cin", "vcin"] + pathControl.placeholderString = "Please drag the desired target from Finder to this place.".localized + } acceptDrop: { pathControl, info in + let urls = info.draggingPasteboard.readObjects(forClasses: [NSURL.self]) + guard let url = urls?.first as? URL else { return false } + let bolPreviousPathValidity = LMMgr.checkCassettePathValidity( + PrefMgr.shared.cassettePath.expandingTildeInPath) + if LMMgr.checkCassettePathValidity(url.path) { + cassettePath = url.path + pathControl.url = url + LMMgr.loadCassetteData() + BookmarkManager.shared.saveBookmark(for: url) + return true + } + // On Error: + IMEApp.buzz() + if !bolPreviousPathValidity { + cassettePath = "" + } + return false } - // On Error: - IMEApp.buzz() - if !bolPreviousPathValidity { - cassettePath = "" - } - return false - } - Button { - if NSEvent.keyModifierFlags == .option, !cassettePath.isEmpty { - NSWorkspace.shared.activateFileViewerSelecting( - [URL(fileURLWithPath: cassettePath)] - ) - return - } - Self.dlgOpenFile.showsResizeIndicator = true - Self.dlgOpenFile.showsHiddenFiles = true - Self.dlgOpenFile.canChooseFiles = true - Self.dlgOpenFile.canChooseDirectories = false - Self.dlgOpenFile.allowsMultipleSelection = false - Self.dlgOpenFile.allowedFileTypes = ["cin2", "vcin", "cin"] - Self.dlgOpenFile.allowsOtherFileTypes = true + Button { + if NSEvent.keyModifierFlags == .option, !cassettePath.isEmpty { + NSWorkspace.shared.activateFileViewerSelecting( + [URL(fileURLWithPath: cassettePath)] + ) + return + } + Self.dlgOpenFile.showsResizeIndicator = true + Self.dlgOpenFile.showsHiddenFiles = true + Self.dlgOpenFile.canChooseFiles = true + Self.dlgOpenFile.canChooseDirectories = false + Self.dlgOpenFile.allowsMultipleSelection = false + Self.dlgOpenFile.allowedFileTypes = ["cin2", "vcin", "cin"] + Self.dlgOpenFile.allowsOtherFileTypes = true - let bolPreviousPathValidity = LMMgr.checkCassettePathValidity( - cassettePath.expandingTildeInPath) + let bolPreviousPathValidity = LMMgr.checkCassettePathValidity( + cassettePath.expandingTildeInPath) - if let window = CtlPrefUIShared.sharedWindow { - Self.dlgOpenFile.beginSheetModal(for: window) { result in - if result == NSApplication.ModalResponse.OK { - guard let url = Self.dlgOpenFile.url else { return } - if LMMgr.checkCassettePathValidity(url.path) { - cassettePath = url.path - LMMgr.loadCassetteData() - BookmarkManager.shared.saveBookmark(for: url) + if let window = CtlPrefUIShared.sharedWindow { + Self.dlgOpenFile.beginSheetModal(for: window) { result in + if result == NSApplication.ModalResponse.OK { + guard let url = Self.dlgOpenFile.url else { return } + if LMMgr.checkCassettePathValidity(url.path) { + cassettePath = url.path + LMMgr.loadCassetteData() + BookmarkManager.shared.saveBookmark(for: url) + } else { + IMEApp.buzz() + if !bolPreviousPathValidity { + cassettePath = "" + } + return + } } else { - IMEApp.buzz() if !bolPreviousPathValidity { cassettePath = "" } return } - } else { - if !bolPreviousPathValidity { - cassettePath = "" - } - return } } + } label: { + Text("...") } - } label: { - Text("...") - } - Button { - cassettePath = "" - } label: { - Text("×") - } - } - Toggle( - LocalizedStringKey("Enable cassette mode, suppressing phonabet input"), - isOn: $cassetteEnabled.onChange { - if cassetteEnabled, !LMMgr.checkCassettePathValidity(cassettePath) { - if let window = CtlPrefUIShared.sharedWindow { - IMEApp.buzz() - let alert = NSAlert(error: NSLocalizedString("Path invalid or file access error.", comment: "")) - alert.informativeText = NSLocalizedString( - "Please reconfigure the cassette path to a valid one before enabling this mode.", comment: "" - ) - alert.beginSheetModal(for: window) { _ in - } - } - LMMgr.resetCassettePath() - cassetteEnabled = false - } else { - LMMgr.loadCassetteData() + Button { + cassettePath = "" + } label: { + Text("×") } - LMMgr.setCassetteEnabled(cassetteEnabled) } - ).controlSize(.small) - Text( - LocalizedStringKey( - "Cassette mode is similar to the CIN support of the Yahoo Kimo IME, allowing users to use their own CIN tables to implement their stroked-based input schema (e.g. Wubi, Cangjie, Boshiamy, etc.) as a plan-B in vChewing IME. However, since vChewing won't compromise its phonabet input mode experience for this cassette mode, users might not feel comfortable enough comparing to their experiences with RIME (recommended) or OpenVanilla (deprecated)." + Spacer() + Text( + LocalizedStringKey( + "Cassette mode is similar to the CIN support of the Yahoo Kimo IME, allowing users to use their own CIN tables to implement their stroked-based input schema (e.g. Wubi, Cangjie, Boshiamy, etc.) as a plan-B in vChewing IME. However, since vChewing won't compromise its phonabet input mode experience for this cassette mode, users might not feel comfortable enough comparing to their experiences with RIME (recommended) or OpenVanilla (deprecated)." + ) ) - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) + .settingsDescription() + Toggle( + LocalizedStringKey("Enable cassette mode, suppressing phonabet input"), + isOn: $cassetteEnabled.onChange { + if cassetteEnabled, !LMMgr.checkCassettePathValidity(cassettePath) { + if let window = CtlPrefUIShared.sharedWindow { + IMEApp.buzz() + let alert = NSAlert(error: NSLocalizedString("Path invalid or file access error.", comment: "")) + alert.informativeText = NSLocalizedString( + "Please reconfigure the cassette path to a valid one before enabling this mode.", comment: "" + ) + alert.beginSheetModal(for: window) { _ in + } + } + LMMgr.resetCassettePath() + cassetteEnabled = false + } else { + LMMgr.loadCassetteData() + } + LMMgr.setCassetteEnabled(cassetteEnabled) + } + ) + } } // MARK: - Something Else - SSPreferences.Settings.Section { + Section { Toggle( LocalizedStringKey("Auto-composite when the longest possible key is formed"), isOn: $autoCompositeWithLongestPossibleCassetteKey ) - Toggle( - LocalizedStringKey("Show translated strokes in composition buffer"), - isOn: $showTranslatedStrokesInCompositionBuffer - ) - Text( - LocalizedStringKey( - "All strokes in the composition buffer will be shown as ASCII keyboard characters unless this option is enabled. Stroke is definable in the “%keyname” section of the CIN file." + VStack(alignment: .leading) { + Toggle( + LocalizedStringKey("Show translated strokes in composition buffer"), + isOn: $showTranslatedStrokesInCompositionBuffer ) - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - Picker( - "", - selection: $forceCassetteChineseConversion - ) { - Text(LocalizedStringKey("Disable forced conversion for cassette outputs")).tag(0) - Text(LocalizedStringKey("Enforce conversion in both input modes")).tag(1) - Text(LocalizedStringKey("Only enforce conversion in Simplified Chinese mode")).tag(2) - Text(LocalizedStringKey("Only enforce conversion in Traditional Chinese mode")).tag(3) + Text( + LocalizedStringKey( + "All strokes in the composition buffer will be shown as ASCII keyboard characters unless this option is enabled. Stroke is definable in the “%keyname” section of the CIN file." + ) + ) + .settingsDescription() } - .labelsHidden() - .pickerStyle(RadioGroupPickerStyle()) - Text( - LocalizedStringKey( - "This conversion only affects the cassette module, converting typed contents to either Simplified Chinese or Traditional Chinese in accordance with this setting and your current input mode." + VStack(alignment: .leading) { + Picker( + "Chinese Conversion:", + selection: $forceCassetteChineseConversion + ) { + Text(LocalizedStringKey("Disable forced conversion for cassette outputs")).tag(0) + Text(LocalizedStringKey("Enforce conversion in both input modes")).tag(1) + Text(LocalizedStringKey("Only enforce conversion in Simplified Chinese mode")).tag(2) + Text(LocalizedStringKey("Only enforce conversion in Traditional Chinese mode")).tag(3) + } + Text( + LocalizedStringKey( + "This conversion only affects the cassette module, converting typed contents to either Simplified Chinese or Traditional Chinese in accordance with this setting and your current input mode." + ) ) - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) + .settingsDescription() + } } - } + }.formStyled().frame(width: CtlPrefUIShared.formWidth) } .frame(maxHeight: CtlPrefUIShared.contentMaxHeight) } diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneDevZone.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneDevZone.swift index fba03652..95225472 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneDevZone.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneDevZone.swift @@ -32,37 +32,32 @@ struct VwrPrefPaneDevZone: View { var body: some View { ScrollView { - SSPreferences.Settings.Container(contentWidth: CtlPrefUIShared.contentWidth) { - SSPreferences.Settings.Section(bottomDivider: true) { - Text( - LocalizedStringKey( - "Warning: This page is for testing future features. \nFeatures listed here may not work as expected.") - ) - .fixedSize(horizontal: false, vertical: true) - Divider() - HStack { - Text("Some previous options are moved to other tabs.".localized) - - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) + Form { + Section(header: Text( + "Warning: This page is for testing future features. \nFeatures listed here may not work as expected." + ), footer: Text("Some previous options are moved to other tabs.".localized).settingsDescription()) { + VStack(alignment: .leading) { + Toggle( + UserDef.kSecurityHardenedCompositionBuffer.metaData?.shortTitle?.localized ?? "", + isOn: $securityHardenedCompositionBuffer + ) + Text( + UserDef.kSecurityHardenedCompositionBuffer.metaData?.description?.localized ?? "" + ) + .settingsDescription() + } + VStack(alignment: .leading) { + Toggle( + "Disable segmented thick underline in marking mode for managed clients".localized, + isOn: $disableSegmentedThickUnderlineInMarkingModeForManagedClients + ) + Text( + "Some clients with web-based front UI may have issues rendering segmented thick underlines drawn by their implemented “setMarkedText()”. This option stops the input method from delivering segmented thick underlines to “client().setMarkedText()”. Note that segmented thick underlines are only used in marking mode, unless the client itself misimplements the IMKTextInput method “setMarkedText()”. This option only affects the inline composition buffer.".localized + ) + .settingsDescription() } - Toggle( - UserDef.kSecurityHardenedCompositionBuffer.metaData?.shortTitle?.localized ?? "", - isOn: $securityHardenedCompositionBuffer - ) - Text( - UserDef.kSecurityHardenedCompositionBuffer.metaData?.description?.localized ?? "" - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - Toggle( - "Disable segmented thick underline in marking mode for managed clients".localized, - isOn: $disableSegmentedThickUnderlineInMarkingModeForManagedClients - ) - Text( - "Some clients with web-based front UI may have issues rendering segmented thick underlines drawn by their implemented “setMarkedText()”. This option stops the input method from delivering segmented thick underlines to “client().setMarkedText()”. Note that segmented thick underlines are only used in marking mode, unless the client itself misimplements the IMKTextInput method “setMarkedText()”. This option only affects the inline composition buffer.".localized - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) } - } + }.formStyled().frame(width: CtlPrefUIShared.formWidth) } .frame(maxHeight: CtlPrefUIShared.contentMaxHeight) } diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneDictionary.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneDictionary.swift index 8e097cc8..716e2fdd 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneDictionary.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneDictionary.swift @@ -55,111 +55,115 @@ struct VwrPrefPaneDictionary: View { var body: some View { ScrollView { - SSPreferences.Settings.Container(contentWidth: CtlPrefUIShared.contentWidth) { + Form { // MARK: - User Data Folder Path Management - SSPreferences.Settings.Section(bottomDivider: true) { + Section { Group { - Text(LocalizedStringKey("Choose your desired user data folder path. Will be omitted if invalid.")) - HStack { - PathControl(pathDroppable: $userDataFolderSpecified) { pathControl in - pathControl.allowedTypes = ["public.folder", "public.directory"] - pathControl.heightAnchor.constraint(equalToConstant: 20).isActive = true - pathControl.widthAnchor.constraint(equalToConstant: CtlPrefUIShared.maxDescriptionWidth).isActive = true - } acceptDrop: { pathControl, info in - let urls = info.draggingPasteboard.readObjects(forClasses: [NSURL.self]) - guard let url = urls?.first as? URL else { return false } - let bolPreviousFolderValidity = LMMgr.checkIfSpecifiedUserDataFolderValid( - PrefMgr.shared.userDataFolderSpecified.expandingTildeInPath) - var newPath = url.path - newPath.ensureTrailingSlash() - if LMMgr.checkIfSpecifiedUserDataFolderValid(newPath) { - userDataFolderSpecified = newPath - pathControl.url = url - BookmarkManager.shared.saveBookmark(for: url) - AppDelegate.shared.updateDirectoryMonitorPath() - return true + VStack(alignment: .leading) { + Text(LocalizedStringKey("Choose your desired user data folder path. Will be omitted if invalid.")) + HStack(spacing: 3) { + PathControl(pathDroppable: $userDataFolderSpecified) { pathControl in + pathControl.allowedTypes = ["public.folder", "public.directory"] + pathControl.placeholderString = "Please drag the desired target from Finder to this place.".localized + } acceptDrop: { pathControl, info in + let urls = info.draggingPasteboard.readObjects(forClasses: [NSURL.self]) + guard let url = urls?.first as? URL else { return false } + let bolPreviousFolderValidity = LMMgr.checkIfSpecifiedUserDataFolderValid( + PrefMgr.shared.userDataFolderSpecified.expandingTildeInPath) + var newPath = url.path + newPath.ensureTrailingSlash() + if LMMgr.checkIfSpecifiedUserDataFolderValid(newPath) { + userDataFolderSpecified = newPath + pathControl.url = url + BookmarkManager.shared.saveBookmark(for: url) + AppDelegate.shared.updateDirectoryMonitorPath() + return true + } + // On Error: + IMEApp.buzz() + if !bolPreviousFolderValidity { + userDataFolderSpecified = fdrUserDataDefault + pathControl.url = URL(fileURLWithPath: fdrUserDataDefault) + } + return false } - // On Error: - IMEApp.buzz() - if !bolPreviousFolderValidity { - userDataFolderSpecified = fdrUserDataDefault - pathControl.url = URL(fileURLWithPath: fdrUserDataDefault) - } - return false - } - Button { - if NSEvent.keyModifierFlags == .option, !userDataFolderSpecified.isEmpty { - NSWorkspace.shared.activateFileViewerSelecting( - [URL(fileURLWithPath: userDataFolderSpecified)] + Button { + if NSEvent.keyModifierFlags == .option, !userDataFolderSpecified.isEmpty { + NSWorkspace.shared.activateFileViewerSelecting( + [URL(fileURLWithPath: userDataFolderSpecified)] + ) + return + } + Self.dlgOpenPath.title = NSLocalizedString( + "Choose your desired user data folder.", comment: "" ) - return - } - Self.dlgOpenPath.title = NSLocalizedString( - "Choose your desired user data folder.", comment: "" - ) - Self.dlgOpenPath.showsResizeIndicator = true - Self.dlgOpenPath.showsHiddenFiles = true - Self.dlgOpenPath.canChooseFiles = false - Self.dlgOpenPath.allowsMultipleSelection = false - Self.dlgOpenPath.canChooseDirectories = true + Self.dlgOpenPath.showsResizeIndicator = true + Self.dlgOpenPath.showsHiddenFiles = true + Self.dlgOpenPath.canChooseFiles = false + Self.dlgOpenPath.allowsMultipleSelection = false + Self.dlgOpenPath.canChooseDirectories = true - let bolPreviousFolderValidity = LMMgr.checkIfSpecifiedUserDataFolderValid( - userDataFolderSpecified.expandingTildeInPath) + let bolPreviousFolderValidity = LMMgr.checkIfSpecifiedUserDataFolderValid( + userDataFolderSpecified.expandingTildeInPath) - if let window = CtlPrefUIShared.sharedWindow { - Self.dlgOpenPath.beginSheetModal(for: window) { result in - if result == NSApplication.ModalResponse.OK { - guard let url = Self.dlgOpenPath.url else { return } - // CommonDialog 讀入的路徑沒有結尾斜槓,這會導致檔案目錄合規性判定失準。 - // 所以要手動補回來。 - var newPath = url.path - newPath.ensureTrailingSlash() - if LMMgr.checkIfSpecifiedUserDataFolderValid(newPath) { - userDataFolderSpecified = newPath - BookmarkManager.shared.saveBookmark(for: url) - AppDelegate.shared.updateDirectoryMonitorPath() + if let window = CtlPrefUIShared.sharedWindow { + Self.dlgOpenPath.beginSheetModal(for: window) { result in + if result == NSApplication.ModalResponse.OK { + guard let url = Self.dlgOpenPath.url else { return } + // CommonDialog 讀入的路徑沒有結尾斜槓,這會導致檔案目錄合規性判定失準。 + // 所以要手動補回來。 + var newPath = url.path + newPath.ensureTrailingSlash() + if LMMgr.checkIfSpecifiedUserDataFolderValid(newPath) { + userDataFolderSpecified = newPath + BookmarkManager.shared.saveBookmark(for: url) + AppDelegate.shared.updateDirectoryMonitorPath() + } else { + IMEApp.buzz() + if !bolPreviousFolderValidity { + userDataFolderSpecified = fdrUserDataDefault + } + return + } } else { - IMEApp.buzz() if !bolPreviousFolderValidity { userDataFolderSpecified = fdrUserDataDefault } return } - } else { - if !bolPreviousFolderValidity { - userDataFolderSpecified = fdrUserDataDefault - } - return } } - } - } label: { - Text("...") + } label: { + Text("...") + }.frame(minWidth: 25) + Button { + userDataFolderSpecified = fdrUserDataDefault + } label: { + Text("↻") + }.frame(minWidth: 25) } - Button { - userDataFolderSpecified = fdrUserDataDefault - } label: { - Text("↻") - } - } - Toggle( - LocalizedStringKey("Automatically reload user data files if changes detected"), - isOn: $shouldAutoReloadUserDataFiles.onChange { - if shouldAutoReloadUserDataFiles { - LMMgr.initUserLangModels() - } - } - ).controlSize(.small) - Text( - LocalizedStringKey( - "Due to security concerns, we don't consider implementing anything related to shell script execution here. An input method doing this without implementing App Sandbox will definitely have system-wide vulnerabilities, considering that its related UserDefaults are easily tamperable to execute malicious shell scripts. vChewing is designed to be invulnerable from this kind of attack. Also, official releases of vChewing are Sandboxed." + Spacer() + Text( + LocalizedStringKey( + "Due to security concerns, we don't consider implementing anything related to shell script execution here. An input method doing this without implementing App Sandbox will definitely have system-wide vulnerabilities, considering that its related UserDefaults are easily tamperable to execute malicious shell scripts. vChewing is designed to be invulnerable from this kind of attack. Also, official releases of vChewing are Sandboxed." + ) ) - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) + .settingsDescription() + Toggle( + LocalizedStringKey("Automatically reload user data files if changes detected"), + isOn: $shouldAutoReloadUserDataFiles.onChange { + if shouldAutoReloadUserDataFiles { + LMMgr.initUserLangModels() + } + } + ) + } } - Divider() - Group { + } + + Section { + VStack(alignment: .leading) { Toggle( LocalizedStringKey("Read external factory dictionary files if possible"), isOn: $useExternalFactoryDict.onChange { @@ -171,25 +175,27 @@ struct VwrPrefPaneDictionary: View { "This will use the plist files deployed by the “make install” command from libvChewing-Data if possible." ) ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - Toggle( - LocalizedStringKey("Only load factory language models if needed"), - isOn: $onlyLoadFactoryLangModelsIfNeeded.onChange { - if !onlyLoadFactoryLangModelsIfNeeded { LMMgr.loadDataModelsOnAppDelegate() } - } - ) - Toggle( - LocalizedStringKey("Enable CNS11643 Support (2023-05-19)"), - isOn: $cns11643Enabled.onChange { - LMMgr.setCNSEnabled(cns11643Enabled) - } - ) - Toggle( - LocalizedStringKey("Enable symbol input support (incl. certain emoji symbols)"), - isOn: $symbolInputEnabled.onChange { - LMMgr.setSymbolEnabled(symbolInputEnabled) - } - ) + .settingsDescription() + } + Toggle( + LocalizedStringKey("Only load factory language models if needed"), + isOn: $onlyLoadFactoryLangModelsIfNeeded.onChange { + if !onlyLoadFactoryLangModelsIfNeeded { LMMgr.loadDataModelsOnAppDelegate() } + } + ) + Toggle( + LocalizedStringKey("Enable CNS11643 Support (2023-05-19)"), + isOn: $cns11643Enabled.onChange { + LMMgr.setCNSEnabled(cns11643Enabled) + } + ) + Toggle( + LocalizedStringKey("Enable symbol input support (incl. certain emoji symbols)"), + isOn: $symbolInputEnabled.onChange { + LMMgr.setSymbolEnabled(symbolInputEnabled) + } + ) + VStack(alignment: .leading) { Toggle( LocalizedStringKey("Applying typing suggestions from half-life user override model"), isOn: $fetchSuggestionsFromUserOverrideModel @@ -197,7 +203,9 @@ struct VwrPrefPaneDictionary: View { Text( "The user override model only possesses memories temporarily. Each memory record gradually becomes ineffective within approximately less than 6 days. You can erase all memory records through the input method menu.".localized ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) + .settingsDescription() + } + VStack(alignment: .leading) { Toggle( LocalizedStringKey("Enable phrase replacement table"), isOn: $phraseReplacementEnabled.onChange { @@ -208,10 +216,11 @@ struct VwrPrefPaneDictionary: View { } ) Text("This will batch-replace specified candidates.".localized) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) + .settingsDescription() } - Divider() - Group { + } + Section { + VStack(alignment: .leading) { Toggle( LocalizedStringKey("Allow boosting / excluding a candidate of single kanji when marking"), isOn: $allowBoostingSingleKanjiAsUserPhrase @@ -221,10 +230,10 @@ struct VwrPrefPaneDictionary: View { "⚠︎ This may hinder the walking algorithm from giving appropriate results." ) ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) + .settingsDescription() } } - } + }.formStyled().frame(width: CtlPrefUIShared.formWidth) } .frame(maxHeight: CtlPrefUIShared.contentMaxHeight) } diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneGeneral.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneGeneral.swift index 204fe0d0..80eba947 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneGeneral.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneGeneral.swift @@ -71,8 +71,8 @@ struct VwrPrefPaneGeneral: View { var body: some View { ScrollView { - SSPreferences.Settings.Container(contentWidth: CtlPrefUIShared.contentWidth) { - SSPreferences.Settings.Section { + Form { + VStack(alignment: .leading) { Text( "\u{2022} " + NSLocalizedString( @@ -84,28 +84,21 @@ struct VwrPrefPaneGeneral: View { comment: "" ) ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth).padding(.bottom, NSFont.systemFontSize) - } - SSPreferences.Settings.Section(title: "UI Language:".localized) { - HStack { - Picker( - LocalizedStringKey("Follow OS settings"), - selection: $appleLanguageTag - ) { - Text(LocalizedStringKey("Follow OS settings")).tag("auto") - Text(LocalizedStringKey("Simplified Chinese")).tag("zh-Hans") - Text(LocalizedStringKey("Traditional Chinese")).tag("zh-Hant") - Text(LocalizedStringKey("Japanese")).tag("ja") - Text(LocalizedStringKey("English")).tag("en") - } - .labelsHidden() - .frame(width: 180.0) - Spacer() + .settingsDescription() + Picker("UI Language:", selection: $appleLanguageTag) { + Text(LocalizedStringKey("Follow OS settings")).tag("auto") + Text(LocalizedStringKey("Simplified Chinese")).tag("zh-Hans") + Text(LocalizedStringKey("Traditional Chinese")).tag("zh-Hant") + Text(LocalizedStringKey("Japanese")).tag("ja") + Text(LocalizedStringKey("English")).tag("en") } Text(LocalizedStringKey("Change user interface language (will reboot the IME).")) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) + .settingsDescription() } - SSPreferences.Settings.Section(label: { Text(LocalizedStringKey("Typing Settings:")) }) { + + // MARK: (header: Text("Typing Settings:")) + + Section { Toggle( LocalizedStringKey("Automatically correct reading combinations when typing"), isOn: $autoCorrectReadingCombination @@ -122,15 +115,17 @@ struct VwrPrefPaneGeneral: View { LocalizedStringKey("Also use “\\” or “¥” key for Hanin Keyboard Symbol Input"), isOn: $classicHaninKeyboardSymbolModeShortcutEnabled ) - Toggle( - LocalizedStringKey("Emulating select-candidate-per-character mode"), - isOn: $useSCPCTypingMode.onChange { - guard useSCPCTypingMode else { return } - LMMgr.loadUserSCPCSequencesData() - } - ) - Text(LocalizedStringKey("An accommodation for elder computer users.")) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) + VStack(alignment: .leading) { + Toggle( + LocalizedStringKey("Emulating select-candidate-per-character mode"), + isOn: $useSCPCTypingMode.onChange { + guard useSCPCTypingMode else { return } + LMMgr.loadUserSCPCSequencesData() + } + ) + Text(LocalizedStringKey("An accommodation for elder computer users.")) + .settingsDescription() + } if Date.isTodayTheDate(from: 0401) { Toggle( LocalizedStringKey("Stop farting (when typed phonetic combination is invalid, etc.)"), @@ -168,19 +163,20 @@ struct VwrPrefPaneGeneral: View { ) } } - SSPreferences.Settings.Section(label: { Text(LocalizedStringKey("Misc Settings:")).controlSize(.small) }) { + + // MARK: (header: Text("Misc Settings:")) + + Section { Toggle( LocalizedStringKey("Check for updates automatically"), isOn: $checkUpdateAutomatically ) - .controlSize(.small) Toggle( LocalizedStringKey("Debug Mode"), isOn: $isDebugModeEnabled ) - .controlSize(.small) } - } + }.formStyled().frame(width: CtlPrefUIShared.formWidth) } .frame(maxHeight: CtlPrefUIShared.contentMaxHeight) } diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneKeyboard.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneKeyboard.swift index b7f2b653..94503e97 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneKeyboard.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneKeyboard.swift @@ -37,9 +37,11 @@ struct VwrPrefPaneKeyboard: View { var body: some View { ScrollView { - SSPreferences.Settings.Container(contentWidth: CtlPrefUIShared.contentWidth) { - SSPreferences.Settings.Section(title: "Quick Setup:".localized) { + Form { + Section { HStack(alignment: .top) { + Text("Quick Setup:") + Spacer() Button { keyboardParser = 0 basicKeyboardLayout = "com.apple.keylayout.ZhuyinBopomofo" @@ -58,12 +60,10 @@ struct VwrPrefPaneKeyboard: View { } label: { Text("↻A") } - }.controlSize(.small) - } - SSPreferences.Settings.Section(title: "Phonetic Parser:".localized) { - HStack { + } + VStack(alignment: .leading) { Picker( - "", + "Phonetic Parser:", selection: $keyboardParser ) { ForEach(KeyboardParser.allCases, id: \.self) { item in @@ -71,65 +71,62 @@ struct VwrPrefPaneKeyboard: View { Text(item.localizedMenuName).tag(item.rawValue) }.id(UUID()) } - .fixedSize() - .labelsHidden() - Spacer(minLength: NSFont.systemFontSize) + Spacer() + Text(NSLocalizedString("Choose the phonetic layout for Mandarin parser.", comment: "")) + .settingsDescription() } - Text(NSLocalizedString("Choose the phonetic layout for Mandarin parser.", comment: "")) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - } - SSPreferences.Settings.Section(title: "Basic Keyboard Layout:".localized) { - HStack { - Picker( - "", - selection: $basicKeyboardLayout - ) { - ForEach(0 ... (IMKHelper.allowedBasicLayoutsAsTISInputSources.count - 1), id: \.self) { id in - let theEntry = IMKHelper.allowedBasicLayoutsAsTISInputSources[id] - if let theEntry = theEntry { + + VStack(alignment: .leading) { + HStack { + Picker( + "Basic Keyboard Layout:", + selection: $basicKeyboardLayout + ) { + ForEach(0 ... (IMKHelper.allowedBasicLayoutsAsTISInputSources.count - 1), id: \.self) { id in + let theEntry = IMKHelper.allowedBasicLayoutsAsTISInputSources[id] + if let theEntry = theEntry { + Text(theEntry.vChewingLocalizedName).tag(theEntry.identifier) + } else { + Divider() + } + }.id(UUID()) + } + } + Spacer() + Text( + NSLocalizedString( + "Choose the macOS-level basic keyboard layout. Non-QWERTY alphanumerical keyboard layouts are for Pinyin parser only. This option will only affect the appearance of the on-screen-keyboard if the current Mandarin parser is neither (any) pinyin nor dynamically reparsable with different western keyboard layouts (like Eten 26, Hsu, etc.).", + comment: "" + ) + ) + .settingsDescription() + } + VStack(alignment: .leading) { + HStack { + Picker( + "Alphanumerical Layout:", + selection: $alphanumericalKeyboardLayout + ) { + ForEach(0 ... (IMKHelper.allowedAlphanumericalTISInputSources.count - 1), id: \.self) { id in + let theEntry = IMKHelper.allowedAlphanumericalTISInputSources[id] Text(theEntry.vChewingLocalizedName).tag(theEntry.identifier) - } else { - Divider() - } - }.id(UUID()) + }.id(UUID()) + } } - .labelsHidden().frame(width: 290) - Spacer(minLength: NSFont.systemFontSize) - } - Text( - NSLocalizedString( - "Choose the macOS-level basic keyboard layout. Non-QWERTY alphanumerical keyboard layouts are for Pinyin parser only. This option will only affect the appearance of the on-screen-keyboard if the current Mandarin parser is neither (any) pinyin nor dynamically reparsable with different western keyboard layouts (like Eten 26, Hsu, etc.).", - comment: "" + Spacer() + Text( + NSLocalizedString( + "Choose the macOS-level alphanumerical keyboard layout. This setting is for Shift-toggled alphanumerical mode only.", + comment: "" + ) ) - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) - } - SSPreferences.Settings.Section(title: "Alphanumerical Layout:".localized) { - HStack { - Picker( - "", - selection: $alphanumericalKeyboardLayout - ) { - ForEach(0 ... (IMKHelper.allowedAlphanumericalTISInputSources.count - 1), id: \.self) { id in - let theEntry = IMKHelper.allowedAlphanumericalTISInputSources[id] - Text(theEntry.vChewingLocalizedName).tag(theEntry.identifier) - }.id(UUID()) - } - .labelsHidden().frame(width: 290) - Spacer(minLength: NSFont.systemFontSize) + .settingsDescription() } - Text( - NSLocalizedString( - "Choose the macOS-level alphanumerical keyboard layout. This setting is for Shift-toggled alphanumerical mode only.", - comment: "" - ) - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) } - SSPreferences.Settings.Section(title: "Keyboard Shortcuts:".localized) { + Section(header: Text("Keyboard Shortcuts:")) { VwrPrefPaneKeyboard_KeyboardShortcuts() } - } + }.formStyled().frame(width: CtlPrefUIShared.formWidth) } .frame(maxHeight: CtlPrefUIShared.contentMaxHeight) } @@ -195,6 +192,7 @@ private struct VwrPrefPaneKeyboard_KeyboardShortcuts: View { isOn: $usingHotKeyRevLookup ) } + Divider() VStack(alignment: .leading) { Toggle( LocalizedStringKey("JIS Shinjitai Output"), @@ -227,70 +225,3 @@ struct VwrPrefPaneKeyboard_Previews: PreviewProvider { VwrPrefPaneKeyboard() } } - -// MARK: - NSComboBox - -// Ref: https://stackoverflow.com/a/71058587/4162914 -// License: https://creativecommons.org/licenses/by-sa/4.0/ - -@available(macOS 10.15, *) -public struct ComboBox: NSViewRepresentable { - // The items that will show up in the pop-up menu: - public var items: [String] = [] - - // The property on our parent view that gets synced to the current - // stringValue of the NSComboBox, whether the user typed it in or - // selected it from the list: - @Binding public var text: String - - public func makeCoordinator() -> Coordinator { - Coordinator(self) - } - - public func makeNSView(context: Context) -> NSComboBox { - let comboBox = NSComboBox() - comboBox.usesDataSource = false - comboBox.completes = false - comboBox.delegate = context.coordinator - comboBox.intercellSpacing = NSSize(width: 0.0, height: 10.0) - return comboBox - } - - public func updateNSView(_ nsView: NSComboBox, context: Context) { - nsView.removeAllItems() - nsView.addItems(withObjectValues: items) - - // ComboBox doesn't automatically select the item matching its text; - // we must do that manually. But we need the delegate to ignore that - // selection-change or we'll get a "state modified during view update; - // will cause undefined behavior" warning. - context.coordinator.ignoreSelectionChanges = true - nsView.stringValue = text - nsView.selectItem(withObjectValue: text) - context.coordinator.ignoreSelectionChanges = false - } - - public class Coordinator: NSObject, NSComboBoxDelegate { - public var parent: ComboBox - public var ignoreSelectionChanges = false - - public init(_ parent: ComboBox) { - self.parent = parent - } - - public func comboBoxSelectionDidChange(_ notification: Notification) { - if !ignoreSelectionChanges, - let box: NSComboBox = notification.object as? NSComboBox, - let newStringValue: String = box.objectValueOfSelectedItem as? String - { - parent.text = newStringValue - } - } - - public func controlTextDidEndEditing(_ obj: Notification) { - if let textField = obj.object as? NSTextField { - parent.text = textField.stringValue - } - } - } -} diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneOutput.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneOutput.swift index b179affd..49266066 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneOutput.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneOutput.swift @@ -35,48 +35,46 @@ struct VwrPrefPaneOutput: View { var body: some View { ScrollView { - SSPreferences.Settings.Container(contentWidth: CtlPrefUIShared.contentWidth) { - SSPreferences.Settings.Section(title: "Output Settings:".localized, bottomDivider: true) { + Form { + Section { + Toggle( + LocalizedStringKey("Auto-convert traditional Chinese glyphs to KangXi characters"), + isOn: $chineseConversionEnabled.onChange { + if chineseConversionEnabled, shiftJISShinjitaiOutputEnabled { + shiftJISShinjitaiOutputEnabled = false + } + } + ) + Toggle( + LocalizedStringKey("Auto-convert traditional Chinese glyphs to JIS Shinjitai characters"), + isOn: $shiftJISShinjitaiOutputEnabled.onChange { + if chineseConversionEnabled, shiftJISShinjitaiOutputEnabled { + chineseConversionEnabled = false + } + } + ) + Toggle( + LocalizedStringKey("Commit Hanyu-Pinyin instead on Ctrl(+Option)+Command+Enter"), + isOn: $inlineDumpPinyinInLieuOfZhuyin + ) + Toggle( + LocalizedStringKey("Trim unfinished readings / strokes on commit"), + isOn: $trimUnfinishedReadingsOnCommit + ) + } + Section(header: Text("Experimental:")) { VStack(alignment: .leading) { Toggle( - LocalizedStringKey("Auto-convert traditional Chinese glyphs to KangXi characters"), - isOn: $chineseConversionEnabled.onChange { - if chineseConversionEnabled, shiftJISShinjitaiOutputEnabled { - shiftJISShinjitaiOutputEnabled = false - } - } + LocalizedStringKey("Harden vertical punctuations during vertical typing (not recommended)"), + isOn: $hardenVerticalPunctuations ) - Toggle( - LocalizedStringKey("Auto-convert traditional Chinese glyphs to JIS Shinjitai characters"), - isOn: $shiftJISShinjitaiOutputEnabled.onChange { - if chineseConversionEnabled, shiftJISShinjitaiOutputEnabled { - chineseConversionEnabled = false - } - } - ) - Toggle( - LocalizedStringKey("Commit Hanyu-Pinyin instead on Ctrl(+Option)+Command+Enter"), - isOn: $inlineDumpPinyinInLieuOfZhuyin - ) - Toggle( - LocalizedStringKey("Trim unfinished readings / strokes on commit"), - isOn: $trimUnfinishedReadingsOnCommit - ) - } - } - SSPreferences.Settings.Section(title: "Experimental:".localized) { - Toggle( - LocalizedStringKey("Harden vertical punctuations during vertical typing (not recommended)"), - isOn: $hardenVerticalPunctuations - ) - Text( - LocalizedStringKey( + Text( "⚠︎ This feature is useful ONLY WHEN the font you are using doesn't support dynamic vertical punctuations. However, typed vertical punctuations will always shown as vertical punctuations EVEN IF your editor has changed the typing direction to horizontal." ) - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) + .settingsDescription() + } } - } + }.formStyled().frame(width: CtlPrefUIShared.formWidth) } .frame(maxHeight: CtlPrefUIShared.contentMaxHeight) } diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPanePhrases.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPanePhrases.swift index 5b4cbca1..83030096 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPanePhrases.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPanePhrases.swift @@ -18,11 +18,16 @@ struct VwrPrefPanePhrases: View { var body: some View { ScrollView { VStack { - VwrPhraseEditorUI(delegate: LMMgr.shared, window: CtlPrefUIShared.sharedWindow) - .frame(width: CtlPrefUIShared.contentWidth + 28, height: 445) - Spacer() + GroupBox { + VwrPhraseEditorUI(delegate: LMMgr.shared, window: CtlPrefUIShared.sharedWindow) + .padding(4) + .frame(maxWidth: .infinity) + .frame(height: 440) + } } + .padding(4) .padding() + .frame(width: CtlPrefUIShared.formWidth) } .frame(maxHeight: CtlPrefUIShared.contentMaxHeight) }