Skip to content

Commit

Permalink
added an async delay to Form.Activated so that it would behave better…
Browse files Browse the repository at this point in the history
… (it was treating the mouse like drag-drop mode when you clicked in the edit box when it wasn't activated)
  • Loading branch information
bobeaton committed Jun 30, 2024
1 parent ec87207 commit 6a979e3
Showing 1 changed file with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<IEncConverter> theTranslators)
{
Expand Down

0 comments on commit 6a979e3

Please sign in to comment.