From 394b590082b669a0059a36fd7858210bad2f03d5 Mon Sep 17 00:00:00 2001 From: mark-sil Date: Wed, 4 Sep 2024 11:40:17 -0400 Subject: [PATCH 1/2] Word Export: Add missing Before/After/Between content - Add between content for CrossRreference types. - Add before and after content for LexicalRelations->Targets. Note: I think passing child to AddCollection() is the correct node for the collection being added. The other implementations of AddCollection() do not use this parameter so they are not affected. This fixes one of the issues identified in LT-21808. Change-Id: I15e621b70f0fe278051e9b922925ecb1373fb333 --- Src/xWorks/ConfiguredLcmGenerator.cs | 5 ++++- Src/xWorks/ILcmContentGenerator.cs | 1 + Src/xWorks/LcmJsonGenerator.cs | 4 ++++ Src/xWorks/LcmWordGenerator.cs | 25 +++++++++++++++++++++++++ Src/xWorks/LcmXhtmlGenerator.cs | 4 ++++ 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Src/xWorks/ConfiguredLcmGenerator.cs b/Src/xWorks/ConfiguredLcmGenerator.cs index dfde8ff89a..c12d48efb7 100644 --- a/Src/xWorks/ConfiguredLcmGenerator.cs +++ b/Src/xWorks/ConfiguredLcmGenerator.cs @@ -2005,9 +2005,12 @@ private static void GenerateContentForLexRefCollection(ConfigurableDictionaryNod var organizedRefs = SortAndFilterLexRefsAndTargets(collection, cmOwner, config); // Now that we have things in the right order, try outputting one type at a time + bool first = true; foreach (var referenceList in organizedRefs) { var xBldr = GenerateCrossReferenceChildren(config, pubDecorator, referenceList, cmOwner, settings); + settings.ContentGenerator.BetweenCrossReferenceType(xBldr, config, first); + first = false; bldr.Append(xBldr); } } @@ -2119,7 +2122,7 @@ private static IFragment GenerateCrossReferenceChildren(ConfigurableDictionaryNo if (!content.IsNullOrEmpty()) { // targets - settings.ContentGenerator.AddCollection(xw, config, IsBlockProperty(child), + settings.ContentGenerator.AddCollection(xw, child, IsBlockProperty(child), CssGenerator.GetClassAttributeForConfig(child), content); settings.StylesGenerator.AddStyles(child); } diff --git a/Src/xWorks/ILcmContentGenerator.cs b/Src/xWorks/ILcmContentGenerator.cs index e15bf53fab..ec8282bedb 100644 --- a/Src/xWorks/ILcmContentGenerator.cs +++ b/Src/xWorks/ILcmContentGenerator.cs @@ -61,6 +61,7 @@ IFragment GenerateGroupingNode(ConfigurableDictionaryNode config, object field, IFragment AddLexReferences(ConfigurableDictionaryNode config, bool generateLexType, IFragment lexTypeContent, string className, IFragment referencesContent, bool typeBefore); void BeginCrossReference(IFragmentWriter writer, ConfigurableDictionaryNode config, bool isBlockProperty, string className); void EndCrossReference(IFragmentWriter writer); + void BetweenCrossReferenceType(IFragment content, ConfigurableDictionaryNode node, bool first); IFragment WriteProcessedSenses(ConfigurableDictionaryNode config, bool isBlock, IFragment senseContent, string className, IFragment sharedCollectionInfo); IFragment AddAudioWsContent(string wsId, Guid linkTarget, IFragment fileContent); IFragment GenerateErrorContent(StringBuilder badStrBuilder); diff --git a/Src/xWorks/LcmJsonGenerator.cs b/Src/xWorks/LcmJsonGenerator.cs index 88c4a40604..23c0f5ebe4 100644 --- a/Src/xWorks/LcmJsonGenerator.cs +++ b/Src/xWorks/LcmJsonGenerator.cs @@ -411,6 +411,10 @@ public void EndCrossReference(IFragmentWriter writer) ((JsonFragmentWriter)writer).InsertRawJson(","); } + public void BetweenCrossReferenceType(IFragment content, ConfigurableDictionaryNode node, bool first) + { + } + /// /// Generates data for all senses of an entry. For better processing of json add sharedGramInfo as a separate property object /// diff --git a/Src/xWorks/LcmWordGenerator.cs b/Src/xWorks/LcmWordGenerator.cs index 40e6de8ae9..a01ef59a8c 100644 --- a/Src/xWorks/LcmWordGenerator.cs +++ b/Src/xWorks/LcmWordGenerator.cs @@ -1440,10 +1440,24 @@ public void EndEntry(IFragmentWriter writer) } public void AddCollection(IFragmentWriter writer, ConfigurableDictionaryNode config, bool isBlockProperty, string className, IFragment content) { + // Add Before text. + if (!string.IsNullOrEmpty(config.Before)) + { + var beforeRun = CreateBeforeAfterBetweenRun(config.Before); + ((WordFragmentWriter)writer).WordFragment.DocBody.Append(beforeRun); + } + if (!content.IsNullOrEmpty()) { ((WordFragmentWriter)writer).WordFragment.Append(content); } + + // Add After text. + if (!string.IsNullOrEmpty(config.After)) + { + var afterRun = CreateBeforeAfterBetweenRun(config.After); + ((WordFragmentWriter)writer).WordFragment.DocBody.Append(afterRun); + } } public void BeginObjectProperty(IFragmentWriter writer, ConfigurableDictionaryNode config, bool isBlockProperty, string getCollectionItemClassAttribute) { @@ -1606,6 +1620,17 @@ public void EndCrossReference(IFragmentWriter writer) { return; } + + public void BetweenCrossReferenceType(IFragment content, ConfigurableDictionaryNode node, bool first) + { + // Add Between text if it is not the first item in the collection. + if (!first && !string.IsNullOrEmpty(node.Between)) + { + var betweenRun = CreateBeforeAfterBetweenRun(node.Between); + ((DocFragment)content).DocBody.PrependChild(betweenRun); + } + } + public IFragment WriteProcessedSenses(ConfigurableDictionaryNode config, bool isBlock, IFragment senseContent, string className, IFragment sharedGramInfo) { // Add Before text for the senses. diff --git a/Src/xWorks/LcmXhtmlGenerator.cs b/Src/xWorks/LcmXhtmlGenerator.cs index 782b60372a..9a0316f621 100644 --- a/Src/xWorks/LcmXhtmlGenerator.cs +++ b/Src/xWorks/LcmXhtmlGenerator.cs @@ -992,6 +992,10 @@ public void EndCrossReference(IFragmentWriter writer) EndObject(writer); } + public void BetweenCrossReferenceType(IFragment content, ConfigurableDictionaryNode node, bool first) + { + } + public IFragment WriteProcessedSenses(ConfigurableDictionaryNode config, bool isBlock, IFragment sensesContent, string classAttribute, IFragment sharedGramInfo) { sharedGramInfo.Append(sensesContent); From a2c841bce8d5957f373f322a39cce3323e2aec1b Mon Sep 17 00:00:00 2001 From: mark-sil Date: Wed, 4 Sep 2024 13:36:17 -0400 Subject: [PATCH 2/2] Word Export: Add missing Before/After/Between content - Add between content for CrossRreference types. - Add before and after content for LexicalRelations->Targets. Note: I think passing child to AddCollection() is the correct node for the collection being added. The other implementations of AddCollection() do not use this parameter so they are not affected. This fixes one of the issues identified in LT-21808. Change-Id: I2bfbea70752fb0acfdd98d550753256b54783e33 --- Src/xWorks/ConfiguredLcmGenerator.cs | 6 +++--- Src/xWorks/ILcmContentGenerator.cs | 2 +- Src/xWorks/LcmJsonGenerator.cs | 2 +- Src/xWorks/LcmWordGenerator.cs | 4 ++-- Src/xWorks/LcmXhtmlGenerator.cs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Src/xWorks/ConfiguredLcmGenerator.cs b/Src/xWorks/ConfiguredLcmGenerator.cs index c12d48efb7..1fd8220138 100644 --- a/Src/xWorks/ConfiguredLcmGenerator.cs +++ b/Src/xWorks/ConfiguredLcmGenerator.cs @@ -2005,12 +2005,12 @@ private static void GenerateContentForLexRefCollection(ConfigurableDictionaryNod var organizedRefs = SortAndFilterLexRefsAndTargets(collection, cmOwner, config); // Now that we have things in the right order, try outputting one type at a time - bool first = true; + bool firstIteration = true; foreach (var referenceList in organizedRefs) { var xBldr = GenerateCrossReferenceChildren(config, pubDecorator, referenceList, cmOwner, settings); - settings.ContentGenerator.BetweenCrossReferenceType(xBldr, config, first); - first = false; + settings.ContentGenerator.BetweenCrossReferenceType(xBldr, config, firstIteration); + firstIteration = false; bldr.Append(xBldr); } } diff --git a/Src/xWorks/ILcmContentGenerator.cs b/Src/xWorks/ILcmContentGenerator.cs index ec8282bedb..753a07dc08 100644 --- a/Src/xWorks/ILcmContentGenerator.cs +++ b/Src/xWorks/ILcmContentGenerator.cs @@ -61,7 +61,7 @@ IFragment GenerateGroupingNode(ConfigurableDictionaryNode config, object field, IFragment AddLexReferences(ConfigurableDictionaryNode config, bool generateLexType, IFragment lexTypeContent, string className, IFragment referencesContent, bool typeBefore); void BeginCrossReference(IFragmentWriter writer, ConfigurableDictionaryNode config, bool isBlockProperty, string className); void EndCrossReference(IFragmentWriter writer); - void BetweenCrossReferenceType(IFragment content, ConfigurableDictionaryNode node, bool first); + void BetweenCrossReferenceType(IFragment content, ConfigurableDictionaryNode node, bool firstItem); IFragment WriteProcessedSenses(ConfigurableDictionaryNode config, bool isBlock, IFragment senseContent, string className, IFragment sharedCollectionInfo); IFragment AddAudioWsContent(string wsId, Guid linkTarget, IFragment fileContent); IFragment GenerateErrorContent(StringBuilder badStrBuilder); diff --git a/Src/xWorks/LcmJsonGenerator.cs b/Src/xWorks/LcmJsonGenerator.cs index 23c0f5ebe4..9564b8fbca 100644 --- a/Src/xWorks/LcmJsonGenerator.cs +++ b/Src/xWorks/LcmJsonGenerator.cs @@ -411,7 +411,7 @@ public void EndCrossReference(IFragmentWriter writer) ((JsonFragmentWriter)writer).InsertRawJson(","); } - public void BetweenCrossReferenceType(IFragment content, ConfigurableDictionaryNode node, bool first) + public void BetweenCrossReferenceType(IFragment content, ConfigurableDictionaryNode node, bool firstItem) { } diff --git a/Src/xWorks/LcmWordGenerator.cs b/Src/xWorks/LcmWordGenerator.cs index a01ef59a8c..45c0a1516c 100644 --- a/Src/xWorks/LcmWordGenerator.cs +++ b/Src/xWorks/LcmWordGenerator.cs @@ -1621,10 +1621,10 @@ public void EndCrossReference(IFragmentWriter writer) return; } - public void BetweenCrossReferenceType(IFragment content, ConfigurableDictionaryNode node, bool first) + public void BetweenCrossReferenceType(IFragment content, ConfigurableDictionaryNode node, bool firstItem) { // Add Between text if it is not the first item in the collection. - if (!first && !string.IsNullOrEmpty(node.Between)) + if (!firstItem && !string.IsNullOrEmpty(node.Between)) { var betweenRun = CreateBeforeAfterBetweenRun(node.Between); ((DocFragment)content).DocBody.PrependChild(betweenRun); diff --git a/Src/xWorks/LcmXhtmlGenerator.cs b/Src/xWorks/LcmXhtmlGenerator.cs index 9a0316f621..bf3ad8b81c 100644 --- a/Src/xWorks/LcmXhtmlGenerator.cs +++ b/Src/xWorks/LcmXhtmlGenerator.cs @@ -992,7 +992,7 @@ public void EndCrossReference(IFragmentWriter writer) EndObject(writer); } - public void BetweenCrossReferenceType(IFragment content, ConfigurableDictionaryNode node, bool first) + public void BetweenCrossReferenceType(IFragment content, ConfigurableDictionaryNode node, bool firstItem) { }