diff --git a/Src/xWorks/XhtmlDocView.cs b/Src/xWorks/XhtmlDocView.cs index 3665499bfc..3df25c0a87 100644 --- a/Src/xWorks/XhtmlDocView.cs +++ b/Src/xWorks/XhtmlDocView.cs @@ -175,7 +175,7 @@ public bool OnJumpToRecord(object argument) DictionaryConfigurationController.ExclusionReasonCode xrc; // Make sure we explain to the user in case hvoTarget is not visible due to // the current Publication layout or Configuration view. - if (!IsObjectVisible(hvoTarget, out xrc)) + if (!IsObjectVisible(hvoTarget, Cache, m_propertyTable, out xrc)) { // Tell the user why we aren't jumping to his record GiveSimpleWarning(xrc); @@ -189,16 +189,27 @@ public bool OnJumpToRecord(object argument) private void GiveSimpleWarning(DictionaryConfigurationController.ExclusionReasonCode xrc) { // Tell the user why we aren't jumping to his record - var msg = xWorksStrings.ksSelectedEntryNotInDict; string caption; - string reason; string shlpTopic; + string msg = GetExclusionWarning(xrc, out caption, out shlpTopic); + // TODO-Linux: Help is not implemented on Mono + MessageBox.Show(FindForm(), msg, caption, MessageBoxButtons.OK, + MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, 0, + m_propertyTable.GetValue("HelpTopicProvider").HelpFile, + HelpNavigator.Topic, shlpTopic); + } + + internal static string GetExclusionWarning(DictionaryConfigurationController.ExclusionReasonCode xrc, out string caption, out string shlpTopic) + { + // Tell the user why we aren't jumping to his record + var msg = xWorksStrings.ksSelectedEntryNotInDict; + string reason; switch (xrc) { case DictionaryConfigurationController.ExclusionReasonCode.NotInPublication: caption = xWorksStrings.ksEntryNotPublished; reason = xWorksStrings.ksEntryNotPublishedReason; - shlpTopic = "User_Interface/Menus/Edit/Find_a_lexical_entry.htm"; //khtpEntryNotPublished + shlpTopic = "User_Interface/Menus/Edit/Find_a_lexical_entry.htm"; //khtpEntryNotPublished break; case DictionaryConfigurationController.ExclusionReasonCode.ExcludedHeadword: caption = xWorksStrings.ksMainNotShown; @@ -213,18 +224,13 @@ private void GiveSimpleWarning(DictionaryConfigurationController.ExclusionReason default: throw new ArgumentException("Unknown ExclusionReasonCode"); } - msg = String.Format(msg, reason); - // TODO-Linux: Help is not implemented on Mono - MessageBox.Show(FindForm(), msg, caption, MessageBoxButtons.OK, - MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, 0, - m_propertyTable.GetValue("HelpTopicProvider").HelpFile, - HelpNavigator.Topic, shlpTopic); + return String.Format(msg, reason); } - private bool IsObjectVisible(int hvoTarget, out DictionaryConfigurationController.ExclusionReasonCode xrc) + internal static bool IsObjectVisible(int hvoTarget, LcmCache cache, PropertyTable propertyTable, out DictionaryConfigurationController.ExclusionReasonCode xrc) { xrc = DictionaryConfigurationController.ExclusionReasonCode.NotExcluded; - var objRepo = Cache.ServiceLocator.GetInstance(); + var objRepo = cache.ServiceLocator.GetInstance(); Debug.Assert(objRepo.IsValidObjectId(hvoTarget), "Invalid hvoTarget!"); if (!objRepo.IsValidObjectId(hvoTarget)) throw new ArgumentException("Unknown object."); @@ -235,8 +241,8 @@ private bool IsObjectVisible(int hvoTarget, out DictionaryConfigurationControlle // Now we have our LexEntry // First deal with whether the active Publication excludes it. - var m_currentPublication = m_propertyTable.GetValue("SelectedPublication", null); - var publications = Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS.Select(p => p).Where(p => p.NameHierarchyString == m_currentPublication.ToString()).FirstOrDefault(); + var m_currentPublication = propertyTable.GetValue("SelectedPublication", null); + var publications = cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS.Select(p => p).Where(p => p.NameHierarchyString == m_currentPublication.ToString()).FirstOrDefault(); //if the publications is null in case of Dictionary view selected as $$All Entries$$. if (publications != null && publications.NameHierarchyString != xWorksStrings.AllEntriesPublication) { @@ -255,7 +261,8 @@ private bool IsObjectVisible(int hvoTarget, out DictionaryConfigurationControlle } // Third deal with whether the entry shouldn't be shown as a minor entry. // commented out until conditions are clarified (LT-11447) - var configuration = new DictionaryConfigurationModel(GetCurrentConfiguration(false), Cache); + string configurationName = DictionaryConfigurationListener.GetCurrentConfiguration(propertyTable, false); + var configuration = new DictionaryConfigurationModel(configurationName, cache); if (entry.EntryRefsOS.Count > 0 && !entry.PublishAsMinorEntry && configuration.IsRootBased) { xrc = DictionaryConfigurationController.ExclusionReasonCode.ExcludedMinorEntry; diff --git a/Src/xWorks/XhtmlRecordDocView.cs b/Src/xWorks/XhtmlRecordDocView.cs index b762b71cc6..7f7b77a87b 100644 --- a/Src/xWorks/XhtmlRecordDocView.cs +++ b/Src/xWorks/XhtmlRecordDocView.cs @@ -2,17 +2,18 @@ // This software is licensed under the LGPL, version 2.1 or later // (http://www.gnu.org/licenses/lgpl-2.1.html) -using System; -using System.Drawing; -using System.Windows.Forms; -using System.Xml; using Gecko; using SIL.FieldWorks.Common.FwUtils; using SIL.LCModel; using SIL.LCModel.Core.KernelInterfaces; -using XCore; using SIL.Utils; using SIL.Windows.Forms.HtmlBrowser; +using System; +using System.Drawing; +using System.Windows.Forms; +using System.Xml; +using XCore; +using static SIL.FieldWorks.XWorks.DictionaryConfigurationController; namespace SIL.FieldWorks.XWorks { @@ -116,6 +117,14 @@ protected override void ShowRecord() xWorksStrings.ksNoConfiguration); return; } + if (!XhtmlDocView.IsObjectVisible(cmo.Hvo, Cache, m_propertyTable, out ExclusionReasonCode xrc)) + { + string caption; + string helpTopic; + string warning = XhtmlDocView.GetExclusionWarning(xrc, out caption, out helpTopic); + m_mainView.DocumentText = String.Format("

{0}

", warning); + return; + } var configuration = new DictionaryConfigurationModel(configurationFile, Cache); var xhtmlPath = LcmXhtmlGenerator.SavePreviewHtmlWithStyles(new [] { cmo.Hvo }, Clerk, null, configuration, m_propertyTable); m_mainView.Url = new Uri(xhtmlPath); diff --git a/Src/xWorks/xWorksStrings.resx b/Src/xWorks/xWorksStrings.resx index 94dfbc51d1..19963b0f16 100644 --- a/Src/xWorks/xWorksStrings.resx +++ b/Src/xWorks/xWorksStrings.resx @@ -812,7 +812,7 @@ Are you sure you want to delete this list? Used in Dictionary view warning dialogs. - The entry you have selected is not shown in Dictionary view, {0}. + The entry you have selected is not shown, {0}. Parameter is the Lexeme Form of the entry.