Handles replacing text
The current implementation doesn't work for different styles, tags, and WSs that are applied by the VC.
Inheritance: FindReplaceCollectorEnvBase
        public void ReplaceAllWithMultipleRuns()
        {
            ITsStrBldr stringBuilder = TsStrBldrClass.Create();

            stringBuilder.Replace(0, 0, "blaBLA", null);
            stringBuilder.SetIntPropValues(0, 6, (int)FwTextPropType.ktptWs, 0, Cache.DefaultVernWs);
            stringBuilder.SetStrPropValue(0, 3, (int)FwTextPropType.ktptNamedStyle, "CStyle3");
            m_pattern.ReplaceWith = stringBuilder.GetString();

            ReplaceAllCollectorEnv collectorEnv = new ReplaceAllCollectorEnv(m_vc,
                                                                             Cache.MainCacheAccessor, m_para1.Owner.Hvo, (int)StTextFrags.kfrText,
                                                                             m_pattern, null);
            int nReplaces = collectorEnv.ReplaceAll();

            Assert.AreEqual(8, nReplaces);
            Assert.AreEqual("This is some text so thblaBLAt we cblaBLAn test the find functionblaBLAlity.",
                            m_para1.Contents.Text);
            Assert.AreEqual("Some more text so thblaBLAt we cblaBLAn test the find blaBLAnd replblaBLAce functionblaBLAlity.",
                            m_para2.Contents.Text);
            Assert.AreEqual("This purugruph doesn't contuin the first letter of the ulphubet.",
                            m_para3.Contents.Text);
            ITsString para1Contents = m_para1.Contents;

            Assert.AreEqual(7, para1Contents.RunCount);
            Assert.AreEqual("bla", para1Contents.get_RunText(1));
            Assert.AreEqual("CStyle3", para1Contents.get_Properties(1).GetStrPropValue(
                                (int)FwTextPropType.ktptNamedStyle));
        }
        public void ReplaceAllWithReadOnly()
        {
            CheckDisposed();

            if (m_vc != null)
            {
                m_vc.Dispose();
            }
            m_vc                  = new DummyScriptureVc(m_para1.Hvo);
            m_vc.Cache            = Cache;
            m_pattern.ReplaceWith = m_strFactory.MakeString("b", Cache.DefaultVernWs);

            ReplaceAllCollectorEnv collectorEnv = new ReplaceAllCollectorEnv(m_vc,
                                                                             Cache.MainCacheAccessor, m_para1.OwnerHVO, (int)StTextFrags.kfrText,
                                                                             m_pattern, null);
            int nReplaces = collectorEnv.ReplaceAll();

            Assert.AreEqual(5, nReplaces);
            Assert.AreEqual("This is some text so that we can test the find functionality.",
                            m_para1.Contents.Text);
            Assert.AreEqual("Some more text so thbt we cbn test the find bnd replbce functionblity.",
                            m_para2.Contents.Text);
            Assert.AreEqual("This purugruph doesn't contuin the first letter of the ulphubet.",
                            m_para3.Contents.Text);
        }
        public void ReplaceAll()
        {
            m_pattern.ReplaceWith = m_strFactory.MakeString("b", Cache.DefaultVernWs);

            ReplaceAllCollectorEnv collectorEnv = new ReplaceAllCollectorEnv(m_vc,
                                                                             Cache.MainCacheAccessor, m_para1.Owner.Hvo, (int)StTextFrags.kfrText,
                                                                             m_pattern, null);
            int nReplaces = collectorEnv.ReplaceAll();

            Assert.AreEqual(8, nReplaces);
            Assert.AreEqual("This is some text so thbt we cbn test the find functionblity.",
                            m_para1.Contents.Text);
            Assert.AreEqual("Some more text so thbt we cbn test the find bnd replbce functionblity.",
                            m_para2.Contents.Text);
            Assert.AreEqual("This purugruph doesn't contuin the first letter of the ulphubet.",
                            m_para3.Contents.Text);
        }
Esempio n. 4
0
		public void ReplaceAll_InBackTranslation()
		{
			CheckDisposed();
			InitializeForReplaceAll();

			// Replace "BT" with "back translation"
			int wsBt = Cache.DefaultAnalWs;
			m_pattern.Pattern = m_strFactory.MakeString("BT", wsBt);
			m_pattern.ReplaceWith = m_strFactory.MakeString("Back Translation", Cache.DefaultAnalWs);

			int hvoRoot;
			IVwViewConstructor vc;
			int frag;
			IVwStylesheet styleSheet;
			m_btDraftView.RootBox.GetRootObject(out hvoRoot, out vc, out frag, out styleSheet);
			ReplaceAllCollectorEnv collectorEnv = new ReplaceAllCollectorEnv(vc,
				Cache.MainCacheAccessor, hvoRoot, frag,	m_pattern, null);
			int nReplaces = collectorEnv.ReplaceAll();

			// Get back translation from Exodus after Replace All.
			StTxtPara headingPara1 = (StTxtPara)m_exodus.SectionsOS[0].HeadingOA.ParagraphsOS[0];
			ITsString btHeading1 = headingPara1.GetBT().Translation.GetAlternative(wsBt).UnderlyingTsString;
			StTxtPara contentPara1 = (StTxtPara)m_exodus.SectionsOS[0].ContentOA.ParagraphsOS[0];
			ITsString btContent1 = contentPara1.GetBT().Translation.GetAlternative(wsBt).UnderlyingTsString;

			StTxtPara headingPara2 = (StTxtPara)m_exodus.SectionsOS[1].HeadingOA.ParagraphsOS[0];
			ITsString btHeading2 = headingPara2.GetBT().Translation.GetAlternative(wsBt).UnderlyingTsString;
			StTxtPara contentPara2 = (StTxtPara)m_exodus.SectionsOS[1].ContentOA.ParagraphsOS[0];
			ITsString btContent2 = contentPara2.GetBT().Translation.GetAlternative(wsBt).UnderlyingTsString;

			// Confirm that "BT" was replaced with "Back Translation"
			Assert.AreEqual(4, nReplaces);
			Assert.AreEqual("Back Translation Heading 1", btHeading1.Text);
			Assert.AreEqual("Back Translation Intro text", btContent1.Text);
			Assert.AreEqual("Back Translation Heading 2", btHeading2.Text);
			Assert.AreEqual("11Back Translation Verse one", btContent2.Text);
		}
Esempio n. 5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Handle the Replace All button click event.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected void OnReplaceAll(object sender, System.EventArgs e)
		{
			if (DataUpdateMonitor.IsUpdateInProgress(DataAccess))
				return;  // discard event
			using (new DataUpdateMonitor(this, DataAccess, m_vwRootsite, "ReplaceAll", true, true))
			{
				Debug.Assert(m_tool != null);
				int replaceCount = 0;

				using (new WaitCursor(this, true))
				{
					m_tool.SetAppModalState(true);
					PrepareToFind();
					m_inReplace = true;

					if (MatchNotFound == null)
						MatchNotFound += new MatchNotFoundHandler(NoMatchFound);

					try
					{
						using (UndoTaskHelper undoTaskHelper = new UndoTaskHelper(m_vwRootsite,
								  "kstidUndoReplace", true))
						{
							DateTime start = DateTime.Now;
							// Do the replace all
							SetupFindPattern();
							SaveDialogValues();
							if (PatternIsValid())
							{
								m_searchKiller.AbortRequest = false;
								m_searchKiller.Control = this;	// used for redrawing
								m_searchKiller.StopControl = this.btnClose;	// need to know the stop button
								m_vwPattern.ReplaceWith = ReplaceText;

								int hvoRoot, frag;
								IVwViewConstructor vc;
								IVwStylesheet styleSheet;
								m_vwRootsite.RootBox.GetRootObject(out hvoRoot, out vc, out frag, out styleSheet);
								ReplaceAllCollectorEnv replaceAll = new ReplaceAllCollectorEnv(vc, DataAccess,
									hvoRoot, frag, m_vwPattern, m_searchKiller);
								replaceCount = replaceAll.ReplaceAll();

								Debug.WriteLine("Replace all took " + (DateTime.Now - start));
							}
						}
					}
					finally
					{
						PostpareToFind(replaceCount > 0);
						m_tool.SetAppModalState(false);
						m_inReplace = false;
					}
				}
				// Display a dialog box if the replace all finished or was stopped
				if (replaceCount > 0)
				{
					bool fShowMsg = true;
					string msg = "";
					if (m_searchKiller.AbortRequest)	// if it's been aborted, change the msg displayed
						msg = string.Format(FwCoreDlgs.kstidReplaceAllStopped, replaceCount);
					else
						msg = string.Format(FwCoreDlgs.kstidReplaceAllDone, replaceCount);

					if (MatchNotFound != null)
						fShowMsg = MatchNotFound(this, msg, MatchType.ReplaceAllFinished);

					if (fShowMsg)
						MessageBox.Show(Owner, msg, Application.ProductName);
				}
				else if (replaceCount == 0)
					InternalMatchNotFound(true);
			}

			// After a replace, focus the find box and select the text in it.
			fweditFindText.FocusAndSelectAll();
		}
		public void ReplaceAllWithReadOnly()
		{
			CheckDisposed();

			if (m_vc != null)
				m_vc.Dispose();
			m_vc = new DummyScriptureVc(m_para1.Hvo);
			m_vc.Cache = Cache;
			m_pattern.ReplaceWith = m_strFactory.MakeString("b", Cache.DefaultVernWs);

			ReplaceAllCollectorEnv collectorEnv = new ReplaceAllCollectorEnv(m_vc,
				Cache.MainCacheAccessor, m_para1.OwnerHVO, (int)StTextFrags.kfrText,
				m_pattern, null);
			int nReplaces = collectorEnv.ReplaceAll();

			Assert.AreEqual(5, nReplaces);
			Assert.AreEqual("This is some text so that we can test the find functionality.",
				m_para1.Contents.Text);
			Assert.AreEqual("Some more text so thbt we cbn test the find bnd replbce functionblity.",
				m_para2.Contents.Text);
			Assert.AreEqual("This purugruph doesn't contuin the first letter of the ulphubet.",
				m_para3.Contents.Text);
		}
		public void ReplaceAllWithMultipleRuns()
		{
			CheckDisposed();

			ITsStrBldr stringBuilder = TsStrBldrClass.Create();
			stringBuilder.Replace(0, 0, "blaBLA", null);
			stringBuilder.SetStrPropValue(0, 3,
				(int)FwTextPropType.ktptNamedStyle, "CStyle3");
			m_pattern.ReplaceWith = stringBuilder.GetString();

			ReplaceAllCollectorEnv collectorEnv = new ReplaceAllCollectorEnv(m_vc,
				Cache.MainCacheAccessor, m_para1.OwnerHVO, (int)StTextFrags.kfrText,
				m_pattern, null);
			int nReplaces = collectorEnv.ReplaceAll();

			Assert.AreEqual(8, nReplaces);
			Assert.AreEqual("This is some text so thblaBLAt we cblaBLAn test the find functionblaBLAlity.",
				m_para1.Contents.Text);
			Assert.AreEqual("Some more text so thblaBLAt we cblaBLAn test the find blaBLAnd replblaBLAce functionblaBLAlity.",
				m_para2.Contents.Text);
			Assert.AreEqual("This purugruph doesn't contuin the first letter of the ulphubet.",
				m_para3.Contents.Text);
			ITsString para1Contents = m_para1.Contents.UnderlyingTsString;
			Assert.AreEqual(7, para1Contents.RunCount);
			Assert.AreEqual("bla", para1Contents.get_RunText(1));
			Assert.AreEqual("CStyle3", para1Contents.get_Properties(1).GetStrPropValue(
				(int)FwTextPropType.ktptNamedStyle));
		}
		public void ReplaceAll()
		{
			m_pattern.ReplaceWith = m_strFactory.MakeString("b", Cache.DefaultVernWs);

			ReplaceAllCollectorEnv collectorEnv = new ReplaceAllCollectorEnv(m_vc,
				Cache.MainCacheAccessor, m_para1.Owner.Hvo, (int)StTextFrags.kfrText,
				m_pattern, null);
			int nReplaces = collectorEnv.ReplaceAll();

			Assert.AreEqual(8, nReplaces);
			Assert.AreEqual("This is some text so thbt we cbn test the find functionblity.",
				m_para1.Contents.Text);
			Assert.AreEqual("Some more text so thbt we cbn test the find bnd replbce functionblity.",
				m_para2.Contents.Text);
			Assert.AreEqual("This purugruph doesn't contuin the first letter of the ulphubet.",
				m_para3.Contents.Text);
		}
Esempio n. 9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Does the replace all.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected void DoReplaceAll()
		{
			int replaceCount = 0;
			if (m_app != null)
				m_app.EnableMainWindows(false);
			var rootSite = ActiveView;
			if (rootSite == null)
				return;

			PrepareToFind();
			m_inReplace = true;

			if (MatchNotFound == null)
				MatchNotFound += NoMatchFound;
			try
			{
				DateTime start = DateTime.Now;
				// Do the replace all
				SetupFindPattern();
				SaveDialogValues();
				if (PatternIsValid())
				{
					m_searchKiller.AbortRequest = false;
					m_searchKiller.Control = this;	// used for redrawing
					m_searchKiller.StopControl = btnClose;	// need to know the stop button
					m_vwPattern.ReplaceWith = ReplaceText;

					int hvoRoot, frag;
					IVwViewConstructor vc;
					IVwStylesheet styleSheet;
					rootSite.RootBox.GetRootObject(out hvoRoot, out vc, out frag, out styleSheet);
					ReplaceAllCollectorEnv replaceAll = new ReplaceAllCollectorEnv(vc, DataAccess,
						hvoRoot, frag, m_vwPattern, m_searchKiller);
					replaceCount = replaceAll.ReplaceAll();

					Debug.WriteLine("Replace all took " + (DateTime.Now - start));
				}
			}
			finally
			{
				PostpareToFind(replaceCount > 0);
				if (m_app != null)
					m_app.EnableMainWindows(true);
				m_inReplace = false;
			}

			// Display a dialog box if the replace all finished or was stopped
			if (replaceCount > 0)
			{
				bool fShowMsg = true;
				string msg = string.Format(m_searchKiller.AbortRequest ?
					FwCoreDlgs.kstidReplaceAllStopped :
					FwCoreDlgs.kstidReplaceAllDone, replaceCount);

				if (MatchNotFound != null)
					fShowMsg = MatchNotFound(this, msg, MatchType.ReplaceAllFinished);

				if (!fShowMsg)
					return;

				try
				{
					if (MiscUtils.IsUnix)
					{
						// Get a wait cursor to display when waiting for the messagebox
						// to show. See FWNX-660.
						this.tabReplace.UseWaitCursor = true;
						this.tabReplace.Parent.UseWaitCursor = true;
					}

					MessageBox.Show(Owner, msg, m_app.ApplicationName);
				}
				finally
				{
					if (MiscUtils.IsUnix)
					{
						this.tabReplace.Parent.UseWaitCursor = false;
						this.tabReplace.UseWaitCursor = false;
					}
				}
			}
			else if (replaceCount == 0)
				InternalMatchNotFound(true);
		}