Exemplo n.º 1
0
		public static void UpdateMainTransFromSegmented(StTxtPara para, int[] wss)
		{
			if (!para.IsValidObject())
				return; // in merge, paragraph may be modified then deleted.
			FdoCache cache = para.Cache;
			BtConverter.EnsureMainParaSegments(para, wss[0]);
			ISilDataAccess sda = cache.MainCacheAccessor;
			List<int> segments = para.Segments;
			int kflidFT = StTxtPara.SegmentFreeTranslationFlid(cache);
			ITsString tssContents = para.Contents.UnderlyingTsString;
			IScripture scr = para.Cache.LangProject.TranslatedScriptureOA;
			ICmTranslation originalBT = para.GetBT(); // Can be null
			string sUnfinished = BackTranslationStatus.Unfinished.ToString();
			foreach (int ws in wss)
			{
				ITsStrBldr bldr = TsStrBldrClass.Create();
				bool wantNextSpace = false; // suppresses space before the first thing we add.
				bool haveBtText = false; // Text that isn't segment label text
				foreach (int hvoSeg in segments)
				{
					// If it's a label, insert it directly. Suppress following space.
					int beginOffset = sda.get_IntProp(hvoSeg, (int) CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginOffset);
					int endOffset = sda.get_IntProp(hvoSeg, (int) CmBaseAnnotation.CmBaseAnnotationTags.kflidEndOffset);
					ITsString tssFt;
					// Whether we want to insert a space before the current segment is determined by the previous one.
					// Save that value so we can set wantSpace appropriately for the following one.
					bool wantSpace = wantNextSpace;
					if (SegmentBreaker.HasLabelText(tssContents, beginOffset, endOffset))
					{
						tssFt = (new CmBaseAnnotation(cache, hvoSeg)).TextAnnotated;
						tssFt = scr.ConvertCVNumbersInStringForBT(CorrectFootnotes(tssFt), ws);
						wantNextSpace = false;
					}
					else
					{
						int hvoFt = sda.get_ObjectProp(hvoSeg, kflidFT);
						tssFt = sda.get_MultiStringAlt(hvoFt, (int) CmAnnotation.CmAnnotationTags.kflidComment, ws);
						haveBtText |= (tssFt.Length > 0);
						wantNextSpace = EndsWithNonSpace(tssFt);
					}
					if (tssFt.Length > 0)
					{
						if (wantSpace)
						{
							// The preceding segment should typically be followed by a space.
							if (!StartsWithSpaceOrOrc(tssFt))
								bldr.Replace(bldr.Length, bldr.Length, " ", null);
						}
						bldr.ReplaceTsString(bldr.Length, bldr.Length, tssFt);
					}
				}

				// If the back translation doesn't have text, we don't want to create verse
				// segment labels. This prevents the problem where the book thinks it has a
				// back translation because of automatically generated verse labels (TE-8283).
				if (!haveBtText)
				{
					// This check might not be needed, but it shouldn't hurt anything.
					if (originalBT != null)
					{
						if (originalBT.Translation.GetAlternative(ws).Length > 0)
						{
							string origStatus = originalBT.Status.GetAlternative(ws);
							if (!String.IsNullOrEmpty(origStatus) && origStatus != sUnfinished)
								originalBT.Status.SetAlternative(sUnfinished, ws);
						}
					}
					continue;
				}

				ITsString newFt = bldr.GetString();
				ICmTranslation trans;
				if (newFt.Length == 0)
				{
					trans = para.GetBT();
					if (trans == null)
						return; // don't bother creating one to store an empty translation!
				}
				else
				{
					trans = para.GetOrCreateBT();

				}
				// Don't write unless it changed...PropChanged can be expensive.
				if (!trans.Translation.GetAlternative(ws).UnderlyingTsString.Equals(newFt))
				{
					trans.Translation.SetAlternative(newFt, ws);
					trans.Status.SetAlternative(sUnfinished, ws);
				}
			}
		}
Exemplo n.º 2
0
		/// <summary>
		/// Set up the specified overrides (as controlled by the initializer) for the specified
		/// range of characters in the specified paragraph. Return true if anything changed.
		/// </summary>
		public bool SetupOverrides(StTxtPara para, int ichMin, int ichLim, DispPropInitializer initializer, IVwRootBox sourceRootBox)
		{
			bool changed = false;
			if (para == null)
			{
				if (m_overridePara != null)
					changed = true;
			}
			else
			{
				if (m_overridePara == null)
					changed = true;
				else
					changed = para.Hvo != m_overridePara.Hvo;
			}
			if (ichMin != m_ichMinOverride)
				changed = true;
			if (ichLim != m_ichLimOverride)
				changed = true;
			// Enhance JohnT: if more than one thing uses this at the same time, it may become necessary to
			// check whether we're setting up the same initializer. I don't know how to do this. Might need
			// another argument and variable to keep track of a type of override.
			if (!changed)
				return false;

			if (m_overridePara != null && m_overridePara.IsValidObject())
			{
				// remove the old override.
				StTxtPara oldPara = m_overridePara;
				m_overridePara = null; // remove it so the redraw won't show highlighting!
				UpdateDisplayOfPara(oldPara, sourceRootBox);
			}
			m_overridePara = para;
			m_ichMinOverride = ichMin;
			m_ichLimOverride = ichLim;
			m_overrideInitializer = initializer;
			if (m_overridePara!= null && m_overridePara.IsValidObject())
			{
				// show the new override.
				UpdateDisplayOfPara(m_overridePara, sourceRootBox);
			}
			return true;
		}