Skip to content

Commit

Permalink
Word Export: Code cleanup (#49)
Browse files Browse the repository at this point in the history
There are no logic changes in this PR, just cleanup.
- Changed the name of some methods.
- Changed eachInAParagraph to eachOnANewLine. For Word Export a
Paragraph is a class and carries a specific meaning. We are not
putting the data in a separate OpenXml.Wordprocessing.Paragraph,
just starting a new line. So I changed the names to try and
reduce confusion.
  • Loading branch information
mark-sil authored May 9, 2024
1 parent cb98e32 commit a9d373c
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions Src/xWorks/LcmWordGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ public void Append(IFragment frag)
/// <summary>
/// Append a table to the doc fragment.
/// </summary>
public void Append(WP.Table table)
public void AppendTable(WP.Table table)
{
// Deep clone the run b/c of its tree of properties and to maintain styles.
this.DocBody.AppendChild(table.CloneNode(true));
Expand Down Expand Up @@ -739,19 +739,19 @@ private IFragment WriteProcessedElementContent(IFragment elementContent, Configu
// Use the style name and type of the config node or its parent to link a style to the elementContent fragment where the processed contents are written.
DocFragment.LinkStyleOrInheritParentStyle(elementContent, config);

bool displayEachInAParagraph = config != null &&
config.DictionaryNodeOptions is IParaOption &&
((IParaOption)(config.DictionaryNodeOptions)).DisplayEachInAParagraph;
bool eachOnANewLine = config != null &&
config.DictionaryNodeOptions is IParaOption &&
((IParaOption)(config.DictionaryNodeOptions)).DisplayEachInAParagraph;

// Add Before text, if it is not going to be displayed in it's own paragraph.
if (!displayEachInAParagraph && !string.IsNullOrEmpty(config.Before))
// Add Before text, if it is not going to be displayed on it's own line.
if (!eachOnANewLine && !string.IsNullOrEmpty(config.Before))
{
var beforeRun = CreateBeforeAfterBetweenRun(config.Before);
((DocFragment)elementContent).DocBody.PrependChild(beforeRun);
}

// Add After text, if it is not going to be displayed in it's own paragraph.
if (!displayEachInAParagraph && !string.IsNullOrEmpty(config.After))
// Add After text, if it is not going to be displayed on it's own line.
if (!eachOnANewLine && !string.IsNullOrEmpty(config.After))
{
var afterRun = CreateBeforeAfterBetweenRun(config.After);
((DocFragment)elementContent).DocBody.Append(afterRun);
Expand All @@ -776,21 +776,21 @@ public IFragment AddSenseData(IFragment senseNumberSpan, Guid ownerGuid, Configu
{
var senseData = new DocFragment();
var senseNode = (DictionaryNodeSenseOptions)config?.DictionaryNodeOptions;
bool eachInAParagraph = false;
bool eachOnANewLine = false;
bool firstSenseInline = false;
string afterNumber = null;
string beforeNumber = null;
if (senseNode != null)
{
eachInAParagraph = senseNode.DisplayEachSenseInAParagraph;
eachOnANewLine = senseNode.DisplayEachSenseInAParagraph;
firstSenseInline = senseNode.DisplayFirstSenseInline;
afterNumber = senseNode.AfterNumber;
beforeNumber = senseNode.BeforeNumber;
}

// We want a break before the first sense item, between items, and after the last item.
// So, only add a break before the content if it is the first sense and it's not displayed in-line.
if (eachInAParagraph && first && !firstSenseInline)
if (eachOnANewLine && first && !firstSenseInline)
{
senseData.AppendBreak();
}
Expand All @@ -811,7 +811,7 @@ public IFragment AddSenseData(IFragment senseNumberSpan, Guid ownerGuid, Configu

senseData.Append(senseContent);

if (eachInAParagraph)
if (eachOnANewLine)
{
senseData.AppendBreak();
}
Expand All @@ -830,12 +830,12 @@ public IFragment AddCollectionItem(bool isBlock, string collectionItemClass, Con
}

var collData = CreateFragment();
bool eachInAParagraph = false;
bool eachOnANewLine = false;
if (config != null &&
config.DictionaryNodeOptions is IParaOption &&
((IParaOption)(config.DictionaryNodeOptions)).DisplayEachInAParagraph)
{
eachInAParagraph = true;
eachOnANewLine = true;

// We want a break before the first collection item, between items, and after the last item.
// So, only add a break before the content if it is the first.
Expand All @@ -845,12 +845,12 @@ config.DictionaryNodeOptions is IParaOption &&
}
}

// Add Between text, if it is not going to be displayed in it's own paragraph
// Add Between text, if it is not going to be displayed on it's own line
// and it is not the first item in the collection.
if (!first &&
config != null &&
config.DictionaryNodeOptions is IParaOption &&
!eachInAParagraph &&
!eachOnANewLine &&
!string.IsNullOrEmpty(config.Between))
{
var betweenRun = CreateBeforeAfterBetweenRun(config.Between);
Expand All @@ -859,7 +859,7 @@ config.DictionaryNodeOptions is IParaOption &&

collData.Append(content);

if (eachInAParagraph)
if (eachOnANewLine)
{
collData.AppendBreak();
}
Expand Down Expand Up @@ -1232,7 +1232,7 @@ public void AddEntryData(IFragmentWriter writer, List<ConfiguredLcmGenerator.Con
break;

case WP.Table table:
wordWriter.WordFragment.Append(table);
wordWriter.WordFragment.AppendTable(table);

// Start a new paragraph with the next run to maintain the correct position of the table.
wordWriter.ForceNewParagraph = true;
Expand Down

0 comments on commit a9d373c

Please sign in to comment.