Skip to content

Commit 028fef1

Browse files
authored
Fix LT-21461: Problems with Choose Allomorph dialog box (#347)
* Fix LT-21461: Problems with Choose Allomorph dialog box * Filter lex entries only have abstract forms * Response to comments from Mark
1 parent ac7dd96 commit 028fef1

3 files changed

Lines changed: 50 additions & 1 deletion

File tree

Src/Common/Controls/XMLViews/MatchingObjectsBrowser.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2014-2017 SIL International
1+
// Copyright (c) 2014-2017 SIL International
22
// This software is licensed under the LGPL, version 2.1 or later
33
// (http://www.gnu.org/licenses/lgpl-2.1.html)
44

@@ -139,6 +139,16 @@ public ICmObject StartingObject
139139
}
140140
}
141141

142+
/// <summary>
143+
/// Delegate for FilterResult.
144+
/// </summary>
145+
public delegate bool FilterResultDelegate(int hvo);
146+
147+
/// <summary>
148+
/// Should we filter a result?
149+
/// </summary>
150+
public FilterResultDelegate FilterResult;
151+
142152
/// <summary>
143153
/// Used by a Find dialog's SearchEngine to determine whether to search on a particular field or not
144154
/// </summary>
@@ -384,6 +394,8 @@ private void UpdateResults(SearchField firstField, IEnumerable<int> results)
384394
hvos = results.Where(hvo => StartingObject == null || StartingObject.Hvo != hvo).ToArray();
385395
}
386396

397+
if (FilterResult != null)
398+
hvos = hvos.Where(hvo => !FilterResult(hvo)).ToArray();
387399
int count = hvos.Length;
388400
int prevIndex = m_bvMatches.SelectedIndex;
389401
int prevHvo = prevIndex == -1 ? 0 : m_bvMatches.AllItems[prevIndex];

Src/Common/FieldWorks/FieldWorks.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,12 @@ private static void EnsureDefaultCollationsPresent(LcmCache cache)
877877
ws.DefaultCollation = new IcuRulesCollationDefinition("standard");
878878
nullCollationWs.Append(ws.DisplayLabel + ",");
879879
}
880+
// Check for invalid collation here rather than in RecordSorter to avoid LT-21461 problem.
881+
// This may also repair the previous if statement.
882+
if (ws != null && ws.DefaultCollation != null && InvalidCollation(ws.DefaultCollation))
883+
{
884+
ws.DefaultCollation = new SystemCollationDefinition { LanguageTag = ws.LanguageTag };
885+
}
880886
}
881887
if (nullCollationWs.Length > 0)
882888
{
@@ -887,6 +893,17 @@ private static void EnsureDefaultCollationsPresent(LcmCache cache)
887893
cache.ServiceLocator.WritingSystemManager.Save();
888894
}
889895

896+
/// <summary>
897+
/// An ICURulesCollationDefinition with empty rules was causing access violations in ICU. (LT-20268)
898+
/// This method supports the band-aid fallback to SystemCollationDefinition.
899+
/// </summary>
900+
/// <returns>true if the CollationDefinition is invalid or is a RulesCollationDefinition with empty rules</returns>
901+
private static bool InvalidCollation(CollationDefinition cd)
902+
{
903+
return !cd.IsValid || (cd is RulesCollationDefinition ? string.IsNullOrEmpty(((RulesCollationDefinition)cd).CollationRules) : false);
904+
}
905+
906+
890907
/// <summary>
891908
/// Ensure a valid folder for LangProject.LinkedFilesRootDir. When moving projects
892909
/// between systems, the stored value may become hopelessly invalid. See FWNX-1005

Src/LexText/LexTextControls/LinkAllomorphDlg.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public override void SetDlgInfo(LcmCache cache, WindowParams wp, Mediator mediat
136136
base.SetDlgInfo(cache, wp, mediator, propertyTable);
137137
// This is needed to make the replacement MatchingEntriesBrowser visible:
138138
Controls.SetChildIndex(m_matchingObjectsBrowser, 0);
139+
m_matchingObjectsBrowser.FilterResult = FilterLexEntry;
139140

140141
m_fwcbAllomorphs.WritingSystemFactory = cache.WritingSystemFactory;
141142
m_fwcbAllomorphs.WritingSystemCode = cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem.Handle;
@@ -150,6 +151,25 @@ public override void SetDlgInfo(LcmCache cache, WindowParams wp, Mediator mediat
150151

151152
#region Other methods
152153

154+
/// <summary>
155+
/// Filter hvo if all of its forms are abstract.
156+
/// </summary>
157+
private bool FilterLexEntry(int hvo)
158+
{
159+
ILexEntry entry = m_cache.ServiceLocator.GetObject(hvo) as ILexEntry;
160+
if (entry == null)
161+
return false;
162+
var lf = entry.LexemeFormOA;
163+
if (lf != null && !lf.IsAbstract)
164+
return false;
165+
foreach (var allo in entry.AlternateFormsOS)
166+
{
167+
if (!allo.IsAbstract)
168+
return false;
169+
}
170+
return true;
171+
}
172+
153173
protected override void HandleMatchingSelectionChanged()
154174
{
155175
if (m_selObject == null)

0 commit comments

Comments
 (0)