diff --git a/Mirivoice/Views/LineBoxView.axaml.cs b/Mirivoice/Views/LineBoxView.axaml.cs index 90a40a3..5dbc6b5 100644 --- a/Mirivoice/Views/LineBoxView.axaml.cs +++ b/Mirivoice/Views/LineBoxView.axaml.cs @@ -93,8 +93,12 @@ public bool ShouldPhonemize if (value) { - PhonemizeLine(); - DeActivatePhonemizer = true; + Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(async () => + { + await PhonemizeLine(); + _shouldPhonemize = false; + DeActivatePhonemizer = true; + }); } } } @@ -131,7 +135,7 @@ private async Task PhonemizeLine(bool ApplyToCurrentEdit = true) } else { - await Task.Run(() => viewModel.phonemizer.PhonemizeAsync(textChanged, this, ApplyToCurrentEdit)); + await Task.Run(() => viewModel.phonemizer.PhonemizeAsync(textChanged, this)); lastPhonemizedText = textChanged; } @@ -157,7 +161,7 @@ private async Task PhonemizeLine(bool ApplyToCurrentEdit = true) public bool ShouldPhonemizeWhenSelected = false; - SingleLineEditorView singleLineEditorView; + public SingleLineEditorView singleLineEditorView; public ObservableCollection MResultsCollection { get; set; } = new ObservableCollection(); @@ -549,6 +553,16 @@ private void OnDragStart(object sender, RoutedEventArgs e) } } + if (singleLineEditorView is not null && lastPhonemizedText is not null && singleLineEditorView.viewModel.mTextBoxEditor.CurrentScript is not null) + { + if (!lastPhonemizedText.Equals(singleLineEditorView.viewModel.mTextBoxEditor.CurrentScript)) + { + DeActivatePhonemizer = false; + ShouldPhonemize = true; + } + } + + if (v.CurrentLineBox != this) { diff --git a/Mirivoice/Views/SingleLineEditorView.axaml.cs b/Mirivoice/Views/SingleLineEditorView.axaml.cs index 097123c..000074d 100644 --- a/Mirivoice/Views/SingleLineEditorView.axaml.cs +++ b/Mirivoice/Views/SingleLineEditorView.axaml.cs @@ -28,18 +28,23 @@ public SingleLineEditorView(LineBoxView lineBoxView, bool FirstUpdate = true) bool ShouldPhonemizeWhenOutFocused = false; - private async void LineTextChanging(object sender, TextChangingEventArgs e) + private void LineTextChanging(object sender, TextChangingEventArgs e) { l.DeActivatePhonemizer = false; if (FirstUpdate) { FirstUpdate = false; - Task.Run(() => l.viewModel.phonemizer.PhonemizeAsync(viewModel.mTextBoxEditor.CurrentScript, l)); + l.DeActivatePhonemizer = false; + l.ShouldPhonemize = true; return; } - if (l.lastPhonemizedText != l.viewModel.LineText) + + if (l.singleLineEditorView is not null && l.lastPhonemizedText is not null && l.singleLineEditorView.viewModel.mTextBoxEditor.CurrentScript is not null) { - ShouldPhonemizeWhenOutFocused = true; + if (!l.lastPhonemizedText.Equals(l.singleLineEditorView.viewModel.mTextBoxEditor.CurrentScript)) + { + ShouldPhonemizeWhenOutFocused = true; + } } if (l.ShouldPhonemize && !l.DeActivatePhonemizer) { @@ -54,26 +59,30 @@ private void LineLostFocus(object sender, RoutedEventArgs e) l.viewModel.LineText = viewModel.mTextBoxEditor.CurrentScript; //Log.Information("SingleLineTBox Lost Focus"); //Log.Debug($"lastPhonemizedText={l.lastPhonemizedText} // LineText={l.viewModel.LineText}"); - if (l.lastPhonemizedText != l.viewModel.LineText) + if (l.singleLineEditorView is not null && l.lastPhonemizedText is not null && l.singleLineEditorView.viewModel.mTextBoxEditor.CurrentScript is not null) { - //Log.Debug("lastPhonemizedText != l.viewModel.LineText"); - l.DeActivatePhonemizer = false; - ShouldPhonemizeWhenOutFocused = true; - + if (!l.lastPhonemizedText.Equals(l.singleLineEditorView.viewModel.mTextBoxEditor.CurrentScript)) + { + l.DeActivatePhonemizer = false; + l.ShouldPhonemize = true; + } } + if (ShouldPhonemizeWhenOutFocused) { //Log.Debug("ShouldPhonemizeWhenOutFocused"); + l.DeActivatePhonemizer = false; l.ShouldPhonemize = true; - Task.Run(() => l.viewModel.phonemizer.PhonemizeAsync(viewModel.mTextBoxEditor.CurrentScript, l)); + ShouldPhonemizeWhenOutFocused = false; } if (FirstUpdate) { FirstUpdate = false; - Task.Run(() => l.viewModel.phonemizer.PhonemizeAsync(viewModel.mTextBoxEditor.CurrentScript, l)); + l.DeActivatePhonemizer = false; + l.ShouldPhonemize = true; return; } @@ -99,7 +108,7 @@ private void InitializeComponent(LineBoxView l) DataContext = viewModel = new SingleLineEditorViewModel(l.viewModel.LineText); } - public async void SetLine(string text) + public void SetLine(string text) { if (text == null) {