Skip to content

Commit 8b28936

Browse files
committed
Use EstablishDefaultSense to update the secondary cache
1 parent 1848ae2 commit 8b28936

6 files changed

Lines changed: 72 additions & 30 deletions

File tree

Src/Common/FwUtils/EventConstants.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public static class EventConstants
3333
public const string RefreshCurrentList = "RefreshCurrentList";
3434
public const string RefreshInterlin = "RefreshInterlin";
3535
public const string RefreshPopupWindowFonts = "RefreshPopupWindowFonts";
36-
public const string RefreshSandbox = "RefreshSandbox";
3736
public const string ReloadAreaTools = "ReloadAreaTools";
3837
public const string RemoveFilters = "RemoveFilters";
3938
public const string RestoreScrollPosition = "RestoreScrollPosition";

Src/LexText/Interlinear/FocusBoxController.cs

Lines changed: 21 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 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 (!suppressFocusChange)
269+
{
270+
Focus();
271+
}
267272
m_fAdjustingSize = false;
268273
}
269274
}
@@ -310,6 +315,20 @@ public virtual void SelectOccurrence(AnalysisOccurrence selected)
310315
ChangeOrCreateSandbox(selected);
311316
}
312317

318+
public void UpdateField(int hvo, int flid)
319+
{
320+
try
321+
{
322+
// This fixes LT-22539.
323+
suppressFocusChange = true;
324+
m_sandbox.UpdateField(hvo, flid);
325+
}
326+
finally
327+
{
328+
suppressFocusChange = false;
329+
}
330+
}
331+
313332
#endregion
314333

315334
internal bool MakeDefaultSelection(object parameter)
@@ -552,6 +571,7 @@ internal interface IAnalysisControlInternal
552571
int GetLineOfCurrentSelection();
553572
bool SelectOnOrBeyondLine(int startLine, int increment);
554573
void UpdateLineChoices(InterlinLineChoices choices);
574+
void UpdateField(int hvo, int flid);
555575
int MultipleAnalysisColor { set; }
556576
bool IsDirty { get; }
557577
}

Src/LexText/Interlinear/InterlinDocForAnalysis.Designer.cs

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Src/LexText/Interlinear/InterlinDocForAnalysis.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,6 @@ public InterlinDocForAnalysis()
4747
InitializeComponent();
4848
RightMouseClickedEvent += InterlinDocForAnalysis_RightMouseClickedEvent;
4949
DoSpellCheck = true;
50-
FwUtils.Subscriber.Subscribe(EventConstants.RefreshSandbox, RefreshSandbox);
51-
}
52-
53-
private void RefreshSandbox(object commandObject)
54-
{
55-
if (IsFocusBoxInstalled && FocusBox.SelectedOccurrence != null)
56-
{
57-
FocusBox.SelectOccurrence(FocusBox.SelectedOccurrence);
58-
MoveFocusBoxIntoPlace();
59-
}
6050
}
6151

6252
void InterlinDocForAnalysis_RightMouseClickedEvent(SimpleRootSite sender, FwRightMouseClickEventArgs e)
@@ -123,6 +113,10 @@ public override void PropChanged(int hvo, int tag, int ivMin, int cvIns, int cvD
123113
MoveFocusBoxIntoPlace();
124114
}
125115
}
116+
if (IsFocusBoxInstalled && FocusBox.SelectedOccurrence != null)
117+
{
118+
FocusBox.UpdateField(hvo, tag);
119+
}
126120
}
127121

128122
protected override void UpdateWordforms(HashSet<IWfiWordform> wordforms)

Src/LexText/Interlinear/SandboxBase.cs

Lines changed: 47 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,22 @@ 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+
int hvoMorph = GetHvoMorphForLexSense(hvo);
1662+
if (hvoMorph != 0)
1663+
{
1664+
ILexSense lexSense = Caches.MainCache.ServiceLocator.GetInstance<ILexSenseRepository>().GetObject(hvo);
1665+
ILexEntry lexEntry = lexSense?.Owner as ILexEntry;
1666+
if (lexSense != null && lexEntry != null)
1667+
{
1668+
// This fixes LT-22534.
1669+
EstablishDefaultSense(hvoMorph, lexEntry, lexSense, null);
1670+
}
1671+
1672+
}
1673+
}
1674+
16591675
/// <summary>
16601676
/// Set the (real) LexEntry that is considered current. Broadcast a notification
16611677
/// to delegates if it changed.
@@ -3956,6 +3972,21 @@ protected List<int> LexSensesForCurrentMorphs()
39563972
return lexSensesForMorphs;
39573973
}
39583974

3975+
private int GetHvoMorphForLexSense(int lexSense)
3976+
{
3977+
int cmorphs = m_caches.DataAccess.get_VecSize(kSbWord, ktagSbWordMorphs);
3978+
for (int i = 0; i < cmorphs; i++)
3979+
{
3980+
int hvoMorph = m_caches.DataAccess.get_VecItem(kSbWord, ktagSbWordMorphs, i);
3981+
int hvoMorphSense = m_caches.DataAccess.get_ObjectProp(hvoMorph, ktagSbMorphGloss);
3982+
if (m_caches.RealHvo(hvoMorphSense) == lexSense)
3983+
{
3984+
return hvoMorph;
3985+
}
3986+
}
3987+
return 0;
3988+
}
3989+
39593990
/// <summary>
39603991
/// get the current dummy sandbox morphs
39613992
/// </summary>

Src/xWorks/PopupToolWindow.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ private void PopupToolWindow_Deactivate(object sender, EventArgs e)
5959
{
6060
oldActiveClerk.ActivateUI(oldUseRecordTreeBar, oldOldUpdateStatusBar);
6161
}
62-
FwUtils.Publisher.Publish(new PublisherParameterObject("RefreshSandbox"));
6362
}
6463

6564
private void PopupToolWindow_Activated(object sender, EventArgs e)

0 commit comments

Comments
 (0)