Skip to content

Commit

Permalink
Merge branch 'release/9.1' into LT-21982
Browse files Browse the repository at this point in the history
  • Loading branch information
aror92 authored Nov 14, 2024
2 parents 05c7d3d + 3e559e7 commit 8dee1fe
Show file tree
Hide file tree
Showing 16 changed files with 308 additions and 301 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run: NDP461-DevPack-KB3105179-ENU.exe /q

- name: Setup dotnet
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
2.1.x
Expand Down
2 changes: 1 addition & 1 deletion Build/mkall.targets
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
<ParatextNugetVersion>9.4.0.1-beta</ParatextNugetVersion>
<LcmNugetVersion>11.0.0-beta0104</LcmNugetVersion>
<IcuNugetVersion>70.1.123</IcuNugetVersion>
<HermitCrabNugetVersion>3.4.1</HermitCrabNugetVersion>
<HermitCrabNugetVersion>3.4.2</HermitCrabNugetVersion>
<IPCFrameworkVersion>1.1.1-beta0001</IPCFrameworkVersion>
<!-- bt393 is the master branch build of ExCss for Windows development. Update when appropriate. -->
<ExCssBuildType Condition="'$(OS)'=='Windows_NT'">bt393</ExCssBuildType>
Expand Down
4 changes: 2 additions & 2 deletions Build/nuget-common/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
<package id="SIL.libpalaso.l10ns" version="6.0.0" targetFramework="net461" />
<package id="SIL.Lift" version="13.0.0-beta0076" targetFramework="net461" />
<package id="SIL.Media" version="13.0.0-beta0076" targetFramework="net461" />
<package id="SIL.Machine" version="3.4.1" targetFramework="netstandard2.0" />
<package id="SIL.Machine.Morphology.HermitCrab" version="3.4.1" targetFramework="netstandard2.0" />
<package id="SIL.Machine" version="3.4.2" targetFramework="netstandard2.0" />
<package id="SIL.Machine.Morphology.HermitCrab" version="3.4.2" targetFramework="netstandard2.0" />
<package id="SIL.ParatextShared" version="7.4.0.1" targetFramework="net40" /> <!-- REVIEW (Hasso) 2023.05: do we still integrate with PT 7? -->
<package id="SIL.Scripture" version="13.0.0-beta0076" targetFramework="net461" />
<package id="SIL.TestUtilities" version="13.0.0-beta0076" targetFramework="net461" />
Expand Down
5 changes: 3 additions & 2 deletions Src/xWorks/ConfigurableDictionaryNode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2017 SIL International
// Copyright (c) 2014-2017 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 @@ -334,7 +334,8 @@ internal ConfigurableDictionaryNode DeepCloneUnderParent(ConfigurableDictionaryN

public override int GetHashCode()
{
return Parent == null ? DisplayLabel.GetHashCode() : DisplayLabel.GetHashCode() ^ Parent.GetHashCode();
object hashingObject = DisplayLabel ?? FieldDescription;
return Parent == null ? hashingObject.GetHashCode() : hashingObject.GetHashCode() ^ Parent.GetHashCode();
}

public override bool Equals(object other)
Expand Down
11 changes: 9 additions & 2 deletions Src/xWorks/ConfiguredLcmGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ private static string GenerateSrcAttributeFromFilePath(ICmFile file, string subF
{
filePath = MakeSafeFilePath(file.AbsoluteInternalPath);
}
return filePath;
return (settings.UseRelativePaths || !settings.UseUri) ? filePath : new Uri(filePath).ToString();
}

private static string GenerateSrcAttributeForMediaFromFilePath(string filename, string subFolder, GeneratorSettings settings)
Expand Down Expand Up @@ -3175,6 +3175,8 @@ public class GeneratorSettings
public LcmCache Cache { get; }
public ReadOnlyPropertyTable PropertyTable { get; }
public bool UseRelativePaths { get; }

public bool UseUri { get; }
public bool CopyFiles { get; }
public string ExportPath { get; }
public bool RightToLeft { get; }
Expand All @@ -3186,8 +3188,12 @@ public GeneratorSettings(LcmCache cache, PropertyTable propertyTable, bool relat
{
}


public GeneratorSettings(LcmCache cache, ReadOnlyPropertyTable propertyTable, bool relativePaths, bool copyFiles, string exportPath, bool rightToLeft = false, bool isWebExport = false, bool isTemplate = false)
: this(cache, propertyTable == null ? null : propertyTable, relativePaths, true, copyFiles, exportPath, rightToLeft, isWebExport, isTemplate)
{
}

public GeneratorSettings(LcmCache cache, ReadOnlyPropertyTable propertyTable, bool relativePaths, bool useUri, bool copyFiles, string exportPath, bool rightToLeft = false, bool isWebExport = false, bool isTemplate = false)
{
if (cache == null || propertyTable == null)
{
Expand All @@ -3196,6 +3202,7 @@ public GeneratorSettings(LcmCache cache, ReadOnlyPropertyTable propertyTable, bo
Cache = cache;
PropertyTable = propertyTable;
UseRelativePaths = relativePaths;
UseUri = useUri;
CopyFiles = copyFiles;
ExportPath = exportPath;
RightToLeft = rightToLeft;
Expand Down
68 changes: 21 additions & 47 deletions Src/xWorks/DictionaryConfigurationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1558,14 +1558,12 @@ private static void SetIsEnabledForSubTree(ConfigurableDictionaryNode node, bool
}

/// <summary>
/// Search the TreeNode tree to find a starting node based on matching the "class"
/// attributes of the generated XHTML tracing back from the XHTML element clicked.
/// If no match is found, SelectedNode is not set. Otherwise, the best match found
/// is used to set SelectedNode.
/// Search the TreeNode tree to find a starting node based on nodeId attribute - a hash of a ConfigurableDictionaryNode
/// generated into the xhtml. If nothing is found SelectedNode is not set.
/// </summary>
internal void SetStartingNode(List<string> classList)
internal void SetStartingNode(string nodeId)
{
if (classList == null || classList.Count == 0)
if (string.IsNullOrEmpty(nodeId))
return;
if (View != null &&
View.TreeControl != null &&
Expand All @@ -1579,22 +1577,15 @@ internal void SetStartingNode(List<string> classList)
var configNode = node.Tag as ConfigurableDictionaryNode;
if (configNode == null)
continue;
var cssClass = CssGenerator.GetClassAttributeForConfig(configNode);
if (classList[0].Split(' ').Contains(cssClass))
topNode = FindConfigNode(configNode, nodeId, new List<ConfigurableDictionaryNode>());
if (topNode != null)
{
topNode = configNode;
break;
}
}
if (topNode == null)
return;
// We have a match, so search through the TreeNode tree to find the TreeNode tagged
// with the given configuration node. If found, set that as the SelectedNode.
classList.RemoveAt(0);
var startingConfigNode = FindConfigNode(topNode, classList);
foreach (TreeNode node in View.TreeControl.Tree.Nodes)
{
var startingTreeNode = FindMatchingTreeNode(node, startingConfigNode);
var startingTreeNode = FindMatchingTreeNode(node, topNode);
if (startingTreeNode != null)
{
View.TreeControl.Tree.SelectedNode = startingTreeNode;
Expand All @@ -1605,48 +1596,31 @@ internal void SetStartingNode(List<string> classList)
}

/// <summary>
/// Recursively descend the configuration tree, progressively matching nodes against CSS class path. Stop
/// when we run out of both tree and classes. Classes can be skipped if not matched. Running out of tree nodes
/// before running out of classes causes one level of backtracking up the configuration tree to look for a better match.
/// Recursively descend the configuration tree depth first until a matching nodeId is found
/// </summary>
/// <remarks>LT-17213 Now 'internal static' so DictionaryConfigurationDlg can use it.</remarks>
internal static ConfigurableDictionaryNode FindConfigNode(ConfigurableDictionaryNode topNode, List<string> classPath)
internal static ConfigurableDictionaryNode FindConfigNode(ConfigurableDictionaryNode topNode, string nodeId, List<ConfigurableDictionaryNode> visited)
{
if (classPath.Count == 0)
if (string.IsNullOrEmpty(nodeId) || $"{topNode.GetHashCode()}".Equals(nodeId))
{
return topNode; // what we have already is the best we can find.
}
visited.Add(topNode);

// If we can't go further down the configuration tree, but still have classes to match, back up one level
// and try matching with the remaining classes. The configuration tree doesn't always map exactly with
// the XHTML tree structure. For instance, in the XHTML, Examples contains instances of Example, each
// of which contains an instance of Translations, which contains instances of Translation. In the configuration
// tree, Examples contains Example and Translations at the same level.
if (topNode.ReferencedOrDirectChildren == null || topNode.ReferencedOrDirectChildren.Count == 0)
{
var match = FindConfigNode(topNode.Parent, classPath);
return ReferenceEquals(match, topNode.Parent)
? topNode // this is the best we can find.
: match; // we found something better!
}
ConfigurableDictionaryNode matchingNode = null;
foreach (var node in topNode.ReferencedOrDirectChildren)
if (topNode.ReferencedOrDirectChildren != null)
{
var cssClass = CssGenerator.GetClassAttributeForConfig(node);
// LT-17359 a reference node might have "senses mainentrysubsenses"
if (cssClass == classPath[0].Split(' ')[0])
foreach (var node in topNode.ReferencedOrDirectChildren)
{
matchingNode = node;
break;
if (visited.Contains(node))
continue;
var match = FindConfigNode(node, nodeId, visited);
if (match != null)
{
return match;
}
}
}
// If we didn't match, skip this class in the list and try the next class, looking at the same configuration
// node. There are classes in the XHTML that aren't represented in the configuration nodes. ("sensecontent"
// and "sense" among others)
if (matchingNode == null)
matchingNode = topNode;
classPath.RemoveAt(0);
return FindConfigNode(matchingNode, classPath);
return null;
}

/// <summary>
Expand Down
17 changes: 1 addition & 16 deletions Src/xWorks/DictionaryConfigurationDlg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,28 +230,13 @@ private static ConfigurableDictionaryNode GetTopLevelNode(ConfigurableDictionary
return childNode;
}

private static bool DoesGeckoElementOriginateFromConfigNode(ConfigurableDictionaryNode configNode, GeckoElement element,
ConfigurableDictionaryNode topLevelNode)
{
Guid dummyGuid;
GeckoElement dummyElement;
var classListForGeckoElement = XhtmlDocView.GetClassListFromGeckoElement(element, out dummyGuid, out dummyElement);
classListForGeckoElement.RemoveAt(0); // don't need the top level class
var nodeToMatch = DictionaryConfigurationController.FindConfigNode(topLevelNode, classListForGeckoElement);
return Equals(nodeToMatch, configNode);
}

private static IEnumerable<GeckoElement> FindMatchingSpans(ConfigurableDictionaryNode selectedNode, GeckoElement parent,
ConfigurableDictionaryNode topLevelNode, LcmCache cache)
{
var elements = new List<GeckoElement>();
var desiredClass = CssGenerator.GetClassAttributeForConfig(selectedNode);
if (ConfiguredLcmGenerator.IsCollectionNode(selectedNode, cache))
desiredClass = CssGenerator.GetClassAttributeForCollectionItem(selectedNode);
foreach (var span in parent.GetElementsByTagName("span"))
{
if (span.GetAttribute("class") != null && span.GetAttribute("class").Split(' ')[0] == desiredClass &&
DoesGeckoElementOriginateFromConfigNode(selectedNode, span, topLevelNode))
if (span.GetAttribute("nodeId") != null && span.GetAttribute("nodeId").Equals($"{selectedNode.GetHashCode()}"))
{
elements.Add(span);
}
Expand Down
Loading

0 comments on commit 8dee1fe

Please sign in to comment.