コード例 #1
0
ファイル: FindManager.cs プロジェクト: netide/netide
        public FindManager(IFindView view)
        {
            if (view == null)
                throw new ArgumentNullException("view");

            _view = view;

            object obj;
            ErrorUtil.ThrowOnFailure(((INiLocalRegistry)_view.GetService(typeof(INiLocalRegistry))).CreateInstance(
                new Guid(NiConstants.FindHelper),
                _view,
                out obj
            ));

            _findHelper = (INiFindHelper)obj;

            LoadSettings();
        }
コード例 #2
0
ファイル: FindManager.cs プロジェクト: vector-man/netide
        public FindManager(IFindView view)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            _view = view;

            object obj;

            ErrorUtil.ThrowOnFailure(((INiLocalRegistry)_view.GetService(typeof(INiLocalRegistry))).CreateInstance(
                                         new Guid(NiConstants.FindHelper),
                                         _view,
                                         out obj
                                         ));

            _findHelper = (INiFindHelper)obj;

            LoadSettings();
        }
コード例 #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));
                }
            }
コード例 #4
0
 public HResult Find(string search, NiFindOptions options, bool resetStartPoint, INiFindHelper helper, out NiFindResult result)
 {
     return(Replace(search, null, options, resetStartPoint, helper, out result));
 }
コード例 #5
0
 public HResult Replace(string search, string replace, NiFindOptions options, bool resetStartPoint, INiFindHelper helper, out NiFindResult result)
 {
     return Control.FindTarget.Replace(search, replace, options, resetStartPoint, helper, out result);
 }
コード例 #6
0
 public HResult Replace(string search, string replace, NiFindOptions options, bool resetStartPoint, INiFindHelper helper, out NiFindResult result)
 {
     return(Control.FindTarget.Replace(search, replace, options, resetStartPoint, helper, out result));
 }
コード例 #7
0
 public HResult Find(string search, NiFindOptions options, bool resetStartPoint, INiFindHelper helper, out NiFindResult result)
 {
     return Replace(search, null, options, resetStartPoint, helper, out result);
 }
コード例 #8
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);
                }
            }