Handles finding text
The current implementation doesn't work for different styles, tags, and WSs that are applied by the VC.
Inheritance: FindReplaceCollectorEnvBase
Exemplo n.º 1
0
        public void Find_FromMiddle()
        {
            using (var collectorEnv = new FindCollectorEnv(m_vc,
                                                           Cache.DomainDataByFlid, m_para1.Owner.Hvo, (int)StTextFrags.kfrText,
                                                           m_pattern, null))
            {
                // Start in the middle
                SelLevInfo[] levInfo = new SelLevInfo[1];
                levInfo[0].hvo = m_para2.Hvo;
                levInfo[0].tag = StTextTags.kflidParagraphs;
                m_sel          = new CollectorEnv.LocationInfo(levInfo, StTxtParaTags.kflidContents, 5);

                VerifyFindNext(collectorEnv, m_para2.Hvo, 20, 21);
                VerifyFindNext(collectorEnv, m_para2.Hvo, 27, 28);
                VerifyFindNext(collectorEnv, m_para2.Hvo, 44, 45);
                VerifyFindNext(collectorEnv, m_para2.Hvo, 52, 53);
                VerifyFindNext(collectorEnv, m_para2.Hvo, 64, 65);
                Assert.IsNull(collectorEnv.FindNext(m_sel));

                // Make sure nothing got replaced by accident.
                Assert.AreEqual("This is some text so that we can test the find functionality.",
                                m_para1.Contents.Text);
                Assert.AreEqual("Some more text so that we can test the find and replace functionality.",
                                m_para2.Contents.Text);
                Assert.AreEqual("This purugruph doesn't contuin the first letter of the ulphubet.",
                                m_para3.Contents.Text);
            }
        }
        public void Find_FromTop()
        {
            CheckDisposed();

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

            // Start at the top
            SelLevInfo[] levInfo = new SelLevInfo[1];
            levInfo[0].hvo = m_para1.Hvo;
            levInfo[0].tag = (int)StText.StTextTags.kflidParagraphs;
            m_sel          = new FindCollectorEnv.LocationInfo(levInfo,
                                                               (int)StTxtPara.StTxtParaTags.kflidContents, 0);

            VerifyFindNext(collectorEnv, m_para1.Hvo, 23, 24);
            VerifyFindNext(collectorEnv, m_para1.Hvo, 30, 31);
            VerifyFindNext(collectorEnv, m_para1.Hvo, 55, 56);
            VerifyFindNext(collectorEnv, m_para2.Hvo, 20, 21);
            VerifyFindNext(collectorEnv, m_para2.Hvo, 27, 28);
            VerifyFindNext(collectorEnv, m_para2.Hvo, 44, 45);
            VerifyFindNext(collectorEnv, m_para2.Hvo, 52, 53);
            VerifyFindNext(collectorEnv, m_para2.Hvo, 64, 65);
            Assert.IsNull(collectorEnv.FindNext(m_sel));

            // Make sure nothing got replaced by accident.
            Assert.AreEqual("This is some text so that we can test the find functionality.",
                            m_para1.Contents.Text);
            Assert.AreEqual("Some more text so that we can test the find and replace functionality.",
                            m_para2.Contents.Text);
            Assert.AreEqual("This purugruph doesn't contuin the first letter of the ulphubet.",
                            m_para3.Contents.Text);
        }
Exemplo n.º 3
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Verifies the find next.
 /// </summary>
 /// <param name="collectorEnv">The collector env.</param>
 /// <param name="hvoExpected">The hvo expected.</param>
 /// <param name="ichMinExpected">The ich min expected.</param>
 /// <param name="ichLimExpected">The ich lim expected.</param>
 /// ------------------------------------------------------------------------------------
 private void VerifyFindNext(FindCollectorEnv collectorEnv, int hvoExpected,
                             int ichMinExpected, int ichLimExpected)
 {
     CollectorEnv.LocationInfo foundLocation = collectorEnv.FindNext(m_sel);
     Assert.IsNotNull(foundLocation);
     Assert.AreEqual(1, foundLocation.m_location.Length);
     Assert.AreEqual(hvoExpected, foundLocation.TopLevelHvo);
     Assert.AreEqual(StTextTags.kflidParagraphs, foundLocation.m_location[0].tag);
     Assert.AreEqual(StTxtParaTags.kflidContents, foundLocation.m_tag);
     Assert.AreEqual(ichMinExpected, foundLocation.m_ichMin);
     Assert.AreEqual(ichLimExpected, foundLocation.m_ichLim);
     m_sel = foundLocation;
 }
Exemplo n.º 4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Change the main window which owns this dialog. Since this dialog attempts to stay
		/// alive as long as the app is alive (or, as long as there is a main window open),
		/// the app should call this to re-assign an owner any time the existing owner is
		/// closing.
		/// </summary>
		/// <param name="cache">The cache belonging to the view.</param>
		/// <param name="rootSite">view</param>
		/// <param name="hwnd">The window handle of the main window that owns the rootsite
		/// </param>
		/// <param name="findPattern">The find/replace pattern of the new owner.</param>
		/// <param name="wsEdit">writing system for the find and replace edit boxes</param>
		/// ------------------------------------------------------------------------------------
		public void SetOwner(FdoCache cache, IVwRootSite rootSite, IntPtr hwnd,
			IVwPattern findPattern, int wsEdit)
		{
			CheckDisposed();

			m_vwRootsite = rootSite;
			if (m_vwRootsite != null && rootSite.RootBox != null)
				fweditFindText.StyleSheet = fweditReplaceText.StyleSheet = rootSite.RootBox.Stylesheet;

			bool fChangingCache = (m_cache != cache);
			m_cache = cache;
			if (m_cache != null && fChangingCache)
			{
				ILgWritingSystemFactory wsf = m_cache.LanguageWritingSystemFactoryAccessor;
				fweditFindText.WritingSystemFactory = fweditReplaceText.WritingSystemFactory = wsf;
				ITsStrFactory strFact = TsStrFactoryClass.Create();
				FindText = strFact.MakeString(string.Empty, m_cache.DefaultVernWs);
				ReplaceText = strFact.MakeString(string.Empty, m_cache.DefaultVernWs);
				// Make sure each of the edit boxes has a reasonable writing system assigned.
				// (See LT-5130 for what can happen otherwise.)
				// The default verncular is not always reasonable enough.
				fweditFindText.WritingSystemCode = wsEdit;	// m_cache.DefaultVernWs;
				fweditReplaceText.WritingSystemCode = wsEdit; // m_cache.DefaultVernWs;
				FindText = EnsureValidWs(wsEdit, findPattern.Pattern);
				ReplaceText = EnsureValidWs(wsEdit, findPattern.ReplaceWith);
				SetCheckboxStates(findPattern);
				m_vwPattern = findPattern;
			}
			Control newOwner = Form.FromHandle(hwnd);
			if (newOwner != null && Owner != newOwner && newOwner is Form)
			{
				Owner = (Form)newOwner;
				m_vwselPattern = null;
				m_findEnvironment = null;
			}
		}
Exemplo n.º 5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Find the next match based on the current pattern settings
		/// </summary>
		/// <param name="fSearchForward">If true, search forward; otherwise search backward</param>
		/// ------------------------------------------------------------------------------------
		private void Find(bool fSearchForward)
		{
			// If no find was done before, show the dialog or focus it.
			if (!btnFindNext.Enabled)
			{
				if (!Visible)
					Show();
				else
					Focus();
				return;
			}

			if (m_fLastDirectionForward != fSearchForward)
			{
				// Changing search direction. Reset current selection (resets the search limit)
				m_vwselPattern = null;
				m_fLastDirectionForward = fSearchForward;
			}

			SetupFindPattern();

			// Get the selection from the root box in order to compare it with the one from
			// the pattern.
			IVwSelection vwselRootb = m_vwRootsite.RootBox.Selection;

			// If the pattern's selection is different from the current selection in the
			// rootbox or if a new search has been started then set things up to begin
			// searching at the current selection.
			bool fFirstTry = (m_vwselPattern == null || m_vwselPattern != vwselRootb);
			if (fFirstTry)
			{
				int hvoRoot, frag;
				IVwViewConstructor vc;
				IVwStylesheet styleSheet;
				m_vwRootsite.RootBox.GetRootObject(out hvoRoot, out vc, out frag, out styleSheet);
				if (fSearchForward)
				{
					m_findEnvironment = new FindCollectorEnv(vc, DataAccess, hvoRoot, frag,
						m_vwPattern, m_searchKiller);
				}
				else
				{
					m_findEnvironment = new ReverseFindCollectorEnv(vc, DataAccess, hvoRoot, frag,
						m_vwPattern, m_searchKiller);
				}
			}
			Debug.Assert(m_findEnvironment != null);

			if (vwselRootb == null)
				vwselRootb = m_vwRootsite.RootBox.MakeSimpleSel(true, true, false, true);

			// Find the pattern.
			if (vwselRootb != null)
			{
				// Even though the find doesn't technically update any data, we don't
				// want the user to be able to change the data underneath us while the
				// find is happening.
				using (new DataUpdateMonitor(this, DataAccess, m_vwRootsite, "Find", true, true))
				{
					// Change the cancel button to a stop
					PrepareToFind();
					m_inFind = true;

					try
					{
						SaveDialogValues();
						if (PatternIsValid())
						{
							m_searchKiller.AbortRequest = false;
							FindFrom(vwselRootb, fSearchForward);
							if (!m_findEnvironment.FoundMatch)
								AttemptWrap(fFirstTry, fSearchForward);
						}
					}
					finally
					{
						PostpareToFind(false);
						m_inFind = false;
					}
				}
			}
		}
Exemplo n.º 6
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Change the main window which owns this dialog. Since this dialog attempts to stay
		/// alive as long as the app is alive (or, as long as there is a main window open),
		/// the app should call this to re-assign an owner any time the existing owner is
		/// closing.
		/// </summary>
		/// <param name="rootSite">view</param>
		/// <param name="newOwner">The main window that owns the rootsite</param>
		/// <param name="findPattern">The find/replace pattern of the new owner. TODO Review (Hasso) 2015.08: unused</param>
		/// <param name="wsEdit">writing system for the find and replace edit boxes TODO Review (Hasso) 2015.08: unused</param>
		/// ------------------------------------------------------------------------------------
		public void SetOwner(IVwRootSite rootSite, Form newOwner, IVwPattern findPattern, int wsEdit)
		{
			CheckDisposed();

			m_vwRootsite = rootSite;
			if (m_vwRootsite != null && rootSite.RootBox != null)
				fweditFindText.StyleSheet = fweditReplaceText.StyleSheet = rootSite.RootBox.Stylesheet;

			if (newOwner != null && Owner != newOwner)
			{
				Owner = newOwner;
				m_vwSelectionForPattern = null;
				m_findEnvironment = null;
			}
		}
Exemplo n.º 7
0
		private void InitializeFindEnvironment(IVwRootSite rootSite, bool fSearchForward = true)
		{
			int hvoRoot, frag;
			IVwViewConstructor vc;
			IVwStylesheet styleSheet;
			rootSite.RootBox.GetRootObject(out hvoRoot, out vc, out frag, out styleSheet);
			m_findEnvironment = fSearchForward
				? new FindCollectorEnv(vc, DataAccess, hvoRoot, frag, m_vwFindPattern, m_searchKiller)
				: new ReverseFindCollectorEnv(vc, DataAccess, hvoRoot, frag, m_vwFindPattern, m_searchKiller);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Verifies the find next.
		/// </summary>
		/// <param name="collectorEnv">The collector env.</param>
		/// <param name="hvoExpected">The hvo expected.</param>
		/// <param name="ichMinExpected">The ich min expected.</param>
		/// <param name="ichLimExpected">The ich lim expected.</param>
		/// ------------------------------------------------------------------------------------
		private void VerifyFindNext(FindCollectorEnv collectorEnv, int hvoExpected,
			int ichMinExpected, int ichLimExpected)
		{
			FindCollectorEnv.LocationInfo foundLocation = collectorEnv.FindNext(m_sel);
			Assert.IsNotNull(foundLocation);
			Assert.AreEqual(1, foundLocation.m_location.Length);
			Assert.AreEqual(hvoExpected, foundLocation.TopLevelHvo);
			Assert.AreEqual((int)StText.StTextTags.kflidParagraphs, foundLocation.m_location[0].tag);
			Assert.AreEqual((int)StTxtPara.StTxtParaTags.kflidContents, foundLocation.m_tag);
			Assert.AreEqual(ichMinExpected, foundLocation.m_ichMin);
			Assert.AreEqual(ichLimExpected, foundLocation.m_ichLim);
			m_sel = foundLocation;
		}
		public void Find_FromMiddle()
		{
			CheckDisposed();

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

			// Start in the middle
			SelLevInfo[] levInfo = new SelLevInfo[1];
			levInfo[0].hvo = m_para2.Hvo;
			levInfo[0].tag = (int)StText.StTextTags.kflidParagraphs;
			m_sel = new FindCollectorEnv.LocationInfo(levInfo,
				(int)StTxtPara.StTxtParaTags.kflidContents, 5);

			VerifyFindNext(collectorEnv, m_para2.Hvo, 20, 21);
			VerifyFindNext(collectorEnv, m_para2.Hvo, 27, 28);
			VerifyFindNext(collectorEnv, m_para2.Hvo, 44, 45);
			VerifyFindNext(collectorEnv, m_para2.Hvo, 52, 53);
			VerifyFindNext(collectorEnv, m_para2.Hvo, 64, 65);
			Assert.IsNull(collectorEnv.FindNext(m_sel));

			// Make sure nothing got replaced by accident.
			Assert.AreEqual("This is some text so that we can test the find functionality.",
				m_para1.Contents.Text);
			Assert.AreEqual("Some more text so that we can test the find and replace functionality.",
				m_para2.Contents.Text);
			Assert.AreEqual("This purugruph doesn't contuin the first letter of the ulphubet.",
				m_para3.Contents.Text);
		}