示例#1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initialize the members of a ScrMarkerMapping from an ImportMappingInfo object
		/// </summary>
		/// <param name="info"></param>
		/// ------------------------------------------------------------------------------------
		internal void InitFromImportMappingInfo(ImportMappingInfo info)
		{
			BeginMarker = info.BeginMarker;
			EndMarker = info.EndMarker;
			Excluded = info.IsExcluded;
			Target = (int)info.MappingTarget;
			Domain = (int)info.Domain;
			StyleRA = info.Style == null ? m_cache.LangProject.TranslatedScriptureOA.FindStyle(info.StyleName) : info.Style;
			WritingSystem = info.WsId;
			NoteTypeRA = info.NoteType;
		}
示例#2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Add a mapping to the mapping list.
		/// </summary>
		/// <param name="mapping">mapping info to add to the list</param>
		/// ------------------------------------------------------------------------------------
		public void Add(ImportMappingInfo mapping)
		{
			if (mapping == null)
				throw new ArgumentNullException();
			if (mapping.BeginMarker == null || mapping.BeginMarker == string.Empty)
				throw new ArgumentException("Begin marker must be set before adding mapping to the list.");

			if (mapping.BeginMarker == MarkerChapter)
			{
				// REVIEW: Do we also need to do this for the Annotations domain. What does the importer expect?
				mapping.StyleName = ScrStyleNames.ChapterNumber;
			}
			else if (mapping.BeginMarker == MarkerVerse)
			{
				// REVIEW: Do we also need to do this for the Annotations domain. What does the importer expect?
				mapping.StyleName = ScrStyleNames.VerseNumber;
			}
			else if (mapping.BeginMarker == MarkerBook)
			{
				// \id markers do not have a style or domain
				mapping.Domain = MarkerDomain.Default;
				mapping.StyleName = null;
			}
			else
			{
				switch (m_mappingSet)
				{
					case MappingSet.Main:
						// If this is a BT marker but it's already in the list in the Default domain, clear the
						// BT flag and make sure it isn't being redefined.
						if ((mapping.Domain & MarkerDomain.BackTrans) != 0 && m_list.ContainsKey(mapping.BeginMarker))
						{
							ImportMappingInfo existingMapping = this[mapping.BeginMarker];
							if ((existingMapping.Domain & MarkerDomain.BackTrans) == 0)
								mapping.Domain = existingMapping.Domain;
						}
						break;

					case MappingSet.Notes:
						// If the mapping is for the annotations domain and it is marked as Note, then
						// set it to Default.
						if (mapping.Domain == MarkerDomain.Note)
							mapping.Domain = MarkerDomain.Default;
						if (mapping.Domain != MarkerDomain.Default)
							throw new ArgumentException("Invalid mapping domain");
						break;
				}
			}
			m_list[mapping.BeginMarker] = mapping;
			mapping.HasChanged = true;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Constructor for runtime.
		/// </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>
		/// <param name="fIsAnnotation">if set to <c>true</c> the current tab is for
		/// annotations.</param>
		/// <param name="helpTopicProvider">The help topic provider.</param>
		/// <param name="app">The application</param>
		/// ------------------------------------------------------------------------------------
		public CharacterMappingSettings(ImportMappingInfo mapping, FwStyleSheet styleSheet,
			FdoCache cache, bool fIsAnnotation, IHelpTopicProvider helpTopicProvider, IApp app) :
			this()
		{
			m_resources = new ResourceManager("SIL.FieldWorks.TE.ScrImportComponents",
				Assembly.GetExecutingAssembly());

			m_cache = cache;
			m_helpTopicProvider = helpTopicProvider;
			m_app = app;
			m_styleSheet = styleSheet;

			InitializeControls(mapping, fIsAnnotation);
		}
示例#4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Display the Add Character Mapping Settings dialog box
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		/// ------------------------------------------------------------------------------------
		protected void btnAdd_Click(object sender, EventArgs e)
		{
			Debug.Assert(m_projectType != ProjectTypes.Paratext);

			// This creates (if necessary) and then displays the Character Mapping Settings
			// Dialog box.
			m_sMarkerBeingModified = null;
			ImportMappingInfo mapping = new ImportMappingInfo(string.Empty, string.Empty, null);
			DisplayInlineMappingDialog(mapping);

			if (m_inlineMappingDialog.DialogResult == DialogResult.OK)
			{
				// create a new mapping in the in-memory list of the settings
				m_settings.SetMapping(tabCtrlMappings.SelectedIndex == 0 ?
					MappingSet.Main : MappingSet.Notes, mapping);

				// put mapping into the listview
				ListViewItem newListViewItem = LoadLVMappingItem(m_lvCurrentMappingList, mapping);

				//unselect everything
				while (m_lvCurrentMappingList.SelectedItems.Count > 0)
					m_lvCurrentMappingList.SelectedItems[0].Selected = false;

				//select the item just added
				newListViewItem.Selected = true;
				newListViewItem.Focused = true;
			}
			m_lvCurrentMappingList.Focus();
		}
示例#5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// <param name="mapping"></param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		private static string MappingStyleNameAsUIString(ImportMappingInfo mapping)
		{
			// If the mapping is excluded, display an indicator instead of the style name
			if (mapping.IsExcluded)
				return ScrImportComponents.kstidExcludedData;

			return MappingDetailsCtrl.MappingToUiStylename(mapping);
		}
示例#6
0
        /// ------------------------------------------------------------------------------------
        /// <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);
        }
示例#7
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// This method will add or modify a single mapping in the list view.
		/// </summary>
		/// <param name="lv">FwListView to add item to</param>
		/// <param name="item">FwListView item to modify or null if a new one should be added.
		/// </param>
		/// <param name="mapping">ECMapping object used to load FwListView item.</param>
		/// <returns>The ListViewItem that was added or modified</returns>
		/// ------------------------------------------------------------------------------------
		private ListViewItem LoadLVMappingItem(FwListView lv, ListViewItem item,
			ImportMappingInfo mapping)
		{
			bool newItem = false;
			if (item == null)
			{
				newItem = true;
				item = new ListViewItem(mapping.BeginMarker);
			}
			else
			{
				item.SubItems.Clear();
				item.Text = mapping.BeginMarker;
			}
			if (mapping.IsInline)
				item.Text += "..." + mapping.EndMarker;

			item.Tag = mapping;
			string styleName = MappingStyleNameAsUIString(mapping);
			item.SubItems.Add(styleName);

			string sSubItem = GetMappingDetailsAsString(mapping);

			item.SubItems.Add(sSubItem);
			if (newItem)
				lv.Items.Add(item);

			return item;
		}
示例#8
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Read the file to build mappings of the markers found
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected void GetMappingsFromStream(TextReader reader)
        {
            string lineIn;

            int chapter   = -1;
            int book      = -1;
            int lineCount = 0;

            // book and chapter strings for reporting info in exceptions
            string sBookId  = null;
            string sChapter = null;
            string sVerse   = null;

            // Keep track of the first reference in the file
            int firstBook    = -1;
            int firstChapter = -1;
            int firstVerse   = -1;

            ReferenceRange currentRange = null;
            string         marker;
            string         lineText;
            string         nextLineText = null;     // used for read-ahead for \fig line when doing strict scanning

            while ((lineIn = reader.ReadLine()) != null)
            {
                lineCount++;
                while (GetNextMarkerFromData(lineIn, out marker, out lineText))
                {
                    // Make sure the marker is valid
                    if (!IsValidMarker(marker))
                    {
                        throw new ScriptureUtilsException(SUE_ErrorCode.InvalidCharacterInMarker,
                                                          FileName, lineCount, lineIn, sBookId, sChapter, sVerse);
                    }

                    ImportMappingInfo markerMapping = GetOrCreateMarkerMapping(ref marker);

                    if (marker == ScrMappingList.MarkerBook)
                    {
                        sBookId = lineText.TrimStart().ToUpperInvariant();

                        // save the book number in the list for this file
                        book = ScrReference.BookToNumber(sBookId);
                        if (book <= 0)
                        {
                            throw new ScriptureUtilsException(SUE_ErrorCode.InvalidBookID, FileName,
                                                              lineCount, lineIn, sBookId, null, null);
                        }
                        sBookId = ScrReference.NumberToBookCode(book);

                        // Make a new reference range with the book id and
                        // start it out with chapter range of 0-0.
                        AddRangeToList(currentRange);
                        currentRange = new ReferenceRange(book, 0, 0);

                        // If this is the first book, remember it
                        if (firstBook == -1)
                        {
                            firstBook = book;
                        }
                        m_booksInFile.Add(book);
                        chapter = -1;
                    }
                    else
                    {
                        // make sure that a book has been started before seeing any non-excluded markers
                        // This error is a "strict" error because files can be added by a user before there
                        // is a chance to exclude markers in the mappings. When the file is added from the settings
                        // for import, then strict checking will be on.
                        if (book == -1 && m_doStrictFileChecking)
                        {
                            // if the marker is not excluded then throw an error
                            if (markerMapping != null && !markerMapping.IsExcluded)
                            {
                                throw new ScriptureUtilsException(SUE_ErrorCode.UnexcludedDataBeforeIdLine,
                                                                  FileName, lineCount, lineIn, null, null, null);
                            }
                        }

                        if (marker == ScrMappingList.MarkerChapter)
                        {
                            // If there is no book, then throw an error since chapter numbers
                            // are not valid without a book
                            if (book == -1)
                            {
                                throw new ScriptureUtilsException(SUE_ErrorCode.ChapterWithNoBook,
                                                                  FileName, lineCount, lineIn, null, null, null);
                            }
                            try
                            {
                                sChapter = lineText;
                                chapter  = ScrReference.ChapterToInt(sChapter);

                                // save the chapter number as the last chapter and possibly the first
                                // chapter number in the range.
                                if (currentRange.StartChapter == 0)
                                {
                                    currentRange.StartChapter = chapter;
                                }
                                currentRange.EndChapter = chapter;
                            }
                            catch (ArgumentException)
                            {
                                throw new ScriptureUtilsException(SUE_ErrorCode.InvalidChapterNumber,
                                                                  FileName, lineCount, lineIn, sBookId, sChapter, null);
                            }
                            // If this is the first chapter, remember it
                            if (firstChapter == -1)
                            {
                                firstChapter = chapter;
                            }
                        }

                        else if (marker == ScrMappingList.MarkerVerse)
                        {
                            // If a verse is seen without a book, throw an exception
                            if (book == -1)
                            {
                                throw new ScriptureUtilsException(SUE_ErrorCode.VerseWithNoBook,
                                                                  FileName, lineCount, lineIn, sBookId, null, lineText);
                            }

                            BCVRef firstRef = new BCVRef(book, chapter, 0);
                            BCVRef lastRef  = new BCVRef(book, chapter, 0);

                            // check for an invalid verse number
                            if (!BCVRef.VerseToScrRef(lineText, ref firstRef, ref lastRef) ||
                                firstRef.Verse == 0 || firstRef.Verse > lastRef.Verse)
                            {
                                throw new ScriptureUtilsException(SUE_ErrorCode.InvalidVerseNumber,
                                                                  FileName, lineCount, lineIn, sBookId, sChapter, lineText);
                            }

                            // If a chapter number has not been seen yet, then throw an exception
                            sVerse = firstRef.Verse.ToString();
                            if (chapter == -1 && !SingleChapterBook(book))
                            {
                                throw new ScriptureUtilsException(SUE_ErrorCode.MissingChapterNumber,
                                                                  FileName, lineCount, lineIn, sBookId, null, sVerse);
                            }

                            // If this is the first verse, remember it
                            if (firstVerse == -1)
                            {
                                firstVerse = firstRef.Verse;
                            }
                        }
                        else if (!markerMapping.IsExcluded && m_doStrictFileChecking &&
                                 markerMapping.MappingTarget == MappingTargetType.Figure)
                        {
                            // First, we need to consider whether any following lines also need
                            // to be read in, since the Figure parameters could be split across
                            // lines. (TE-7669)
                            Debug.Assert(nextLineText == null);
                            int    cExtraLinesRead = 0;
                            string sTempMarker, sTempLineText;
                            if (!GetNextMarkerFromData(lineText, out sTempMarker, out sTempLineText))
                            {
                                while ((nextLineText = reader.ReadLine()) != null)
                                {
                                    cExtraLinesRead++;
                                    if (GetNextMarkerFromData(nextLineText, out sTempMarker, out sTempLineText))
                                    {
                                        // Normally, we want to break the line right before the first marker.
                                        int ichMarkerPos = nextLineText.IndexOf(sTempMarker);
                                        // But if it's a \fig*, break after the marker.
                                        if (sTempMarker == markerMapping.EndMarker)
                                        {
                                            ichMarkerPos += sTempMarker.Length;
                                        }
                                        lineText    += " " + nextLineText.Substring(0, ichMarkerPos);
                                        nextLineText = nextLineText.Substring(ichMarkerPos);
                                        break;
                                    }
                                    else
                                    {
                                        lineText += " " + nextLineText;
                                    }
                                }
                            }

                            string figureParams    = lineText;
                            int    endMarkerLength = 0;
                            // Validate the tokens for a mapping target (only in strict checking)
                            if (!String.IsNullOrEmpty(markerMapping.EndMarker))
                            {
                                endMarkerLength = markerMapping.EndMarker.Length;
                                int ichEnd = figureParams.IndexOf(markerMapping.EndMarker);
                                if (ichEnd >= 0)
                                {
                                    figureParams = figureParams.Substring(0, ichEnd);
                                }
                                else
                                {
                                    endMarkerLength = 0;                                     // end marker is optional and not present
                                }
                            }
                            string[] tokens = figureParams.Split('|');
                            if (tokens.Length < 6)
                            {
                                throw new ScriptureUtilsException(SUE_ErrorCode.BadFigure, FileName,
                                                                  lineCount, lineIn, sBookId, sChapter, sVerse);
                            }
                            lineText   = lineText.Substring(figureParams.Length + endMarkerLength);
                            lineCount += cExtraLinesRead;
                        }
                    }
                    // Mark this mapping as "in-use" because it was found in the scanned file
                    markerMapping.SetIsInUse(m_domain, m_wsId, m_noteType, true);

                    if (m_scanInlineBackslashMarkers)
                    {
                        lineIn = lineText;
                    }
                    else
                    {
                        lineIn       = nextLineText;
                        nextLineText = null;
                        if (lineIn == null)
                        {
                            break;
                        }
                    }
                    if (string.IsNullOrEmpty(lineIn) && !string.IsNullOrEmpty(nextLineText))
                    {
                        lineIn       = nextLineText;
                        nextLineText = null;
                    }
                }
            }
            // Add the last range to the list
            AddRangeToList(currentRange);

            // If no books were found in the file then throw an exception
            if (book == -1)
            {
                throw new ScriptureUtilsException(SUE_ErrorCode.MissingBook,
                                                  FileName, lineCount, null, null, null, null);
            }


            // If no chapters were found then throw an exception
            if (chapter == -1 && !SingleChapterBook(book))
            {
                throw new ScriptureUtilsException(SUE_ErrorCode.NoChapterNumber,
                                                  FileName, lineCount, null, sBookId, null, null);
            }

            // Store the first reference for the file
            m_startRef.Book    = firstBook;
            m_startRef.Chapter = firstChapter == -1 ? 1 : firstChapter;
            m_startRef.Verse   = firstVerse == -1 ? 1 : firstVerse;
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Add a mapping to the mapping list.
        /// </summary>
        /// <param name="mapping">mapping info to add to the list</param>
        /// ------------------------------------------------------------------------------------
        public void Add(ImportMappingInfo mapping)
        {
            if (mapping == null)
            {
                throw new ArgumentNullException();
            }
            if (mapping.BeginMarker == null || mapping.BeginMarker == string.Empty)
            {
                throw new ArgumentException("Begin marker must be set before adding mapping to the list.");
            }

            if (mapping.BeginMarker == MarkerChapter)
            {
                // REVIEW: Do we also need to do this for the Annotations domain. What does the importer expect?
                mapping.StyleName = ScrStyleNames.ChapterNumber;
            }
            else if (mapping.BeginMarker == MarkerVerse)
            {
                // REVIEW: Do we also need to do this for the Annotations domain. What does the importer expect?
                mapping.StyleName = ScrStyleNames.VerseNumber;
            }
            else if (mapping.BeginMarker == MarkerBook)
            {
                // \id markers do not have a style or domain
                mapping.Domain    = MarkerDomain.Default;
                mapping.StyleName = null;
            }
            else
            {
                switch (m_mappingSet)
                {
                case MappingSet.Main:
                    // If this is a BT marker but it's already in the list in the Default domain, clear the
                    // BT flag and make sure it isn't being redefined.
                    if ((mapping.Domain & MarkerDomain.BackTrans) != 0 && m_list.ContainsKey(mapping.BeginMarker))
                    {
                        ImportMappingInfo existingMapping = this[mapping.BeginMarker];
                        if ((existingMapping.Domain & MarkerDomain.BackTrans) == 0)
                        {
                            mapping.Domain = existingMapping.Domain;
                        }
                    }
                    break;

                case MappingSet.Notes:
                    // If the mapping is for the annotations domain and it is marked as Note, then
                    // set it to Default.
                    if (mapping.Domain == MarkerDomain.Note)
                    {
                        mapping.Domain = MarkerDomain.Default;
                    }
                    if (mapping.Domain != MarkerDomain.Default)
                    {
                        throw new ArgumentException("Invalid mapping domain");
                    }
                    break;
                }
            }
            m_list[mapping.BeginMarker] = mapping;
            mapping.HasChanged          = true;
        }
示例#10
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Copy constructor
		/// </summary>
		/// <param name="copy"></param>
		/// ------------------------------------------------------------------------------------
		public ImportMappingInfo(ImportMappingInfo copy)
		{
			m_beginMarker = copy.m_beginMarker;
			m_endMarker = copy.m_endMarker;
			m_isExcluded = copy.m_isExcluded;
			m_mappingTarget = copy.m_mappingTarget;
			m_domain = copy.m_domain;
			m_styleName = copy.m_styleName;
			m_style = copy.m_style;
			m_wsId = copy.m_wsId;
			m_noteType = copy.m_noteType;
		}
示例#11
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Delete a mapping from the designated mapping list
		/// </summary>
		/// <param name="mappingSet">Indicates the mapping list to delete from.</param>
		/// <param name="mapping">The mapping info</param>
		/// ------------------------------------------------------------------------------------
		public void DeleteMapping(MappingSet mappingSet, ImportMappingInfo mapping)
		{
			lock (SyncRoot)
				GetMappingList(mappingSet).Delete(mapping);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Can be called on an existing dialog to modify or create a new mapping.
		/// </summary>
		/// <param name="mapping">Provides initial values displayed in dialog.</param>
		/// <param name="forceAnnotation">true to only allow annotation domain mappings</param>
		/// ------------------------------------------------------------------------------------
		public void InitializeControls(ImportMappingInfo mapping, bool forceAnnotation)
		{
			CheckDisposed();

			Debug.Assert(mapping != null);
			// If we are modifying an existing mapping then load the information about it.
			txtBeginningMarker.Text = mapping.BeginMarker;
			txtEndingMarker.Text = mapping.EndMarker;
			txtBeginningMarker.Focus();
			m_mapping = mapping;

			// Include all character styles
			mappingDetailsCtrl.m_styleListHelper.ShowOnlyStylesOfType = StyleType.kstCharacter;
			// Include footnote paragraph styles because they behave like character mappings.
			mappingDetailsCtrl.m_styleListHelper.UnionIncludeAndTypeFilter = true;

			mappingDetailsCtrl.Initialize(false, m_mapping, m_styleSheet, m_cache, forceAnnotation, false);
		}
示例#13
0
		/// ------------------------------------------------------------------------------------
		/// <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:
				case MappingTargetType.DefaultParaChars:
					return mapping.StyleName;
				default:
					Debug.Fail("Unexpected Mapping Target Type");
					return null;
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Clean up for a test.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public override void TestTearDown()
		{
			m_dialog.Dispose();
			m_dialog = null;
			m_mapping = null;
			m_styleSheet = null;
			m_Scripture = null;
			base.TestTearDown();
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Init for a test.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public override void TestSetup()
		{
			base.TestSetup();
			m_Scripture = Cache.LangProject.TranslatedScriptureOA;

			m_styleSheet = new FwStyleSheet();
			m_styleSheet.Init(Cache, m_Scripture.Hvo, ScriptureTags.kflidStyles);

			m_mapping = new ImportMappingInfo("emph{", "}", "Emphasis");
			Options.ShowTheseStylesSetting = Options.ShowTheseStyles.All;
			m_dialog = new DummyCharacterMappingSettings(m_mapping, m_styleSheet, Cache);
			m_dialog.StyleListHelper.MaxStyleLevel = int.MaxValue;
		}
示例#16
0
		/// ------------------------------------------------------------------------------------
		/// <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="helpTopicProvider">The help topic provider.</param>
		/// <param name="isAnnotationMapping">If <c>true</c>, forces this mapping to be in the
		/// Annotation domain.</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>
		/// <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, IHelpTopicProvider helpTopicProvider,
			bool isAnnotationMapping, bool fBackTransDomainLocked)
		{
			CheckDisposed();
			m_helpTopicProvider = helpTopicProvider;
			this.markerLabel.Text = mapping.BeginMarker;
			this.endMarkerLabel.Text = mapping.EndMarker;
			this.mappingDetailsCtrl.Initialize(fParatextMapping, mapping, styleSheet, cache,
				isAnnotationMapping, fBackTransDomainLocked);
		}
示例#17
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Delete an ImportMappingInfo object from the list
		/// </summary>
		/// <param name="mapping">mapping object to delete</param>
		/// ------------------------------------------------------------------------------------
		public void Delete(ImportMappingInfo mapping)
		{
			if (m_list.ContainsKey(mapping.BeginMarker))
			{
				m_list.Remove(mapping.BeginMarker);
				m_fMappingDeleted = true;
			}
		}
示例#18
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Add a default mapping for the given Standard Format marker if it does not exist yet.
		/// </summary>
		/// <param name="marker">The SF marker</param>
		/// <param name="endMarker">The end marker (or null)</param>
		/// <param name="importDomain">The import domain from which this marker originates</param>
		/// <param name="fAutoMapBtMarkers">Indicates whether markers beginning with "bt" should
		/// be treated as back-translation markers if possible.</param>
		/// <param name="isInUse">Indicates whether this marker is actually in use in one or more
		/// of the import files (for P6, this is currently always false since we're getting the
		/// markers from the STY file -- we come back in a second pass and set it to true if we
		/// find it in a file).</param>
		/// <returns>The newly added mapping info, or the existing one if already in the list
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public ImportMappingInfo AddDefaultMappingIfNeeded(string marker, string endMarker,
			ImportDomain importDomain, bool fAutoMapBtMarkers, bool isInUse)
		{
			// Look for the marker - if it is found and it maps to a Style, then we are done
			if (this[marker] != null && !String.IsNullOrEmpty(this[marker].StyleName))
				return this[marker];

			// Read the TEStyles XML file to generate a table of mappings
			if (s_defaultMappings.Count == 0)
				ReadDefaultMappings();

			string styleName;
			bool excluded;
			MappingTargetType target;
			MarkerDomain markerDomain = (importDomain != ImportDomain.BackTrans) ?
				MarkerDomain.Default : MarkerDomain.BackTrans;

			if (importDomain == ImportDomain.Annotations)
			{
				// TODO (TE-5004): Map \rem (and possibly other markers?) automatically in annotations
				// domain. Probably need to have a separate import mapping set in TeStyles.xml that has
				// default mappings for the Annotations domain.
				styleName = null;
				excluded = s_defaultExclusions.ContainsKey(marker); //Make sure to check exclusions (TE-5703)
				target = MappingTargetType.TEStyle;
			}
			else if (!GetDefaultMapping(marker, out styleName, out excluded, out target, ref markerDomain))
			{
				if (fAutoMapBtMarkers && importDomain == ImportDomain.Main &&
					marker.StartsWith(@"\bt") && marker != @"\btc")
				{
					// pick out the corresponding vernacular marker. "\btblah" -> "\blah"
					string correspondingVernMarker = marker.Remove(1, 2);

					// if domain is DeprecatedScripture and the corresponding vernacular marker is defined...
					ImportMappingInfo correspondingVernMarkerInfo = this[correspondingVernMarker];
					if (correspondingVernMarkerInfo != null &&
						(correspondingVernMarkerInfo.Domain & MarkerDomain.DeprecatedScripture) != 0)
					{
						// clear the DeprecatedScripture bit.
						correspondingVernMarkerInfo.Domain ^= MarkerDomain.DeprecatedScripture;
					}
					if (correspondingVernMarkerInfo != null)
					{
						// If the corresponding vernacular marker is already defined...
						if (correspondingVernMarkerInfo.Domain != MarkerDomain.Note &&
							(correspondingVernMarkerInfo.Domain & MarkerDomain.BackTrans) == 0 &&
							(correspondingVernMarkerInfo.MappingTarget != MappingTargetType.TEStyle ||
							correspondingVernMarkerInfo.StyleName != null))
						{
							styleName = correspondingVernMarkerInfo.StyleName;
							target = correspondingVernMarkerInfo.MappingTarget;
							markerDomain = correspondingVernMarkerInfo.Domain;

							// We only want to map to the BackTrans domain when mapping to a paragraph
							// style because character styles automatically assume the domain of their
							// containing paragraphs.
							if (m_stylesheet == null || styleName == null ||
								m_stylesheet.GetType(styleName) == (int)StyleType.kstParagraph)
							{
								markerDomain |= MarkerDomain.BackTrans;
							}
						}
					}
					else if (GetDefaultMapping(correspondingVernMarker, out styleName, out excluded, out target,
						ref markerDomain))
					{
						// The corresponding vernacular marker has default mapping info so make this marker
						// a back translation of it - unless it is an annotation or BT.
						if (markerDomain == MarkerDomain.Note || markerDomain == MarkerDomain.BackTrans)
						{
							styleName = null;
							excluded = false;
							target = MappingTargetType.TEStyle;
							markerDomain = MarkerDomain.Default;
						}
						else
							markerDomain |= MarkerDomain.BackTrans;
					}
				}
			}
			// Create a mapping for the marker using the default mapping
			ImportMappingInfo newMapping = new ImportMappingInfo(marker, endMarker, excluded, target,
				markerDomain, styleName, null, null, isInUse, importDomain);
			Add(newMapping);
			return newMapping;
		}
示例#19
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get the encoding converter for the current domain
		/// </summary>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		private IEncConverter GetEncodingConverterForMarkerDomain(ImportMappingInfo markerMapping)
		{
			Debug.Assert(markerMapping.WsId == null);

			string id;

			switch (markerMapping.Domain & ~MarkerDomain.Footnote)
			{
				case MarkerDomain.Default:
					id = m_currentFile.WsId;
					if (id == null) // Get the converter from default vern WS
					{
						id = (m_domain == ImportDomain.Main) ? Cache.LanguageProject.DefaultVernacularWritingSystem.Id
							: Cache.LanguageProject.DefaultAnalysisWritingSystem.Id;
					}
					break;

				case MarkerDomain.BackTrans:
				case MarkerDomain.Note:
					// Get the converter from default analysis WS
					id = (m_domain == ImportDomain.Main) ?
						Cache.LanguageProject.DefaultAnalysisWritingSystem.Id : m_currentFile.WsId;
					break;

				default:
					throw new ArgumentException(
						"Parameter markerMapping passed to GetEncodingConverterForMarkerDomain had invalid domain");
			}
			return GetEncodingConverterForWs(id, markerMapping.BeginMarker);
		}
示例#20
0
		/// ------------------------------------------------------------------------------------
		/// <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;
		}
示例#21
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Set (add or modify) a mapping in the designated mapping list
		/// </summary>
		/// <param name="mappingSet">Indicates the desired mapping list.</param>
		/// <param name="mapping">The mapping info</param>
		/// ------------------------------------------------------------------------------------
		public void SetMapping(MappingSet mappingSet, ImportMappingInfo mapping)
		{
			lock (SyncRoot)
				GetMappingList(mappingSet).Add(mapping);
		}
示例#22
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates (if necessary) and shows the CharacterMappingSettings dialog.
		/// This is a public virtual so that test code can override it.
		/// </summary>
		/// <param name="mapping">Provides intial values displayed in dialog.</param>
		/// ------------------------------------------------------------------------------------
		protected override void DisplayInlineMappingDialog(ImportMappingInfo mapping)
		{
			if (m_inlineMappingDialog == null)
			{
				m_inlineMappingDialog = new DummyCharacterMappingSettings(mapping, m_StyleSheet, m_cache);
				m_fDisposeInlineMappingDialog = true;
				m_inlineMappingDialog.IsDuplicateMapping += new DummyCharacterMappingSettings.IsDuplicateMappingHandler(IsDup);
			}
			else
			{
				m_inlineMappingDialog.InitializeControls(mapping, false);
				// clear warningHappened flag here in our dummy dialog
				((DummyCharacterMappingSettings)m_inlineMappingDialog).MappingInvalidWarningHappened =
					false;
				// This is pretty dumb, but we have to set it to cancel by default for testing purposes
				// because if the test asked for the OK button to be pressed but a validation error
				// occurs, we'll still pretend to close the dialog. If we return OK (as the user
				// requested), the subsequent code will think everything was okay.
				m_inlineMappingDialog.DialogResult = DialogResult.Cancel;
			}

			DummyCharacterMappingSettings mappingDlg = (DummyCharacterMappingSettings)m_inlineMappingDialog;
			if (m_MappingDialogDummyAccept)
			{
				mappingDlg.BeginningTextBox.Text = m_MappingDialogDummyData.BeginMarker;
				mappingDlg.EndingTextBox.Text = m_MappingDialogDummyData.EndMarker;
				mappingDlg.m_MappingDialogDummyData = m_MappingDialogDummyData;

				// fake the ok button being pressed.
				m_inlineMappingDialog.btnOk_Click(null, null);
			}
			else
				m_inlineMappingDialog.DialogResult = DialogResult.Cancel;
		}
示例#23
0
        public bool LoadProjectMappings(string project, ScrMappingList mappingList, ImportDomain domain)
        {
            // If the new project ID is null, then do not load mappings.
            if (project == null)
            {
                return(false);
            }

            // Load the tags from the paratext project and create mappings for them.
            ScrText scParatextText;

            try
            {
                // REVIEW (EberhardB): I'm not sure if ScrTextCollection.Get() returns a
                // reference to a ScrText or a new object (in which case we would have to
                // call Dispose() on it)
                scParatextText = ScrTextCollection.Get(project);
            }
            catch (Exception ex)
            {
                Logger.WriteError(ex);
                return(false);
            }

            mappingList.ResetInUseFlags(domain);
            try
            {
                foreach (ScrTag 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);
                }
                ScrParser parser = scParatextText.Parser();
                foreach (int bookNum in scParatextText.BooksPresentSet.SelectedBookNumbers())
                {
                    foreach (UsfmToken token in parser.GetUsfmTokens(new VerseRef(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);
                        }

                        // ENHANCE (TE-4408): Consider Detecting markers that occur in the data but are missing
                        // from the STY file. How can we write a test for this?
                        //else if (ScrImportFileInfo.IsValidMarker(sMarker))
                        //{
                        //    mappingList.AddDefaultMappingIfNeeded(sMarker,domain, false, true);
                        //}
                        //else
                        //{
                        //    throw new ScriptureUtilsException(SUE_ErrorCode.InvalidCharacterInMarker, null, 0,
                        //        sMarker + sText, new ScrReference(scParatextTextSegment.FirstReference.BBCCCVVV));
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteError(ex);
                return(false);
            }
            return(true);
        }
示例#24
0
			/// -------------------------------------------------------------------------------------
			/// <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.
			}
示例#25
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Add a default mapping for the given Standard Format marker if it does not exist yet.
        /// </summary>
        /// <param name="marker">The SF marker</param>
        /// <param name="endMarker">The end marker (or null)</param>
        /// <param name="importDomain">The import domain from which this marker originates</param>
        /// <param name="fAutoMapBtMarkers">Indicates whether markers beginning with "bt" should
        /// be treated as back-translation markers if possible.</param>
        /// <param name="isInUse">Indicates whether this marker is actually in use in one or more
        /// of the import files (for P6, this is currently always false since we're getting the
        /// markers from the STY file -- we come back in a second pass and set it to true if we
        /// find it in a file).</param>
        /// <returns>The newly added mapping info, or the existing one if already in the list
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public ImportMappingInfo AddDefaultMappingIfNeeded(string marker, string endMarker,
                                                           ImportDomain importDomain, bool fAutoMapBtMarkers, bool isInUse)
        {
            // Look for the marker - if it is found, then we are done
            if (this[marker] != null)
            {
                return(this[marker]);
            }

            // Read the TEStyles XML file to generate a table of mappings
            if (s_defaultMappings.Count == 0)
            {
                ReadDefaultMappings();
            }

            string            styleName;
            bool              excluded;
            MappingTargetType target;
            MarkerDomain      markerDomain = (importDomain != ImportDomain.BackTrans) ?
                                             MarkerDomain.Default : MarkerDomain.BackTrans;

            if (importDomain == ImportDomain.Annotations)
            {
                // TODO (TE-5004): Map \rem (and possibly other markers?) automatically in annotations
                // domain. Probably need to have a separate import mapping set in TeStyles.xml that has
                // default mappings for the Annotations domain.
                styleName = null;
                excluded  = s_defaultExclusions.ContainsKey(marker);                //Make sure to check exclusions (TE-5703)
                target    = MappingTargetType.TEStyle;
            }
            else if (!GetDefaultMapping(marker, out styleName, out excluded, out target, ref markerDomain))
            {
                if (fAutoMapBtMarkers && importDomain == ImportDomain.Main &&
                    marker.StartsWith(@"\bt") && marker != @"\btc")
                {
                    // pick out the corresponding vernacular marker. "\btblah" -> "\blah"
                    string correspondingVernMarker = marker.Remove(1, 2);

                    // if domain is DeprecatedScripture and the corresponding vernacular marker is defined...
                    ImportMappingInfo correspondingVernMarkerInfo = this[correspondingVernMarker];
                    if (correspondingVernMarkerInfo != null &&
                        (correspondingVernMarkerInfo.Domain & MarkerDomain.DeprecatedScripture) != 0)
                    {
                        // clear the DeprecatedScripture bit.
                        correspondingVernMarkerInfo.Domain ^= MarkerDomain.DeprecatedScripture;
                    }
                    if (correspondingVernMarkerInfo != null)
                    {
                        // If the corresponding vernacular marker is already defined...
                        if (correspondingVernMarkerInfo.Domain != MarkerDomain.Note &&
                            (correspondingVernMarkerInfo.Domain & MarkerDomain.BackTrans) == 0 &&
                            (correspondingVernMarkerInfo.MappingTarget != MappingTargetType.TEStyle ||
                             correspondingVernMarkerInfo.StyleName != null))
                        {
                            styleName    = correspondingVernMarkerInfo.StyleName;
                            target       = correspondingVernMarkerInfo.MappingTarget;
                            markerDomain = correspondingVernMarkerInfo.Domain;

                            // We only want to map to the BackTrans domain when mapping to a paragraph
                            // style because character styles automatically assume the domain of their
                            // containing paragraphs.
                            if (m_stylesheet == null || styleName == null ||
                                m_stylesheet.GetType(styleName) == (int)StyleType.kstParagraph)
                            {
                                markerDomain |= MarkerDomain.BackTrans;
                            }
                        }
                    }
                    else if (GetDefaultMapping(correspondingVernMarker, out styleName, out excluded, out target,
                                               ref markerDomain))
                    {
                        // The corresponding vernacular marker has default mapping info so make this marker
                        // a back translation of it - unless it is an annotation or BT.
                        if (markerDomain == MarkerDomain.Note || markerDomain == MarkerDomain.BackTrans)
                        {
                            styleName    = null;
                            excluded     = false;
                            target       = MappingTargetType.TEStyle;
                            markerDomain = MarkerDomain.Default;
                        }
                        else
                        {
                            markerDomain |= MarkerDomain.BackTrans;
                        }
                    }
                }
            }
            // Create a mapping for the marker using the default mapping
            ImportMappingInfo newMapping = new ImportMappingInfo(marker, endMarker, excluded, target,
                                                                 markerDomain, styleName, null, null, isInUse, importDomain);

            Add(newMapping);
            return(newMapping);
        }
示例#26
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Add an Import style proxy for the given mapping and include it in the hash map.
		/// </summary>
		/// <param name="mapping">The mapping for which the proxy entry is to be created</param>
		/// <param name="styleProxies">Dictionary to add the proxy to</param>
		/// <remarks>A second styleProxy is added if the mapping has an end marker.
		/// </remarks>
		/// ------------------------------------------------------------------------------------
		protected void AddImportStyleProxyForMapping(ImportMappingInfo mapping,
			Dictionary<string, ImportStyleProxy> styleProxies)
		{
			string styleName = mapping.StyleName;

			// If there is no style name and the target type is a style then don't
			// add a proxy entry for it.
			if (styleName == null && !mapping.IsExcluded &&
				mapping.MappingTarget == MappingTargetType.TEStyle)
			{
				return;
			}

			ImportStyleProxy proxy;
			int ws = 0;
			// add the new style proxy to the hash table
			if (mapping.WsId != null)
			{
				IWritingSystem wsObj;
				if (m_cache.ServiceLocator.WritingSystemManager.TryGet(mapping.WsId, out wsObj))
					ws = wsObj.Handle;
			}

			if (ws == 0)
			{
				// If domain is unspecified or if this is a BT marker, defer resolving the WS
				// until later, so it can be based on the context.
				if (mapping.Domain == MarkerDomain.Note)
					ws = m_wsAnal;
				else
					ws = -1;
			}
			if (styleName == StyleUtils.DefaultParaCharsStyleName && !mapping.IsExcluded)
			{
				// Any marker that maps to "Default Paragraph Characters" should be
				// treated like an end marker.
				proxy = new ImportStyleProxy(null, 0, ws, ContextValues.EndMarker, mapping.Domain,
					m_styleSheet);

				styleProxies[mapping.BeginMarker] = proxy;
				// Use same proxy for end marker, if it is defined. This will cause optional \ft*
				// marker to be processed correctly.
				if (!string.IsNullOrEmpty(mapping.EndMarker))
				{
					proxy.EndMarker = mapping.EndMarker;
					styleProxies[mapping.EndMarker] = proxy;
				}
				return;
			}
			else
			{
				// note that kstParagraph is overridden by real type for existing styles.
				proxy = new ImportStyleProxy(mapping, ws, m_styleSheet);
			}

			// make another proxy just for the end marker
			if (mapping.EndMarker != null && mapping.EndMarker.Length > 0)
			{
				proxy.EndMarker = mapping.EndMarker;

				int wsStuffAfterMarker = -1;
				MarkerDomain endMarkerDomain = MarkerDomain.Default;
				if (proxy.StyleType != StyleType.kstParagraph)
					endMarkerDomain = proxy.Domain;
				else if ((proxy.Domain & MarkerDomain.Footnote) == MarkerDomain.Footnote)
					endMarkerDomain = proxy.Domain ^ MarkerDomain.Footnote;
				styleProxies[mapping.EndMarker + "\uFEFF" + mapping.BeginMarker] = new ImportStyleProxy(
					null, //for an EndMarker, most params are irrelevant
					0, wsStuffAfterMarker, ContextValues.EndMarker,
					endMarkerDomain, m_styleSheet);
			}

			styleProxies[mapping.BeginMarker] = proxy;
		}
示例#27
0
        /// ------------------------------------------------------------------------------------
        /// <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));
        }
示例#28
0
		public void AddImportStyleProxyForMapping_Normal()
		{
			m_importer.HtStyleProxy.Clear();
			ImportMappingInfo mapping = new ImportMappingInfo(@"\hello", MarkerDomain.Default,
				ScrStyleNames.MainBookTitle, "de", null);
			int wsExpected = Cache.ServiceLocator.WritingSystemManager.GetWsFromStr("de");
			m_importer.AddImportStyleProxyForMapping(mapping, m_importer.HtStyleProxy);
			ImportStyleProxy proxy = ((ImportStyleProxy)m_importer.HtStyleProxy[@"\hello"]);
			Assert.AreEqual(StyleType.kstParagraph, proxy.StyleType);
			ITsPropsFactory pillowtex = TsPropsFactoryClass.Create();
			int cb = proxy.ParaProps.Length;
			ITsTextProps proxyParaProps = pillowtex.DeserializePropsRgb(proxy.ParaProps, ref cb);
			string sHowDifferent;
			if (!TsTextPropsHelper.PropsAreEqual(StyleUtils.ParaStyleTextProps(ScrStyleNames.MainBookTitle),
				proxyParaProps, out sHowDifferent))
			{
				Assert.Fail(sHowDifferent);
			}
			Assert.AreEqual(wsExpected, proxy.TsTextProps.GetWs());
		}
示例#29
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// This method will add or modify a single mapping to the list view.
		/// </summary>
		/// <param name="lv">FwListView to add item to</param>
		/// <param name="mapping">mapping info object used to load FwListView item.</param>
		/// <returns>The newly added ListViewItem</returns>
		/// ------------------------------------------------------------------------------------
		private ListViewItem LoadLVMappingItem(FwListView lv, ImportMappingInfo mapping)
		{
			return LoadLVMappingItem(lv, null, mapping);
		}
示例#30
0
		public void AddImportStyleProxyForMapping_InvalidWritingSystem()
		{
			m_importer.HtStyleProxy.Clear();
			ImportMappingInfo mapping = new ImportMappingInfo(@"\bye", MarkerDomain.Note,
				ScrStyleNames.MainBookTitle, "blah", null);
			m_importer.AddImportStyleProxyForMapping(mapping, m_importer.HtStyleProxy);
			ImportStyleProxy proxy = ((ImportStyleProxy)m_importer.HtStyleProxy[@"\bye"]);
			ITsPropsFactory chrysler = TsPropsFactoryClass.Create();
			int cb = proxy.ParaProps.Length;
			ITsTextProps proxyParaProps = chrysler.DeserializePropsRgb(proxy.ParaProps, ref cb);
			string sHowDifferent;
			if (!TsTextPropsHelper.PropsAreEqual(StyleUtils.ParaStyleTextProps(ScrStyleNames.MainBookTitle),
				proxyParaProps, out sHowDifferent))
			{
				Assert.Fail(sHowDifferent);
			}
			Assert.AreEqual(m_wsAnal, proxy.TsTextProps.GetWs());
		}
示例#31
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// For the given mapping, compute a string to display in the details column of the
		/// mapping list.
		/// </summary>
		/// <param name="mapping">The mapping</param>
		/// <returns>String to display</returns>
		/// ------------------------------------------------------------------------------------
		private string GetMappingDetailsAsString(ImportMappingInfo mapping)
		{
			string sSubItem = string.Empty;

			// if the style is excluded then don't display anything in the details column
			if (!mapping.IsExcluded)
			{
				switch (mapping.Domain)
				{
					case MarkerDomain.BackTrans:
						sSubItem = ScrImportComponents.kstidImportWizMappingDetailBackTrans;
						break;
					case MarkerDomain.Note:
						sSubItem = ScrImportComponents.kstidImportWizMappingDetailNotes;
						break;
					case MarkerDomain.Footnote:
						sSubItem = ScrImportComponents.kstidImportWizMappingDetailFootnotes;
						break;
					case MarkerDomain.Footnote | MarkerDomain.BackTrans:
						sSubItem = ScrImportComponents.kstidImportWizMappingDetailBTFootnotes;
						break;
					case MarkerDomain.Default:
						break;
					default:
						throw new Exception("Unexpected domain");
				}

				// Figure out what the writing system's name is to display it in the list view.
				if (mapping.WsId != null)
				{
					IWritingSystem ws = m_cache.ServiceLocator.WritingSystemManager.Get(mapping.WsId);

					string wsName = ws.DisplayLabel;
					if (wsName != null)
					{
						if (sSubItem != string.Empty)
							sSubItem += ", ";
						sSubItem += wsName;
					}
				}
			}
			return sSubItem;
		}
示例#32
0
		public void AddImportStyleProxyForMapping_Inline()
		{
			m_importer.HtStyleProxy.Clear();
			ImportMappingInfo mapping = new ImportMappingInfo("|b{", "}", MarkerDomain.Default,
				"Really bold text", "de", null);
			int wsExpected = Cache.ServiceLocator.WritingSystemManager.GetWsFromStr("de");
			m_importer.AddImportStyleProxyForMapping(mapping, m_importer.HtStyleProxy);
			ImportStyleProxy proxy = ((ImportStyleProxy)m_importer.HtStyleProxy[mapping.BeginMarker]);
			Assert.AreEqual(StyleType.kstCharacter, proxy.StyleType);
			ITsPropsFactory pillowtex = TsPropsFactoryClass.Create();
			ITsTextProps proxyTextProps = proxy.TsTextProps;
			string sHowDifferent;
			if (!TsTextPropsHelper.PropsAreEqual(StyleUtils.CharStyleTextProps("Really bold text", wsExpected),
				proxyTextProps, out sHowDifferent))
			{
				Assert.Fail(sHowDifferent);
			}
			Assert.AreEqual(ContextValues.General, m_styleSheet.FindStyle("Really bold text").Context);
		}
示例#33
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates (if necessary) and shows the CharacterMappingSettings dialog.
		/// This is a public virtual so that test code can override it.
		/// </summary>
		/// <param name="mapping">Provides intial values displayed in dialog.</param>
		/// ------------------------------------------------------------------------------------
		protected virtual void DisplayInlineMappingDialog(ImportMappingInfo mapping)
		{
			if (m_inlineMappingDialog == null)
			{
				m_inlineMappingDialog = new CharacterMappingSettings(mapping, m_StyleSheet, m_cache,
					tabCtrlMappings.SelectedIndex == kiAnnotationMappingTab, m_helpTopicProvider, m_app);
				m_inlineMappingDialog.IsDuplicateMapping += IsDup;
			}
			else
			{
				// If the "scripture" tab is not selected, force the dialog to only allow annotation mappings
				m_inlineMappingDialog.InitializeControls(mapping, tabCtrlMappings.SelectedIndex != 0);
			}
			m_inlineMappingDialog.ShowDialog();
		}
示例#34
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Exposes the <see cref="TeSfmImporter.AddImportStyleProxyForMapping"/> method
		/// </summary>
		/// <param name="mapping">The mapping for which the proxy entry is to be created</param>
		/// <param name="styleProxies">Dictionary to add the proxy to</param>
		/// ------------------------------------------------------------------------------------
		public new void AddImportStyleProxyForMapping(ImportMappingInfo mapping,
			Dictionary<string, ImportStyleProxy> styleProxies)
		{
			CheckDisposed();

			base.AddImportStyleProxyForMapping(mapping, styleProxies);
		}
示例#35
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Constructor with ContextValues and MarkerDomain as a parameters.
		/// </summary>
		/// <param name="mapping">The Scr marker mapping.</param>
		/// <param name="ws">character or paragraph writing system</param>
		/// <param name="styleSheet">The style sheet</param>
		/// ------------------------------------------------------------------------------------
		public ImportStyleProxy(ImportMappingInfo mapping, int ws, FwStyleSheet styleSheet) :
			this(mapping.StyleName,	mapping.IsInline ? StyleType.kstCharacter : StyleType.kstParagraph,
				ws, ContextValues.General, mapping.Domain, styleSheet)
		{
			Excluded = mapping.IsExcluded;
			MappingTarget = mapping.MappingTarget;
			m_annotationType = mapping.NoteType;
		}
示例#36
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Update the mapping depending on the selectedStyleName's text.
		/// </summary>
		/// <param name="mapping">Mapping to update</param>
		/// <param name="selectedStyleName">the style selected in calling function</param>
		/// ------------------------------------------------------------------------------------
		internal static void UpdateMapping(ImportMappingInfo mapping, string selectedStyleName)
		{
			if (s_PsuedoStyleNamesToTargetType.Count == 0)
			{
				// Populate it for first-time use.
				s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidFigureStyle] = MappingTargetType.Figure;
				s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidFigureCaptionStyle] = MappingTargetType.FigureCaption;
				s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidFigureCopyrightStyle] = MappingTargetType.FigureCopyright;
				s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidFigureDescriptionStyle] = MappingTargetType.FigureDescription;
				s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidFigureFilenameStyle] = MappingTargetType.FigureFilename;
				s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidFigureLayoutPositionStyle] = MappingTargetType.FigureLayoutPosition;
				s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidFigureRefRangeStyle] = MappingTargetType.FigureRefRange;
				s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidFigureScaleStyle] = MappingTargetType.FigureScale;
				s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidTitleShortStyle] = MappingTargetType.TitleShort;
				s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidChapterLabelStyle] = MappingTargetType.ChapterLabel;
			}

			MappingTargetType targetType;
			if (s_PsuedoStyleNamesToTargetType.TryGetValue(selectedStyleName, out targetType))
				mapping.MappingTarget = targetType;
			else
				mapping.MappingTarget = MappingTargetType.TEStyle;

			mapping.StyleName = selectedStyleName;
		}