From 6a979e39a7c47122c2f2d5c0d908d937bdaa1c79 Mon Sep 17 00:00:00 2001 From: bobeaton Date: Sat, 29 Jun 2024 19:11:06 -0500 Subject: [PATCH] added an async delay to Form.Activated so that it would behave better (it was treating the mouse like drag-drop mode when you clicked in the edit box when it wasn't activated) --- .../BackTranslationHelperForm.cs | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/ParatextPluginBackTranslationHelper/BackTranslationHelperForm.cs b/src/ParatextPluginBackTranslationHelper/BackTranslationHelperForm.cs index 28dfecf..8d6afca 100644 --- a/src/ParatextPluginBackTranslationHelper/BackTranslationHelperForm.cs +++ b/src/ParatextPluginBackTranslationHelper/BackTranslationHelperForm.cs @@ -1338,33 +1338,38 @@ private void BackTranslationHelperForm_Deactivate(object sender, EventArgs e) private bool disableActivateRefreshUntilNextVerse = true; // require us to wait to do activate refresh until we get the converters situated - private void BackTranslationHelperForm_Activated(object sender, EventArgs e) + private async void BackTranslationHelperForm_Activated(object sender, EventArgs e) { _isNotInFocus = false; - System.Diagnostics.Debug.WriteLine($"PtxBTH: BackTranslationHelperForm_Activated: _isNotInFocus = '{_isNotInFocus}', IsModified: {backTranslationHelperCtrl.IsModified}, _verseReference: {_verseReference}"); -#if false - // THIS is now done in ScriptureDataChangedHandlerSource & ScriptureDataChangedHandlerTarget - // make the source and target data stale, and trigger a requery... - PurgeSourceData(_verseReference); + // Allow any pending UI events to process before starting the lengthy operation + // (possibly including allowing backTranslationHelperCtrl.IsModified and the + // disableActivateRefreshUntilNextVerse flag getting set), either of which + // would block calling GetNewReference--e.g. if the user clicks the 'Close' button) + // Otherwise, we can get some bogus MouseDown/Up events that cause the editable + // textbox to annoyingly be in 'select text/drag' mode. + await Task.Delay(100); - var bookChapterKey = GetBookChapterKey(_verseReference); - if (UsfmTokensTarget.ContainsKey(bookChapterKey)) - { - UsfmTokensTarget.Remove(bookChapterKey); - } -#endif + System.Diagnostics.Debug.WriteLine($"PtxBTH: BackTranslationHelperForm_Activated: _isNotInFocus = '{_isNotInFocus}', IsModified: {backTranslationHelperCtrl.IsModified}, _verseReference: {_verseReference}"); // unless we were editing it, and then force it to stay the same - if (backTranslationHelperCtrl.IsModified) - return; + // UPDATE: if the user made changes in Paratext, activated the form by clicking + // save changes, then if we don't update to the changes they made, we'll end + // up writing the old version before their changes... so we really do want to + // call GetNewReference below even if it's modified, and we solve this by + // returning nothing from CurrentTargetData if it's modified, causing the ctrl's + // UpdateData to just use what's in the edit box instead. + //if (backTranslationHelperCtrl.IsModified) + // return; // we have this issue that if we launch a dialog (and thus become inactive), when that // dialog goes away, it looks like we need to refresh... But this can get us into near // infinite loops, so have a way to disable this until we get to another verse if (!disableActivateRefreshUntilNextVerse) + { GetNewReference(_verseReference); } + } public void TranslatorSetChanged(List theTranslators) {