コード例 #1
0
        public static void ReplaceAll(IProgressMonitor monitor)
        {
            SetSearchOptions(monitor);
            ClearSelection();
            find.Reset();
            if (!find.SearchStrategy.CompilePattern(monitor))
            {
                return;
            }

            List <ITextEditor> textAreas = new List <ITextEditor>();
            ITextEditor        textArea  = null;

            for (int count = 0;; count++)
            {
                SearchResultMatch result = SearchReplaceManager.find.FindNext(monitor);

                if (result == null)
                {
                    if (count != 0)
                    {
                        foreach (ITextEditor ta in textAreas)
                        {
                            ta.Document.EndUndoableAction();
                        }
                    }
                    ShowReplaceDoneMessage(count, monitor);
                    find.Reset();
                    return;
                }
                else
                {
                    if (textArea == null || textArea.FileName != result.FileName)
                    {
                        // we need to open another text area
                        textArea = OpenTextArea(result.FileName);
                        if (textArea != null)
                        {
                            if (!textAreas.Contains(textArea))
                            {
                                textArea.Document.StartUndoableAction();
                                textArea.Select(textArea.SelectionStart, 0);
                                textAreas.Add(textArea);
                            }
                        }
                    }
                    if (textArea != null)
                    {
                        string transformedPattern = result.TransformReplacePattern(SearchOptions.ReplacePattern);
                        find.Replace(result.Offset, result.Length, transformedPattern);
                        if (find.CurrentDocumentInformation.IsDocumentCreatedFromTextBuffer)
                        {
                            textArea.Document.Replace(result.Offset, result.Length, transformedPattern);
                        }
                    }
                    else
                    {
                        count--;
                    }
                }
            }
        }
コード例 #2
0
        public static void ReplaceAll(IProgressMonitor monitor)
        {
            SetSearchOptions(monitor);
            ClearSelection();
            find.Reset();
            if (!find.SearchStrategy.CompilePattern(monitor))
            {
                return;
            }

            List <TextEditorControl> textAreas = new List <TextEditorControl>();
            TextEditorControl        textArea  = null;

            for (int count = 0;; count++)
            {
                SearchResultMatch result = SearchReplaceManager.find.FindNext(monitor);

                if (result == null)
                {
                    if (count != 0)
                    {
                        foreach (TextEditorControl ta in textAreas)
                        {
                            ta.EndUpdate();
                            ta.Refresh();
                        }
                    }
                    ShowReplaceDoneMessage(count, monitor);
                    find.Reset();
                    return;
                }
                else
                {
                    if (textArea == null || textArea.FileName != result.FileName)
                    {
                        // we need to open another text area
                        textArea = OpenTextArea(result.FileName);
                        if (textArea != null)
                        {
                            if (!textAreas.Contains(textArea))
                            {
                                textArea.BeginUpdate();
                                textArea.ActiveTextAreaControl.TextArea.SelectionManager.SelectionCollection.Clear();
                                textAreas.Add(textArea);
                            }
                        }
                    }
                    if (textArea != null)
                    {
                        string transformedPattern = result.TransformReplacePattern(SearchOptions.ReplacePattern);
                        find.Replace(result.Offset, result.Length, transformedPattern);
                        if (find.CurrentDocumentInformation.Document == null)
                        {
                            textArea.Document.Replace(result.Offset, result.Length, transformedPattern);
                        }
                    }
                    else
                    {
                        count--;
                    }
                }
            }
        }