Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LT-21980: Crash changing or modifying grammatical info #235

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Bin/_setLatestBuildConfig.bat
Bin/_setroot.bat
Lib/debug/DebugProcs.lib
Lib/debug/Generic.lib
Lib/debug/System.ValueTuple.dll
Lib/debug/unit++.*
Lib/release/DebugProcs.lib
Lib/release/Generic.lib
Expand Down
32 changes: 32 additions & 0 deletions Src/Common/Controls/DetailControls/MSAReferenceComboBoxSlice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class MSAReferenceComboBoxSlice : FieldSlice, IVwNotifyChange

//private bool m_processSelectionEvent = true;
private bool m_handlingMessage = false;
private bool m_forceRefresh = false;

/// ------------------------------------------------------------------------------------
/// <summary>
Expand Down Expand Up @@ -98,6 +99,8 @@ public override Mediator Mediator
m_MSAPopupTreeManager = new MSAPopupTreeManager(m_tree, m_cache, list,
m_tree.WritingSystemCode, true, m_mediator, m_propertyTable,
m_propertyTable.GetValue<Form>("window"));
m_MSAPopupTreeManager.BeforeChange += m_MSAPopupTreeManager_BeforeChange;
m_MSAPopupTreeManager.AfterChange += m_MSAPopupTreeManager_AfterChange;
m_MSAPopupTreeManager.AfterSelect += m_MSAPopupTreeManager_AfterSelect;
m_MSAPopupTreeManager.Sense = m_obj as ILexSense;
m_MSAPopupTreeManager.PersistenceProvider = m_persistProvider;
Expand Down Expand Up @@ -222,6 +225,33 @@ protected override void UpdateDisplayFromDatabase()
// What do we need to do here, if anything?
}

public void m_MSAPopupTreeManager_BeforeChange(object sender, TreeViewEventArgs e)
{
if (!ContainingDataTree.DoNotRefresh)
{
// Postpone refreshing the screen until m_MSAPopupTreeManager_AfterChange (LT-21980).
ContainingDataTree.DoNotRefresh = true;
m_forceRefresh = true;
}
}

public void m_MSAPopupTreeManager_AfterChange(object sender, TreeViewEventArgs e)
{
if (m_forceRefresh)
{
m_forceRefresh = false;
// We can't call RefreshDataTree directly,
// since that will cause Windows to crash accessing a disposed object.
// So, we queue it on the UI thread instead.
this.BeginInvoke(new Action(RefreshDataTree));
}
}

public void RefreshDataTree()
{
ContainingDataTree.DoNotRefresh = false;
}

private void m_MSAPopupTreeManager_AfterSelect(object sender, TreeViewEventArgs e)
{
// unless we get a mouse click or simulated mouse click (e.g. by ENTER or TAB),
Expand Down Expand Up @@ -286,7 +316,9 @@ private void m_MSAPopupTreeManager_AfterSelect(object sender, TreeViewEventArgs
// We still can't refresh the data at this point without causing a crash due to
// a pending Windows message. See LT-9713 and LT-9714.
if (ContainingDataTree.DoNotRefresh != fOldDoNotRefresh)
{
Mediator.BroadcastMessage("DelayedRefreshList", fOldDoNotRefresh);
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions Src/LexText/LexTextControls/MSAPopupTreeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class MSAPopupTreeManager : PopupTreeManager

#region Events

public event TreeViewEventHandler BeforeChange;
public event TreeViewEventHandler AfterChange;

#endregion Events

/// <summary>
Expand Down Expand Up @@ -419,11 +422,19 @@ private bool EditExistingMsa()
m_sense.MorphoSyntaxAnalysisRA.Hvo, true, m_sEditGramFunc);
if (dlg.ShowDialog(ParentForm) == DialogResult.OK)
{
if (BeforeChange != null)
{
BeforeChange(this, null);
}
Cache.DomainDataByFlid.BeginUndoTask(String.Format(LexTextControls.ksUndoSetX, FieldName),
String.Format(LexTextControls.ksRedoSetX, FieldName));
m_sense.SandboxMSA = dlg.SandboxMSA;
Cache.DomainDataByFlid.EndUndoTask();
LoadPopupTree(m_sense.MorphoSyntaxAnalysisRA.Hvo);
if (AfterChange != null)
{
AfterChange(this, null);
}
return true;
}
}
Expand Down
Loading