Ejemplo n.º 1
0
        private bool HasAnyMatch(string content)
        {
            int    found;
            int    matchLength;
            string replacementText;
            bool   isFound;

            ErrorUtil.ThrowOnFailure(_findHelper.FindInText(
                                         _state.FindWhat,
                                         null,
                                         _state.Options,
                                         content,
                                         0,
                                         out found,
                                         out matchLength,
                                         out replacementText,
                                         out isFound
                                         ));

            return(isFound);
        }
            public HResult Replace(string search, string replace, NiFindOptions options, bool resetStartPoint, INiFindHelper helper, out NiFindResult result)
            {
                result = NiFindResult.NotFound;

                try
                {
                    if (search == null)
                    {
                        throw new ArgumentNullException("search");
                    }
                    if (helper == null)
                    {
                        throw new ArgumentNullException("helper");
                    }

                    var    document = _textAreaControl.Document;
                    string text     = document.TextContent;

                    int offset;

                    if (options.HasFlag(NiFindOptions.Backwards))
                    {
                        if (resetStartPoint)
                        {
                            offset = text.Length;
                        }
                        else
                        {
                            offset = _textAreaControl.Caret.Offset;
                        }
                    }
                    else
                    {
                        if (resetStartPoint)
                        {
                            offset = 0;
                        }
                        else if (_textAreaControl.SelectionManager.HasSomethingSelected)
                        {
                            offset = _textAreaControl.SelectionManager.SelectionCollection.Last().EndOffset;
                        }
                        else
                        {
                            offset = _textAreaControl.Caret.Offset;
                        }
                    }

                    int    matchLength;
                    string replacement;
                    bool   found;
                    ErrorUtil.ThrowOnFailure(helper.FindInText(
                                                 search,
                                                 replace,
                                                 options,
                                                 text,
                                                 offset,
                                                 out offset,
                                                 out matchLength,
                                                 out replacement,
                                                 out found
                                                 ));

                    if (found)
                    {
                        MarkSpan(GetTextSpan(document, offset, matchLength));
                        result = replace == null ? NiFindResult.Found : NiFindResult.Replaced;
                    }
                    else
                    {
                        result = NiFindResult.NotFound;
                    }

                    return(HResult.OK);
                }
                catch (Exception ex)
                {
                    return(ErrorUtil.GetHResult(ex));
                }
            }
Ejemplo n.º 3
0
            public HResult Replace(string search, string replace, NiFindOptions options, bool resetStartPoint, INiFindHelper helper, out NiFindResult result)
            {
                result = NiFindResult.NotFound;

                try
                {
                    if (search == null)
                        throw new ArgumentNullException("search");
                    if (helper == null)
                        throw new ArgumentNullException("helper");

                    var document = _textAreaControl.Document;
                    string text = document.TextContent;

                    int offset;

                    if (options.HasFlag(NiFindOptions.Backwards))
                    {
                        if (resetStartPoint)
                            offset = text.Length;
                        else
                            offset = _textAreaControl.Caret.Offset;
                    }
                    else
                    {
                        if (resetStartPoint)
                            offset = 0;
                        else if (_textAreaControl.SelectionManager.HasSomethingSelected)
                            offset = _textAreaControl.SelectionManager.SelectionCollection.Last().EndOffset;
                        else
                            offset = _textAreaControl.Caret.Offset;
                    }

                    int matchLength;
                    string replacement;
                    bool found;
                    ErrorUtil.ThrowOnFailure(helper.FindInText(
                        search,
                        replace,
                        options,
                        text,
                        offset,
                        out offset,
                        out matchLength,
                        out replacement,
                        out found
                    ));

                    if (found)
                    {
                        MarkSpan(GetTextSpan(document, offset, matchLength));
                        result = replace == null ? NiFindResult.Found : NiFindResult.Replaced;
                    }
                    else
                    {
                        result = NiFindResult.NotFound;
                    }

                    return HResult.OK;
                }
                catch (Exception ex)
                {
                    return ErrorUtil.GetHResult(ex);
                }
            }