Ejemplo n.º 1
0
        ///////////////////////////////////////////////////////////////////////

        public TclBuild(
            FindFlags findFlags,
            LoadFlags loadFlags,
            object findData,
            string fileName,
            Priority priority,
            Sequence sequence,
            OperatingSystemId operatingSystemId,
            Version patchLevel,
            Tcl_ReleaseLevel releaseLevel,
            ushort magic,
            bool threaded,
            bool debug
            )
        {
            this.findFlags         = findFlags;
            this.loadFlags         = loadFlags;
            this.findData          = findData;
            this.fileName          = fileName;
            this.priority          = priority;
            this.sequence          = sequence;
            this.operatingSystemId = operatingSystemId;
            this.patchLevel        = patchLevel;
            this.releaseLevel      = releaseLevel;
            this.magic             = magic;
            this.threaded          = threaded;
            this.debug             = debug;

            //
            // NOTE: The version may only contain the major and minor parts.
            //
            this.version = GlobalState.GetTwoPartVersion(patchLevel);
        }
Ejemplo n.º 2
0
        private void searchMenuItem_Click(object sender, RoutedEventArgs e)
        {
            FindFlags flag = (FindFlags)FindFlags.Parse(FindFlags.GetType(), (sender as MenuItem).Tag.ToString());

            FindFlags ^= flag;
            OnSearch();
        }
 public void FindAgain(bool reverse)
 {
     // The find dialog might have been disposed, so we can only find using previous
     // find state information.
     if (string.IsNullOrEmpty(lastExpression))
     {
         return;
     }
     try {
         if (reverse)
         {
             lastFlags |= FindFlags.Backwards;
         }
         else
         {
             lastFlags &= ~FindFlags.Backwards;
         }
         FindResult rc = target.FindNext(lastExpression, lastFlags, filter);
         if (rc == FindResult.Found && !this.IsDisposed)
         {
             this.MoveFindDialog(target.MatchRect);
         }
         if (rc == FindResult.None)
         {
             OnNotFound();
         }
         else if (rc == FindResult.NoMore)
         {
             OnFindDone();
         }
     } catch (Exception ex) {
         OnError(ex, SR.FindErrorCaption);
     }
 }
Ejemplo n.º 4
0
        bool FindNext(bool quiet, bool didReplace = false)
        {
            FindFlags flags = FindFlags.Normal;

            if (this.checkBoxRegex.Checked)
            {
                flags |= FindFlags.Regex;
            }
            else if (this.checkBoxXPath.Checked)
            {
                flags |= FindFlags.XPath;
            }
            if (this.checkBoxMatchCase.Checked)
            {
                flags |= FindFlags.MatchCase;
            }
            if (this.checkBoxWholeWord.Checked)
            {
                flags |= FindFlags.WholeWord;
            }
            if (this.radioButtonUp.Checked)
            {
                flags |= FindFlags.Backwards;
            }

            string expr = this.Expression;

            if (expr.Contains(" ") && this.checkBoxWholeWord.Checked)
            {
                throw new Exception(SR.FindWholeWordOnlyFindsWords);
            }
            this._recentFindStrings.AddItem(expr);

            _lastFlags      = flags;
            _lastExpression = expr;

            FindResult rc = _target.FindNext(expr, flags, _filter);

            if (rc == FindResult.Found && !this.IsDisposed)
            {
                this.MoveFindDialog(_target.MatchRect);
            }
            if (!quiet)
            {
                if (didReplace && rc == FindResult.None)
                {
                    rc = FindResult.NoMore;
                }
                if (rc == FindResult.None)
                {
                    OnNotFound();
                }
                else if (rc == FindResult.NoMore)
                {
                    OnFindDone(didReplace);
                }
            }
            return(rc == FindResult.Found);
        }
Ejemplo n.º 5
0
        bool FindNext(bool quiet)
        {
            FindFlags flags = FindFlags.Normal;

            if (this.checkBoxRegex.Checked)
            {
                flags |= FindFlags.Regex;
            }
            else if (this.checkBoxXPath.Checked)
            {
                flags |= FindFlags.XPath;
            }
            if (this.checkBoxMatchCase.Checked)
            {
                flags |= FindFlags.MatchCase;
            }
            if (this.checkBoxWholeWord.Checked)
            {
                flags |= FindFlags.WholeWord;
            }
            if (this.radioButtonUp.Checked)
            {
                flags |= FindFlags.Backwards;
            }

            string expr = this.Expression;

            if (!this.comboBoxFind.Items.Contains(expr))
            {
                this.comboBoxFind.Items.Add(expr);
                if (this.comboBoxFind.Items.Count > MaxRecentlyUsed)
                {
                    this.comboBoxFind.Items.RemoveAt(0);
                }
            }

            _lastFlags      = flags;
            _lastExpression = expr;

            FindResult rc = _target.FindNext(expr, flags, _filter);

            if (rc == FindResult.Found && !this.IsDisposed)
            {
                this.MoveFindDialog(_target.MatchRect);
            }
            if (!quiet)
            {
                if (rc == FindResult.None)
                {
                    OnNotFound();
                }
                else if (rc == FindResult.NoMore)
                {
                    OnFindDone();
                }
            }
            return(rc == FindResult.Found);
        }
Ejemplo n.º 6
0
 public static extern SafeFindHandle FindFirstFileEx(
     [MarshalAs(UnmanagedType.LPTStr)]
     string fileName,
     [In] FindInfoLevel fInfoLevelId,
     [In, Out] FindData lpFindFileData,
     [In] FindSearchOps fSearchOp,
     IntPtr lpSearchFilter,
     [In] FindFlags dwAdditionalFlags
     );
Ejemplo n.º 7
0
 public Transaction2FindNext2Request(byte[] parameters, byte[] data, bool isUnicode) : base()
 {
     SID              = LittleEndianConverter.ToUInt16(parameters, 0);
     SearchCount      = LittleEndianConverter.ToUInt16(parameters, 2);
     InformationLevel = (FindInformationLevel)LittleEndianConverter.ToUInt16(parameters, 4);
     ResumeKey        = LittleEndianConverter.ToUInt32(parameters, 6);
     Flags            = (FindFlags)LittleEndianConverter.ToUInt16(parameters, 10);
     FileName         = SMBHelper.ReadSMBString(parameters, 12, isUnicode);
 }
Ejemplo n.º 8
0
 private void StartSearch(FindFlags searchFlags, string searchText)
 {
     StopSearch();
     if (searchText == "")
     {
         return;
     }
     _search.Start(searchText, searchFlags);
     _foundTextTimer.Start();
 }
 void CheckCurrentState(string expression, FindFlags flags, SearchFilter filter)
 {
     if (this.expression != expression || this.flags != flags || this.filter != filter)
     {
         this.expression = expression;
         this.flags      = flags;
         this.filter     = filter;
         this.list       = null;
         this.match      = null;
     }
 }
Ejemplo n.º 10
0
 private void StartSearch(FindFlags searchFlags, string searchText)
 {
     StopSearch();
     if (searchText == "")
     {
         return;
     }
     _prevRecord      = -1;
     _searchText      = searchText;
     _searchFlags     = searchFlags;
     _searchPageIndex = 0;
     _searchTimer.Start();
 }
Ejemplo n.º 11
0
        public Transaction2FindFirst2Request(byte[] parameters, byte[] data, bool isUnicode) : base()
        {
            SearchAttributes  = (FileAttributes)LittleEndianConverter.ToUInt16(parameters, 0);
            SearchCount       = LittleEndianConverter.ToUInt16(parameters, 2);
            Flags             = (FindFlags)LittleEndianConverter.ToUInt16(parameters, 4);
            InformationLevel  = (FindInformationLevel)LittleEndianConverter.ToUInt16(parameters, 6);
            SearchStorageType = (SearchStorageType)LittleEndianConverter.ToUInt32(parameters, 8);
            FileName          = SMBHelper.ReadSMBString(parameters, 12, isUnicode);

            if (InformationLevel == FindInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST)
            {
                GetExtendedAttributeList = new FullExtendedAttributeList(data, 0);
            }
        }
Ejemplo n.º 12
0
        public Transaction2FindNext2Request(byte[] parameters, byte[] data, bool isUnicode) : base()
        {
            SID              = LittleEndianConverter.ToUInt16(parameters, 0);
            SearchCount      = LittleEndianConverter.ToUInt16(parameters, 2);
            InformationLevel = (FindInformationLevel)LittleEndianConverter.ToUInt16(parameters, 4);
            ResumeKey        = LittleEndianConverter.ToUInt32(parameters, 6);
            Flags            = (FindFlags)LittleEndianConverter.ToUInt16(parameters, 10);
            FileName         = SMB1Helper.ReadSMBString(parameters, 12, isUnicode);

            if (InformationLevel == FindInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST)
            {
                GetExtendedAttributeList = new ExtendedAttributeNameList(data, 0);
            }
        }
Ejemplo n.º 13
0
        ///////////////////////////////////////////////////////////////////////

#if NATIVE && TCL
        public static bool HasFlags(
            FindFlags flags,
            FindFlags hasFlags,
            bool all
            )
        {
            if (all)
            {
                return((flags & hasFlags) == hasFlags);
            }
            else
            {
                return((flags & hasFlags) != FindFlags.None);
            }
        }
Ejemplo n.º 14
0
        ///////////////////////////////////////////////////////////////////////

        public bool MaybeAddOrReplace(
            FindFlags flags, /* in */
            string key,      /* in */
            TclBuild value,  /* in */
            ref Result error /* out */
            )
        {
            if (key == null)
            {
                error = String.Format(
                    "can't add Tcl build file {0}: invalid key",
                    FormatOps.TclBuildFileName(value));

                return(false);
            }

            if (FlagOps.HasFlags(flags, FindFlags.TrustedOnly, true) &&
                ((value == null) ||
                 !RuntimeOps.IsFileTrusted(value.FileName, IntPtr.Zero)))
            {
                error = String.Format(
                    "can't add Tcl build file {0}: not trusted",
                    FormatOps.TclBuildFileName(value));

                return(false);
            }

            if (!this.ContainsKey(key))
            {
                this.Add(key, value);
                return(true);
            }

            if (FlagOps.HasFlags(
                    flags, FindFlags.OverwriteBuilds, true))
            {
                this[key] = value;
                return(true);
            }

            error = String.Format(
                "can't add Tcl build file {0}: already present",
                FormatOps.TclBuildFileName(value));

            return(false);
        }
Ejemplo n.º 15
0
        public Transaction2FindNext2Request(byte[] parameters, byte[] data, bool isUnicode) : base()
        {
            SID              = LittleEndianConverter.ToUInt16(parameters, 0);
            SearchCount      = LittleEndianConverter.ToUInt16(parameters, 2);
            InformationLevel = (FindInformationLevel)LittleEndianConverter.ToUInt16(parameters, 4);
            ResumeKey        = LittleEndianConverter.ToUInt32(parameters, 6);
            Flags            = (FindFlags)LittleEndianConverter.ToUInt16(parameters, 10);

            if (isUnicode && parameters.Length == 13 && parameters[12] == 0x00)
            {
                // Workaround for PlayStation2 Slim
                FileName = String.Empty;
            }
            else
            {
                FileName = SMB1Helper.ReadSMBString(parameters, 12, isUnicode);
            }


            if (InformationLevel == FindInformationLevel.SMB_INFO_QUERY_EAS_FROM_LIST)
            {
                GetExtendedAttributeList = new ExtendedAttributeNameList(data, 0);
            }
        }
Ejemplo n.º 16
0
        //---------------------------------------------------------------------
        // 
        // Public methods
        //
        //---------------------------------------------------------------------
 
        #region Public methods
 
        /// <summary> 
        /// Performs find operation on of a given text range.
        /// </summary> 
        /// <param name="findContainerStartPosition">Text position to start search.</param>
        /// <param name="findContainerEndPosition">Text position to end search.</param>
        /// <param name="findPattern">Pattern to find.</param>
        /// <param name="flags">Find flags.</param> 
        /// <param name="cultureInfo">Culture specific information.</param>
        /// <returns>TextRange for the result or <c>null</c></returns> 
        /// <remarks> 
        /// Very limited functionality for now
        /// </remarks> 
        public static ITextRange Find(
            ITextPointer findContainerStartPosition,
            ITextPointer findContainerEndPosition,
            string findPattern, 
            FindFlags flags,
            CultureInfo cultureInfo) 
        { 
            //
            if (findContainerStartPosition == null 
                || findContainerEndPosition == null
                || findContainerStartPosition.CompareTo(findContainerEndPosition) == 0
                || findPattern == null
                || findPattern == string.Empty ) 
            {
                return (null); 
            } 

            TextRange findResult = null; 
            bool matchCase = (flags & FindFlags.MatchCase) != 0;
            bool matchWholeWord = (flags & FindFlags.FindWholeWordsOnly) != 0;
            bool matchLast = (flags & FindFlags.FindInReverse) != 0;
            bool matchDiacritics = (flags & FindFlags.MatchDiacritics) != 0; 
            bool matchKashida = (flags & FindFlags.MatchKashida) != 0;
            bool matchAlefHamza = (flags & FindFlags.MatchAlefHamza) != 0; 
 
            if (matchWholeWord)
            { 
                UInt16[] findPatternStartCharType1 = new UInt16[1];
                UInt16[] findPatternEndCharType1 = new UInt16[1];
                char[] charFindPattern = findPattern.ToCharArray();
 
                // Get the character type for the start/end character of the find pattern.
                SafeNativeMethods.GetStringTypeEx(0 /* ignored */, SafeNativeMethods.CT_CTYPE1, new char[] { charFindPattern[0] }, 1, findPatternStartCharType1); 
                SafeNativeMethods.GetStringTypeEx(0 /* ignored */, SafeNativeMethods.CT_CTYPE1, new char[] { charFindPattern[findPattern.Length - 1] }, 1, findPatternEndCharType1); 

                // Reset the finding whole word flag if FindPattern includes the space 
                // or blank character at the start or end position.
                if ((findPatternStartCharType1[0] & SafeNativeMethods.C1_SPACE) != 0 ||
                    (findPatternStartCharType1[0] & SafeNativeMethods.C1_BLANK) != 0 ||
                    (findPatternEndCharType1[0] & SafeNativeMethods.C1_SPACE) != 0 || 
                    (findPatternEndCharType1[0] & SafeNativeMethods.C1_BLANK) != 0)
                { 
                    matchWholeWord = false; 
                }
            } 

            //If this we're searching on a Fixed layout, we need to do a faster search that takes into accout
            //page-per-stream scenarios
            if (findContainerStartPosition is DocumentSequenceTextPointer || 
                findContainerStartPosition is FixedTextPointer)
            { 
                return FixedFindEngine.Find(findContainerStartPosition, 
                                            findContainerEndPosition,
                                            findPattern, 
                                            cultureInfo,
                                            matchCase,
                                            matchWholeWord,
                                            matchLast, 
                                            matchDiacritics,
                                            matchKashida, 
                                            matchAlefHamza); 

            } 

            // Find the text with the specified option flags.
            findResult = InternalFind(
                findContainerStartPosition, 
                findContainerEndPosition,
                findPattern, 
                cultureInfo, 
                matchCase,
                matchWholeWord, 
                matchLast,
                matchDiacritics,
                matchKashida,
                matchAlefHamza); 

            return (findResult); 
        } 
Ejemplo n.º 17
0
        //---------------------------------------------------------------------
        //
        // Public methods
        //
        //---------------------------------------------------------------------

        #region Public methods

        /// <summary>
        /// Performs find operation on of a given text range.
        /// </summary>
        /// <param name="findContainerStartPosition">Text position to start search.</param>
        /// <param name="findContainerEndPosition">Text position to end search.</param>
        /// <param name="findPattern">Pattern to find.</param>
        /// <param name="flags">Find flags.</param>
        /// <param name="cultureInfo">Culture specific information.</param>
        /// <returns>TextRange for the result or <c>null</c></returns>
        /// <remarks>
        /// Very limited functionality for now
        /// </remarks>
        public static ITextRange Find(
            ITextPointer findContainerStartPosition,
            ITextPointer findContainerEndPosition,
            string findPattern,
            FindFlags flags,
            CultureInfo cultureInfo)
        {
            //  throw exceptions here
            if (findContainerStartPosition == null ||
                findContainerEndPosition == null ||
                findContainerStartPosition.CompareTo(findContainerEndPosition) == 0 ||
                findPattern == null ||
                findPattern == string.Empty)
            {
                return(null);
            }

            TextRange findResult      = null;
            bool      matchCase       = (flags & FindFlags.MatchCase) != 0;
            bool      matchWholeWord  = (flags & FindFlags.FindWholeWordsOnly) != 0;
            bool      matchLast       = (flags & FindFlags.FindInReverse) != 0;
            bool      matchDiacritics = (flags & FindFlags.MatchDiacritics) != 0;
            bool      matchKashida    = (flags & FindFlags.MatchKashida) != 0;
            bool      matchAlefHamza  = (flags & FindFlags.MatchAlefHamza) != 0;

            if (matchWholeWord)
            {
                UInt16[] findPatternStartCharType1 = new UInt16[1];
                UInt16[] findPatternEndCharType1   = new UInt16[1];
                char[]   charFindPattern           = findPattern.ToCharArray();

                // Get the character type for the start/end character of the find pattern.
                SafeNativeMethods.GetStringTypeEx(0 /* ignored */, SafeNativeMethods.CT_CTYPE1, new char[] { charFindPattern[0] }, 1, findPatternStartCharType1);
                SafeNativeMethods.GetStringTypeEx(0 /* ignored */, SafeNativeMethods.CT_CTYPE1, new char[] { charFindPattern[findPattern.Length - 1] }, 1, findPatternEndCharType1);

                // Reset the finding whole word flag if FindPattern includes the space
                // or blank character at the start or end position.
                if ((findPatternStartCharType1[0] & SafeNativeMethods.C1_SPACE) != 0 ||
                    (findPatternStartCharType1[0] & SafeNativeMethods.C1_BLANK) != 0 ||
                    (findPatternEndCharType1[0] & SafeNativeMethods.C1_SPACE) != 0 ||
                    (findPatternEndCharType1[0] & SafeNativeMethods.C1_BLANK) != 0)
                {
                    matchWholeWord = false;
                }
            }

            //If this we're searching on a Fixed layout, we need to do a faster search that takes into accout
            //page-per-stream scenarios
            if (findContainerStartPosition is DocumentSequenceTextPointer ||
                findContainerStartPosition is FixedTextPointer)
            {
                return(FixedFindEngine.Find(findContainerStartPosition,
                                            findContainerEndPosition,
                                            findPattern,
                                            cultureInfo,
                                            matchCase,
                                            matchWholeWord,
                                            matchLast,
                                            matchDiacritics,
                                            matchKashida,
                                            matchAlefHamza));
            }

            // Find the text with the specified option flags.
            findResult = InternalFind(
                findContainerStartPosition,
                findContainerEndPosition,
                findPattern,
                cultureInfo,
                matchCase,
                matchWholeWord,
                matchLast,
                matchDiacritics,
                matchKashida,
                matchAlefHamza);

            return(findResult);
        }
Ejemplo n.º 18
0
        public static TextRange FindText(TextPointer findContainerStartPosition, TextPointer findContainerEndPosition, String input, FindFlags flags, CultureInfo cultureInfo)
        {
            TextRange textRange = null;

            if (findContainerStartPosition.CompareTo(findContainerEndPosition) < 0)
            {
                try
                {
                    if (findMethod == null)
                    {
                        findMethod = typeof(FrameworkElement).Assembly.GetType("System.Windows.Documents.TextFindEngine").
                                     GetMethod("Find", BindingFlags.Static | BindingFlags.Public);
                    }
                    Object result = findMethod.Invoke(null, new Object[] { findContainerStartPosition,
                                                                           findContainerEndPosition,
                                                                           input, flags, CultureInfo.CurrentCulture });
                    textRange = result as TextRange;
                }
                catch (ApplicationException)
                {
                    textRange = null;
                }
            }

            return(textRange);
        }
Ejemplo n.º 19
0
        public FindResult FindNext(string expression, FindFlags flags, SearchFilter filter)
        {
            CheckCurrentState(expression, flags, filter);

            this._match = null;

            if (string.IsNullOrEmpty(expression))
            {
                return(FindResult.None);
            }

            if (this._list == null)
            {
                FindNodes();
                this._position = -1;
                this._start    = -1; // we have not yet moved to one of the found nodes.
            }
            else if (this._resetPosition)
            {
                this._resetPosition = false;
                FindNodes();
                if (this._start >= _list.Count)
                {
                    this._start = _list.Count - 1;
                }

                if (this._position >= _list.Count)
                {
                    this._position = _list.Count - 1;
                }
            }

            int  s     = this._start;
            bool first = (this._start == -1);

            var  rc    = FindSelectedNode();
            int  pos   = rc.Item1;
            bool exact = rc.Item2;

            if (pos != this._position)
            {
                // user has moved the selection somewhere else, so start the find ring over again.
                first = true;
            }

            bool hasSomething = this._list != null && this._list.Count > 0;

            while (hasSomething)
            {
                if (this.Backwards)
                {
                    pos--;
                    if (pos < 0)
                    {
                        pos = _list.Count - 1;
                    }
                }
                else
                {
                    pos++;
                    if (pos >= _list.Count)
                    {
                        pos = 0;
                    }
                }

                if (first)
                {
                    this._start = s = pos;
                    first       = false;
                }
                else if (pos == this._start)
                {
                    // we have wrapped around!
                    break;
                }

                this._position = pos;

                XmlNodeMatch m = _list[pos] as XmlNodeMatch;
                if (m.Replaced)
                {
                    continue;
                }
                XmlNode node = m.Node;
                this._match = m;

                if (node != null)
                {
                    this._current = this._view.FindNode(node);
                    if (this._current != null)
                    {
                        this._view.SelectedNode = this._current;
                        if (m.IsName)
                        {
                            _ev = this._view.TreeView;
                        }
                        else
                        {
                            _ev = this._view.NodeTextView;
                        }
                        if (_ev.BeginEdit(null))
                        {
                            _ev.SelectText(m.Index, m.Length);
                        }
                    }
                }
                return(FindResult.Found);
            }

            this._start = -1; // get ready for another cycle around.
            return(hasSomething ? FindResult.NoMore : FindResult.None);
        }
        // Token: 0x060039B2 RID: 14770 RVA: 0x001059FC File Offset: 0x00103BFC
        public static ITextRange Find(ITextPointer findContainerStartPosition, ITextPointer findContainerEndPosition, string findPattern, FindFlags flags, CultureInfo cultureInfo)
        {
            if (findContainerStartPosition == null || findContainerEndPosition == null || findContainerStartPosition.CompareTo(findContainerEndPosition) == 0 || findPattern == null || findPattern == string.Empty)
            {
                return(null);
            }
            bool matchCase       = (flags & FindFlags.MatchCase) > FindFlags.None;
            bool flag            = (flags & FindFlags.FindWholeWordsOnly) > FindFlags.None;
            bool matchLast       = (flags & FindFlags.FindInReverse) > FindFlags.None;
            bool matchDiacritics = (flags & FindFlags.MatchDiacritics) > FindFlags.None;
            bool matchKashida    = (flags & FindFlags.MatchKashida) > FindFlags.None;
            bool matchAlefHamza  = (flags & FindFlags.MatchAlefHamza) > FindFlags.None;

            if (flag)
            {
                ushort[] array  = new ushort[1];
                ushort[] array2 = new ushort[1];
                char[]   array3 = findPattern.ToCharArray();
                SafeNativeMethods.GetStringTypeEx(0U, 1U, new char[]
                {
                    array3[0]
                }, 1, array);
                SafeNativeMethods.GetStringTypeEx(0U, 1U, new char[]
                {
                    array3[findPattern.Length - 1]
                }, 1, array2);
                if ((array[0] & 8) != 0 || (array[0] & 64) != 0 || (array2[0] & 8) != 0 || (array2[0] & 64) != 0)
                {
                    flag = false;
                }
            }
            if (findContainerStartPosition is DocumentSequenceTextPointer || findContainerStartPosition is FixedTextPointer)
            {
                return(FixedFindEngine.Find(findContainerStartPosition, findContainerEndPosition, findPattern, cultureInfo, matchCase, flag, matchLast, matchDiacritics, matchKashida, matchAlefHamza));
            }
            return(TextFindEngine.InternalFind(findContainerStartPosition, findContainerEndPosition, findPattern, cultureInfo, matchCase, flag, matchLast, matchDiacritics, matchKashida, matchAlefHamza));
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Called when the search routine should be launched
 /// </summary>
 /// <param name="searchFlags">Search flags</param>
 /// <param name="searchText">Text for search</param>
 protected virtual void OnNeedSearch(FindFlags searchFlags, string searchText)
 {
     StartSearch(searchFlags, searchText);
 }
Ejemplo n.º 22
0
            public static IEnumerable <TextRange> FindText(FlowDocument document, String input, FindFlags flags, CultureInfo cultureInfo)
            {
                TextPointer start = document.ContentStart;
                TextPointer end   = document.ContentEnd;
                TextRange   last  = null;

                try
                {
                    if (findMethod == null)
                    {
                        findMethod = typeof(FrameworkElement).Assembly
                                     .GetType("System.Windows.Documents.TextFindEngine")
                                     .GetMethod("Find", BindingFlags.Static | BindingFlags.Public);
                    }
                }
                catch (ApplicationException)
                {
                    last = null;
                }

                while (findMethod != null && start.CompareTo(end) < 0)
                {
                    try
                    {
                        var parameters = new object[] { start, end, input, flags, CultureInfo.CurrentCulture };
                        last = findMethod.Invoke(null, parameters) as TextRange;
                    }
                    catch (ApplicationException)
                    {
                        last = null;
                    }

                    if (last == null)
                    {
                        yield break;
                    }

                    yield return(last);

                    start = last.End;
                }
            }
Ejemplo n.º 23
0
 public void FindAgain(bool reverse)
 {
     // The find dialog might have been disposed, so we can only find using previous
     // find state information.
     if (string.IsNullOrEmpty(lastExpression)) {
         return;
     }
     try {
         if (reverse) {
             lastFlags |= FindFlags.Backwards;
         } else {
             lastFlags &= ~FindFlags.Backwards;
         }
         FindResult rc = target.FindNext(lastExpression, lastFlags, filter);
         if (rc == FindResult.Found && !this.IsDisposed) {
             this.MoveFindDialog(target.MatchRect);
         }
         if (rc == FindResult.None) {
             OnNotFound();
         } else if (rc == FindResult.NoMore) {
             OnFindDone();
         }
     } catch (Exception ex) {
         OnError(ex, SR.FindErrorCaption);
     }
 }
Ejemplo n.º 24
0
 void CheckCurrentState(string expression, FindFlags flags, SearchFilter filter)
 {
     if (this.expression != expression || this.flags != flags || this.filter != filter) {
         this.expression = expression;
         this.flags = flags;
         this.filter = filter;
         this.list = null;
         this.match = null;
     }
 }
Ejemplo n.º 25
0
        public FindResult FindNext(string expression, FindFlags flags, SearchFilter filter)
        {
            CheckCurrentState(expression, flags, filter);

            if (ev != null && ev.IsEditing) {
                start = ev.SelectionStart; // remember where we were in the editor.
                ev.EndEdit(false);
            }
            this.ev = null;
            this.match = null;

            if (string.IsNullOrEmpty(expression))
                return FindResult.None;

            if (this.list == null) {
                FindNodes();
            }

            // In case user changed the selection since the last find.
            int pos = FindSelectedNode();
            int wrap = -1;
            bool first = true;
            bool hasSomething = this.list.Count > 0;
            while (this.list != null && hasSomething &&
                (first || pos != wrap)) {
                first = false;
                if (wrap == -1) wrap = pos;
                if (this.Backwards) {
                    pos--;
                    if (pos < 0) pos = list.Count - 1;
                } else {
                    pos++;
                    if (pos >= list.Count) pos = 0;
                }

                XmlNodeMatch m = list[pos] as XmlNodeMatch;
                XmlNode node = m.Node;
                this.match = m;

                if (node != null) {
                    this.current = this.view.FindNode(node);
                    if (this.current == this.view.SelectedNode) {
                        continue;
                    }
                    if (this.current != null) {
                        this.view.SelectedNode = this.current;
                        if (m.IsName) {
                            ev = this.view.TreeView;
                        } else {
                            ev = this.view.NodeTextView;
                        }
                        if (ev.BeginEdit(null)) {
                            ev.SelectText(m.Index, m.Length);
                        }
                    }
                }
                return FindResult.Found;
            }
            return hasSomething ? FindResult.NoMore : FindResult.None;
        }
        public FindResult FindNext(string expression, FindFlags flags, SearchFilter filter)
        {
            CheckCurrentState(expression, flags, filter);

            if (ev != null && ev.IsEditing)
            {
                start = ev.SelectionStart; // remember where we were in the editor.
                ev.EndEdit(false);
            }
            this.ev    = null;
            this.match = null;

            if (string.IsNullOrEmpty(expression))
            {
                return(FindResult.None);
            }

            if (this.list == null)
            {
                FindNodes();
            }

            // In case user changed the selection since the last find.
            int  pos          = FindSelectedNode();
            int  wrap         = -1;
            bool first        = true;
            bool hasSomething = this.list.Count > 0;

            while (this.list != null && hasSomething &&
                   (first || pos != wrap))
            {
                first = false;
                if (wrap == -1)
                {
                    wrap = pos;
                }
                if (this.Backwards)
                {
                    pos--;
                    if (pos < 0)
                    {
                        pos = list.Count - 1;
                    }
                }
                else
                {
                    pos++;
                    if (pos >= list.Count)
                    {
                        pos = 0;
                    }
                }

                XmlNodeMatch m    = list[pos] as XmlNodeMatch;
                XmlNode      node = m.Node;
                this.match = m;

                if (node != null)
                {
                    this.current = this.view.FindNode(node);
                    if (this.current == this.view.SelectedNode)
                    {
                        continue;
                    }
                    if (this.current != null)
                    {
                        this.view.SelectedNode = this.current;
                        if (m.IsName)
                        {
                            ev = this.view.TreeView;
                        }
                        else
                        {
                            ev = this.view.NodeTextView;
                        }
                        if (ev.BeginEdit(null))
                        {
                            ev.SelectText(m.Index, m.Length);
                        }
                    }
                }
                return(FindResult.Found);
            }
            return(hasSomething ? FindResult.NoMore : FindResult.None);
        }
Ejemplo n.º 27
0
         public static IEnumerable<TextRange> FindText(FlowDocument document, String input, FindFlags flags, CultureInfo cultureInfo)
         {
            TextPointer start = document.ContentStart;
            TextPointer end = document.ContentEnd;
            TextRange last = null;
            var textRange = new List<TextRange>();

            try
            {
               if (findMethod == null)
               {
                  findMethod = typeof(FrameworkElement).Assembly.GetType("System.Windows.Documents.TextFindEngine").
                         GetMethod("Find", BindingFlags.Static | BindingFlags.Public);
               }
            }
            catch (ApplicationException)
            {
               last = null;
            }

            while (findMethod != null && start.CompareTo(end) < 0)
            {
               try
               {
                  last = findMethod.Invoke(null,
                                          new Object[] { start,
                                                      end,
                                                      input, 
                                                      flags, 
                                                      CultureInfo.CurrentCulture 
                                       }) as TextRange;
               }
               catch (ApplicationException)
               {
                  last = null;
               }

               if (last == null)
                  yield break;
               else
                  yield return last;
               start = last.End;
            }
         }
        internal static ITextRange Find(FindToolBar findToolBar, TextEditor textEditor, ITextView textView, ITextView masterPageTextView)
        {
            ITextPointer textPointer = null;

            Invariant.Assert(findToolBar != null);
            Invariant.Assert(textEditor != null);
            FindFlags findFlags = FindFlags.None;

            findFlags |= (findToolBar.SearchUp ? FindFlags.FindInReverse : FindFlags.None);
            findFlags |= (findToolBar.MatchCase ? FindFlags.MatchCase : FindFlags.None);
            findFlags |= (findToolBar.MatchWholeWord ? FindFlags.FindWholeWordsOnly : FindFlags.None);
            findFlags |= (findToolBar.MatchDiacritic ? FindFlags.MatchDiacritics : FindFlags.None);
            findFlags |= (findToolBar.MatchKashida ? FindFlags.MatchKashida : FindFlags.None);
            findFlags |= (findToolBar.MatchAlefHamza ? FindFlags.MatchAlefHamza : FindFlags.None);
            ITextContainer textContainer       = textEditor.TextContainer;
            ITextRange     selection           = textEditor.Selection;
            string         searchText          = findToolBar.SearchText;
            CultureInfo    documentCultureInfo = DocumentViewerHelper.GetDocumentCultureInfo(textContainer);
            ITextPointer   textPointer2;
            ITextPointer   textPointer3;
            ITextRange     textRange;

            if (selection.IsEmpty)
            {
                if (textView != null && !textView.IsValid)
                {
                    textView = null;
                }
                if (textView != null && textView.Contains(selection.Start))
                {
                    textPointer2 = (findToolBar.SearchUp ? textContainer.Start : selection.Start);
                    textPointer3 = (findToolBar.SearchUp ? selection.Start : textContainer.End);
                }
                else
                {
                    if (masterPageTextView != null && masterPageTextView.IsValid)
                    {
                        foreach (TextSegment textSegment in masterPageTextView.TextSegments)
                        {
                            if (!textSegment.IsNull)
                            {
                                if (textPointer == null)
                                {
                                    textPointer = ((!findToolBar.SearchUp) ? textSegment.Start : textSegment.End);
                                }
                                else if (!findToolBar.SearchUp)
                                {
                                    if (textSegment.Start.CompareTo(textPointer) < 0)
                                    {
                                        textPointer = textSegment.Start;
                                    }
                                }
                                else if (textSegment.End.CompareTo(textPointer) > 0)
                                {
                                    textPointer = textSegment.End;
                                }
                            }
                        }
                    }
                    if (textPointer != null)
                    {
                        textPointer2 = (findToolBar.SearchUp ? textContainer.Start : textPointer);
                        textPointer3 = (findToolBar.SearchUp ? textPointer : textContainer.End);
                    }
                    else
                    {
                        textPointer2 = textContainer.Start;
                        textPointer3 = textContainer.End;
                    }
                }
            }
            else
            {
                textRange = TextFindEngine.Find(selection.Start, selection.End, searchText, findFlags, documentCultureInfo);
                if (textRange != null && textRange.Start != null && textRange.Start.CompareTo(selection.Start) == 0 && textRange.End.CompareTo(selection.End) == 0)
                {
                    textPointer2 = (findToolBar.SearchUp ? selection.Start : selection.End);
                    textPointer3 = (findToolBar.SearchUp ? textContainer.Start : textContainer.End);
                }
                else
                {
                    textPointer2 = (findToolBar.SearchUp ? selection.End : selection.Start);
                    textPointer3 = (findToolBar.SearchUp ? textContainer.Start : textContainer.End);
                }
            }
            textRange = null;
            if (textPointer2 != null && textPointer3 != null && textPointer2.CompareTo(textPointer3) != 0)
            {
                if (textPointer2.CompareTo(textPointer3) > 0)
                {
                    ITextPointer textPointer4 = textPointer2;
                    textPointer2 = textPointer3;
                    textPointer3 = textPointer4;
                }
                textRange = TextFindEngine.Find(textPointer2, textPointer3, searchText, findFlags, documentCultureInfo);
                if (textRange != null && !textRange.IsEmpty)
                {
                    selection.Select(textRange.Start, textRange.End);
                }
            }
            return(textRange);
        }
Ejemplo n.º 29
0
        bool FindNext(bool quiet)
        {
            FindFlags flags = FindFlags.Normal;
            if (this.checkBoxRegex.Checked) flags |= FindFlags.Regex;
            else if (this.checkBoxXPath.Checked) flags |= FindFlags.XPath;
            if (this.checkBoxMatchCase.Checked) flags |= FindFlags.MatchCase;
            if (this.checkBoxWholeWord.Checked) flags |= FindFlags.WholeWord;
            if (this.radioButtonUp.Checked) flags |= FindFlags.Backwards;

            string expr = this.Expression;
            if (!this.comboBoxFind.Items.Contains(expr)) {
                this.comboBoxFind.Items.Add(expr);
                if (this.comboBoxFind.Items.Count > MaxRecentlyUsed) {
                    this.comboBoxFind.Items.RemoveAt(0);
                }
            }

            lastFlags = flags;
            lastExpression = expr;

            FindResult rc = target.FindNext(expr, flags, filter);
            if (rc == FindResult.Found && !this.IsDisposed) {
                this.MoveFindDialog(target.MatchRect);
            }
            if (!quiet) {
                if (rc == FindResult.None) {
                    OnNotFound();
                } else if (rc == FindResult.NoMore) {
                    OnFindDone();
                }
            }
            return rc == FindResult.Found;
        }
Ejemplo n.º 30
0
         public static TextRange FindText(TextPointer findContainerStartPosition, TextPointer findContainerEndPosition, String input, FindFlags flags, CultureInfo cultureInfo)
         {
            TextRange textRange = null;
            if (findContainerStartPosition.CompareTo(findContainerEndPosition) < 0)
            {
               try
               {
                  if (findMethod == null)
                  {
                     findMethod = typeof(FrameworkElement).Assembly.GetType("System.Windows.Documents.TextFindEngine").
                            GetMethod("Find", BindingFlags.Static | BindingFlags.Public);
                  }

                  textRange = findMethod.Invoke(null,
                     new Object[] { findContainerStartPosition,
                                    findContainerEndPosition,
                                    input, 
                                    flags, 
                                    CultureInfo.CurrentCulture 
                     }) as TextRange;
               }
               catch (ApplicationException)
               {
                  textRange = null;
               }
            }

            return textRange;
         }