@@ -249,6 +249,22 @@ internal static string GetWsForEntryType(ICmObject entry, LcmCache cache)
249249 return wsString ;
250250 }
251251
252+ /// <summary>
253+ /// Get the ConfigurableDictionaryNode for the main entry.
254+ /// </summary>
255+ private static ConfigurableDictionaryNode MainEntryNode ( DictionaryConfigurationModel configuration )
256+ {
257+ return configuration . Parts [ 0 ] ;
258+ }
259+
260+ /// <summary>
261+ /// Get the ConfigurableDictionaryNode for the minor entry.
262+ /// </summary>
263+ private static ConfigurableDictionaryNode MinorEntryNode ( ICmObject entry , DictionaryConfigurationModel configuration )
264+ {
265+ return configuration . Parts . Skip ( 1 ) . LastOrDefault ( part => IsListItemSelectedForExport ( part , entry ) ) ;
266+ }
267+
252268 /// <summary>
253269 /// Generating the xhtml representation for the given ICmObject using the given configuration node to select which data to write out
254270 /// If it is a Dictionary Main Entry or non-Dictionary entry, uses the first configuration node.
@@ -259,7 +275,7 @@ public static IFragment GenerateContentForEntry(ICmObject entryObj, DictionaryCo
259275 DictionaryPublicationDecorator publicationDecorator , GeneratorSettings settings , int index = - 1 )
260276 {
261277 if ( IsMainEntry ( entryObj , configuration ) )
262- return GenerateContentForMainEntry ( entryObj , configuration . Parts [ 0 ] , publicationDecorator , settings , index ) ;
278+ return GenerateContentForMainEntry ( entryObj , MainEntryNode ( configuration ) , publicationDecorator , settings , index ) ;
263279
264280 var entry = ( ILexEntry ) entryObj ;
265281 return entry . PublishAsMinorEntry
@@ -279,7 +295,7 @@ private static IFragment GenerateContentForMinorEntry(ICmObject entry, Dictionar
279295 DictionaryPublicationDecorator publicationDecorator , GeneratorSettings settings , int index )
280296 {
281297 // LT-15232: show minor entries using only the last applicable Minor Entry node (not more than once)
282- var applicablePart = configuration . Parts . Skip ( 1 ) . LastOrDefault ( part => IsListItemSelectedForExport ( part , entry ) ) ;
298+ var applicablePart = MinorEntryNode ( entry , configuration ) ;
283299 return applicablePart == null ? settings . ContentGenerator . CreateFragment ( ) : GenerateContentForEntry ( entry , applicablePart , publicationDecorator , settings , index ) ;
284300 }
285301
@@ -300,6 +316,61 @@ internal static bool IsMainEntry(ICmObject entry, DictionaryConfigurationModel c
300316 return lexEntry . EntryRefsOS . Any ( ler => ler . RefType == LexEntryRefTags . krtComplexForm ) ;
301317 }
302318
319+ /// <summary>
320+ /// Checks if a lexical entry is displayed.
321+ /// </summary>
322+ /// <returns>true if displayed.</returns>
323+ private static bool EntryIsDisplayed ( ILexEntry lexEntry , List < ConfigurableDictionaryNode > nodeList ,
324+ DictionaryPublicationDecorator publicationDecorator , GeneratorSettings settings )
325+ {
326+ // If there is no publication decorator then we are generating a preview. For previews always
327+ // treat a target as displayed.
328+ if ( publicationDecorator == null )
329+ {
330+ return true ;
331+ }
332+
333+ bool displayed = false ;
334+ DictionaryConfigurationModel configModel = nodeList . First ( ) . Model ;
335+ bool mainEntry = IsMainEntry ( lexEntry , configModel ) ;
336+
337+ // First determine if the dictionary configuration is set to display the entry type.
338+ if ( mainEntry )
339+ {
340+ displayed = MainEntryNode ( configModel ) . IsEnabled ;
341+ }
342+ else
343+ {
344+ var node = MinorEntryNode ( lexEntry , configModel ) ;
345+ displayed = node != null && node . IsEnabled ;
346+ }
347+
348+ // Second check if we are publishing minor entries.
349+ if ( displayed && ! mainEntry && ! lexEntry . PublishAsMinorEntry )
350+ {
351+ displayed = false ;
352+ }
353+
354+ // Third check if the active Publication excludes it.
355+ var currentPubPoss = publicationDecorator . Publication ;
356+ if ( displayed && currentPubPoss != null &&
357+ currentPubPoss . NameHierarchyString != xWorksStrings . AllEntriesPublication )
358+ {
359+ if ( ! lexEntry . PublishIn . Contains ( currentPubPoss ) )
360+ {
361+ displayed = false ;
362+ }
363+ // Note: A better name for ShowMainEntryIn() would probably be
364+ // ShowAsHeadwordIn(), since it applies to both main and minor entries.
365+ if ( ! lexEntry . ShowMainEntryIn . Contains ( currentPubPoss ) )
366+ {
367+ displayed = false ;
368+ }
369+ }
370+
371+ return displayed ;
372+ }
373+
303374 /// <summary>Generates content with the GeneratorSettings.ContentGenerator for an ICmObject for a specific ConfigurableDictionaryNode</summary>
304375 /// <remarks>the configuration node must match the entry type</remarks>
305376 internal static IFragment GenerateContentForEntry ( ICmObject entry , ConfigurableDictionaryNode configuration ,
@@ -585,7 +656,7 @@ internal static IFragment GenerateContentForFieldByReflection(object field, List
585656 return settings . ContentGenerator . CreateFragment ( ) ;
586657 }
587658
588- var bldr = GenerateContentForValue ( field , propertyValue , nodeList , settings ) ;
659+ var bldr = GenerateContentForValue ( field , propertyValue , nodeList , publicationDecorator , settings ) ;
589660 if ( config . ReferencedOrDirectChildren != null )
590661 {
591662 foreach ( var child in config . ReferencedOrDirectChildren )
@@ -2549,48 +2620,40 @@ private static bool IsCollectionEmpty(object collection)
25492620 /// <param name="config"></param>
25502621 /// <param name="settings"></param>
25512622 private static IFragment GenerateContentForValue ( object field , object propertyValue , List < ConfigurableDictionaryNode > nodeList ,
2552- GeneratorSettings settings )
2623+ DictionaryPublicationDecorator publicationDecorator , GeneratorSettings settings )
25532624 {
25542625 // If we're working with a headword, either for this entry or another one (Variant or Complex Form, etc.), store that entry's GUID
25552626 // so we can generate a link to the main or minor entry for this headword.
25562627 var guid = Guid . Empty ;
25572628 var config = nodeList . Last ( ) ;
25582629 if ( config . IsHeadWord )
25592630 {
2560- if ( field is ILexEntry )
2631+ ILexEntry lexEntry = null ;
2632+ if ( field is ILexEntry entry )
25612633 {
2562- // For Complex Forms, don't generate the reference if we are not going to publish the entry to Webonary.
2563- if ( settings . IsWebExport &&
2564- ! ( ( ILexEntry ) field ) . PublishAsMinorEntry &&
2565- ( ( ILexEntry ) field ) . EntryRefsOS . Count > 0 )
2566- {
2567- guid = Guid . Empty ;
2568- }
2569- else
2570- {
2571- guid = ( ( ILexEntry ) field ) . Guid ;
2572- }
2634+ lexEntry = entry ;
25732635 }
2574- else if ( field is ILexEntryRef )
2636+ else if ( field is ILexEntryRef entryRef )
25752637 {
2576- // For Variants, don't generate the reference if we are not going to publish the entry to Webonary.
2577- if ( settings . IsWebExport &&
2578- ! ( ( ILexEntryRef ) field ) . OwningEntry . PublishAsMinorEntry )
2579- {
2580- guid = Guid . Empty ;
2581- }
2582- else
2583- {
2584- guid = ( ( ILexEntryRef ) field ) . OwningEntry . Guid ;
2585- }
2638+ lexEntry = entryRef . OwningEntry ;
2639+ }
2640+ else if ( field is ISenseOrEntry senseOrEntry )
2641+ {
2642+ lexEntry = senseOrEntry . Item is ILexEntry ? ( ILexEntry ) ( senseOrEntry . Item ) : ( ( ILexSense ) ( senseOrEntry . Item ) ) . Entry ;
2643+ }
2644+ else if ( field is ILexSense sense )
2645+ {
2646+ lexEntry = sense . OwnerOfClass ( LexEntryTags . kClassId ) as ILexEntry ;
25862647 }
2587- else if ( field is ISenseOrEntry )
2588- guid = ( ( ISenseOrEntry ) field ) . EntryGuid ;
2589- else if ( field is ILexSense )
2590- guid = ( ( ILexSense ) field ) . OwnerOfClass ( LexEntryTags . kClassId ) . Guid ;
25912648 else
25922649 Debug . WriteLine ( String . Format ( "Need to find Entry Guid for {0}" ,
25932650 field == null ? DictionaryConfigurationMigrator . BuildPathStringFromNode ( config ) : field . GetType ( ) . Name ) ) ;
2651+
2652+ // Check if the Lexical Entry is going to be displayed.
2653+ if ( lexEntry != null && EntryIsDisplayed ( lexEntry , nodeList , publicationDecorator , settings ) )
2654+ {
2655+ guid = lexEntry . Guid ;
2656+ }
25942657 }
25952658
25962659 if ( propertyValue is ITsString )
0 commit comments