diff --git a/Src/xWorks/LcmXhtmlGenerator.cs b/Src/xWorks/LcmXhtmlGenerator.cs
index 458c6cd9e7..f89e6d3ed4 100644
--- a/Src/xWorks/LcmXhtmlGenerator.cs
+++ b/Src/xWorks/LcmXhtmlGenerator.cs
@@ -45,13 +45,13 @@ public class LcmXhtmlGenerator : ILcmContentGenerator
///
/// The path to the XHTML file
public static string SavePreviewHtmlWithStyles(int[] entryHvos, RecordClerk clerk, DictionaryPublicationDecorator publicationDecorator, DictionaryConfigurationModel configuration, XCore.PropertyTable propertyTable,
- IThreadedProgress progress = null, int entriesPerPage = EntriesPerPage)
+ IThreadedProgress progress = null, int entriesPerPage = EntriesPerPage, bool isLexEditPreviewOnly = false)
{
var preferredPath = GetPreferredPreviewPath(configuration, propertyTable.GetValue("cache"), entryHvos.Length == 1);
var xhtmlPath = Path.ChangeExtension(preferredPath, "xhtml");
try
{
- SavePublishedHtmlWithStyles(entryHvos, clerk, publicationDecorator, entriesPerPage, configuration, propertyTable, xhtmlPath, progress);
+ SavePublishedHtmlWithStyles(entryHvos, clerk, publicationDecorator, entriesPerPage, configuration, propertyTable, xhtmlPath, progress, isLexEditPreviewOnly: isLexEditPreviewOnly);
}
catch (IOException ioEx)
{
@@ -63,7 +63,7 @@ public static string SavePreviewHtmlWithStyles(int[] entryHvos, RecordClerk cler
xhtmlPath = Path.ChangeExtension(preferredPath + i, "xhtml");
try
{
- SavePublishedHtmlWithStyles(entryHvos, clerk, publicationDecorator, entriesPerPage, configuration, propertyTable, xhtmlPath, progress);
+ SavePublishedHtmlWithStyles(entryHvos, clerk, publicationDecorator, entriesPerPage, configuration, propertyTable, xhtmlPath, progress, isLexEditPreviewOnly: isLexEditPreviewOnly);
}
catch (IOException e)
{
@@ -81,13 +81,18 @@ public static string SavePreviewHtmlWithStyles(int[] entryHvos, RecordClerk cler
///
public static void SavePublishedHtmlWithStyles(int[] entryHvos, RecordClerk clerk, DictionaryPublicationDecorator publicationDecorator, int entriesPerPage,
DictionaryConfigurationModel configuration, XCore.PropertyTable propertyTable, string xhtmlPath, IThreadedProgress progress = null,
- bool isXhtmlExport = false)
+ bool isXhtmlExport = false, bool isLexEditPreviewOnly = false)
{
var entryCount = entryHvos.Length;
var cssPath = Path.ChangeExtension(xhtmlPath, "css");
var cache = propertyTable.GetValue("cache", null);
+ if (publicationDecorator == null)
+ {
+ // Used by unit tests.
+ isLexEditPreviewOnly = true;
+ }
// Don't display letter headers if we're showing a preview in the Edit tool or we're not sorting by headword
- var wantLetterHeaders = (entryCount > 1 || !IsLexEditPreviewOnly(publicationDecorator)) && (RecordClerk.IsClerkSortingByHeadword(clerk));
+ var wantLetterHeaders = (entryCount > 1 || !isLexEditPreviewOnly) && (RecordClerk.IsClerkSortingByHeadword(clerk));
using (var xhtmlWriter = XmlWriter.Create(xhtmlPath))
using (var cssWriter = new StreamWriter(cssPath, false, Encoding.UTF8))
{
@@ -146,7 +151,7 @@ public static void SavePublishedHtmlWithStyles(int[] entryHvos, RecordClerk cler
if (progress != null)
progress.Message = xWorksStrings.ksGeneratingStyleInfo;
- if (!IsLexEditPreviewOnly(publicationDecorator) && !IsExport(settings))
+ if (!isLexEditPreviewOnly && !IsExport(settings))
{
cssWriter.Write(CssGenerator.GenerateCssForSelectedEntry(settings.RightToLeft));
ConfiguredLcmGenerator.CopyFileSafely(settings, Path.Combine(FwDirectoryFinder.FlexFolder, ImagesFolder, CurrentEntryMarker), CurrentEntryMarker);
@@ -311,11 +316,6 @@ private static string GetPreferredPreviewPath(DictionaryConfigurationModel confi
return Path.Combine(basePath, fileName);
}
- private static bool IsLexEditPreviewOnly(DictionaryPublicationDecorator decorator)
- {
- return decorator == null;
- }
-
private static void GenerateTopOfPageButtonsIfNeeded(ConfiguredLcmGenerator.GeneratorSettings settings, int[] entryHvos, int entriesPerPage, Tuple currentPageBounds, XmlWriter xhtmlWriter, StreamWriter cssWriter)
{
var pageRanges = GetPageRanges(entryHvos, entriesPerPage);
diff --git a/Src/xWorks/XhtmlRecordDocView.cs b/Src/xWorks/XhtmlRecordDocView.cs
index 7f7b77a87b..008b4f20bd 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, isLexEditPreviewOnly: true);
m_mainView.Url = new Uri(xhtmlPath);
m_mainView.Refresh(WebBrowserRefreshOption.Completely);
}