public void CreateAndUpdateOneOfTwoFts()
		{
			string pc1 = "Das buch ist rot. ";
			string pc2 = "Das Madchen ist shon.";
			string verse1 = "9";
			m_para.Contents.UnderlyingTsString = m_tsf.MakeString(pc1 + verse1 + pc2, m_wsVern);
			string trans1 = "The book is red.";
			string trans2 = "The girl is beautiful";
			ICmIndirectAnnotation ft = MakeFt(m_para, trans1, 0, pc1.Length);
			ICmBaseAnnotation verseSeg = MakeVerseSegment(m_para, pc1.Length, verse1.Length);
			ICmIndirectAnnotation ft2 = MakeFt(m_para, trans2, pc1.Length + verse1.Length, pc2.Length);
			FreeTransEditMonitor monitor = new FreeTransEditMonitor(Cache, m_wsTrans); // BEFORE propChanged!
			Cache.PropChanged(ft.Hvo, (int)CmAnnotation.CmAnnotationTags.kflidComment, 0, 0, 0);
			Cache.PropChanged(ft.Hvo, (int)CmAnnotation.CmAnnotationTags.kflidComment, 0, 0, 0);
			Assert.AreEqual(0, m_para.TranslationsOC.Count, "monitor should not have updated for change to same ft.");

			Cache.PropChanged(ft2.Hvo, (int)CmAnnotation.CmAnnotationTags.kflidComment, 0, 0, 0);

			Assert.AreEqual(1, m_para.TranslationsOC.Count, "monitor should have updated on changing another property");
			Assert.AreEqual(trans1 + " " + verse1 + trans2,
				m_para.TranslationsOC.ToList()[0].Translation.GetAlternative(m_wsTrans).Text,
				"translation should be correct after changing prop2");

			string trans2b = "The girl is pretty.";
			ft2.Comment.SetAlternative(trans2b, m_wsTrans); // should generate propChanged for same prop.
			Assert.AreEqual(trans1 + " " + verse1 + trans2,
				m_para.TranslationsOC.ToList()[0].Translation.GetAlternative(m_wsTrans).Text,
				"Another change to same prop should not produce yet another update");
			monitor.Dispose();
			Assert.AreEqual(trans1 + " " + verse1 + trans2b,
				m_para.TranslationsOC.ToList()[0].Translation.GetAlternative(m_wsTrans).Text,
				"Should get final update on Dispose");
		}
		public void CreateAndUpdateSingleFt()
		{
			string paraContents = "Das buch ist rot";
			string trans = "The book is red";
			m_para.Contents.UnderlyingTsString = m_tsf.MakeString(paraContents, m_wsVern);
			ICmIndirectAnnotation ft = MakeFt(m_para, trans, 0, paraContents.Length);
			FreeTransEditMonitor monitor = new FreeTransEditMonitor(Cache, m_wsTrans); // BEFORE propChanged!
			Cache.PropChanged(ft.Hvo, (int)CmAnnotation.CmAnnotationTags.kflidComment, 0, 0, 0);
			monitor.LoseFocus();
			Assert.AreEqual(1, m_para.TranslationsOC.Count, "monitor should have made a CmTranslation");
			Assert.AreEqual(trans, m_para.TranslationsOC.ToList()[0].Translation.GetAlternative(m_wsTrans).Text);
			string trans2 = "The book is green";
			ft.Comment.SetAlternative(trans2, m_wsTrans);
			monitor.Dispose(); // should trigger update.
			Assert.AreEqual(1, m_para.TranslationsOC.Count, "monitor should not have made another translation");
			Assert.AreEqual(trans2, m_para.TranslationsOC.ToList()[0].Translation.GetAlternative(m_wsTrans).Text);
		}
		private void DisposeFtMonitor()
		{
			if (m_ftMonitor != null)
			{
				if (TopLevelControl is Form)
					(TopLevelControl as Form).FormClosing -= new FormClosingEventHandler(FormClosing);
				m_ftMonitor.Dispose();
				m_ftMonitor = null;
			}
			if (m_cmtMonitor != null)
			{
				if (TopLevelControl is Form)
					(TopLevelControl as Form).FormClosing -= new FormClosingEventHandler(FormClosing);
				m_cmtMonitor.Dispose();
				m_cmtMonitor = null;
			}
		}
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Focus got set to the draft view
		/// </summary>
		/// <param name="e">The event data</param>
		/// -----------------------------------------------------------------------------------
		protected override void OnGotFocus(EventArgs e)
		{
			base.OnGotFocus(e);

			// Supposedly, m_ftMonitor should always be null, since it only gets set in OnGetFocus
			// and it gets cleared in OnLostFocus. However there have been odd cases. If we're already
			// tracking a change we don't want to lose it.
			// Enhance JohnT: we don't really need this unless we're doing segment BTs.
			if (m_ftMonitor == null)
			{
				m_ftMonitor = new FreeTransEditMonitor(Cache, BackTranslationWS);
				// Unfortunately, when the main window closes, both our Dispose() method and our OnLostFocus() method
				// get called during the Dispose() of the main window, which is AFTER the FdoCache gets disposed.
				// We need to dispose our FreeTransEditMonitor before the cache is disposed, so we can update the
				// CmTranslation if necessary.
				if (TopLevelControl is Form)
					(TopLevelControl as Form).FormClosing += new FormClosingEventHandler(FormClosing);
			}
			if (m_cmtMonitor == null)
			{
				m_cmtMonitor = new CmTranslationEditMonitor(Cache, BackTranslationWS);
				// Unfortunately, when the main window closes, both our Dispose() method and our OnLostFocus() method
				// get called during the Dispose() of the main window, which is AFTER the FdoCache gets disposed.
				// We need to dispose our FreeTransEditMonitor before the cache is disposed, so we can update the
				// CmTranslation if necessary.
				if (TopLevelControl is Form)
					(TopLevelControl as Form).FormClosing += new FormClosingEventHandler(FormClosing);
			}
		}
		public void NonScriptureText()
		{
			IText text = new Text();
			Cache.LangProject.TextsOC.Add(text);
			StText sttext = new StText();
			text.ContentsOA = sttext;
			m_para = new StTxtPara();
			sttext.ParagraphsOS.Append(m_para);
			string paraContents = "Das buch ist rot";
			string trans = "The book is red";
			m_para.Contents.UnderlyingTsString = m_tsf.MakeString(paraContents, m_wsVern);
			ICmIndirectAnnotation ft = MakeFt(m_para, trans, 0, paraContents.Length);
			FreeTransEditMonitor monitor = new FreeTransEditMonitor(Cache, m_wsTrans); // BEFORE propChanged!
			Cache.PropChanged(ft.Hvo, (int)CmAnnotation.CmAnnotationTags.kflidComment, 0, 0, 0);
			monitor.LoseFocus();
			Assert.AreEqual(0, m_para.TranslationsOC.Count, "monitor should not make CmTranslation for non-Scripture");
		}
Пример #6
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Focus got set to the draft view
		/// </summary>
		/// <param name="e">The event data</param>
		/// -----------------------------------------------------------------------------------
		protected override void OnGotFocus(EventArgs e)
		{
			base.OnGotFocus(e);

			if (DesignMode || !m_fRootboxMade)
				return;

			// Reset the previous selected paragraph value to reset the optimization
			// for scrolling the footnote pane.
			m_prevSelectedParagraph = 0;

			if (m_SelectionHelper != null)
			{
				if (m_SelectionHelper.SetSelection(this) == null)
				{
					// Set selection to beginning of first book if project has any books
					if (BookFilter.BookCount > 0)
						SetInsertionPoint((int)ScrBook.ScrBookTags.kflidTitle, 0, 0);
				}

				m_SelectionHelper = null;
			}
			// Supposedly, m_ftMonitor should always be null, since it only gets set in OnGetFocus
			// and it gets cleared in OnLostFocus. However there have been odd cases. If we're already
			// tracking a change we don't want to lose it.
			if (m_contentType == StVc.ContentTypes.kctSegmentBT && m_ftMonitor == null)
			{
				m_ftMonitor = new FreeTransEditMonitor(Cache, BackTranslationWS);
				// Unfortunately, when the main window closes, both our Dispose() method and our OnLostFocus() method
				// get called during the Dispose() of the main window, which is AFTER the FdoCache gets disposed.
				// We need to dispose our FreeTransEditMonitor before the cache is disposed, so we can update the
				// CmTranslation if necessary.
				if (TopLevelControl is Form)
					(TopLevelControl as Form).FormClosing += new FormClosingEventHandler(DraftView_FormClosing);
			}
			if (m_contentType == StVc.ContentTypes.kctSimpleBT && m_cmtMonitor == null)
			{
				m_cmtMonitor = new CmTranslationEditMonitor(Cache, BackTranslationWS);
				if (TopLevelControl is Form)
					(TopLevelControl as Form).FormClosing += new FormClosingEventHandler(DraftView_FormClosing);
			}

			// A draft view which has focus cannot display selected-segment highlighting.
			if (m_draftViewVc != null)
				m_draftViewVc.SetupOverrides(null, 0, 0, null, null);
		}