From ff35b4a76d2fa05dabf4d6f0526b8242adddc696 Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Thu, 30 Apr 2026 11:38:37 -0700 Subject: [PATCH] Fix new problem with LT-11746: Make Preview aware of publication --- Src/xWorks/XhtmlRecordDocView.cs | 43 +++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/Src/xWorks/XhtmlRecordDocView.cs b/Src/xWorks/XhtmlRecordDocView.cs index 7f7b77a87b..58e1e19e73 100644 --- a/Src/xWorks/XhtmlRecordDocView.cs +++ b/Src/xWorks/XhtmlRecordDocView.cs @@ -10,6 +10,7 @@ using SIL.Windows.Forms.HtmlBrowser; using System; using System.Drawing; +using System.Linq; using System.Windows.Forms; using System.Xml; using XCore; @@ -25,6 +26,38 @@ public class XhtmlRecordDocView : RecordView, IVwNotifyChange { private XWebBrowser m_mainView; internal string m_configObjectName; + private DictionaryPublicationDecorator m_pubDecorator; + + public DictionaryPublicationDecorator PublicationDecorator + { + get + { + if (m_pubDecorator == null) + { + m_pubDecorator = new DictionaryPublicationDecorator(Cache, Clerk.VirtualListPublisher, Clerk.VirtualFlid); + } + var pubName = GetCurrentPublication(); + if (xWorksStrings.AllEntriesPublication == pubName) + { + // A null publication means show everything + m_pubDecorator.Publication = null; + } + else + { + // look up the publication object + + var pub = (from item in Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS + where item.Name.UserDefaultWritingSystem.Text == pubName + select item).FirstOrDefault(); + if (pub != null && pub != m_pubDecorator.Publication) + { + // change the publication if it is different from the current one + m_pubDecorator.Publication = pub; + } + } + return m_pubDecorator; + } + } public override void Init(Mediator mediator, PropertyTable propertyTable, XmlNode configurationParameters) { @@ -56,6 +89,13 @@ protected override void ReadParameters() m_configObjectName = XmlUtils.GetOptionalAttributeValue(m_configurationParameters, "configureObjectName", null); } + private string GetCurrentPublication() + { + // Returns the current publication and use '$$all_entries$$' if none has yet been set + return m_propertyTable.GetStringProperty("SelectedPublication", + xWorksStrings.AllEntriesPublication); + } + /// /// Handle a mouse click in the web browser displaying the xhtml. /// @@ -126,7 +166,8 @@ protected override void ShowRecord() return; } var configuration = new DictionaryConfigurationModel(configurationFile, Cache); - var xhtmlPath = LcmXhtmlGenerator.SavePreviewHtmlWithStyles(new [] { cmo.Hvo }, Clerk, null, configuration, m_propertyTable); + PublicationDecorator.Refresh(); + var xhtmlPath = LcmXhtmlGenerator.SavePreviewHtmlWithStyles(new [] { cmo.Hvo }, Clerk, PublicationDecorator, configuration, m_propertyTable); m_mainView.Url = new Uri(xhtmlPath); m_mainView.Refresh(WebBrowserRefreshOption.Completely); }