private static void ProcessHits(int numberOfHits, RapidFindReplaceControl box, bool fromFindButton)
 {
     if (box.Query != null && (box.Query.Length >= box.AsYouTypeFindMinimumCharacters || fromFindButton))
     {
         if (box.FindOptions.FindAsYouType)   //-------------Find as you type
         {
             box.hitState = numberOfHits > 0 ? HitStates.Hits : HitStates.NoHits;
         }
         else if (numberOfHits > 0)            //-------------No find as you type, but hits anyway
         {
             box.hitState = HitStates.Hits;
         }
         else if (fromFindButton)            //-------------No find as you type, but button and no hits
         {
             box.hitState = HitStates.NoHits;
         }
         else                                //-------------No find as you type and not from button
         {
             box.hitState = HitStates.NoFind;
         }
     }
     else
     {
         box.hitState = HitStates.NoFind;
     }
     VisualStateManager.GoToState(box, box.hitState.ToString(), true);
 }
        static void NumberOfHitsChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            RapidFindReplaceControl box = (sender as RapidFindReplaceControl);

            ProcessHits((int)e.NewValue, box, false);

            /* if (
             *   (((int)e.OldValue) == 0 && ((int)e.NewValue) > 0) ||
             *   (((int)e.OldValue) > 0 && ((int)e.NewValue) == 0)
             *   )
             *   box.RaisePropertyChanged("AreHits");
             */
        }
Пример #3
0
        //called recursively, searchIn doesn't have to be a UIElement because we will look at it's children for any child UIElemenets
        /// <summary>
        /// Recursively searches <c>searchIn</c> for the Query.
        /// </summary>
        /// <param name="searchIn">DependencyObject to search inside.</param>
        /// <param name="parentUIElementIsFindable">Whether the parent UI element has been determined as 'findable'.  If the parent is findable then <c>searchIn</c> is finable too unless explicitly marked otherwise with IsFindable="false".</param>
        /// <returns>Whether searchIn or any of it's children where marked as either 'findable' or not (IsFindable="true" or IsFindable="false").</returns>
        protected bool FindText(DependencyObject searchIn, bool parentUIElementIsFindable)
        {
            bool foundIsFindableAttribute = false;//whether this element searchIn or its children were marked with isfindable

            bool searchChildren = parentUIElementIsFindable;

            if (searchIn == null)
            {
                return(foundIsFindableAttribute);
            }
            currentGlobalScanHighlightCount = 0;
            bool?isFindable = searchIn is UIElement?RapidFindReplaceControl.GetIsFindable(searchIn as UIElement) : true;

            if (searchIn is UIElement)
            {
                foundIsFindableAttribute = RapidFindReplaceControl.GetIsFindable(searchIn as UIElement) != null;
            }


            IRunReader runReader = null;

            if (searchIn is UIElement && WillSearchInElement(searchIn as UIElement, parentUIElementIsFindable, ref searchChildren, isFindable))//GetIsFindable is bool? - if null then just not set so use parentUIElementIsFindable
            {
                searchChildren = true;
                runReader      = FindHandlerRegistry.CreateIRunReaderHandlerFor(searchIn);
            }
            else if (!(searchIn is UIElement))
            {
                runReader = FindHandlerRegistry.CreateIRunReaderHandlerFor(searchIn);//we might be able to get a runreader for non UIElement (eg RunCollectionRunReader)
            }
            if (runReader != null)
            {
                HighlightHandler handler = highlightHandlers.GetCreateHighlightHandler(searchIn, bodyHighlightAdornerBrush, bodyHighlightAdornerPen, bodyIterativeHighlightAdornerBrush, bodyIterativeHighlightAdornerPen);
                FindTextIn(runReader, handler.AddHighlight, Query);
            }


            //recurse through children
            if (searchIn is Visual || searchIn is System.Windows.Media.Media3D.Visual3D)
            {
                var childCount = VisualTreeHelper.GetChildrenCount(searchIn);

                for (var i = 0; i < childCount; ++i)
                {
                    foundIsFindableAttribute |= FindText(VisualTreeHelper.GetChild(searchIn, i), searchChildren && isFindable != false);
                }
            }
            return(foundIsFindableAttribute);
        }
 void BindTwoWayToFindBox(DependencyProperty myProperty, RapidFindReplaceControl findBox, DependencyProperty findBoxProperty)
 {
     //if (FindScope != null && FindScope != DependencyProperty.UnsetValue)
     if (GetValue(myProperty) != null && GetValue(myProperty) != DependencyProperty.UnsetValue)
     {
         findBox.SetValue(findBoxProperty, GetValue(myProperty));
         //PART_RapidFindReplaceControl.FindScope = FindScope;
     }
     else
     {
         SetValue(myProperty, findBox.GetValue(findBoxProperty));
         //FindScope = PART_RapidFindReplaceControl.FindScope;
     }
     BindingOperations.SetBinding(this, myProperty, new Binding {
         Source = findBox, Path = new PropertyPath(findBoxProperty.Name), Mode = BindingMode.TwoWay
     });
 }
Пример #5
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);
 }
        private static void QueryChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            RapidFindReplaceControl box = (sender as RapidFindReplaceControl);

            if (box.Query.Length == 0)
            {
                VisualStateManager.GoToState(box, "NoQuery", true);
            }
            else
            {
                VisualStateManager.GoToState(box, "Query", true);
                if (!box.findOptions.FindAsYouType)
                {
                    box.hitState = HitStates.NoFind;
                    VisualStateManager.GoToState(box, "NoFind", true);
                }
            }



            box.QueryContainer.QueryText = (string)e.NewValue;
            if (box.FindOptions.FindAsYouType)//box.AsYouTypeFindEnabled)
            {
                if (box.Query.Length >= box.AsYouTypeFindMinimumCharacters)
                {
//                    box.QueryContainer.QueryText = (string)e.NewValue;
                    box.ViewModel.FindText(box.FindScope /*, box.queryContainer*/);
                    ProcessHits(box.NumberOfHits, box, false);
                    //box.ViewModel.FindTextCommand.Execute(null);
                }
                else
                {
                    box.ViewModel.ResetHighlights();

                    ProcessHits(0, box, false);
                    //box.ProcessResults(0);
                    //box.hitState = HitStates.NoFind;
                    //VisualStateManager.GoToState(box, box.hitState.ToString(), true);
                }
            }
        }
        private static void ProcessHits(int numberOfHits, RapidFindReplaceControl box, bool fromFindButton)
        {
            if (box.Query != null && (box.Query.Length >= box.AsYouTypeFindMinimumCharacters || fromFindButton))
            {
                if(box.FindOptions.FindAsYouType)   //-------------Find as you type
                    box.hitState = numberOfHits > 0 ? HitStates.Hits : HitStates.NoHits;
                else if (numberOfHits>0)            //-------------No find as you type, but hits anyway
                    box.hitState = HitStates.Hits;
                else if (fromFindButton)            //-------------No find as you type, but button and no hits
                    box.hitState = HitStates.NoHits;
                else                                //-------------No find as you type and not from button
                    box.hitState = HitStates.NoFind;

            }
            else box.hitState = HitStates.NoFind;
            VisualStateManager.GoToState(box, box.hitState.ToString(), true);
        }
 void BindTwoWayToFindBox(DependencyProperty myProperty, RapidFindReplaceControl findBox, DependencyProperty findBoxProperty){
     //if (FindScope != null && FindScope != DependencyProperty.UnsetValue)
     if(GetValue(myProperty)!=null && GetValue(myProperty)!=DependencyProperty.UnsetValue){
         findBox.SetValue(findBoxProperty, GetValue(myProperty));
         //PART_RapidFindReplaceControl.FindScope = FindScope;
     }else{
         SetValue(myProperty, findBox.GetValue(findBoxProperty));
         //FindScope = PART_RapidFindReplaceControl.FindScope;
     }
     BindingOperations.SetBinding(this, myProperty, new Binding { Source = findBox, Path = new PropertyPath(findBoxProperty.Name), Mode = BindingMode.TwoWay });
 
 }