Skip to content
Open
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
39 changes: 25 additions & 14 deletions Src/FwParatextLexiconPlugin/FdoLexicon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Web;
using Paratext.LexicalContracts;
using SIL.LCModel.Core.Text;
using SIL.LCModel.Core.KernelInterfaces;
using SIL.FieldWorks.WordWorks.Parser;
using SIL.LCModel;
using SIL.LCModel.Core.KernelInterfaces;
using SIL.LCModel.Core.Text;
using SIL.LCModel.DomainImpl;
using SIL.LCModel.DomainServices;
using SIL.LCModel.Infrastructure;
using SIL.LCModel.Utils;
using SIL.FieldWorks.WordWorks.Parser;
using SIL.Machine.Morphology;
using SIL.ObjectModel;
using SIL.PlatformUtilities;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Web;
using XCore;
using WordAnalysis = Paratext.LexicalContracts.WordAnalysis;

namespace SIL.FieldWorks.ParatextLexiconPlugin
Expand All @@ -39,7 +40,8 @@ internal class FdoLexicon : DisposableBase, Paratext.LexicalContracts.Lexicon, W
private readonly int m_defaultVernWs;
private PoorMansStemmer<string, char> m_stemmer;
private readonly string m_projectId;

Mediator Mediator { get; set; }
PropertyTable PropertyTable { get; set; }
internal FdoLexicon(string scrTextName, string projectId, LcmCache cache, int defaultVernWs)
{
m_scrTextName = scrTextName;
Expand Down Expand Up @@ -79,6 +81,10 @@ protected override void DisposeManagedResources()
{
m_parser.Dispose();
m_parser = null;
Mediator.Dispose();
Mediator = null;
PropertyTable.Dispose();
PropertyTable = null;
}
}

Expand Down Expand Up @@ -646,7 +652,12 @@ private void InstantiateParser()
switch (m_cache.LanguageProject.MorphologicalDataOA.ActiveParser)
{
case "XAmple":
m_parser = new XAmpleParser(m_cache, parserDataDir);
// LT-22708 As of 2026.08.26, this is only called within FLEx from
// FdoLexiconTests.
// Creating the mediator and property table here works fine.
Mediator = new Mediator();
PropertyTable = new PropertyTable(Mediator);
m_parser = new XAmpleParser(m_cache, parserDataDir, PropertyTable);
break;
case "HC":
m_parser = new HCParser(m_cache);
Expand Down
13 changes: 10 additions & 3 deletions Src/LexText/ParserCore/ParserCoreTests/ParseWorkerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class ParseWorkerTests : MemoryOnlyBackendProviderTestBase
private String m_taskDetailsString;
private IdleQueue m_idleQueue;
private CoreWritingSystemDefinition m_vernacularWS;
Mediator Mediator { get; set; }
PropertyTable PropertyTable { get; set; }
#endregion Data Members

#region Non-test methods
Expand Down Expand Up @@ -67,14 +69,19 @@ public override void FixtureSetup()
base.FixtureSetup();
m_vernacularWS = Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem;
m_idleQueue = new IdleQueue {IsPaused = true};
Mediator = new Mediator();
PropertyTable = new PropertyTable(Mediator);
}

public override void FixtureTeardown()
{
m_vernacularWS = null;
m_idleQueue.Dispose();
m_idleQueue = null;

Mediator.Dispose();
Mediator = null;
PropertyTable.Dispose();
PropertyTable = null;
base.FixtureTeardown();
}

Expand Down Expand Up @@ -106,7 +113,7 @@ protected void UndoAll()
public void TryAWord()
{
XDocument lowerXDoc = new XDocument(new XComment("cats"));
var parserWorker = new ParserWorker(Cache, null, HandleTaskUpdate, m_idleQueue, null);
var parserWorker = new ParserWorker(Cache, PropertyTable, HandleTaskUpdate, m_idleQueue, null);
parserWorker.Parser = new TestParserClass(null, lowerXDoc);

// SUT
Expand Down Expand Up @@ -141,7 +148,7 @@ public void UpdateWordform()
});
});

var parserWorker = new ParserWorker(Cache, null, HandleTaskUpdate, m_idleQueue, null);
var parserWorker = new ParserWorker(Cache, PropertyTable, HandleTaskUpdate, m_idleQueue, null);
parserWorker.Parser = new TestParserClass(lowerResult, null);

// SUT
Expand Down
2 changes: 1 addition & 1 deletion Src/LexText/ParserCore/ParserWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ParserWorker(LcmCache cache, PropertyTable propertyTable, Action<TaskRepo
switch (m_cache.LanguageProject.MorphologicalDataOA.ActiveParser)
{
case "XAmple":
m_parser = new XAmpleParser(cache, dataDir);
m_parser = new XAmpleParser(cache, dataDir, m_propertyTable);
agent = cache.ServiceLocator.GetInstance<ICmAgentRepository>().GetObject(CmAgentTags.kguidAgentXAmpleParser);
break;
case "HC":
Expand Down
22 changes: 15 additions & 7 deletions Src/LexText/ParserCore/XAmpleParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

using SIL.FieldWorks.Common.FwUtils;
using SIL.LCModel;
using SIL.LCModel.DomainServices;
using SIL.LCModel.Infrastructure;
using SIL.ObjectModel;
using SIL.Xml;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -11,12 +17,8 @@
using System.Text;
using System.Xml;
using System.Xml.Linq;
using SIL.LCModel;
using SIL.LCModel.DomainServices;
using SIL.LCModel.Infrastructure;
using SIL.ObjectModel;
using SIL.Xml;
using XAmpleManagedWrapper;
using XCore;

namespace SIL.FieldWorks.WordWorks.Parser
{
Expand All @@ -25,6 +27,7 @@ public class XAmpleParser : DisposableBase, IParser
private static readonly char[] Digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

private XAmpleWrapper m_xample;
private PropertyTable m_propTable;
private readonly string m_dataDir;
private readonly LcmCache m_cache;
private ParserModelChangeListener m_changeListener;
Expand All @@ -33,7 +36,7 @@ public class XAmpleParser : DisposableBase, IParser
private bool m_forceUpdate;
private XElement xampleAddonFileRoot;

public XAmpleParser(LcmCache cache, string dataDir)
public XAmpleParser(LcmCache cache, string dataDir, PropertyTable propertyTable)
{
m_cache = cache;
m_xample = new XAmpleWrapper();
Expand All @@ -43,6 +46,7 @@ public XAmpleParser(LcmCache cache, string dataDir)
m_database = ConvertNameToUseAnsiCharacters(m_cache.ProjectId.Name);
m_transformer = new M3ToXAmpleTransformer(m_database);
m_forceUpdate = true;
m_propTable = propertyTable;
InitXAmpleAddonDataInfo();
}
private void InitXAmpleAddonDataInfo()
Expand All @@ -58,7 +62,11 @@ private void InitXAmpleAddonDataInfo()
{
xampleAddonFileRoot = doc.Root;
var preparer = new XAmplePropertiesPreparer(m_cache, xampleAddonFileRoot, false);
preparer.AddListsAndFields();
if (!preparer.ListsAlreadyAdded())
{
preparer.AddListsAndFields();
FwUtils.Publisher.Publish(new PublisherParameterObject(EventConstants.ReloadAreaTools, "lists", m_propTable.GetWindow()));
Comment thread
AndyBlack marked this conversation as resolved.
}
}
}
}
Expand Down
29 changes: 16 additions & 13 deletions Src/LexText/ParserCore/XAmplePropertiesPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Collections;
using System.Xml.XPath;
using XCore;

namespace SIL.FieldWorks.WordWorks.Parser
{
Expand Down Expand Up @@ -57,13 +57,24 @@ where fd.IsCustomField
select fd).ToList();
}

public Boolean ListsAlreadyAdded()
{
var possListRepository = Cache.ServiceLocator.GetInstance<ICmPossibilityListRepository>();
return possListRepository.AllInstances().Any(list => list.Name.BestAnalysisAlternative.Text == customListName);
}

public Boolean XAmplePropertiesCustomFieldAlreadyAdded(string fieldName, int fieldClassId)
Comment thread
AndyBlack marked this conversation as resolved.
{
var customFields = GetListOfCustomFields();
return customFields.Any(fd => fd.Name == fieldName && fd.Class == fieldClassId);
}

public void AddListsAndFields()
{
if (Root == null)
{
return;
}

AddXAmplePropertiesList();
var customFields = GetListOfCustomFields();
AddXAmplePropertiesCustomField(entryCustomFieldName, LexEntryTags.kClassId);
Expand All @@ -75,8 +86,7 @@ public void AddListsAndFields()
/// </summary>
public void AddXAmplePropertiesCustomField(string fieldName, int fieldClassId)
{
var customFields = GetListOfCustomFields();
if (customFields.Find(fd => fd.Name == fieldName) != null)
if (XAmplePropertiesCustomFieldAlreadyAdded(fieldName, fieldClassId))
{
// already done; quit
return;
Expand Down Expand Up @@ -117,22 +127,15 @@ public void AddXAmplePropertiesCustomField(string fieldName, int fieldClassId)
/// </summary>
public void AddXAmplePropertiesList()
{
if (Root == null)
if (Root == null || ListsAlreadyAdded())
{
// nothing to do
return;
}
var possListRepository = Cache.ServiceLocator.GetInstance<ICmPossibilityListRepository>();
var customList = possListRepository.AllInstances().FirstOrDefault(list => list.Name.BestAnalysisAlternative.Text == customListName);
if (customList != null)
{
return;
}
NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () =>
{
int ws = WritingSystemServices.kwsAnal;
Cache.ServiceLocator.GetInstance<ICmPossibilityListFactory>().CreateUnowned(customListName, ws);
customList = possListRepository.AllInstances().Last();
var customList = Cache.ServiceLocator.GetInstance<ICmPossibilityListFactory>().CreateUnowned(customListName, ws);
var propPoss = Cache.ServiceLocator.GetInstance<ICmCustomItemFactory>();
ws = Cache.DefaultAnalWs;
var elements = Root.XPathSelectElements("CustomList/Contents/Element");
Expand Down
3 changes: 2 additions & 1 deletion Src/Utilities/pcpatrflex/ToneParsFLExDll/ToneParsFLExForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,8 @@ private bool XAmpleFilesAreUpToDate()
Path.Combine(
FwDirectoryFinder.CodeDirectory,
FwDirectoryFinder.ksFlexFolderName
)
),
PropTable
);
}
return m_XAmpleParser.IsUpToDate();
Expand Down
Loading