Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Src/xWorks/LcmXhtmlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public class LcmXhtmlGenerator : ILcmContentGenerator
/// </summary>
/// <returns>The path to the XHTML file</returns>
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<LcmCache>("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)
{
Expand All @@ -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)
{
Expand All @@ -81,13 +81,18 @@ public static string SavePreviewHtmlWithStyles(int[] entryHvos, RecordClerk cler
/// </summary>
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<LcmCache>("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))
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<int, int> currentPageBounds, XmlWriter xhtmlWriter, StreamWriter cssWriter)
{
var pageRanges = GetPageRanges(entryHvos, entriesPerPage);
Expand Down
43 changes: 42 additions & 1 deletion Src/xWorks/XhtmlRecordDocView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
}

/// <summary>
/// Handle a mouse click in the web browser displaying the xhtml.
/// </summary>
Expand Down Expand Up @@ -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);
}
Expand Down
Loading