SwiftUI // Fix the wrong term "onChange" to "didChange".
This commit is contained in:
parent
77f39023ab
commit
a448c4cf7a
|
@ -101,12 +101,12 @@ public struct VwrSettingsPaneBehavior: View {
|
||||||
UserDef.kShareAlphanumericalModeStatusAcrossClients.bind($shareAlphanumericalModeStatusAcrossClients).render()
|
UserDef.kShareAlphanumericalModeStatusAcrossClients.bind($shareAlphanumericalModeStatusAcrossClients).render()
|
||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
UserDef.kTogglingAlphanumericalModeWithLShift.bind(
|
UserDef.kTogglingAlphanumericalModeWithLShift.bind(
|
||||||
$togglingAlphanumericalModeWithLShift.onChange {
|
$togglingAlphanumericalModeWithLShift.didChange {
|
||||||
SessionCtl.theShiftKeyDetector.toggleWithLShift = togglingAlphanumericalModeWithLShift
|
SessionCtl.theShiftKeyDetector.toggleWithLShift = togglingAlphanumericalModeWithLShift
|
||||||
}
|
}
|
||||||
).render()
|
).render()
|
||||||
UserDef.kTogglingAlphanumericalModeWithRShift.bind(
|
UserDef.kTogglingAlphanumericalModeWithRShift.bind(
|
||||||
$togglingAlphanumericalModeWithRShift.onChange {
|
$togglingAlphanumericalModeWithRShift.didChange {
|
||||||
SessionCtl.theShiftKeyDetector.toggleWithRShift = togglingAlphanumericalModeWithRShift
|
SessionCtl.theShiftKeyDetector.toggleWithRShift = togglingAlphanumericalModeWithRShift
|
||||||
}
|
}
|
||||||
).render()
|
).render()
|
||||||
|
|
|
@ -68,7 +68,7 @@ public struct VwrSettingsPaneCandidates: View {
|
||||||
UserDef.kUseHorizontalCandidateList.bind($useHorizontalCandidateList).render()
|
UserDef.kUseHorizontalCandidateList.bind($useHorizontalCandidateList).render()
|
||||||
.pickerStyle(RadioGroupPickerStyle())
|
.pickerStyle(RadioGroupPickerStyle())
|
||||||
UserDef.kCandidateListTextSize.bind(
|
UserDef.kCandidateListTextSize.bind(
|
||||||
$candidateListTextSize.onChange {
|
$candidateListTextSize.didChange {
|
||||||
guard !(12 ... 196).contains(candidateListTextSize) else { return }
|
guard !(12 ... 196).contains(candidateListTextSize) else { return }
|
||||||
candidateListTextSize = max(12, min(candidateListTextSize, 196))
|
candidateListTextSize = max(12, min(candidateListTextSize, 196))
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ private struct VwrSettingsPaneCandidates_SelectionKeys: View {
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
UserDef.kCandidateKeys.bind(
|
UserDef.kCandidateKeys.bind(
|
||||||
$candidateKeys.onChange {
|
$candidateKeys.didChange {
|
||||||
let value = candidateKeys
|
let value = candidateKeys
|
||||||
let keys = value.trimmingCharacters(in: .whitespacesAndNewlines).lowercased().deduplicated
|
let keys = value.trimmingCharacters(in: .whitespacesAndNewlines).lowercased().deduplicated
|
||||||
// Start Error Handling.
|
// Start Error Handling.
|
||||||
|
|
|
@ -124,7 +124,7 @@ public struct VwrSettingsPaneCassette: View {
|
||||||
.settingsDescription()
|
.settingsDescription()
|
||||||
Toggle(
|
Toggle(
|
||||||
LocalizedStringKey("Enable cassette mode, suppressing phonabet input"),
|
LocalizedStringKey("Enable cassette mode, suppressing phonabet input"),
|
||||||
isOn: $cassetteEnabled.onChange {
|
isOn: $cassetteEnabled.didChange {
|
||||||
if cassetteEnabled, !LMMgr.checkCassettePathValidity(cassettePath) {
|
if cassetteEnabled, !LMMgr.checkCassettePathValidity(cassettePath) {
|
||||||
if let window = CtlSettingsUI.shared?.window {
|
if let window = CtlSettingsUI.shared?.window {
|
||||||
IMEApp.buzz()
|
IMEApp.buzz()
|
||||||
|
|
|
@ -148,7 +148,7 @@ public struct VwrSettingsPaneDictionary: View {
|
||||||
)
|
)
|
||||||
.settingsDescription()
|
.settingsDescription()
|
||||||
UserDef.kShouldAutoReloadUserDataFiles.bind(
|
UserDef.kShouldAutoReloadUserDataFiles.bind(
|
||||||
$shouldAutoReloadUserDataFiles.onChange {
|
$shouldAutoReloadUserDataFiles.didChange {
|
||||||
if shouldAutoReloadUserDataFiles {
|
if shouldAutoReloadUserDataFiles {
|
||||||
LMMgr.initUserLangModels()
|
LMMgr.initUserLangModels()
|
||||||
}
|
}
|
||||||
|
@ -160,23 +160,23 @@ public struct VwrSettingsPaneDictionary: View {
|
||||||
|
|
||||||
Section {
|
Section {
|
||||||
UserDef.kUseExternalFactoryDict.bind(
|
UserDef.kUseExternalFactoryDict.bind(
|
||||||
$useExternalFactoryDict.onChange {
|
$useExternalFactoryDict.didChange {
|
||||||
LMMgr.connectCoreDB()
|
LMMgr.connectCoreDB()
|
||||||
}
|
}
|
||||||
).render()
|
).render()
|
||||||
UserDef.kCNS11643Enabled.bind(
|
UserDef.kCNS11643Enabled.bind(
|
||||||
$cns11643Enabled.onChange {
|
$cns11643Enabled.didChange {
|
||||||
LMMgr.syncLMPrefs()
|
LMMgr.syncLMPrefs()
|
||||||
}
|
}
|
||||||
).render()
|
).render()
|
||||||
UserDef.kSymbolInputEnabled.bind(
|
UserDef.kSymbolInputEnabled.bind(
|
||||||
$symbolInputEnabled.onChange {
|
$symbolInputEnabled.didChange {
|
||||||
LMMgr.syncLMPrefs()
|
LMMgr.syncLMPrefs()
|
||||||
}
|
}
|
||||||
).render()
|
).render()
|
||||||
UserDef.kFetchSuggestionsFromUserOverrideModel.bind($fetchSuggestionsFromUserOverrideModel).render()
|
UserDef.kFetchSuggestionsFromUserOverrideModel.bind($fetchSuggestionsFromUserOverrideModel).render()
|
||||||
UserDef.kPhraseReplacementEnabled.bind(
|
UserDef.kPhraseReplacementEnabled.bind(
|
||||||
$phraseReplacementEnabled.onChange {
|
$phraseReplacementEnabled.didChange {
|
||||||
LMMgr.syncLMPrefs()
|
LMMgr.syncLMPrefs()
|
||||||
if phraseReplacementEnabled {
|
if phraseReplacementEnabled {
|
||||||
LMMgr.loadUserPhraseReplacement()
|
LMMgr.loadUserPhraseReplacement()
|
||||||
|
|
|
@ -89,7 +89,7 @@ public struct VwrSettingsPaneGeneral: View {
|
||||||
|
|
||||||
Section {
|
Section {
|
||||||
UserDef.kReadingNarrationCoverage.bind(
|
UserDef.kReadingNarrationCoverage.bind(
|
||||||
$readingNarrationCoverage.onChange {
|
$readingNarrationCoverage.didChange {
|
||||||
SpeechSputnik.shared.refreshStatus()
|
SpeechSputnik.shared.refreshStatus()
|
||||||
}
|
}
|
||||||
).render()
|
).render()
|
||||||
|
@ -99,14 +99,14 @@ public struct VwrSettingsPaneGeneral: View {
|
||||||
UserDef.kClassicHaninKeyboardSymbolModeShortcutEnabled
|
UserDef.kClassicHaninKeyboardSymbolModeShortcutEnabled
|
||||||
.bind($classicHaninKeyboardSymbolModeShortcutEnabled).render()
|
.bind($classicHaninKeyboardSymbolModeShortcutEnabled).render()
|
||||||
UserDef.kUseSCPCTypingMode.bind(
|
UserDef.kUseSCPCTypingMode.bind(
|
||||||
$useSCPCTypingMode.onChange {
|
$useSCPCTypingMode.didChange {
|
||||||
guard useSCPCTypingMode else { return }
|
guard useSCPCTypingMode else { return }
|
||||||
LMMgr.loadSCPCSequencesData()
|
LMMgr.loadSCPCSequencesData()
|
||||||
}
|
}
|
||||||
).render()
|
).render()
|
||||||
if Date.isTodayTheDate(from: 0401) {
|
if Date.isTodayTheDate(from: 0401) {
|
||||||
UserDef.kShouldNotFartInLieuOfBeep.bind(
|
UserDef.kShouldNotFartInLieuOfBeep.bind(
|
||||||
$shouldNotFartInLieuOfBeep.onChange { onFartControlChange() }
|
$shouldNotFartInLieuOfBeep.didChange { onFartControlChange() }
|
||||||
).render()
|
).render()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,14 +36,14 @@ public struct VwrSettingsPaneOutput: View {
|
||||||
Form {
|
Form {
|
||||||
Section {
|
Section {
|
||||||
UserDef.kChineseConversionEnabled.bind(
|
UserDef.kChineseConversionEnabled.bind(
|
||||||
$chineseConversionEnabled.onChange {
|
$chineseConversionEnabled.didChange {
|
||||||
if chineseConversionEnabled, shiftJISShinjitaiOutputEnabled {
|
if chineseConversionEnabled, shiftJISShinjitaiOutputEnabled {
|
||||||
shiftJISShinjitaiOutputEnabled = false
|
shiftJISShinjitaiOutputEnabled = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
).render()
|
).render()
|
||||||
UserDef.kShiftJISShinjitaiOutputEnabled.bind(
|
UserDef.kShiftJISShinjitaiOutputEnabled.bind(
|
||||||
$shiftJISShinjitaiOutputEnabled.onChange {
|
$shiftJISShinjitaiOutputEnabled.didChange {
|
||||||
if chineseConversionEnabled, shiftJISShinjitaiOutputEnabled {
|
if chineseConversionEnabled, shiftJISShinjitaiOutputEnabled {
|
||||||
chineseConversionEnabled = false
|
chineseConversionEnabled = false
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,7 +195,7 @@ public struct VwrPhraseEditorUI: View {
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
VStack(spacing: 4) {
|
VStack(spacing: 4) {
|
||||||
HStack {
|
HStack {
|
||||||
Picker("", selection: $selInputMode.onChange { dropDownMenuDidChange() }) {
|
Picker("", selection: $selInputMode.didChange { dropDownMenuDidChange() }) {
|
||||||
switch currentIMEInputMode {
|
switch currentIMEInputMode {
|
||||||
case .imeModeCHS:
|
case .imeModeCHS:
|
||||||
Text(Shared.InputMode.imeModeCHS.localizedDescription).tag(Shared.InputMode.imeModeCHS)
|
Text(Shared.InputMode.imeModeCHS.localizedDescription).tag(Shared.InputMode.imeModeCHS)
|
||||||
|
@ -215,7 +215,7 @@ public struct VwrPhraseEditorUI: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.labelsHidden()
|
.labelsHidden()
|
||||||
Picker("", selection: $selUserDataType.onChange { dropDownMenuDidChange() }) {
|
Picker("", selection: $selUserDataType.didChange { dropDownMenuDidChange() }) {
|
||||||
Text(vChewingLM.ReplacableUserDataType.thePhrases.localizedDescription).tag(
|
Text(vChewingLM.ReplacableUserDataType.thePhrases.localizedDescription).tag(
|
||||||
vChewingLM.ReplacableUserDataType.thePhrases)
|
vChewingLM.ReplacableUserDataType.thePhrases)
|
||||||
Text(vChewingLM.ReplacableUserDataType.theFilter.localizedDescription).tag(
|
Text(vChewingLM.ReplacableUserDataType.theFilter.localizedDescription).tag(
|
||||||
|
@ -251,7 +251,9 @@ public struct VwrPhraseEditorUI: View {
|
||||||
.disabled(selInputMode == .imeModeNULL || isLoading)
|
.disabled(selInputMode == .imeModeNULL || isLoading)
|
||||||
.frame(minWidth: 320, minHeight: 240)
|
.frame(minWidth: 320, minHeight: 240)
|
||||||
.onChange(of: fileChangeIndicator.id) { _ in
|
.onChange(of: fileChangeIndicator.id) { _ in
|
||||||
if Self.autoReloadExternalModifications { update() }
|
Task {
|
||||||
|
if Self.autoReloadExternalModifications { update() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +269,7 @@ public struct VwrPhraseEditorUI: View {
|
||||||
if selUserDataType == .thePhrases {
|
if selUserDataType == .thePhrases {
|
||||||
TextField(
|
TextField(
|
||||||
lblAddPhraseTag3,
|
lblAddPhraseTag3,
|
||||||
text: $txtAddPhraseField3.onChange {
|
text: $txtAddPhraseField3.didChange {
|
||||||
guard let weightVal = Double(txtAddPhraseField3) else { return }
|
guard let weightVal = Double(txtAddPhraseField3) else { return }
|
||||||
if weightVal > 0 { txtAddPhraseField3 = "" }
|
if weightVal > 0 { txtAddPhraseField3 = "" }
|
||||||
}
|
}
|
||||||
|
@ -288,7 +290,7 @@ public struct VwrPhraseEditorUI: View {
|
||||||
HStack {
|
HStack {
|
||||||
Toggle(
|
Toggle(
|
||||||
LocalizedStringKey("This editor only: Auto-reload modifications happened outside of this editor"),
|
LocalizedStringKey("This editor only: Auto-reload modifications happened outside of this editor"),
|
||||||
isOn: $selAutoReloadExternalModifications.onChange {
|
isOn: $selAutoReloadExternalModifications.didChange {
|
||||||
Self.autoReloadExternalModifications = selAutoReloadExternalModifications
|
Self.autoReloadExternalModifications = selAutoReloadExternalModifications
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,13 +8,13 @@
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
// MARK: - Add "onChange" support.
|
// MARK: - Add "didChange" support to bindings.
|
||||||
|
|
||||||
// Ref: https://mjeld.com/swiftui-macos-10-15-toggle-onchange/
|
// Ref: https://mjeld.com/swiftui-macos-10-15-toggle-onchange/
|
||||||
|
|
||||||
@available(macOS 10.15, *)
|
@available(macOS 10.15, *)
|
||||||
public extension Binding {
|
public extension Binding {
|
||||||
func onChange(_ action: @escaping () -> Void) -> Binding {
|
func didChange(_ action: @escaping () -> Void) -> Binding {
|
||||||
Binding(
|
Binding(
|
||||||
get: {
|
get: {
|
||||||
wrappedValue
|
wrappedValue
|
||||||
|
|
Loading…
Reference in New Issue