Пример #1
0
        static void QueryHistoryCapacityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            RapidFindReplaceControlViewModel model = (sender as RapidFindReplaceControlViewModel);

            if (((int)e.NewValue) != model.QueryHistory.Capacity)
            {
                model.QueryHistory.Resize((int)e.NewValue);
            }
        }
        /// <summary>
        /// New.
        /// </summary>
        public RapidFindReplaceControl()
        {
            queryContainer = new Query("");
            // this.Resources.MergedDictionaries.Add(SharedDictionaryManager.SharedDictionary);
            //AsYouTypeFindMinimumCharacters = 2;
            //AsYouTypeFindEnabled = true;


            ViewModel = new RapidFindReplaceControlViewModel();//must use setter as it does a binding
        }
Пример #3
0
        public void MakeInvalid()
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.FindOptions.UseRegularExpressions = true;
            Query q = new Query(".*[");
            RunQueue rq = new RunQueue(1);
            rq.Enqueue(new System.Windows.Documents.Run("hello this is it"));
            model.ScanQueuedRuns(rq, q, null);
            Assert.IsFalse(q.Valid);
            Assert.AreEqual("Regular expression error, parsing \".*[\" - Unterminated [] set.", q.ReasonInvalid);

        }
Пример #4
0
        private static void FindScopeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            RapidFindReplaceControlViewModel kf = sender as RapidFindReplaceControlViewModel;

            if (kf.focusMonitor == null)
            {
                kf.focusMonitor = FocusMonitor.GetCreateInstanceFor(e.NewValue as DependencyObject);
            }
            else
            {
                kf.focusMonitor.BeginMonitoring(e.NewValue as DependencyObject);
            }
        }
Пример #5
0
 public void FlowProblem1()
 {
     RapidFindReplaceControlViewModel finder = new RapidFindReplaceControlViewModel();
     bool hit=false;
     FlowDocument content = LoadFlowDocument("FlowDocument1.xaml");
     System.Collections.Generic.List<Run> runs = new System.Collections.Generic.List<Run>(5);
     FindRuns(content.Blocks, runs);
     finder.FindTextIn(runs, delegate(Run run, int index, int length)
         {
             hit = true;
         },   new Query("urna jimmy"));
     
     Assert.IsTrue(hit);
 }
Пример #6
0
 public DependencyObject LastKeyboardFocussedControl(RapidFindReplaceControlViewModel model)
 {
     //look for most recent UIElement that got focus that we will search (mostly this is to ignore menus and buttons that might have opened the find popup)
     foreach (WeakReference reference in focussedElementBuffer)
     {
         if (reference != null && reference.IsAlive)
         {
             UIElement targ  = reference.Target as UIElement;
             bool      dummy = true;
             if (model.WillSearchInElement(targ, true, ref dummy, RapidFindReplaceControl.GetIsFindable(targ)))
             {
                 return(targ as DependencyObject);
             }
         }
     }
     return(null);
 }
Пример #7
0
        public void ReplaceReplaceAllProblem1()
        {
            RapidFindReplaceControlViewModel finder = new RapidFindReplaceControlViewModel();
            FlowDocument content = LoadFlowDocument("FlowDocument1.xaml");
            System.Collections.Generic.List<Run> runs = new System.Collections.Generic.List<Run>(5);
            //FindRuns(content.Blocks, runs);
            runs.Add(new Run("aaaa"));

            RunCollectionContainer coll = new RunCollectionContainer(runs);

           
            finder.Query = new Query("aaaa");
            finder.FindText(coll);

           
            
            finder.ReplaceMatchCommand.Execute("ddd");
            finder.ReplaceAllMatchesCommand.Execute("ddd");
            
        }
Пример #8
0
        public void Match_Simple_NoOptions()
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.FindOptions.FindWholeWordsOnly            = false;
            model.FindOptions.IgnorePunctuationCharacters   = false;
            model.FindOptions.IgnoreWhitespaceCharacters    = false;
            model.FindOptions.MatchCase                     = false;
            model.FindOptions.MatchPrefix                   = false;
            model.FindOptions.MatchSuffix                   = false;
            model.FindOptions.UseWildcards                  = false;



            Assert.AreEqual(-1, model.GetNextMatch_FOR_TESTING("xxx", 0, "this is some text").Start);
            Assert.AreEqual(13, model.GetNextMatch_FOR_TESTING( "text", 0, "this is some text").Start);
            Assert.AreEqual(13, model.GetNextMatch_FOR_TESTING("tex", 0, "this is some text").Start);
            Assert.AreEqual(13, model.GetNextMatch_FOR_TESTING("te", 0, "this is some text").Start);
            Assert.AreEqual(0, model.GetNextMatch_FOR_TESTING("t", 0, "this is some text").Start);
            Assert.AreEqual(13, model.GetNextMatch_FOR_TESTING("t", 1, "this is some text").Start);
            Assert.AreEqual(0, model.GetNextMatch_FOR_TESTING("this", 0, "this is some text").Start);
            Assert.AreEqual(0, model.GetNextMatch_FOR_TESTING("this is some text", 0, "this is some text").Start);
        }
Пример #9
0
        public void FindDoubleSpace()
        {
            RapidFindReplaceControlViewModel finder = new RapidFindReplaceControlViewModel();
           
            System.Collections.Generic.List<Run> runs = new System.Collections.Generic.List<Run>(5);
            //FindRuns(content.Blocks, runs);
            runs.Add(new Run("a  a"));
            runs.Add(new Run("T"));

            RunCollectionContainer coll = new RunCollectionContainer(runs);

 
            finder.Query = new Query("  ");
            finder.FindText(coll);

            finder.SelectNextMatch();
            
         
            Assert.AreEqual(1, finder.CurrentMatch.AbsoluteStart);
            Assert.AreEqual(3, finder.CurrentMatch.AbsoluteEnd);
            
        }
Пример #10
0
        public void Flow_3()
        {
            RapidFindReplaceControlViewModel finder = new RapidFindReplaceControlViewModel();
           // finder.FindOptions.IgnoreWhitespaceCharacters = true;
            bool hit = false;
            FlowDocument content = LoadFlowDocument("FlowDocument3.xaml");
            finder.FindTextIn(FindHandlerRegistry.CreateIRunReaderHandlerFor(content), delegate(Run run, int index, int length)
            {
                hit = true;
            }, new Query("a b c"));

            Assert.IsTrue(hit);
        }
Пример #11
0
        public void FlowProblem1_AsFlowDocument_WithRegistry()
        {
            RapidFindReplaceControlViewModel finder = new RapidFindReplaceControlViewModel();
            bool hit = false;
            FlowDocument content = LoadFlowDocument("FlowDocument1.xaml");
            finder.FindTextIn(FindHandlerRegistry.CreateIRunReaderHandlerFor(content), delegate(Run run, int index, int length)
            {
                hit = true;
            }, new Query("urna jimmy"));

            Assert.IsTrue(hit);
        }
Пример #12
0
        public void FlowProblem_Jimmy_SecondColumn_no2()
        {
            RapidFindReplaceControlViewModel finder = new RapidFindReplaceControlViewModel();
            FlowDocument content = LoadFlowDocument("FlowDocument4.xaml");
            int hitCount = 0;
            finder.FindTextIn(new FlowDocumentRunReader(content), delegate(Run run, int index, int length)
            {
                hitCount++;
            }, new Query("jimmy"));

            Assert.AreEqual(2, hitCount);
        }
Пример #13
0
        public void Match_Wildcards()
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.FindOptions.FindWholeWordsOnly = false;
            model.FindOptions.IgnorePunctuationCharacters = false;
            model.FindOptions.IgnoreWhitespaceCharacters = false;
            model.FindOptions.MatchCase = false;
            model.FindOptions.MatchPrefix = false;
            model.FindOptions.MatchSuffix = false;
            model.FindOptions.UseWildcards = true;

            Hit match;
            string testText = "this was some text";




            match = model.GetNextMatch_FOR_TESTING("th*as", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(8, match.Length);

            match = model.GetNextMatch_FOR_TESTING("th*", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(2, match.Length);

            match = model.GetNextMatch_FOR_TESTING("th*xt", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(18, match.Length);

            match = model.GetNextMatch_FOR_TESTING("t*xt", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(18, match.Length);

            match = model.GetNextMatch_FOR_TESTING("th*as", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(8, match.Length);

            match = model.GetNextMatch_FOR_TESTING("xt*a", 0, testText);
            Assert.AreEqual(-1, match.Start);
            Assert.AreEqual(0, match.Length);

            match = model.GetNextMatch_FOR_TESTING("*as", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(8, match.Length);

            match = model.GetNextMatch_FOR_TESTING("***", 0, testText);
            Assert.AreEqual(-1, match.Start);
            Assert.AreEqual(0, match.Length);

            match = model.GetNextMatch_FOR_TESTING("***was***", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(8, match.Length);



        }
Пример #14
0
        public void Match_Wildcard_Replace()
        {
            List<Run> runs = new List<Run>();
            runs.Add(new Run("1aa1 2222 1aa1"));
            runs.Add(new Run("3333 4444"));
            runs.Add(new Run("5555 6666"));
            runs.Add(new Run("7777 8888"));
            runs.Add(new Run("9999 aaaa"));
            
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.FindOptions.UseWildcards = true;
            Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer container = new Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer(runs);
            model.Query = new Query("1*1");
            model.FindText(container/*, new Query("33([0-9])3")*/);


            model.SelectNextMatch();
            Assert.AreEqual("1aa1", model.CurrentMatch.Text);
            Assert.AreEqual(runs[0], model.CurrentMatch.Run);
            model.ReplaceMatch("abcdefg");

            Assert.AreEqual("abcdefg 2222 1aa1", runs[0].Text);

            
            Assert.AreEqual(runs[0], model.CurrentMatch.Run);
            model.ReplaceMatch("abcdefg");
            Assert.AreEqual("abcdefg 2222 abcdefg", runs[0].Text);

            
        }
Пример #15
0
        public void TestHistoryQueue()
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.QueryHistoryCapacity = 5;
            Assert.AreEqual(0, model.QueryHistory.Count);


            model.AddQueryToHistory("t1");
            Assert.AreEqual(1, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[]{"t1"}));

            model.AddQueryToHistory("t2");
            Assert.AreEqual(2, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t2", "t1" }));

            model.AddQueryToHistory("t3");
            Assert.AreEqual(3, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t3", "t2", "t1" }));

            model.AddQueryToHistory("t4");
            Assert.AreEqual(4, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t4", "t3", "t2", "t1" }));

            model.AddQueryToHistory("t5");
            Assert.AreEqual(5, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t5", "t4", "t3", "t2", "t1" }));

            model.AddQueryToHistory("t6");
            Assert.AreEqual(5, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] {  "t6", "t5", "t4", "t3", "t2" }));

            model.QueryHistoryCapacity = 3;
            Assert.AreEqual(3, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t6", "t5", "t4" }));

            model.AddQueryToHistory("t7");
            Assert.AreEqual(3, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t7", "t6", "t5" }));

            model.QueryHistoryCapacity = 6;
            Assert.AreEqual(3, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t7", "t6", "t5" }));

            model.AddQueryToHistory("t8");
            Assert.AreEqual(4, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t8", "t7", "t6", "t5" }));

            model.AddQueryToHistory("t9");
            Assert.AreEqual(5, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t9", "t8", "t7", "t6", "t5" }));

            model.AddQueryToHistory("t10");
            Assert.AreEqual(6, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t10", "t9", "t8", "t7", "t6", "t5" }));

            model.AddQueryToHistory("t11");
            Assert.AreEqual(6, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] { "t11", "t10", "t9", "t8", "t7", "t6"  }));
            
            
            model.QueryHistoryCapacity = 0;
            Assert.AreEqual(0, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] {  }));

            model.AddQueryToHistory("t11");
            Assert.AreEqual(0, model.QueryHistory.Count);
            Assert.IsTrue(CheckContents(model.QueryHistory.GetEnumerator(), new string[] {  }));
           

        }
Пример #16
0
        public DependencyObject LastKeyboardFocussedControl(RapidFindReplaceControlViewModel model)
        {

            //look for most recent UIElement that got focus that we will search (mostly this is to ignore menus and buttons that might have opened the find popup)
                foreach (WeakReference reference in focussedElementBuffer)
                {
                    if (reference != null && reference.IsAlive)
                    {
                        UIElement targ = reference.Target as UIElement;
                        bool dummy=true;
                        if (model.WillSearchInElement(targ, true, ref dummy, RapidFindReplaceControl.GetIsFindable(targ)))
                        {
                            return targ as DependencyObject;
                        }
                    }
                    
                }
                return null;

            
        }
Пример #17
0
        public void Match_Blend_WholeWords_Prefix()
        {
            //should essentially match whole words only
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.FindOptions.FindWholeWordsOnly            = true;
            model.FindOptions.IgnorePunctuationCharacters   = false;
            model.FindOptions.IgnoreWhitespaceCharacters    = false;
            model.FindOptions.MatchCase                     = false;
            model.FindOptions.MatchPrefix                   = true;
            model.FindOptions.MatchSuffix                   = false;
            model.FindOptions.UseWildcards                  = false;



            Assert.AreEqual(-1, model.GetNextMatch_FOR_TESTING("xxx", 0, "this is some text").Start);
            Assert.AreEqual(13, model.GetNextMatch_FOR_TESTING("text", 0, "this is some text").Start);
            Assert.AreEqual(13, model.GetNextMatch_FOR_TESTING("Text", 0, "this is some text").Start);
            Assert.AreEqual(0, model.GetNextMatch_FOR_TESTING("this", 0, "this is some text").Start);
            Assert.AreEqual(-1, model.GetNextMatch_FOR_TESTING("thi", 0, "this is some text").Start);
            Assert.AreEqual(8, model.GetNextMatch_FOR_TESTING("thi", 0, "this is thi thi").Start);
            Assert.AreEqual(12, model.GetNextMatch_FOR_TESTING("thi", 9, "this is thi thi").Start);
            Assert.AreEqual(0, model.GetNextMatch_FOR_TESTING("this is some text", 0, "this is some text").Start);

        }
Пример #18
0
        public void Match_Wildcard_WithIgnoreWhitespace()
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.FindOptions.FindWholeWordsOnly = false;
            model.FindOptions.IgnorePunctuationCharacters = false;
            model.FindOptions.IgnoreWhitespaceCharacters = true;
            model.FindOptions.MatchCase = false;
            model.FindOptions.MatchPrefix = false;
            model.FindOptions.MatchSuffix = false;
            model.FindOptions.UseWildcards = true;
            model.FindOptions.UseRegularExpressions = false;

            Hit match;
            string testText = "this     was some text";

            match = model.GetNextMatch_FOR_TESTING("th*s was", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(12, match.Length);

            testText = "this   was some text";

            match = model.GetNextMatch_FOR_TESTING("this w*s", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(10, match.Length);
        }
Пример #19
0
        public void OptionFlipping()
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.Query = new Query("some more");
            model.FindOptions.IgnoreWhitespaceCharacters = false;
            List<Run> runs = new List<Run>();
            runs.Add(new Run("some more"));
            Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer container = new Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer(runs);

            model.FindText(container);
            model.SelectNextMatch();
            Assert.AreEqual(model.CurrentMatch.AbsoluteEnd, 9);
            Assert.AreEqual(model.CurrentMatch.AbsoluteStart, 0);



            model.FindOptions.IgnoreWhitespaceCharacters = true;
            model.FindOptions.IgnoreWhitespaceCharacters = false;

            model.Query.QueryText = "some more ";
            model.FindText(container);
            model.SelectNextMatch();


            model.Query.QueryText = "some more";
            model.FindText(container);
            model.SelectNextMatch();
            Assert.AreEqual(model.CurrentMatch.AbsoluteEnd, 9);
            Assert.AreEqual(model.CurrentMatch.AbsoluteStart, 0);

        }
Пример #20
0
        public void Match_Wildcard_WithIgnorePunctuation()//problem is ignore punct will destroy the wildacard in the query, could just not strip it in query??
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.FindOptions.FindWholeWordsOnly = false;
            model.FindOptions.IgnorePunctuationCharacters = true;
            model.FindOptions.IgnoreWhitespaceCharacters = false;
            model.FindOptions.MatchCase = false;
            model.FindOptions.MatchPrefix = false;
            model.FindOptions.MatchSuffix = false;
            model.FindOptions.UseWildcards = true;
            model.FindOptions.UseRegularExpressions = false;

            Hit match;
            string testText = "this 'was some text";

            //Because we cannot remove punct from the query when the match is wildcard or regex, we have to search without it.
            match = model.GetNextMatch_FOR_TESTING("th*s was", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(9, match.Length);

            //Because we cannot remove punct from the query when the match is wildcard or regex, we have to search without it.
            match = model.GetNextMatch_FOR_TESTING("this was", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(9, match.Length);
        }
Пример #21
0
        public void Match_Regex_WithIgnorePunctuation()//problem is ignore punct will destroy the regex in the query, could just not strip it in query??
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.FindOptions.FindWholeWordsOnly = false;
            model.FindOptions.IgnorePunctuationCharacters = true;
            model.FindOptions.IgnoreWhitespaceCharacters = false;
            model.FindOptions.MatchCase = false;
            model.FindOptions.MatchPrefix = false;
            model.FindOptions.MatchSuffix = false;
            model.FindOptions.UseWildcards = false;
            model.FindOptions.UseRegularExpressions = true;

            Hit match;
            string testText = "this 'was some text";

            match = model.GetNextMatch_FOR_TESTING("th.* was", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(9, match.Length);
        }
Пример #22
0
        public void Match_Regex()
        {
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.FindOptions.FindWholeWordsOnly = false;
            model.FindOptions.IgnorePunctuationCharacters = false;
            model.FindOptions.IgnoreWhitespaceCharacters = false;
            model.FindOptions.MatchCase = false;
            model.FindOptions.MatchPrefix = false;
            model.FindOptions.MatchSuffix = false;
            model.FindOptions.UseWildcards = false;
            model.FindOptions.UseRegularExpressions = true;

            Hit match;
            string testText = "this was some text";

            match = model.GetNextMatch_FOR_TESTING("th.*as", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(8, match.Length);

            match = model.GetNextMatch_FOR_TESTING("th.*", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(18, match.Length);

            match = model.GetNextMatch_FOR_TESTING("th.*xt", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(18, match.Length);

            match = model.GetNextMatch_FOR_TESTING("t.*xt", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(18, match.Length);

            match = model.GetNextMatch_FOR_TESTING("th.*as", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(8, match.Length);

            match = model.GetNextMatch_FOR_TESTING("xt.*a", 0, testText);
            Assert.AreEqual(-1, match.Start);
            Assert.AreEqual(0, match.Length);

            match = model.GetNextMatch_FOR_TESTING(".*as", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(8, match.Length);

            match = model.GetNextMatch_FOR_TESTING(".*.*.*", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(18, match.Length);

            
            
            testText = "this was some text\r\nxxxx yyy";


            //Go with VS behaviour, which is !SingleLine mode (ie . cannot eat \n)
            match = model.GetNextMatch_FOR_TESTING("text.*yyy", 0, testText);
            Assert.AreEqual(-1, match.Start);
            Assert.AreEqual(0, match.Length);


            testText = "This was SOME text\r\nxxxx yyy";

            model.FindOptions.MatchCase = true;
            match = model.GetNextMatch_FOR_TESTING("th[a-z]s", 0, testText);
            Assert.AreEqual(-1, match.Start);
            Assert.AreEqual(0, match.Length);

            model.FindOptions.MatchCase = true;
            match = model.GetNextMatch_FOR_TESTING("Th[a-z]s", 0, testText);
            Assert.AreEqual(0, match.Start);
            Assert.AreEqual(4, match.Length);

            model.FindOptions.MatchCase = true;
            match = model.GetNextMatch_FOR_TESTING("S.*E", 0, testText);
            Assert.AreEqual(9, match.Start);
            Assert.AreEqual(4, match.Length);

            



        }
Пример #23
0
        public void Match_Standard_Replace()
        {

            List<Run> runs = GetTestRuns();
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer container = new Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer(runs);
            model.Query = new Query("1111");
            model.FindText(container/*, new Query("33([0-9])3")*/);


            model.SelectNextMatch();
            Assert.AreEqual(runs[0], model.CurrentMatch.Run);
            model.ReplaceMatch("1");

            Assert.AreEqual("1 2222 1111", runs[0].Text);

            model.ReplaceMatch("1");

            Assert.AreEqual("1 2222 1", runs[0].Text);

            //also need to fix single line tb when highlight goes outside of box width
        }
Пример #24
0
        public void Match_Wildcard_Replace2()
        {
            List<Run> runs = new List<Run>();
            runs.Add(new Run("TextBox search word"));
            runs.Add(new Run("TextBox"));
            runs.Add(new Run("TextBox"));
            runs.Add(new Run("Hello"));
            runs.Add(new Run("here is some more"));
            runs.Add(new Run("and some more"));

            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.FindOptions.UseWildcards = true;
            Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer container = new Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer(runs);
            model.Query = new Query("r*");
            model.FindText(container);


            model.SelectNextMatch();
            Assert.AreEqual("r", model.CurrentMatch.Text);
            Assert.AreEqual(runs[0], model.CurrentMatch.Run);
            //model.ReplaceMatch("   ");
            model.ReplaceAllMatches("   ");

            Assert.AreEqual("TextBox sea   ch wo   d", runs[0].Text);


           


        }
Пример #25
0
        public void Match_ReplaceAll()
        {
            List<Run> runs = new List<Run>();
            runs.Add(new Run("aa aa aa"));

            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer container = new Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer(runs);
            container.IterationStartIndex = 3;// runs[0].Text.Length - 1;
            model.Query = new Query("aa");
            model.FindText(container/*, new Query("33([0-9])3")*/);

            model.ReplaceAllMatches("bb");


            Assert.AreEqual("bb bb bb", runs[0].Text);
        }
Пример #26
0
        public void TestScanRunQueueMultipleTimes3()
        {
            //harder one
            int callInc = 0;
            RunQueue rq2 = new RunQueue(5);
            FillRunQueue(rq2, GetTestRuns2());
            
            rq2.Enqueue(new Run("3 3"));
            rq2.Enqueue(new Run("232"));
            RunQueue rq2_clone = rq2.Clone();
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.ScanQueuedRuns(rq2, "3",
                delegate(Run run, int index, int length)
                {
                    Assert.IsTrue(callInc< 4);
                    if (callInc == 0)
                    {

                        Assert.AreEqual(rq2_clone[1].Run, run);
                        Assert.AreEqual(0, index);
                        Assert.AreEqual(1, length);
                    }
                    else if (callInc == 1)
                    {

                        Assert.AreEqual(rq2_clone[3].Run, run);
                        Assert.AreEqual(0, index);
                        Assert.AreEqual(1, length);
                    }
                    else if (callInc == 2)
                    {

                        Assert.AreEqual(rq2_clone[3].Run, run);
                        Assert.AreEqual(2, index);
                        Assert.AreEqual(1, length);
                    }
                    else if (callInc == 3)
                    {

                        Assert.AreEqual(rq2_clone[4].Run, run);
                        Assert.AreEqual(1, index);
                        Assert.AreEqual(1, length);
                    }
                    callInc++;

                }
            );
            

        }
Пример #27
0
        public void ReplaceAsFindWithPrependSpace()
        {
            RapidFindReplaceControlViewModel finder = new RapidFindReplaceControlViewModel();
            

            System.Collections.Generic.List<Run> runs = new System.Collections.Generic.List<Run>(5);
            //FindRuns(content.Blocks, runs);
            runs.Add(new Run("ax  ax"));
            runs.Add(new Run("T"));

            RunCollectionContainer coll = new RunCollectionContainer(runs);


            finder.Query = new Query("ax");
            finder.FindText(coll);

          

            finder.ReplaceAllMatchesCommand.Execute(" ax");
           
        }
Пример #28
0
        public void TestCrossRunMatch2()
        {
            RunQueue queue = new RunQueue(2);
            Run r1 = new Run("1234co"), r2 = new Run("co5678");
            int callInc = 0;
            queue.Enqueue(r1);
            queue.Enqueue(r2);
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.ScanQueuedRuns(queue, "coco",
                delegate(Run run, int index, int length)
                {
                    Assert.IsTrue(callInc < 2);
                    if (callInc == 0)
                    {

                        Assert.AreEqual(r1, run);
                        Assert.AreEqual(4, index);
                        Assert.AreEqual(2, length);
                    }
                    else if (callInc == 1)
                    {
                        Assert.AreEqual(r2, run);
                        Assert.AreEqual(0, index);
                        Assert.AreEqual(2, length);
                    }
                    callInc++;
                }
             );
            Assert.AreEqual(2, callInc);
        }
        /// <summary>
        /// New.
        /// </summary>
        public RapidFindReplaceControl()
        {
            

            queryContainer = new Query("");
           // this.Resources.MergedDictionaries.Add(SharedDictionaryManager.SharedDictionary);
            //AsYouTypeFindMinimumCharacters = 2;
            //AsYouTypeFindEnabled = true;


            ViewModel = new RapidFindReplaceControlViewModel();//must use setter as it does a binding


        }
Пример #30
0
        public void TestScanRunQueue()
        {
            RunQueue rq = new RunQueue(5) ;
            
            FillRunQueue(rq, GetTestRuns());

            RunQueue rq_clone = rq.Clone();
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            //easy one
            model.ScanQueuedRuns(rq, new Keyoti.RapidFindReplace.WPF.Query("1111"), 
                delegate(Run run, int index, int length){
                    Assert.AreEqual(rq_clone[0].Run, run);
                    Assert.AreEqual(0, index);
                    Assert.AreEqual(4, length);
                }
            );

            //easy one
            model.ScanQueuedRuns(rq, "4444",
                delegate(Run run, int index, int length)
                {
                    Assert.AreEqual(rq_clone[1].Run, run);
                    Assert.AreEqual(5, index);
                    Assert.AreEqual(4, length);
                }
            );

            //harder one
            int callInc = 0;
            model.ScanQueuedRuns(rq, "44445555",
                delegate(Run run, int index, int length)
                {
                    if (callInc == 0)
                    {
                        Assert.AreEqual(rq_clone[1].Run, run);
                        Assert.AreEqual(5, index);
                        Assert.AreEqual(4, length);
                    }
                    else if (callInc == 1)
                    {
                        Assert.AreEqual(rq_clone[2].Run, run);
                        Assert.AreEqual(0, index);
                        Assert.AreEqual(4, length);
                    }
                    callInc++;
                }
            );

            //harder one
            callInc = 0;
            RunQueue rq2 = new RunQueue(5);
            
            FillRunQueue(rq2, GetTestRuns2());
            RunQueue rq2_clone = rq2.Clone();
            model.ScanQueuedRuns(rq2, "22223",
                delegate(Run run, int index, int length)
                {
                    if (callInc == 0)
                    {
                        Assert.AreEqual(rq2_clone[0].Run, run);
                        Assert.AreEqual(2, index);
                        Assert.AreEqual(4, length);
                    }
                    else if (callInc == 1)
                    {
                        Assert.AreEqual(rq2_clone[1].Run, run);
                        Assert.AreEqual(0, index);
                        Assert.AreEqual(1, length);
                    }

                    Assert.IsTrue(callInc < 2);
                    callInc++;
                }
            );
        
        }
Пример #31
0
        public void TestScanRunQueueMultipleTimes2()
        {
            //harder one
            int callInc = 0;
            RunQueue rq2 = new RunQueue(5);
            FillRunQueue(rq2, GetTestRuns2());
            RunQueue rq2_clone = rq2.Clone();
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.ScanQueuedRuns(rq2, "3",
                delegate(Run run, int index, int length)
                {
                    Assert.IsTrue(callInc < 1);
                    if (callInc == 0)
                    {
                        Assert.AreEqual(rq2_clone[1].Run, run);
                        Assert.AreEqual(0, index);
                        Assert.AreEqual(1, length);
                    }
                    callInc++;

                }
            );
            //add new item and search again, this time we don't want to hit 3 again
            rq2.Enqueue(new Run("3"));
            model.ScanQueuedRuns(rq2, "3",
                delegate(Run run, int index, int length)
                {

                    Assert.AreEqual("3", run.Text);

                }
            );

        }
Пример #32
0
        public void Match_Regex_Replace()
        {

            List<Run> runs = GetTestRuns();
            RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel();
            model.FindOptions.UseRegularExpressions = true;
            Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer container = new Keyoti.RapidFindReplace.WPF.FindHandlers.RunCollectionContainer(runs);
            model.Query = new Query("33([0-9])3");
            model.FindText(container/*, new Query("33([0-9])3")*/);


            model.SelectNextMatch();
            Assert.AreEqual(runs[1], model.CurrentMatch.Run);
            model.ReplaceMatch("xx$1");

            Assert.AreEqual("xx3 4444", runs[1].Text);
        
            //also need to fix single line tb when highlight goes outside of box width
        }