Beispiel #1
0
        /// <summary>Execute the command.</summary>
        public override void Execute()
        {
            if (!Enabled)
            {
                return;
            }

            // if the window is an editor, grab the highlighted text
            IFindReplaceProvider findReplaceProvider = HostWindow.ActiveChildForm as IFindReplaceProvider;

            if (FindReplaceWindow == null || FindReplaceWindow.IsDisposed)
            {
                FindReplaceWindow = new FindReplaceForm(Services);
            }

            if (findReplaceProvider is IEditor)
            {
                FindReplaceWindow.FindString = ((IEditor)findReplaceProvider).SelectedText;
            }

            FindReplaceWindow.TopMost = true;

            if (!FindReplaceWindow.Visible)
            {
                FindReplaceWindow.Show(HostWindow.Instance);
            }
        }
        /// <summary>Execute the command.</summary>
        public override void Execute()
        {
            IFindReplaceProvider editorFindProvider = HostWindow.ActiveChildForm as IFindReplaceProvider;

            if (editorFindProvider != null)
            {
                FindTextRequest req = null;
                int             key = editorFindProvider.GetHashCode();

                // is there a request in the table for this window?
                if (SearchToolsCommon.FindReplaceTextRequests.ContainsKey(key))
                {
                    req = SearchToolsCommon.FindReplaceTextRequests[key];
                }

                if (req != null)
                {
                    // wrap around to start if at last pos
                    if (req.Position != 0)
                    {
                        req.Position = editorFindProvider.CursorOffset;
                    }

                    if (editorFindProvider.ReplaceString(req.ReplaceValue, req.Position - req.SearchValue.Length, req.SearchValue.Length))
                    {
                        CommandManager.GetCommandInstance <FindNextStringCommand>().Execute();
                    }
                }
            }
        }
        /// <summary>
        /// 	Initializes a new instance of the <see cref = "FindTextRequest" /> class. Creates a new request using the specified <paramref name = "textProvider" /> for searching.
        /// </summary>
        /// <param name = "textProvider">The search provider for this request,</param>
        /// <param name = "searchValue">The text to be searched on.</param>
        public FindTextRequest(IFindReplaceProvider textProvider, string searchValue)
        {
            TextProvider = textProvider;
            if (searchValue != null)
            {
                SearchValue = searchValue;
            }

            Position = 0;
            StringComparison = StringComparison.CurrentCultureIgnoreCase;
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref = "FindTextRequest" /> class. Creates a new request using the specified <paramref name = "textProvider" /> for searching.
        /// </summary>
        /// <param name = "textProvider">The search provider for this request,</param>
        /// <param name = "searchValue">The text to be searched on.</param>
        public FindTextRequest(IFindReplaceProvider textProvider, string searchValue)
        {
            TextProvider = textProvider;
            if (searchValue != null)
            {
                SearchValue = searchValue;
            }

            Position         = 0;
            StringComparison = StringComparison.CurrentCultureIgnoreCase;
        }
Beispiel #5
0
        /// <summary>The btn replace_ click.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void btnReplace_Click(object sender, EventArgs e)
        {
            IFindReplaceProvider provider = _services.HostWindow.ActiveChildForm as IFindReplaceProvider;

            if (provider == null)
            {
                SystemSounds.Beep.Play();
            }
            else
            {
                HandleReplaceNext(provider, FindString, ReplaceString);
            }
        }
        /// <summary>Two execution methods - through the "Find Text" window or by hitting F3.
        /// If simply hitting F3, we are executing the current search from current cursor position for this window.
        /// Different windows can also have different search text.</summary>
        public override void Execute()
        {
            IFindReplaceProvider editorFindProvider = HostWindow.ActiveChildForm as IFindReplaceProvider;

            if (editorFindProvider != null)
            {
                FindTextRequest findTextRequest = null;
                int             key             = editorFindProvider.GetHashCode();

                // is there a request in the table for this window?
                if (SearchToolsCommon.FindReplaceTextRequests.ContainsKey(key))
                {
                    findTextRequest = SearchToolsCommon.FindReplaceTextRequests[key];
                }
                else
                {
                    if (SearchToolsCommon.FindReplaceTextRequests.Count > 0)
                    {
                        // if there is an entry in the list of searches create an instance
                        findTextRequest          = new FindTextRequest(editorFindProvider);
                        findTextRequest.Position = editorFindProvider.CursorOffset;
                    }
                    else
                    {
                        // none in table, default to curently selected text if its the editor
                        IEditor editor = ActiveFormAsEditor;
                        if (editor != null && editor.SelectedText.Length > 0)
                        {
                            findTextRequest          = new FindTextRequest(editorFindProvider, editor.SelectedText);
                            findTextRequest.Position = editorFindProvider.CursorOffset;
                        }
                    }
                }

                if (findTextRequest != null)
                {
                    // wrap around to start if at last pos
                    if (findTextRequest.Position != 0)
                    {
                        findTextRequest.Position = editorFindProvider.CursorOffset;
                    }

                    findTextRequest = editorFindProvider.TextFindService.FindNext(findTextRequest);
                    SearchToolsCommon.FindReplaceTextRequests[key] = findTextRequest;
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Finds the current line position and duplicates that line.
        /// </summary>
        public override void Execute()
        {
            IFindReplaceProvider findReplaceProvider = HostWindow.ActiveChildForm as IFindReplaceProvider;

            if (findReplaceProvider == null || !findReplaceProvider.CanReplaceText)
            {
                return;
            }

            // todo!

            int offset = findReplaceProvider.CursorOffset;
            int originalLineStartOffset = 0;
            int lineLength = 0;

            string line = "?";

            // find current text "line", back to start or \n and find next \n or eof

            line = line + Environment.NewLine + line;

            findReplaceProvider.ReplaceString(line, 0, 0);
        }
Beispiel #8
0
        /// <summary>The create find request.</summary>
        /// <param name="provider">The provider.</param>
        /// <param name="findString">The find string.</param>
        /// <param name="replaceValue">The replace value.</param>
        private void CreateFindRequest(IFindReplaceProvider provider, string findString, string replaceValue)
        {
            int             key = provider.GetHashCode();
            FindTextRequest request;

            if (SearchToolsCommon.FindReplaceTextRequests.ContainsKey(key))
            {
                request = SearchToolsCommon.FindReplaceTextRequests[key];
                if (request.SearchValue != findString)
                {
                    // reset find text and set the starting position to the current cursor location
                    request.SearchValue  = findString;
                    request.ReplaceValue = replaceValue;
                    request.Position     = provider.CursorOffset;
                }
            }
            else
            {
                request = new FindTextRequest(provider, findString);
                request.ReplaceValue = replaceValue;
            }

            SearchToolsCommon.FindReplaceTextRequests[key] = request;
        }
Beispiel #9
0
 /// <summary>The handle replace next.</summary>
 /// <param name="provider">The provider.</param>
 /// <param name="findString">The find string.</param>
 /// <param name="replaceValue">The replace value.</param>
 private void HandleReplaceNext(IFindReplaceProvider provider, string findString, string replaceValue)
 {
     CommandManager.GetCommandInstance <ReplaceStringCommand>().Execute();
 }
Beispiel #10
0
 /// <summary>The handle find next.</summary>
 /// <param name="provider">The provider.</param>
 /// <param name="findString">The find string.</param>
 /// <param name="replaceValue">The replace value.</param>
 private void HandleFindNext(IFindReplaceProvider provider, string findString, string replaceValue)
 {
     CreateFindRequest(provider, findString, replaceValue);
     CommandManager.GetCommandInstance <FindNextStringCommand>().Execute();
 }
 /// <summary>
 /// 	Initializes a new instance of the <see cref = "FindTextRequest" /> class. Creates a new request using the specified <paramref name = "textProvider" /> for searching.
 /// </summary>
 /// <param name = "textProvider">The search provider for this request,</param>
 public FindTextRequest(IFindReplaceProvider textProvider)
     : this(textProvider, null)
 {
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref = "FindTextRequest" /> class. Creates a new request using the specified <paramref name = "textProvider" /> for searching.
 /// </summary>
 /// <param name = "textProvider">The search provider for this request,</param>
 public FindTextRequest(IFindReplaceProvider textProvider)
     : this(textProvider, null)
 {
 }
 /// <summary>The handle replace next.</summary>
 /// <param name="provider">The provider.</param>
 /// <param name="findString">The find string.</param>
 /// <param name="replaceValue">The replace value.</param>
 private void HandleReplaceNext(IFindReplaceProvider provider, string findString, string replaceValue)
 {
     CommandManager.GetCommandInstance<ReplaceStringCommand>().Execute();
 }
 /// <summary>The handle find next.</summary>
 /// <param name="provider">The provider.</param>
 /// <param name="findString">The find string.</param>
 /// <param name="replaceValue">The replace value.</param>
 private void HandleFindNext(IFindReplaceProvider provider, string findString, string replaceValue)
 {
     CreateFindRequest(provider, findString, replaceValue);
     CommandManager.GetCommandInstance<FindNextStringCommand>().Execute();
 }
        /// <summary>The create find request.</summary>
        /// <param name="provider">The provider.</param>
        /// <param name="findString">The find string.</param>
        /// <param name="replaceValue">The replace value.</param>
        private void CreateFindRequest(IFindReplaceProvider provider, string findString, string replaceValue)
        {
            int key = provider.GetHashCode();
            FindTextRequest request;

            if (SearchToolsCommon.FindReplaceTextRequests.ContainsKey(key))
            {
                request = SearchToolsCommon.FindReplaceTextRequests[key];
                if (request.SearchValue != findString)
                {
                    // reset find text and set the starting position to the current cursor location
                    request.SearchValue = findString;
                    request.ReplaceValue = replaceValue;
                    request.Position = provider.CursorOffset;
                }
            }
            else
            {
                request = new FindTextRequest(provider, findString);
                request.ReplaceValue = replaceValue;
            }

            SearchToolsCommon.FindReplaceTextRequests[key] = request;
        }