Skip to content

Commit 7affcfe

Browse files
authored
Fix LT-21826: Usage figures for Publications show inverted values (#282)
* Fix LT-21826: Usage figures for Publications show inverted values * Fix LT-21826: Add PublicationLabelNode with proper CountUsages
1 parent aebae99 commit 7affcfe

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Src/Common/Controls/XMLViews/ReallySimpleListChooser.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,8 @@ public virtual bool WantNodeForLabel(ObjectLabel label)
18431843
/// <returns></returns>
18441844
protected virtual LabelNode CreateLabelNode(ObjectLabel nol, bool displayUsage)
18451845
{
1846+
if (nol.Object.Owner.ToString() == "Publications")
1847+
return new PublicationLabelNode(nol, m_stylesheet, displayUsage);
18461848
return new LabelNode(nol, m_stylesheet, displayUsage);
18471849
}
18481850

@@ -2863,4 +2865,38 @@ private bool HasLeaves(ObjectLabel label)
28632865
}
28642866
}
28652867

2868+
/// ------------------------------------------------------------------------------------
2869+
/// <summary>
2870+
/// PublicationLabelNode
2871+
/// </summary>
2872+
/// ------------------------------------------------------------------------------------
2873+
public class PublicationLabelNode : LabelNode
2874+
{
2875+
2876+
/// <summary>
2877+
/// Initializes a new instance of the <see cref="PublicationLabelNode"/> class.
2878+
/// </summary>
2879+
public PublicationLabelNode(ObjectLabel label, IVwStylesheet stylesheet, bool displayUsage)
2880+
: base(label, stylesheet, displayUsage)
2881+
{
2882+
}
2883+
/// <summary>
2884+
/// Publication is the value of DoNotPublishIn,
2885+
/// so we need to invert the count.
2886+
/// </summary>
2887+
/// <returns></returns>
2888+
protected override int CountUsages()
2889+
{
2890+
int count = 0;
2891+
// I think only label.Object is likely to be null, but let's prevent crashes thoroughly.
2892+
if (Label?.Object?.ReferringObjects != null)
2893+
{
2894+
ILexEntryRepository repository = Label.Object.Cache.ServiceLocator.GetInstance<ILexEntryRepository>();
2895+
count = repository.Count - Label.Object.ReferringObjects.Count;
2896+
}
2897+
return count;
2898+
}
2899+
2900+
}
2901+
28662902
}

0 commit comments

Comments
 (0)