Skip to content

Commit d4ee1ba

Browse files
authored
Fix LT-22539: Loss of focus from gloss field (#931)
* Use EstablishDefaultSense to update the secondary cache * This also fixes LT-22541 * Allow for the case where a sense appears in more than one morpheme
1 parent 6edd67d commit d4ee1ba

4 files changed

Lines changed: 102 additions & 22 deletions

File tree

Src/LexText/Interlinear/FocusBoxController.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ internal bool IsDirty
4747
get { return m_sandbox.IsDirty; }
4848
}
4949

50+
private bool m_suppressFocusChange = false;
51+
5052
// There is no logical reason for other buttons ever to get the focus. But .NET helpfully focuses the link words button
5153
// as we hide the focus box. And in some other circumstance, which I can't even figure out, it focuses the menu button.
5254
// I can't figure out how to prevent it, but it's better for the confirm
@@ -263,7 +265,10 @@ internal void AdjustSizeAndLocationForControls(bool fAdjustOverallSize)
263265
}
264266
finally
265267
{
266-
Focus();
268+
if (!m_suppressFocusChange)
269+
{
270+
Focus();
271+
}
267272
m_fAdjustingSize = false;
268273
}
269274
}
@@ -310,6 +315,25 @@ public virtual void SelectOccurrence(AnalysisOccurrence selected)
310315
ChangeOrCreateSandbox(selected);
311316
}
312317

318+
public void UpdateField(int hvo, int flid)
319+
{
320+
if (IsDisposed || m_sandbox == null)
321+
{
322+
return;
323+
}
324+
325+
try
326+
{
327+
// This fixes LT-22539.
328+
m_suppressFocusChange = true;
329+
m_sandbox.UpdateField(hvo, flid);
330+
}
331+
finally
332+
{
333+
m_suppressFocusChange = false;
334+
}
335+
}
336+
313337
#endregion
314338

315339
internal bool MakeDefaultSelection(object parameter)
@@ -552,6 +576,7 @@ internal interface IAnalysisControlInternal
552576
int GetLineOfCurrentSelection();
553577
bool SelectOnOrBeyondLine(int startLine, int increment);
554578
void UpdateLineChoices(InterlinLineChoices choices);
579+
void UpdateField(int hvo, int flid);
555580
int MultipleAnalysisColor { set; }
556581
bool IsDirty { get; }
557582
}

Src/LexText/Interlinear/ITextDllTests/InterlinDocForAnalysisTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,11 @@ public void UpdateLineChoices(InterlinLineChoices choices)
558558
throw new NotImplementedException();
559559
}
560560

561+
public void UpdateField(int hvo, int flid)
562+
{
563+
throw new NotImplementedException();
564+
}
565+
561566
public int MultipleAnalysisColor
562567
{
563568
set { ; }

Src/LexText/Interlinear/InterlinDocForAnalysis.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,9 @@ public override void PropChanged(int hvo, int tag, int ivMin, int cvIns, int cvD
113113
MoveFocusBoxIntoPlace();
114114
}
115115
}
116-
if (IsFocusBoxInstalled && FocusBox.SelectedOccurrence != null
117-
&& tag == LexSenseTags.kflidGloss && FocusBox.ContainsLexEntry(hvo))
116+
if (IsFocusBoxInstalled && FocusBox.SelectedOccurrence != null)
118117
{
119-
// Somebody changed something in the sandbox. Reset the focus box to reflect the change.
120-
FocusBox.SelectOccurrence(FocusBox.SelectedOccurrence);
121-
MoveFocusBoxIntoPlace();
118+
FocusBox.UpdateField(hvo, tag);
122119
}
123120
}
124121

Src/LexText/Interlinear/SandboxBase.cs

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@
33
// (http://www.gnu.org/licenses/lgpl-2.1.html)
44

55
//#define TraceMouseCalls // uncomment this line to trace mouse messages
6-
using System;
7-
using System.Collections.Generic;
8-
using System.Drawing;
9-
using System.Linq;
10-
using System.Windows.Forms;
11-
using System.Diagnostics;
12-
using System.Text;
13-
using SIL.LCModel;
14-
using SIL.FieldWorks.Common.RootSites;
15-
using SIL.LCModel.Utils;
6+
using Icu.Collation;
167
using SIL.FieldWorks.Common.FwUtils;
8+
using SIL.FieldWorks.Common.RootSites;
179
using SIL.FieldWorks.Common.ViewsInterfaces;
18-
using SIL.FieldWorks.FdoUi;
1910
using SIL.FieldWorks.Common.Widgets;
20-
using SIL.LCModel.DomainServices;
21-
using SIL.LCModel.Infrastructure;
11+
using SIL.FieldWorks.FdoUi;
12+
using SIL.LCModel;
2213
using SIL.LCModel.Core.Cellar;
23-
using SIL.LCModel.Core.Text;
2414
using SIL.LCModel.Core.KernelInterfaces;
15+
using SIL.LCModel.Core.Text;
16+
using SIL.LCModel.DomainServices;
17+
using SIL.LCModel.Infrastructure;
18+
using SIL.LCModel.Utils;
2519
using SIL.PlatformUtilities;
26-
using XCore;
2720
using SIL.WritingSystems;
28-
using Icu.Collation;
21+
using System;
22+
using System.Collections.Generic;
23+
using System.Diagnostics;
24+
using System.Drawing;
25+
using System.Linq;
26+
using System.Text;
27+
using System.Windows.Forms;
28+
using XCore;
2929

3030
namespace SIL.FieldWorks.IText
3131
{
@@ -1656,6 +1656,43 @@ private int CreateSecondaryAndCopyStrings(int flidChoices, int hvoMain, int flid
16561656
m_caches.MainCache.MainCacheAccessor, m_caches.DataAccess as IVwCacheDa);
16571657
}
16581658

1659+
public void UpdateField(int hvo, int flid)
1660+
{
1661+
CheckDisposed();
1662+
if (!m_cache.ServiceLocator.IsValidObjectId(hvo))
1663+
{
1664+
return;
1665+
}
1666+
ICmObject hvoObject = Caches.MainCache.ServiceLocator.GetInstance<ICmObjectRepository>().GetObject(hvo);
1667+
if (hvoObject is ILexSense lexSense)
1668+
{
1669+
// This lex sense changed. Update morphs that use it.
1670+
foreach (int hvoMorph in GetHvoMorphsForLexSense(hvo))
1671+
{
1672+
// This fixes LT-22534.
1673+
EstablishDefaultSense(hvoMorph, lexSense.Entry, lexSense, null);
1674+
}
1675+
}
1676+
if (hvoObject != null && hvoObject.Owner is IMoMorphSynAnalysis msa)
1677+
{
1678+
if (msa.Owner is ILexEntry entry)
1679+
{
1680+
foreach (var sense in entry.AllSenses)
1681+
{
1682+
if (sense.MorphoSyntaxAnalysisRA == msa)
1683+
{
1684+
// This lex sense changed. Update morphs that use it.
1685+
foreach (int hvoMorph in GetHvoMorphsForLexSense(sense.Hvo))
1686+
{
1687+
// This fixes LT-22541.
1688+
EstablishDefaultSense(hvoMorph, entry, sense, null);
1689+
}
1690+
}
1691+
}
1692+
}
1693+
}
1694+
}
1695+
16591696
/// <summary>
16601697
/// Set the (real) LexEntry that is considered current. Broadcast a notification
16611698
/// to delegates if it changed.
@@ -3956,6 +3993,22 @@ protected List<int> LexSensesForCurrentMorphs()
39563993
return lexSensesForMorphs;
39573994
}
39583995

3996+
private IList<int> GetHvoMorphsForLexSense(int lexSense)
3997+
{
3998+
IList<int> hvoMorphs = new List<int>();
3999+
int cmorphs = m_caches.DataAccess.get_VecSize(kSbWord, ktagSbWordMorphs);
4000+
for (int i = 0; i < cmorphs; i++)
4001+
{
4002+
int hvoMorph = m_caches.DataAccess.get_VecItem(kSbWord, ktagSbWordMorphs, i);
4003+
int hvoMorphSense = m_caches.DataAccess.get_ObjectProp(hvoMorph, ktagSbMorphGloss);
4004+
if (m_caches.RealHvo(hvoMorphSense) == lexSense)
4005+
{
4006+
hvoMorphs.Add(hvoMorph);
4007+
}
4008+
}
4009+
return hvoMorphs;
4010+
}
4011+
39594012
/// <summary>
39604013
/// get the current dummy sandbox morphs
39614014
/// </summary>

0 commit comments

Comments
 (0)