示例#1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Parses the user typed in string. Creates and returns a ScrReference object.
		/// </summary>
		/// <param name="sTextToBeParsed">Reference string the user types in.</param>
		/// <returns>The generated scReference object.</returns>
		/// ------------------------------------------------------------------------------------
		public override ScrReference ParseRefString(string sTextToBeParsed)
		{

			ScrReference scrRef = new ScrReference();
			List<int> bookOrds = GetBookOrds();

			// Search for a reference that is actually in the database.
			for (int startBook = 0; startBook < 66;)
			{
				int prevStartBook = startBook;
				scrRef = base.ParseRefString(sTextToBeParsed, startBook);

				// If the book is in the Scripture project
				// (or if we get the same book back from the parse method or go back to the start)...
				if (bookOrds != null && bookOrds.Contains(scrRef.Book) ||
					prevStartBook == scrRef.Book || prevStartBook > scrRef.Book)
				{
					break; // we're finished searching.
				}
				else
					startBook = scrRef.Book; // start searching in next book returned.
			}

			// If the Scripture reference is not in the project (and we have books)...
			if (!bookOrds.Contains(scrRef.Book) && m_scripture.ScriptureBooksOS.Count > 0)
			{
				// set it to the first book in the project.
				return new ScrReference(m_scripture.ScriptureBooksOS[0].CanonicalNum, 1, 1,
					m_scripture.Versification);
			}
			return scrRef;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Construct a DummyScrImportFileInfo.
		/// </summary>
		/// <param name="fileName">Name of the file whose info this represents</param>
		/// <param name="domain">The import domain to which this file belongs</param>
		/// <param name="icuLocale">The ICU locale of the source to which this file belongs
		/// (null for Scripture source)</param>
		/// <param name="noteTypeHvo">The HVO of the CmAnnotationDefn of the source to which
		/// this file belongs (only used for Note sources)</param>
		/// <param name="booksInFile">A list of integers representing 1-based canonical book
		/// numbers that are in this file</param>
		/// <param name="fileEncoding">The file encoding</param>
		/// <param name="startRef">The first reference encountered in the file</param>
		/// ------------------------------------------------------------------------------------
		public DummyScrImportFileInfo(string fileName, ImportDomain domain, string icuLocale,
			int noteTypeHvo, List<int> booksInFile, Encoding fileEncoding, ScrReference startRef) :
			base(fileName, null, domain, icuLocale, noteTypeHvo, false)
		{
			m_booksInFile = booksInFile;
			m_fileEncoding = fileEncoding;
			m_startRef = startRef;
		}
示例#3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="GotoReferenceDialog"/> class.
		/// </summary>
		/// <param name="reference">The initial reference to populate the control.</param>
		/// <param name="scr">The Scripture object.</param>
		/// ------------------------------------------------------------------------------------
		public GotoReferenceDialog(ScrReference reference, IScripture scr)
		{
			Logger.WriteEvent("Opening 'Goto Reference' dialog");

			m_scripture = scr;
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			scrPassageControl = new ScrPassageControl(reference, (Scripture)m_scripture, true);
			scrPassageControl.Location = new System.Drawing.Point(16, 16);
			scrPassageControl.Name = "scrPassageControl";
			scrPassageControl.Size = new System.Drawing.Size(Width - 36, 24);
			Controls.Add(scrPassageControl);

			scrPassageControl.TabIndex = 0;
			btn_OK.TabIndex = 1;
			btn_cancel.TabIndex = 2;
			btn_help.TabIndex = 3;
		}
示例#4
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Copy a reference
 /// </summary>
 /// <param name="from">The ScrReference to copy.</param>
 /// ------------------------------------------------------------------------------------
 public ScrReference(ScrReference from)
     : this(from.Book, from.Chapter, from.Verse, from.Segment, from.m_versification)
 {
 }
示例#5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Attempt to set the selection immediately following the last character of the closest
        /// verse number to the requested verse. If no section exists within one chapter of the
        /// requested verse, the selection will not be changed.
        /// </summary>
        /// <param name="targetRef">Reference to seek</param>
        /// <returns>true if the selected is changed (to the requested verse or one nearby);
        /// false otherwise</returns>
        /// ------------------------------------------------------------------------------------
        public bool GotoVerse(ScrReference targetRef)
        {
            CheckDisposed();

            Scripture scr = new Scripture(m_fdoCache, HvoScripture);

            int iBook = 0;
            foreach (ScrBook book in scr.ScriptureBooksOS)
            {
                if (book.BookIdRA.OwnOrd == targetRef.Book)
                {
                    // found the book
                    ScrSection prevSection;
                    int iSection = 0;
                    foreach (ScrSection section in book.SectionsOS)
                    {
                        if (section.VerseRefStart <= targetRef)
                        {
                            if (section.VerseRefEnd >= targetRef)
                            {
                                int ihvoPara; // index of paragraph containing the verse
                                int ichPosition; //place to put IP.

                                FindVerseNumber(section, targetRef, out ihvoPara,
                                    out ichPosition);

                                SetInsertionPoint(iBook, iSection, ihvoPara, ichPosition,
                                    false);
                                return true;
                            }
                            prevSection = section;
                        }
                        else
                        {
                            // try finding a close enough verse ref in previous section
                        }
                        iSection++;
                    }
                }
                iBook++;
            }
            return false;
        }
示例#6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Given a Scripture section, this method returns the index of the paragraph containing
        /// the requested verse and the position of the character immediately following the
        /// verse number in that paragraph. If an exact match isn't found, the closest
        /// approximate place is found.
        /// </summary>
        /// <param name="section">The section whose paragraphs will be searched</param>
        /// <param name="targetRef">The reference being sought</param>
        /// <param name="ihvoPara"></param>
        /// <param name="ichPosition"></param>
        /// <remarks>Currently, this does NOT attempt to find a close match, but some day it
        /// should</remarks>
        /// ------------------------------------------------------------------------------------
        protected void FindVerseNumber(ScrSection section, ScrReference targetRef,
			out int ihvoPara, out int ichPosition)
        {
            ihvoPara = 0;
            ichPosition = 0;

            bool fChapterFound = ((ScrReference)section.VerseRefStart).Chapter == targetRef.Chapter;
            foreach (StTxtPara para in section.ContentOA.ParagraphsOS)
            {
                TsStringAccessor contents = para.Contents;
                TsRunInfo tsi;
                ITsTextProps ttpRun;
                int ich = 0;
                while (ich < contents.Text.Length)
                {
                    // Get props of current run.
                    ttpRun = contents.UnderlyingTsString.FetchRunInfoAt(ich, out tsi);
                    // See if it is our verse number style.
                    if (fChapterFound)
                    {
                        if (StStyle.IsStyle(ttpRun, ScrStyleNames.VerseNumber))
                        {
                            // The whole run is the verse number. Extract it.
                            string sVerseNum = contents.Text.Substring(tsi.ichMin,
                                tsi.ichLim - tsi.ichMin);
                            int startVerse, endVerse;
                            ScrReference.VerseToInt(sVerseNum, out startVerse, out endVerse);
                            if (targetRef.Verse >= startVerse && targetRef.Verse <= endVerse)
                            {
                                ihvoPara = para.OwnOrd - 1;
                                ichPosition = tsi.ichLim;
                                return;
                            }
                            // TODO: Currently, this does NOT attempt to detect when we have
                            // a close match
                        }
                    }
                        // See if it is our chapter number style.
                    else if (StStyle.IsStyle(ttpRun, ScrStyleNames.ChapterNumber))
                    {
                        // Assume the whole run is the chapter number. Extract it.
                        string sChapterNum = contents.Text.Substring(tsi.ichMin,
                            tsi.ichLim - tsi.ichMin);
                        int nChapter = ScrReference.ChapterToInt(sChapterNum);
                        fChapterFound = (nChapter == targetRef.Chapter);
                    }
                    ich = tsi.ichLim;
                }
            }
        }
示例#7
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Completes the import.
		/// </summary>
		/// <param name="firstImported">The reference of the first thing that was imported</param>
		/// ------------------------------------------------------------------------------------
		protected ScrReference CompleteImport(ScrReference firstImported)
		{
			if (firstImported == null)
				return ScrReference.Empty;

			// An ampty first imported reference can happen if we imported just the BT.
			//Debug.Assert(!firstImported.IsEmpty, "We should have a useful reference if we imported something!");

			if (m_importedSavedVersion != null && m_importedSavedVersion.BooksOS.Count > 0)
			{
				DisplayImportedBooksDlg(m_undoImportManager.BackupVersion);
				// Now re-check to see if we have any imported books left. If not, and if we didn't
				// import a partial BT either, then the net effect of this import was to do nothing.
				// So we discard our undo action altogether.
				if (m_importedSavedVersion.BooksOS.Count == 0/* && !fPartialBtImported*/)
				{
					m_undoImportManager.DiscardImportedVersionAndUndoActions();
					return ScrReference.Empty;
				}
			}

			m_undoImportManager.RemoveEmptyBackupSavedVersion();
			m_undoImportManager.CollapseAllUndoActions();
			// sync stuff
			if (FwApp.App != null)
			{
				using (new WaitCursor(m_mainWnd))
				{
					// Refresh all the views of all applications connected to the same DB. This
					// will cause any needed Scripture data to be reloaded lazily.
					FwApp.App.Synchronize(new SyncInfo(SyncMsg.ksyncScriptureImport, 0, 0), m_cache);
					FwApp.App.Synchronize(new SyncInfo(SyncMsg.ksyncStyle, 0, 0), m_cache);
					FwApp.App.Synchronize(new SyncInfo(SyncMsg.ksyncReloadScriptureControl, 0, 0), m_cache);
				}
			}
			return firstImported;
		}
示例#8
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Determines whether this instance [can find text in verse] the specified wfi wordform.
		/// </summary>
		/// <param name="wfiWordform">The wfi wordform.</param>
		/// <param name="verse">The verse.</param>
		/// <returns><c>true</c> if this instance [can find text in verse] the specified wfi
		/// wordform; otherwise, <c>false</c>.
		/// </returns>
		/// ------------------------------------------------------------------------------------
		bool CanFindTextInVerse(IWfiWordform wfiWordform, ScrReference verse)
		{
			int iDummy;
			return TeEditingHelper.FindTextInVerse(m_scr,
				wfiWordform.Form.GetAlternativeTss(wfiWordform.Cache.DefaultVernWs),
				verse, true, out iDummy, out iDummy, out iDummy, out iDummy);
		}
示例#9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Handles the event when the Scripture passage reference changes in the scrBookTo
		/// control.
		/// </summary>
		/// <param name="newReference">The new reference.</param>
		/// ------------------------------------------------------------------------------------
		private void scrBookTo_PassageChanged(ScrReference newReference)
		{
			if (newReference != ScrReference.Empty && newReference < scrBookFrom.ScReference)
				scrBookFrom.ScReference = newReference;
		}
示例#10
0
		public void IsRangeInKtRef_OutOfRange_ConvertedVersification()
		{
			// Jonah 2:1 in Original != Jonah 2:1 in English
			ScrReference[] refRange = new ScrReference[2];
			refRange[0] = refRange[1] = new ScrReference(32002001, Paratext.ScrVers.English);
			int hvoKtRef = m_inMemoryCache.NewHvo(ChkRef.kClassId);
			KeyTermRef ktRefJonah2_1 = new KeyTermRef(Cache, hvoKtRef);
			ktRefJonah2_1.Ref = 32002001;
			Assert.IsFalse(KeyTermsViewWrapper.IsRangeInKtRef(ktRefJonah2_1, refRange, refRange));
		}
示例#11
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Check all files in the given reference range to see if there are any reference
		/// overlaps. If so, resolve the conflict.
		/// </summary>
		/// <param name="start">Start reference</param>
		/// <param name="end">End Reference</param>
		/// ------------------------------------------------------------------------------------
		internal void CheckForOverlappingFilesInRange(ScrReference start, ScrReference end)
		{
			List<ScrImportFileInfo> removedList = new List<ScrImportFileInfo>();
			foreach (ScrImportFileInfo file1 in this)
			{
				if (removedList.Contains(file1))
					continue;
				foreach (ReferenceRange range in file1.BookReferences)
				{
					if (range.OverlapsRange(start, end))
					{
						foreach (ScrImportFileInfo file2 in this)
						{
							if (file1 == file2 || removedList.Contains(file2))
								continue;
							if (ScrImportFileInfo.CheckForOverlap(file1, file2))
							{
								Debug.Assert(m_resolver != null, "Must set OverlappingFileResolver before calling CheckForOverlappingFilesInRange.");
								removedList.Add(m_resolver.ChooseFileToRemove(file1, file2));
							}
						}
					}
				}
			}
			// Remove all of the overlapping files from the import files collection
			// that we decided we didn't want.
			foreach (ScrImportFileInfo file in removedList)
				Remove(file);
		}
示例#12
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes the form's controls from the settings in the filter.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void InitializeFromFilter()
		{
			if (m_filter == null || m_filter.RowsOS.Count == 0 || m_filter.RowsOS[0].CellsOS.Count == 0)
				return;

			// Get the pairs of class ids and flids.
			string[] pairs = m_filter.ColumnInfo.Split('|');
			Debug.Assert(m_filter.RowsOS[0].CellsOS.Count == pairs.Length);

			for (int i = 0; i < pairs.Length; i++)
			{
				CmCell cell = (CmCell)m_filter.RowsOS[0].CellsOS[i];
				Guid guid;

				// Get the flid for this cell.
				string[] pair = pairs[i].Split(',');
				int flid = 0;
				int.TryParse(pair[1], out flid);

				switch (flid)
				{
					case (int)ScrScriptureNote.ScrScriptureNoteTags.kflidResolutionStatus:
						chkStatus.Checked = true;
						cell.ParseIntegerMatchCriteria();
						rbResolved.Checked = (cell.MatchValue == 1);
						rbUnresolved.Checked = (cell.MatchValue == 0);
						break;

					case (int)CmAnnotation.CmAnnotationTags.kflidAnnotationType:
						chkType.Checked = true;
						cell.ParseObjectMatchCriteria();
						guid = StringUtils.GetGuidFromRun(cell.Contents.UnderlyingTsString, 1);
						rbConsultant.Checked = (guid == LangProject.kguidAnnConsultantNote);
						rbTranslator.Checked = (guid == LangProject.kguidAnnTranslatorNote);
						break;

					case (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginRef:
						chkScrRange.Checked = true;
						cell.ParseIntegerMatchCriteria();
						ScrReference scrRef = new ScrReference(cell.MatchValue, m_scr.Versification);
						// If the reference was adjusted to 0:0 to include notes in the title and
						// introduction, adjust it back to 1:1 so we don't confuse the user.
						if (scrRef.Chapter == 0)
							scrRef.Chapter = 1;
						if (scrRef.Verse == 0)
							scrRef.Verse = 1;

						if (cell.ComparisonType == CmCell.ComparisionTypes.kGreaterThanEqual)
							scrBookFrom.ScReference = scrRef;
						else
							scrBookTo.ScReference = scrRef;
						break;
				}
			}
		}
示例#13
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Construct a reference with an initial BBCCCVVV value
 /// </summary>
 /// <param name="initialRef"></param>
 /// <param name="versification">The versification scheme</param>
 /// ------------------------------------------------------------------------------------
 public ScrReference(int initialRef, Paratext.ScrVers versification)
     : this(ScrReference.GetBookFromBcv(initialRef),
            ScrReference.GetChapterFromBcv(initialRef), ScrReference.GetVerseFromBcv(initialRef),
            versification)
 {
 }
示例#14
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Construct a Scripture utils exception. These are used for import errors.
 /// </summary>
 /// <param name="errorCode">numeric error code</param>
 /// <param name="fileName">file name where the error was encountered</param>
 /// <param name="lineNumber">line number in the file where the error occurred</param>
 /// <param name="lineContents">Contents of problematic line (or segment)</param>
 /// <param name="scrRef">scripture reference where the error occurred</param>
 /// <param name="fInterleavedImport"></param>
 /// ------------------------------------------------------------------------------------
 public ScriptureUtilsException(SUE_ErrorCode errorCode, string fileName, int lineNumber,
                                string lineContents, BCVRef scrRef, bool fInterleavedImport) :
     this(errorCode, fileName, lineNumber, lineContents, ScrReference.NumberToBookCode(scrRef.Book),
          scrRef.Chapter.ToString(), scrRef.Verse.ToString(), fInterleavedImport)
 {
 }
示例#15
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Set selections after import.
		/// </summary>
		/// <param name="firstReference">The first reference of imported stuff.</param>
		/// ------------------------------------------------------------------------------------
		private void SetSelectionsAfterImport(ScrReference firstReference)
		{
			if (!firstReference.IsEmpty)
			{
				// Set the IP at the beginning of the imported material (i.e. the first reference,
				// not the first segment).
				m_importCallbacks.GotoVerse(firstReference);
			}

			// If we are in the Key Terms view then update the view in case we imported
			// a book so that it is possible to select the verse for the current key term.
			m_importCallbacks.UpdateKeyTermsView();
		}
示例#16
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Add an annotation to a language project.
		/// </summary>
		/// <param name="scrInMemoryCache">in-memory cache to use for testing</param>
		/// <param name="noteText">text to include in discussion</param>
		/// <param name="startRef"></param>
		/// <param name="endRef"></param>
		/// <param name="topPara">Begin StTxtPara to annotate</param>
		/// <param name="bottomPara">End StTxtPara to annotate</param>
		/// <returns>a new annotation</returns>
		/// ------------------------------------------------------------------------------------
		internal static IScrScriptureNote AddAnnotation(ScrInMemoryFdoCache scrInMemoryCache, string noteText,
			ScrReference startRef, ScrReference endRef, ICmObject topPara, ICmObject bottomPara)
		{
			ILangProject lp = scrInMemoryCache.Cache.LangProject;
			ScrBookAnnotations annotations = (ScrBookAnnotations)lp.TranslatedScriptureOA.BookAnnotationsOS[startRef.Book - 1];
			IScrScriptureNote note = annotations.InsertNote(startRef, endRef, topPara, bottomPara,
				StandardNoteType(scrInMemoryCache).Guid);

			StTxtPara discussionPara = (StTxtPara)note.DiscussionOA.ParagraphsOS[0];
			scrInMemoryCache.AddRunToMockedPara(discussionPara, noteText, scrInMemoryCache.Cache.DefaultAnalWs);

			note.DateCreated = new DateTime(s_Ticks++);

			return note;
		}
示例#17
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Add an annotation to a language project that applies to a single verse reference and
		/// a single paragraph.
		/// </summary>
		/// <param name="scrInMemoryCache">in-memory cache to use for testing</param>
		/// <param name="noteText">text to include in annotation</param>
		/// <param name="reference">The reference.</param>
		/// <param name="para">StTxtPara to annotate</param>
		/// <returns>a new annotation</returns>
		/// ------------------------------------------------------------------------------------
		internal static IScrScriptureNote AddAnnotation(ScrInMemoryFdoCache scrInMemoryCache, string noteText,
			ScrReference reference, ICmObject para)
		{
			return AddAnnotation(scrInMemoryCache, noteText, reference, reference, para, para);
		}
示例#18
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Copy a reference, converting it to the specified versification if necessary
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public ScrReference(ScrReference from, Paratext.ScrVers targetVersification)
     : this(from.Book, from.Chapter, from.Verse, from.Segment, from.m_versification)
 {
     VersificationTable.Get(targetVersification).ChangeVersification(this);
 }
示例#19
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Set scripture reference using TE's object.
		/// </summary>
		/// <param name="reference">The reference.</param>
		/// ------------------------------------------------------------------------------------
		public void SetTeScriptureReference(ScrReference reference)
		{
			VerseRef ref2 = new VerseRef(reference.Book, reference.Chapter, reference.Verse);
			ref2.Versification = reference.Versification;
			SetScriptureReference(ref2);
		}
示例#20
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Handles the event when the Scripture passage reference changes in the scrBookFrom
		/// control.
		/// </summary>
		/// <param name="newReference">The new reference.</param>
		/// ------------------------------------------------------------------------------------
		private void scrBookFrom_PassageChanged(ScrReference newReference)
		{
			if (newReference > scrBookTo.ScReference)
				scrBookTo.ScReference = newReference;
		}
示例#21
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Determines whether the specified key term reference falls within the given range of
		/// references. Normally this will only return <c>true</c> if the anchor and end are the
		/// same. That is to say, the selection represented by the given ranges must fall wholly
		/// within a single verse. (There is an anomalous case where it could succeed If the range crosses a verse number (or bridge) such that the end
		/// reference
		/// </summary>
		/// <param name="keyTermRef">The key term ref.</param>
		/// <param name="anchorRefRange">The anchor ref range (which is made up of two
		/// references to account for possible verse bridges).</param>
		/// <param name="endRefRange">The end ref range (which is made up of two
		/// references to account for possible verse bridges).</param>
		/// <returns>
		/// 	<c>true</c> if the specified key term ref falls within the given range;
		/// otherwise, <c>false</c>.
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public static bool IsRangeInKtRef(KeyTermRef keyTermRef, ScrReference[] anchorRefRange,
			ScrReference[] endRefRange)
		{
			ScrReference selectedKtRef = keyTermRef.RefInCurrVersification;
			return (anchorRefRange[0] <= selectedKtRef && anchorRefRange[1] >= selectedKtRef &&
				endRefRange[0] == anchorRefRange[0] && endRefRange[1] == anchorRefRange[1]);
		}
示例#22
0
		public void IsRangeInKtRef_InRange_VerseBridge()
		{
			ScrReference[] refRange = new ScrReference[2];
			refRange[0] = new ScrReference(01001001, Paratext.ScrVers.English);
			refRange[1] = new ScrReference(01001003, Paratext.ScrVers.English);
			int hvoKtRef = m_inMemoryCache.NewHvo(ChkRef.kClassId);
			KeyTermRef ktRef = new KeyTermRef(Cache, hvoKtRef);
			ktRef.Ref = 01001002;
			Assert.IsTrue(KeyTermsViewWrapper.IsRangeInKtRef(ktRef, refRange, refRange));
		}
示例#23
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Updates the key term equivalents.
		/// </summary>
		/// <param name="progressDlg">The progress dialog box.</param>
		/// <param name="parameters">Not used</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		private object UpdateKeyTermEquivalents(IAdvInd4 progressDlg, params object[] parameters)
		{
			m_cache.EnableBulkLoadingIfPossible(true);
			List<InvalidRendering> invalidRenderings = new List<InvalidRendering>();
			try
			{
				// first build a map from verses to the keyterms that should have renderings.
				Set<int> chkTermIds = m_ktTree.ChkTermsWithRefs;
				if (progressDlg != null)
				{
					progressDlg.Message = TeResourceHelper.GetResourceString("kstidUpdateKeyTermEquivalentsProgressLoading");
					progressDlg.SetRange(0, chkTermIds.Count);
				}
				Dictionary<int, List<KeyTermRef>> bcvToChkRefs = new Dictionary<int, List<KeyTermRef>>();
				foreach (int keyTermHvo in chkTermIds)
				{
					AddChkRefsToBCVmap(keyTermHvo, ref bcvToChkRefs);
					if (progressDlg != null)
						progressDlg.Step(0);
				}
				// set progress bar to the number of verses to step through.
				if (progressDlg != null)
					progressDlg.SetRange(0, bcvToChkRefs.Count);
				// for each keyterm occurrences in each verse, make sure renderings are up to date.
				List<int> sortedKeys = new List<int>(bcvToChkRefs.Keys);
				sortedKeys.Sort();
				foreach (int bcv in sortedKeys)
				{
					// REVIEW (TE-6532): For now, all Key Term Refs in the DB use the Original
					// versisifcation. Should we support other versifications?
					ScrReference currentVerse = new ScrReference(bcv, Paratext.ScrVers.Original,
						m_scr.Versification);
					if (progressDlg != null)
					{
						progressDlg.Message = String.Format(TeResourceHelper.GetResourceString("kstidUpdateKeyTermEquivalentsProgressMessage"),
							currentVerse.AsString);
					}
					List<KeyTermRef> chkRefsForVerse = bcvToChkRefs[bcv];
					foreach (KeyTermRef chkRef in chkRefsForVerse)
					{
						Dictionary<int, bool> renderingActuallyExistsInVerse = new Dictionary<int, bool>();
						// skip doing anything about references that have been marked as "Ignore"
						if (chkRef.Status == KeyTermRenderingStatus.Ignored)
							continue;
						if (chkRef.RenderingRAHvo != 0)
						{
							if (CanFindTextInVerse(chkRef.RenderingRA, currentVerse))
							{
								if (chkRef.RenderingStatus == KeyTermRenderingStatus.Missing)
									chkRef.RenderingStatus = KeyTermRenderingStatus.Assigned;
								continue;
							}
						}
						// if an expected rendering is not found (or there was no previous assignment)
						// see if we can find an alternative rendering to AutoAssign.
						IChkTerm parentKeyTerm = chkRef.Owner as IChkTerm;
						bool fFound = false;
						foreach (IChkRendering rendering in parentKeyTerm.RenderingsOC)
						{
							if (rendering.SurfaceFormRA == null)
							{
								// We found a surface form that is not defined. Later we'll need to
								// remove this rendering, but for now we'll continue to the next one.
								invalidRenderings.Add(new InvalidRendering(parentKeyTerm, rendering));
								continue;
							}
							if (CanFindTextInVerse(rendering.SurfaceFormRA, currentVerse))
							{
								try
								{
									chkRef.RenderingRA = rendering.SurfaceFormRA;
									if (chkRef.RenderingStatus != KeyTermRenderingStatus.AutoAssigned)
										chkRef.RenderingStatus = KeyTermRenderingStatus.AutoAssigned;
									fFound = true;
									break;
								}
								catch
								{
									// Unable to set rendering because it is invalid.
									invalidRenderings.Add(new InvalidRendering(parentKeyTerm, rendering));
									continue;
								}
							}
						}
						if (!fFound)
						{
							if (chkRef.RenderingStatus == KeyTermRenderingStatus.Assigned)
							{
								// keep RenderingsRA info, so we know what is missing.
								chkRef.RenderingStatus = KeyTermRenderingStatus.Missing;
							}
							else
							{
								if (chkRef.RenderingRA != null)
									chkRef.RenderingRA = null;
								if (chkRef.RenderingStatus != KeyTermRenderingStatus.Unassigned)
									chkRef.RenderingStatus = KeyTermRenderingStatus.Unassigned;
							}
						}
					}
					if (progressDlg != null)
						progressDlg.Step(0);
				}
				return null;
			}
			finally
			{
				if (invalidRenderings.Count > 0)
				{
					// We found at least one invalid surface form, so we need to search through our
					// renderings and remove any that are invalid.
					foreach (InvalidRendering rendering in invalidRenderings)
						rendering.m_parentKeyTerm.RenderingsOC.Remove(rendering.m_rendering);
				}

				m_cache.EnableBulkLoadingIfPossible(false);
			}
		}
示例#24
0
		public void IsRangeInKtRef_InRangeButAnchorAndEndAreDifferent()
		{
			ScrReference[] anchorRefRange = new ScrReference[2];
			ScrReference[] endRefRange = new ScrReference[2];
			anchorRefRange[0] = endRefRange[0] = new ScrReference(01001001, Paratext.ScrVers.English);
			anchorRefRange[1] = new ScrReference(01001001, Paratext.ScrVers.English);
			endRefRange[1] = new ScrReference(01001003, Paratext.ScrVers.English);
			int hvoKtRef = m_inMemoryCache.NewHvo(ChkRef.kClassId);
			KeyTermRef ktRef = new KeyTermRef(Cache, hvoKtRef);
			ktRef.Ref = 01001001;
			Assert.IsFalse(KeyTermsViewWrapper.IsRangeInKtRef(ktRef, anchorRefRange, endRefRange));
		}
示例#25
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Attempt to set the selection in the corresponding draft view immediately following
		/// the last character of the closest verse number to the requested verse. If no section
		/// exists within one chapter of the requested verse, the selection will not be changed.
		/// </summary>
		/// <param name="targetRef">Reference to seek</param>
		/// <returns>true if the selection is changed (to the requested verse or one nearby);
		/// false otherwise</returns>
		/// ------------------------------------------------------------------------------------
		public override bool GotoVerse(ScrReference targetRef)
		{
			CheckDisposed();

			if (m_draftView != null)
			{
				m_draftView.Focus();
				return m_draftViewEditingHelper.GotoVerse(targetRef);
			}

			return false;
		}