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
26 changes: 12 additions & 14 deletions Src/xWorks/DictionaryConfigurationController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2017 SIL International
// Copyright (c) 2014-2026 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

Expand Down Expand Up @@ -551,46 +551,44 @@ public DictionaryConfigurationController(IDictionaryConfigurationView view, Prop
/// Note: homograph parameters are used for sense numbers in both the dictionary and reversal. They are never used for reversal numbers.
/// So, homograph parameters should always be set based on the dictionary configuration and not the reversal index configuration.
/// </summary>
/// <param name="model"></param>
/// <param name="cache"></param>
public static void SetConfigureHomographParameters(PropertyTable propertyTable, LcmCache cache)
{
var cacheHc = cache.ServiceLocator.GetInstance<HomographConfiguration>();

// Load the dictionary configuration.
var dictionaryConfigPath = propertyTable.GetStringProperty("DictionaryPublicationLayout", string.Empty);
var dictionaryConfigPath = DictionaryConfigurationListener.GetCurrentConfiguration(
propertyTable, false, DictionaryConfigurationListener.DictConfigDirName, null, false);
var dictionaryModel = new DictionaryConfigurationModel(dictionaryConfigPath, cache);
if (dictionaryModel.HomographConfiguration == null)
{
dictionaryModel.HomographConfiguration = new DictionaryHomographConfiguration(new HomographConfiguration());
}
dictionaryModel.HomographConfiguration ??=
new DictionaryHomographConfiguration(new HomographConfiguration());

ConfigurableDictionaryNode dictionarySenseNode = null;

if (dictionaryModel.Parts.Count > 0)
{
// Find the "Senses" node in the dictionary configuration
var dictionaryMainEntry = dictionaryModel.Parts[0];
dictionarySenseNode = dictionaryMainEntry.Children
.Where(prop => prop.Label == "Senses").FirstOrDefault();
dictionarySenseNode = dictionaryMainEntry.Children.FirstOrDefault(prop => prop.Label == "Senses");
}

if (dictionarySenseNode != null)
{
var cacheHc = cache.ServiceLocator.GetInstance<HomographConfiguration>();

var dictionarySenseOptions = (DictionaryNodeSenseOptions)dictionarySenseNode.DictionaryNodeOptions;
// Apply the dictionary sense numbering styles to the cache
cacheHc.ksSenseNumberStyle = dictionarySenseOptions.NumberingStyle;

// Similarly for subsenses
var dictionarySubSenseNode = dictionarySenseNode.Children.Where(prop => prop.Label == "Subsenses").FirstOrDefault();
var dictionarySubSenseNode = dictionarySenseNode.Children.FirstOrDefault(prop => prop.Label == "Subsenses");
if (dictionarySubSenseNode != null)
{
var dictionarySubSenseOptions = (DictionaryNodeSenseOptions)dictionarySubSenseNode.DictionaryNodeOptions;
cacheHc.ksSubSenseNumberStyle = dictionarySubSenseOptions.NumberingStyle;
cacheHc.ksParentSenseNumberStyle = dictionarySubSenseOptions.ParentSenseNumberingStyle;

// And for subsubsenses
var dictionarySubSubSenseNode = dictionarySubSenseNode.ReferencedOrDirectChildren.Where(prop => prop.Label == "Subsenses").FirstOrDefault();
var dictionarySubSubSenseNode =
dictionarySubSenseNode.ReferencedOrDirectChildren.FirstOrDefault(prop =>
prop.Label == "Subsenses");
if (dictionarySubSubSenseNode != null)
{
var dictionarySubSubSenseOptions = (DictionaryNodeSenseOptions)dictionarySubSubSenseNode.DictionaryNodeOptions;
Expand Down
37 changes: 12 additions & 25 deletions Src/xWorks/DictionaryConfigurationListener.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2016 SIL International
// Copyright (c) 2014-2026 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

Expand All @@ -8,16 +8,9 @@
using System.Linq;
using System.Windows.Forms;
using System.Xml;
using SIL.Extensions;
using SIL.FieldWorks.Common.FwUtils;
using static SIL.FieldWorks.Common.FwUtils.FwUtils;
using SIL.FieldWorks.Common.RootSites;
using SIL.FieldWorks.Common.Widgets;
using SIL.LCModel;
using SIL.LCModel.DomainImpl;
using SIL.FieldWorks.FwCoreDlgs;
using SIL.FieldWorks.XWorks.LexText;
using SIL.LCModel.Core.WritingSystems;
using XCore;
using SIL.FieldWorks.FdoUi;

Expand Down Expand Up @@ -268,36 +261,30 @@ public static string GetCurrentConfiguration(PropertyTable propertyTable, string
return GetCurrentConfiguration(propertyTable, true, innerConfigDir, obj);
}

private static void SetConfigureHomographParameters(PropertyTable propertyTable, LcmCache cache)
{
DictionaryConfigurationController.SetConfigureHomographParameters(propertyTable, cache);
}


/// <summary>
/// Returns the path to the current Dictionary or ReversalIndex configuration file, based on client specification or the current tool
/// Guarantees that the path is set to an existing configuration file, which may cause a redisplay of the XHTML view if fUpdate is true.
/// </summary>
public static string GetCurrentConfiguration(PropertyTable propertyTable, bool fUpdate, string innerConfigDir = null, ICmObject obj = null)
public static string GetCurrentConfiguration(PropertyTable propertyTable,
bool fBroadcastIfChanged, string innerConfigDir = null, ICmObject obj = null,
bool fSetConfigureHomographParameters = true)
{
// Since this is used in the display of the title and XWorksViews sometimes tries to display the title
// before full initialization (if this view is the one being displayed on startup) test the propertyTable before continuing.
if(propertyTable == null)
return null;
if (innerConfigDir == null)
{
innerConfigDir = GetInnermostConfigurationDirectory(propertyTable, obj) ??
ReversalIndexServices.RevIndexDir;
}
innerConfigDir ??= GetInnermostConfigurationDirectory(propertyTable, obj) ?? DictConfigDirName;
var pubLayoutPropName = GetPropNameForConfigType(innerConfigDir);
var currentConfig = pubLayoutPropName != null
? propertyTable.GetStringProperty(pubLayoutPropName, string.Empty)
: null;
var cache = propertyTable.GetValue<LcmCache>("cache");
if (!string.IsNullOrEmpty(currentConfig) && File.Exists(currentConfig))
{
var dictionaryConfigDir = GetProjectConfigurationDirectory(propertyTable, DictConfigDirName);
SetConfigureHomographParameters(propertyTable, cache);
if (fSetConfigureHomographParameters)
{
DictionaryConfigurationController.SetConfigureHomographParameters(propertyTable, cache);
}
return currentConfig;
}
var defaultConfigFileName = GetDefaultConfigFileName(innerConfigDir);
Expand All @@ -307,7 +294,7 @@ public static string GetCurrentConfiguration(PropertyTable propertyTable, bool f
// and the value is "publishSomething", try to use the new "Something" config
if (currentConfig != null && currentConfig.StartsWith("publish", StringComparison.Ordinal))
{
var selectedPublication = currentConfig.Replace("publish", string.Empty);
var selectedPublication = currentConfig.Substring("publish".Length);
if (innerConfigDir == RevIndexConfigDirName)
{
var languageCode = selectedPublication.Replace("Reversal-", string.Empty);
Expand All @@ -327,7 +314,7 @@ public static string GetCurrentConfiguration(PropertyTable propertyTable, bool f
// check in projectConfigDir for files whose name = default analysis ws
if (TryMatchingReversalConfigByWritingSystem(propertyTable, projectConfigDir, cache, out currentConfig))
{
propertyTable.SetProperty(pubLayoutPropName, currentConfig, fUpdate);
propertyTable.SetProperty(pubLayoutPropName, currentConfig, fBroadcastIfChanged);
return currentConfig;
}
}
Expand All @@ -340,7 +327,7 @@ public static string GetCurrentConfiguration(PropertyTable propertyTable, bool f
}
if (File.Exists(currentConfig) && pubLayoutPropName != null)
{
propertyTable.SetProperty(pubLayoutPropName, currentConfig, fUpdate);
propertyTable.SetProperty(pubLayoutPropName, currentConfig, fBroadcastIfChanged);
}
else if(pubLayoutPropName != null)
{
Expand Down
9 changes: 7 additions & 2 deletions Src/xWorks/DictionaryExportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,13 @@
if (progress != null)
progress.Maximum = entriesToSave.Length;

var dictConfig = new DictionaryConfigurationModel(
DictionaryConfigurationListener.GetCurrentConfiguration(m_propertyTable, "ReversalIndex"), m_cache);
// ReSharper disable once ObjectCreationAsStatement - The Reversal Configuration needs

Check warning on line 136 in Src/xWorks/DictionaryExportService.cs

View workflow job for this annotation

GitHub Actions / Report comment hygiene

comment-hygiene (comment-too-long)

254 chars (budget 200): ReSharper disable once ObjectCreationAsStatement - The Reversal Configuration needs
// to be loaded per https://github.com/sillsdev/FieldWorks/pull/939
// REVIEW (Hasso) 2026.08: why is this needed? The revConfig is passed in, so it must
// have been loaded already.
new DictionaryConfigurationModel(
DictionaryConfigurationListener.GetCurrentConfiguration(m_propertyTable,
"ReversalIndex"), m_cache);

string reversalFilePath = filePath.Split(new string[] { ".docx"}, StringSplitOptions.None)[0] + "-reversal-" + reversalWs + ".docx";
LcmWordGenerator.SavePublishedDocx(entriesToSave, revClerk, pubDecorator, int.MaxValue, revConfig, m_propertyTable,
Expand Down
27 changes: 26 additions & 1 deletion Src/xWorks/xWorksTests/DictionaryConfigurationControllerTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2017 SIL International
// Copyright (c) 2014-2026 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

Expand All @@ -17,6 +17,7 @@
using SIL.FieldWorks.Common.FwUtils;
using SIL.FieldWorks.Common.Widgets;
using SIL.LCModel;
using SIL.LCModel.DomainImpl;
using SIL.LCModel.DomainServices;
using SIL.LCModel.Infrastructure;
using SIL.LCModel.Utils;
Expand Down Expand Up @@ -44,6 +45,30 @@ public void Setup()
m_model = new DictionaryConfigurationModel();
}

[Test]
public void SetConfigureHomographParameters_InvalidPathInPropertyTable_UsesDefaultConfiguration()
{
var nonExistentPath = Path.Combine(Path.GetTempPath(),
Guid.NewGuid() + DictionaryConfigurationModel.FileExtension);
m_propertyTable.SetProperty("DictionaryPublicationLayout", nonExistentPath, false);

// set sense numbering styles to something other than the default to verify that
// values are loaded from the default configuration file.
var hc = Cache.ServiceLocator.GetInstance<HomographConfiguration>();
hc.ksSenseNumberStyle = "sense-";
hc.ksSubSenseNumberStyle = "numbing";
// not setting subsubsense numbering style because the default configuration file
// does not have a value for it

// SUT
DictionaryConfigurationController.SetConfigureHomographParameters(m_propertyTable, Cache);

Assert.That(hc, Is.Not.Null, "HomographConfiguration instance should exist");
Assert.That(hc.ksSenseNumberStyle, Is.EqualTo("%d"), "Sense numbering style should have been configured");
Assert.That(hc.ksSubSenseNumberStyle, Is.EqualTo("%d"), "Subsense numbering style should have been configured");
Assert.That(hc.ksSubSubSenseNumberStyle, Is.EqualTo("%d"), "Subsubsense numbering style should still be configured");
}

[OneTimeSetUp]
public override void FixtureSetup()
{
Expand Down
Loading