/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the style-name of the mapping, or if this is one of our special internal /// pseudo-styles, returns a UI-friendly version. /// </summary> /// <param name="mapping">The mapping.</param> /// ------------------------------------------------------------------------------------ internal static string MappingToUiStylename(ImportMappingInfo mapping) { switch (mapping.MappingTarget) { case MappingTargetType.ChapterLabel: return(ScrImportComponents.kstidChapterLabelStyle); case MappingTargetType.TitleShort: return(ScrImportComponents.kstidTitleShortStyle); case MappingTargetType.Figure: return(ScrImportComponents.kstidFigureStyle); case MappingTargetType.FigureCaption: return(ScrImportComponents.kstidFigureCaptionStyle); case MappingTargetType.FigureCopyright: return(ScrImportComponents.kstidFigureCopyrightStyle); case MappingTargetType.FigureDescription: return(ScrImportComponents.kstidFigureDescriptionStyle); case MappingTargetType.FigureFilename: return(ScrImportComponents.kstidFigureFilenameStyle); case MappingTargetType.FigureLayoutPosition: return(ScrImportComponents.kstidFigureLayoutPositionStyle); case MappingTargetType.FigureRefRange: return(ScrImportComponents.kstidFigureRefRangeStyle); case MappingTargetType.FigureScale: return(ScrImportComponents.kstidFigureScaleStyle); case MappingTargetType.TEStyle: return(mapping.StyleName); default: Debug.Fail("Unexpected Mapping Target Type"); return(null); } }
public void AddDefaultMappingIfNeeded_btMappingsWithNonDefaultMappings() { DynamicMock mockStylesheet = new DynamicMock(typeof(IVwStylesheet)); mockStylesheet.SetupResultForParams("GetContext", (int)ContextValues.General, "Emphasis"); mockStylesheet.SetupResultForParams("GetType", (int)StyleType.kstCharacter, "Emphasis"); ScrMappingList list = new ScrMappingList(MappingSet.Main, (IVwStylesheet)mockStylesheet.MockInstance); list.Add(new ImportMappingInfo(@"\p", null, "Emphasis")); list.AddDefaultMappingIfNeeded(@"\btp", ImportDomain.Main, true); Assert.AreEqual(2, list.Count); // Test that \btp maps automatically to the corresponding vernacular style ("Emphasis") // but does not map into the Back-trans marker domain because Emphasis is a character style. ImportMappingInfo info = list[@"\btp"]; Assert.AreEqual(MarkerDomain.Default, info.Domain, @"\btp should not map automatically as a Back-trans marker"); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget); Assert.AreEqual("Emphasis", info.StyleName); }
public void AddDefaultMappingIfNeeded_btMappingsWithNonDefaultMappings() { IVwStylesheet stylesheet = MockRepository.GenerateStub <IVwStylesheet>(); stylesheet.Stub(x => x.GetContext("Emphasis")).Return((int)ContextValues.General); stylesheet.Stub(x => x.GetType("Emphasis")).Return((int)StyleType.kstCharacter); ScrMappingList list = new ScrMappingList(MappingSet.Main, stylesheet, TestTeStylesPath); list.Add(new ImportMappingInfo(@"\p", null, "Emphasis")); list.AddDefaultMappingIfNeeded(@"\btp", ImportDomain.Main, true); Assert.AreEqual(2, list.Count); // Test that \btp maps automatically to the corresponding vernacular style ("Emphasis") // but does not map into the Back-trans marker domain because Emphasis is a character style. ImportMappingInfo info = list[@"\btp"]; Assert.AreEqual(MarkerDomain.Default, info.Domain, @"\btp should not map automatically as a Back-trans marker"); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget); Assert.AreEqual("Emphasis", info.StyleName); }
public void AddDefaultMappingIfNeeded_FigureMarkers() { DynamicMock mockStylesheet = new DynamicMock(typeof(IVwStylesheet)); ScrMappingList list = new ScrMappingList(MappingSet.Main, (IVwStylesheet)mockStylesheet.MockInstance); list.AddDefaultMappingIfNeeded(@"\cap", ImportDomain.Main, true); list.AddDefaultMappingIfNeeded(@"\cat", ImportDomain.Main, true); list.AddDefaultMappingIfNeeded(@"\gmb", ImportDomain.Main, true); list.AddDefaultMappingIfNeeded(@"\gmbj", ImportDomain.Main, true); Assert.AreEqual(4, list.Count); ImportMappingInfo info = list[@"\cap"]; Assert.AreEqual(MarkerDomain.Default, info.Domain); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.FigureCaption, info.MappingTarget); Assert.IsNull(info.StyleName); info = list[@"\cat"]; Assert.AreEqual(MarkerDomain.Default, info.Domain); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.FigureFilename, info.MappingTarget); Assert.IsNull(info.StyleName); info = list[@"\gmb"]; Assert.AreEqual(MarkerDomain.Default, info.Domain); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.FigureFilename, info.MappingTarget); Assert.IsNull(info.StyleName); info = list[@"\gmbj"]; Assert.AreEqual(MarkerDomain.Default, info.Domain); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.FigureCaption, info.MappingTarget); Assert.IsNull(info.StyleName); }
public void AddDefaultMappingIfNeeded_FigureMarkers() { IVwStylesheet stylesheet = MockRepository.GenerateMock <IVwStylesheet>(); ScrMappingList list = new ScrMappingList(MappingSet.Main, stylesheet, TestTeStylesPath); list.AddDefaultMappingIfNeeded(@"\cap", ImportDomain.Main, true); list.AddDefaultMappingIfNeeded(@"\cat", ImportDomain.Main, true); list.AddDefaultMappingIfNeeded(@"\gmb", ImportDomain.Main, true); list.AddDefaultMappingIfNeeded(@"\gmbj", ImportDomain.Main, true); Assert.AreEqual(4, list.Count); ImportMappingInfo info = list[@"\cap"]; Assert.AreEqual(MarkerDomain.Default, info.Domain); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.FigureCaption, info.MappingTarget); Assert.IsNull(info.StyleName); info = list[@"\cat"]; Assert.AreEqual(MarkerDomain.Default, info.Domain); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.FigureFilename, info.MappingTarget); Assert.IsNull(info.StyleName); info = list[@"\gmb"]; Assert.AreEqual(MarkerDomain.Default, info.Domain); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.FigureFilename, info.MappingTarget); Assert.IsNull(info.StyleName); info = list[@"\gmbj"]; Assert.AreEqual(MarkerDomain.Default, info.Domain); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.FigureCaption, info.MappingTarget); Assert.IsNull(info.StyleName); }
public void SetMappings_Notes() { ScrMappingList list = new ScrMappingList(MappingSet.Notes, null); list.Add(new ImportMappingInfo(@"\a", null, false, MappingTargetType.TEStyle, MarkerDomain.Note, ScrStyleNames.Remark, null)); list.Add(new ImportMappingInfo(@"\b", null, false, MappingTargetType.TEStyle, MarkerDomain.Default, ScrStyleNames.Remark, null)); try { list.Add(new ImportMappingInfo(@"\q", null, false, MappingTargetType.TEStyle, MarkerDomain.BackTrans, ScrStyleNames.NormalParagraph, null)); Assert.Fail("Illegal mapping (to BackTrans domain) was not caught"); } catch (ArgumentException) {} Assert.AreEqual(2, list.Count); ImportMappingInfo mapping = list[0]; Assert.AreEqual(@"\a", mapping.BeginMarker); Assert.AreEqual(MarkerDomain.Default, mapping.Domain); mapping = list[1]; Assert.AreEqual(@"\b", mapping.BeginMarker); Assert.AreEqual(MarkerDomain.Default, mapping.Domain); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged /// resources; <c>false</c> to release only unmanaged resources. /// </param> /// ----------------------------------------------------------------------------------- protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) { return; } if (disposing) { if (components != null) { components.Dispose(); } } m_styleListHelper = null; m_StyleSheet = null; m_mapping = null; m_cache = null; m_scr = null; base.Dispose(disposing); }
/// ------------------------------------------------------------------------------------- /// <summary> /// Constructor /// </summary> /// <param name="mapping">Provides intial values displayed in dialog.</param> /// <param name="styleSheet">Provides the character styles user can pick from.</param> /// <param name="cache">The DB cache</param> /// ------------------------------------------------------------------------------------- public DummyCharacterMappingSettings(ImportMappingInfo mapping, FwStyleSheet styleSheet, FdoCache cache) : base(mapping, styleSheet, cache, false, null, null) { // No code needed so far. }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initialize this dialog /// </summary> /// <param name="fParatextMapping"><c>true</c> if a Paratext mapping is being modified; /// <c>false</c> otherwise</param> /// <param name="mapping">Mapping object being modified</param> /// <param name="styleSheet">Stylesheet containing styles that will appear in the list /// </param> /// <param name="cache">The cache representing the DB connection</param> /// <param name="fBackTransDomainLocked">If <c>true</c>, won't allow the user to /// check or clear the BT checkbox. If the incoming mapping is for the back translation /// and has a domain of either Scripture or Footnote, these two domains remain /// enabled so the user can switch between them, but the Notes domain will be /// disabled. If the incoming mapping is not for the back translation, then /// this only affects the BT checkbox, not the domain options. /// </param> /// <param name="isAnnotationMapping">If <c>true</c>, forces this mapping to be in the /// Annotation domain.</param> /// <remarks>We separated this from the constructor so that we can create a mock object /// for testing purposes.</remarks> /// ------------------------------------------------------------------------------------ public virtual void Initialize(bool fParatextMapping, ImportMappingInfo mapping, FwStyleSheet styleSheet, FdoCache cache, bool isAnnotationMapping, bool fBackTransDomainLocked) { CheckDisposed(); m_fParatextMapping = fParatextMapping; m_cache = cache; m_scr = cache.LangProject.TranslatedScriptureOA; m_mapping = mapping; m_StyleSheet = styleSheet; m_isAnnotationMapping = isAnnotationMapping; m_fBackTransDomainLocked = fBackTransDomainLocked; m_styleListHelper.StyleSheet = styleSheet as FwStyleSheet; // // if there are items in the styles list and there is not one selected then // // set the first item to be the selected item. // if (lbStyles.SelectedIndex == -1 && lbStyles.Items.Count > 0) // lbStyles.SelectedIndex = 0; // Fill in the list selector combo box with the filters for the style list // Also set the maximum style level for the style list helper before the // style list gets filled in. cboList.Items.Clear(); cboList.Items.Add(TeResourceHelper.GetResourceString("kstidStyleFilterBasic")); cboList.Items.Add(TeResourceHelper.GetResourceString("kstidStyleFilterAllStyles")); cboList.Items.Add(TeResourceHelper.GetResourceString("kstidStyleFilterCustomList")); cboList.SelectedIndex = 1; // This code was not completely removed for the highly likely case that // it gets put back :) // switch (Options.ShowTheseStylesSetting) // { // case Options.ShowTheseStyles.Basic: // cboList.SelectedIndex = 0; // m_styleListHelper.MaxStyleLevel = 0; // break; // case Options.ShowTheseStyles.All: // cboList.SelectedIndex = 1; // m_styleListHelper.MaxStyleLevel = int.MaxValue; // break; // case Options.ShowTheseStyles.Custom: // cboList.SelectedIndex = 2; // m_styleListHelper.MaxStyleLevel = ToolsOptionsDialog.MaxStyleLevel; // break; // } chkBackTranslation.Checked = (mapping.Domain & MarkerDomain.BackTrans) != 0; // Check the appropriate button for the domain. This will cause the // style list to be loaded correctly for the domain. switch (mapping.Domain & ~MarkerDomain.BackTrans) { case MarkerDomain.Footnote: rbtnFootnotes.Checked = true; break; case MarkerDomain.Note: rbtnNotes.Checked = true; break; default: rbtnScripture.Checked = true; break; } // select the style name and add the handler for style changes. This needs // to be done after setting the domain since that causes the style list to // be loaded the first time. m_styleListHelper.SelectedStyleName = MappingToUiStylename(mapping); m_styleListHelper.StyleChosen += new StyleChosenHandler(StyleChosen); // if the selected mapping is excluded, then check the box if (chkExclude.Checked != mapping.IsExcluded) { chkExclude.Checked = mapping.IsExcluded; } else { SetControlStatesBasedOnExcludeCheckBox(null, null); } cboWritingSys.Items.Clear(); // Create a fake WS for the "Based on Context" item cboWritingSys.Items.Add(TeResourceHelper.GetResourceString("kstidBasedOnContext")); string initialWritingSystem = string.Empty; // Iterate through the available writing systems and add them to the writing systems // combo box. foreach (IWritingSystem wsObj in cache.ServiceLocator.WritingSystems.AllWritingSystems) { cboWritingSys.Items.Add(wsObj); // If the mapping's ICULocale matches the current writing system's ICULocale, // save the string just added to the combo box so we can initialize the // combo box's value with it. if (mapping.WsId == wsObj.Id) { initialWritingSystem = wsObj.ToString(); } } // Initialize the combo's value. cboWritingSys.SelectedIndex = (initialWritingSystem == string.Empty ? 0 : cboWritingSys.FindString(initialWritingSystem)); }
public void AddDefaultMappingIfNeeded_btMappings() { DynamicMock mockStylesheet = new DynamicMock(typeof(IVwStylesheet)); mockStylesheet.SetupResultForParams("GetContext", (int)ContextValues.Note, ScrStyleNames.NormalFootnoteParagraph); mockStylesheet.SetupResultForParams("GetContext", (int)ContextValues.Text, ScrStyleNames.NormalParagraph); mockStylesheet.SetupResultForParams("GetContext", (int)ContextValues.General, "Emphasis"); mockStylesheet.SetupResultForParams("GetContext", (int)ContextValues.Annotation, ScrStyleNames.Remark); mockStylesheet.SetupResultForParams("GetType", (int)StyleType.kstParagraph, ScrStyleNames.NormalFootnoteParagraph); mockStylesheet.SetupResultForParams("GetType", (int)StyleType.kstParagraph, ScrStyleNames.NormalParagraph); mockStylesheet.SetupResultForParams("GetType", (int)StyleType.kstCharacter, "Emphasis"); mockStylesheet.SetupResultForParams("GetType", (int)StyleType.kstParagraph, ScrStyleNames.Remark); ScrMappingList list = new ScrMappingList(MappingSet.Main, (IVwStylesheet)mockStylesheet.MockInstance); list.AddDefaultMappingIfNeeded(@"\bt", ImportDomain.Main, true); list.AddDefaultMappingIfNeeded(@"\btc", ImportDomain.Main, true); list.AddDefaultMappingIfNeeded(@"\btf", ImportDomain.Main, true); list.AddDefaultMappingIfNeeded(@"\btp", ImportDomain.Main, true); list.Add(new ImportMappingInfo(@"\emph", null, "Emphasis")); list.AddDefaultMappingIfNeeded(@"\btemph", ImportDomain.Main, true); list.AddDefaultMappingIfNeeded(@"\btrem", ImportDomain.Main, true); list.AddDefaultMappingIfNeeded(@"\bty", ImportDomain.Main, true); Assert.AreEqual(8, list.Count); // Test that \bt does not map automatically as a Back-trans marker. ImportMappingInfo info = list[@"\bt"]; Assert.AreEqual(MarkerDomain.Default, info.Domain, @"\bt should not map automatically as a Back-trans marker"); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget); Assert.IsNull(info.StyleName); // Test that \btc does not map automatically as a Back-trans marker (this is a special exception to the rul). info = list[@"\btc"]; Assert.AreEqual(MarkerDomain.Default, info.Domain, @"\btc should not map automatically as a Back-trans marker"); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget); Assert.IsNull(info.StyleName); // Test that \btf maps automatically as a Back-trans marker. info = list[@"\btf"]; Assert.AreEqual(MarkerDomain.BackTrans | MarkerDomain.Footnote, info.Domain, @"\btf should map automatically as a Back-trans marker"); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget); Assert.AreEqual(ScrStyleNames.NormalFootnoteParagraph, info.StyleName); // Test that \btp maps automatically as a Back-trans marker. info = list[@"\btp"]; Assert.AreEqual(MarkerDomain.BackTrans, info.Domain, @"\btp should map automatically as a Back-trans marker"); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget); Assert.AreEqual(ScrStyleNames.NormalParagraph, info.StyleName); // Test that \btemph maps automatically to the corresponding vernacular style but does not map // into the Back-trans marker domain because \emph is a character style. info = list[@"\btemph"]; Assert.AreEqual(MarkerDomain.Default, info.Domain, @"\btemph should not map automatically as a Back-trans marker"); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget); Assert.AreEqual("Emphasis", info.StyleName); // Test that \btrem does not map automatically as a Back-trans marker (because \rem is a Note style). info = list[@"\btrem"]; Assert.AreEqual(MarkerDomain.Default, info.Domain, @"\btrem should not map automatically as a Back-trans marker"); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget); Assert.IsNull(info.StyleName); // Test that \bty does not map automatically as a Back-trans marker (because \y has no default mapping). info = list[@"\bty"]; Assert.AreEqual(MarkerDomain.Default, info.Domain, @"\bty should not map automatically as a Back-trans marker"); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget); Assert.IsNull(info.StyleName); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Convert the source line into unicode if necessary /// </summary> /// ------------------------------------------------------------------------------------ private string ConvertSource(string source, ImportMappingInfo markerMapping) { // If the file is already Unicode then no need to convert it. if (m_currentFile.FileEncoding != Encoding.ASCII) { return(source); } IEncConverter dataEncoding; if (markerMapping == null) { // If the marker is not mapped, use the containing paragraph's encoding. dataEncoding = m_prevDataEncoding; } else { // book markers are a special case - do not convert them if (markerMapping.BeginMarker == ScrMappingList.MarkerBook) { return(source); } if (markerMapping.WsId != null) { dataEncoding = GetEncodingConverterForWs(markerMapping.WsId, markerMapping.BeginMarker); } else { // For paragraph styles or markers that do not map to existing styles, // or verse or chapter numbers or any default para char style that is // not inline get the encoder from the current domain. Otherwise use // the containing paragraph's encoder if (markerMapping.Style == null || markerMapping.IsParagraphStyle || markerMapping.StyleName == ScrStyleNames.VerseNumber || markerMapping.StyleName == ScrStyleNames.ChapterNumber || (!markerMapping.IsInline && markerMapping.StyleName == StyleUtils.DefaultParaCharsStyleName)) { dataEncoding = GetEncodingConverterForMarkerDomain(markerMapping); } else { dataEncoding = m_prevDataEncoding; } } // If the marker maps to a paragraph style or pertains to a non-default domain, // then save the encoder as the current paragraph encoder if (m_domain == ImportDomain.Main && ((markerMapping.StyleName != StyleUtils.DefaultParaCharsStyleName && (markerMapping.Style == null || markerMapping.IsParagraphStyle)) || (markerMapping.Domain & ~MarkerDomain.Footnote) != MarkerDomain.Default)) { m_prevDataEncoding = dataEncoding; } } // If an encoder was not found, then just return the text if (dataEncoding == null) { return(source); } // get a converter and convert the text dataEncoding.CodePageInput = EncodingConstants.kMagicCodePage; if (source != string.Empty) { try { source = dataEncoding.Convert(source); } catch (Exception e) { throw new EncodingConverterException( string.Format(ScriptureUtilsException.GetResourceString( "kstidEncConverterError"), e.Message, dataEncoding.Name), "/Beginning_Tasks/Import_Standard_Format/Unable_to_Import/Encoding_conversion_failed.htm"); } } return(source); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Process a segment of text. If there are inline markers, then break out the /// pieces and return the next segment /// </summary> /// <param name="source">source text to process</param> /// <param name="marker">text of the marker</param> /// <param name="literalVerse">literal verse string to use</param> /// <returns>the next text segment</returns> /// ------------------------------------------------------------------------------------ private ISCTextSegment ProcessNextSegmentOfText(string source, string marker, string literalVerse) { bool fContinuationLine = (source == m_remainingLineText && !string.IsNullOrEmpty(source)); int startPos; string startMarker = FindNextMarker(source, 0, out startPos); ImportMappingInfo markerMapping = m_settings.MappingForMarker(marker, m_mappingSet); // If there are no markers, return the entire string as the segment if (startMarker == null) { m_remainingLineText = string.Empty; } else if (startPos != 0 || marker != string.Empty) { // If the first marker is not at the start or if this is the very first time // through for this line, then save the text from the marker and // process the leading text (which may actually be an empty string if this // is a line beginning with a paragraph marker followed immediately by an // in-line marker). m_remainingLineText = source.Substring(startPos); source = source.Substring(0, startPos); } else { // An inline marker was found at the beginning of the line so process it now int endPos; string endMarker = FindNextMarker(source, startPos + startMarker.Length, out endPos); if (endMarker != null) { m_remainingLineText = source.Substring(endPos); int ichStartOfSegment = startPos + startMarker.Length; if (m_settings.ImportTypeEnum == TypeOfImport.Paratext5 && endPos > ichStartOfSegment) { // P5 in-line begin markers don't include the trailing space (for display // purposes), but it is required. Start markers do not end in "*", end // markers do. if (!startMarker.EndsWith("*")) { Debug.Assert(source[ichStartOfSegment] == ' ' || source[ichStartOfSegment] == '\t'); ichStartOfSegment += 1; } } source = source.Substring(ichStartOfSegment, endPos - ichStartOfSegment); } else { source = source.Substring(startPos + startMarker.Length); m_remainingLineText = string.Empty; } // For inline markers, get the mapping info markerMapping = m_settings.MappingForMarker(startMarker, m_mappingSet); marker = startMarker; } // need to process chapter/verse references on continuation lines if (fContinuationLine && (marker == @"\v" || marker == @"\c")) { GetReferenceForLine(marker, ref source, ref literalVerse); } // Build a segment to return return(new SCTextSegment(ConvertSource(source, markerMapping), marker, literalVerse, m_currentStartRef, m_currentEndRef, m_currentFile.FileName, m_lineNumber)); }
private bool LoadProjectMappings(string project, ScrMappingList mappingList, ImportDomain domain) { // If the new project ID is null, then do not load mappings. if (string.IsNullOrEmpty(project)) { return(false); } // Load the tags from the paratext project and create mappings for them. IScrText scParatextText; try { // ParatextShared has a static collection that is responsible for the dispose of any IScrText objects scParatextText = ScriptureProvider.Get(project); } catch (Exception ex) { Logger.WriteError(ex); m_IsParatextInitialized = false; return(false); } foreach (ImportMappingInfo mapping in mappingList) { mapping.SetIsInUse(domain, false); } try { foreach (var tag in scParatextText.DefaultStylesheet.Tags) { if (tag == null) { break; } string marker = @"\" + tag.Marker; string endMarker = string.Empty; if (!string.IsNullOrEmpty(tag.Endmarker)) { endMarker = @"\" + tag.Endmarker; } // When the nth marker has an end marker, the nth + 1 marker will be // that end marker. Therefore, we have to skip those "end style" markers. if (tag.StyleType == ScrStyleType.scEndStyle) { continue; } // Create a new mapping for this marker. mappingList.AddDefaultMappingIfNeeded(marker, endMarker, domain, false, false); } var parser = scParatextText.Parser; foreach (int bookNum in scParatextText.BooksPresentSet.SelectedBookNumbers) { foreach (var token in parser.GetUsfmTokens(ScriptureProvider.MakeVerseRef(bookNum, 0, 0), false, true)) { if (token.Marker == null) { continue; // Tokens alternate between text and marker types } ImportMappingInfo mapping = mappingList[@"\" + token.Marker]; if (mapping != null) { mapping.SetIsInUse(domain, true); } } } } catch (Exception ex) { Logger.WriteError(ex); // A lot goes on in the try block, so this exception doesn't necessarily mean Paratext is inaccessible, // so don't mark Paratext as uninitialized return(false); } return(true); }
public void AddDefaultMappingIfNeeded_btMappings() { IVwStylesheet stylesheet = MockRepository.GenerateStub <IVwStylesheet>(); stylesheet.Stub(x => x.GetContext(ScrStyleNames.NormalFootnoteParagraph)).Return((int)ContextValues.Note); stylesheet.Stub(x => x.GetContext(ScrStyleNames.NormalParagraph)).Return((int)ContextValues.Text); stylesheet.Stub(x => x.GetContext("Emphasis")).Return((int)ContextValues.General); stylesheet.Stub(x => x.GetContext(ScrStyleNames.Remark)).Return((int)ContextValues.Annotation); stylesheet.Stub(x => x.GetType(ScrStyleNames.NormalFootnoteParagraph)).Return((int)StyleType.kstParagraph); stylesheet.Stub(x => x.GetType(ScrStyleNames.NormalParagraph)).Return((int)StyleType.kstParagraph); stylesheet.Stub(x => x.GetType("Emphasis")).Return((int)StyleType.kstCharacter); stylesheet.Stub(x => x.GetType(ScrStyleNames.Remark)).Return((int)StyleType.kstParagraph); ScrMappingList list = new ScrMappingList(MappingSet.Main, stylesheet, TestTeStylesPath); list.AddDefaultMappingIfNeeded(@"\bt", ImportDomain.Main, true); list.AddDefaultMappingIfNeeded(@"\btc", ImportDomain.Main, true); list.AddDefaultMappingIfNeeded(@"\btf", ImportDomain.Main, true); list.AddDefaultMappingIfNeeded(@"\btp", ImportDomain.Main, true); list.Add(new ImportMappingInfo(@"\emph", null, "Emphasis")); list.AddDefaultMappingIfNeeded(@"\btemph", ImportDomain.Main, true); list.AddDefaultMappingIfNeeded(@"\btrem", ImportDomain.Main, true); list.AddDefaultMappingIfNeeded(@"\bty", ImportDomain.Main, true); Assert.AreEqual(8, list.Count); // Test that \bt does not map automatically as a Back-trans marker. ImportMappingInfo info = list[@"\bt"]; Assert.AreEqual(MarkerDomain.Default, info.Domain, @"\bt should not map automatically as a Back-trans marker"); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget); Assert.IsNull(info.StyleName); // Test that \btc does not map automatically as a Back-trans marker (this is a special exception to the rul). info = list[@"\btc"]; Assert.AreEqual(MarkerDomain.Default, info.Domain, @"\btc should not map automatically as a Back-trans marker"); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget); Assert.IsNull(info.StyleName); // Test that \btf maps automatically as a Back-trans marker. info = list[@"\btf"]; Assert.AreEqual(MarkerDomain.BackTrans | MarkerDomain.Footnote, info.Domain, @"\btf should map automatically as a Back-trans marker"); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget); Assert.AreEqual(ScrStyleNames.NormalFootnoteParagraph, info.StyleName); // Test that \btp maps automatically as a Back-trans marker. info = list[@"\btp"]; Assert.AreEqual(MarkerDomain.BackTrans, info.Domain, @"\btp should map automatically as a Back-trans marker"); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget); Assert.AreEqual(ScrStyleNames.NormalParagraph, info.StyleName); // Test that \btemph maps automatically to the corresponding vernacular style but does not map // into the Back-trans marker domain because \emph is a character style. info = list[@"\btemph"]; Assert.AreEqual(MarkerDomain.Default, info.Domain, @"\btemph should not map automatically as a Back-trans marker"); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget); Assert.AreEqual("Emphasis", info.StyleName); // Test that \btrem does not map automatically as a Back-trans marker (because \rem is a Note style). info = list[@"\btrem"]; Assert.AreEqual(MarkerDomain.Default, info.Domain, @"\btrem should not map automatically as a Back-trans marker"); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget); Assert.IsNull(info.StyleName); // Test that \bty does not map automatically as a Back-trans marker (because \y has no default mapping). info = list[@"\bty"]; Assert.AreEqual(MarkerDomain.Default, info.Domain, @"\bty should not map automatically as a Back-trans marker"); Assert.IsFalse(info.IsExcluded); Assert.AreEqual(MappingTargetType.TEStyle, info.MappingTarget); Assert.IsNull(info.StyleName); }