Пример #1
0
        void ReplaceInSelection()
        {
            int startOffset = Math.Min(selection.Offset, selection.EndOffset);
            int endOffset   = Math.Max(selection.Offset, selection.EndOffset);

            if (findFirst)
            {
                SetCaretPosition(textEditor.ActiveTextAreaControl.TextArea, startOffset);
            }

            try {
                ignoreSelectionChanges = true;
                if (findFirst)
                {
                    findFirst = false;
                    SearchReplaceManager.ReplaceFirstInSelection(startOffset, endOffset - startOffset, null);
                }
                else
                {
                    findFirst = !SearchReplaceManager.ReplaceNextInSelection(null);
                    if (findFirst)
                    {
                        SearchReplaceUtilities.SelectText(textEditor, startOffset, endOffset);
                    }
                }
            } finally {
                ignoreSelectionChanges = false;
            }
        }
Пример #2
0
        /// <summary>
        /// action: 0 = find, 1 = mark, 2 = replace
        /// </summary>
        void RunAllInSelection(int action)
        {
            const IProgressMonitor monitor = null;

            int startOffset = Math.Min(selection.Offset, selection.EndOffset);
            int endOffset   = Math.Max(selection.Offset, selection.EndOffset);

            SearchReplaceUtilities.SelectText(textEditor, startOffset, endOffset);
            SetCaretPosition(textEditor.ActiveTextAreaControl.TextArea, startOffset);

            try {
                ignoreSelectionChanges = true;
                if (action == 0)
                {
                    SearchInFilesManager.FindAll(startOffset, endOffset - startOffset, monitor);
                }
                else if (action == 1)
                {
                    SearchReplaceManager.MarkAll(startOffset, endOffset - startOffset, monitor);
                }
                else if (action == 2)
                {
                    SearchReplaceManager.ReplaceAll(startOffset, endOffset - startOffset, monitor);
                }
                SearchReplaceUtilities.SelectText(textEditor, startOffset, endOffset);
            } finally {
                ignoreSelectionChanges = false;
            }
        }
        public static void FindNext(IProgressMonitor monitor)
        {
            SetSearchOptions(monitor);
            if (find == null ||
                SearchOptions.FindPattern == null ||
                SearchOptions.FindPattern.Length == 0)
            {
                return;
            }

            if (!find.SearchStrategy.CompilePattern(monitor))
            {
                find.Reset();
                lastResult = null;
                return;
            }

            TextEditorControl textArea = null;

            while (textArea == null)
            {
                SearchResultMatch result = find.FindNext(monitor);
                if (result == null)
                {
                    ShowNotFoundMessage(monitor);
                    find.Reset();
                    lastResult = null;
                    return;
                }
                else
                {
                    textArea = OpenTextArea(result.FileName);
                    if (textArea != null)
                    {
                        if (lastResult != null && lastResult.FileName == result.FileName &&
                            textArea.ActiveTextAreaControl.Caret.Offset != lastResult.Offset + lastResult.Length)
                        {
                            find.Reset();
                        }
                        int startPos = Math.Min(textArea.Document.TextLength, Math.Max(0, result.Offset));
                        int endPos   = Math.Min(textArea.Document.TextLength, startPos + result.Length);

                        SearchReplaceUtilities.SelectText(textArea, startPos, endPos);
                        lastResult = result;
                    }
                }
            }
        }
        public static bool FindNextInSelection(IProgressMonitor monitor)
        {
            TextEditorControl textArea = null;

            while (textArea == null)
            {
                SearchResultMatch result = find.FindNext(textSelection.Offset, textSelection.Length);
                if (result == null)
                {
                    if (!foundAtLeastOneItem)
                    {
                        ShowNotFoundMessage(monitor);
                    }
                    find.Reset();
                    lastResult          = null;
                    foundAtLeastOneItem = false;
                    return(false);
                }
                else
                {
                    textArea = OpenTextArea(result.FileName);
                    if (textArea != null)
                    {
                        foundAtLeastOneItem = true;
                        if (lastResult != null && lastResult.FileName == result.FileName &&
                            textArea.ActiveTextAreaControl.Caret.Offset != lastResult.Offset + lastResult.Length)
                        {
                        }
                        int startPos = Math.Min(textArea.Document.TextLength, Math.Max(0, result.Offset));
                        int endPos   = Math.Min(textArea.Document.TextLength, startPos + result.Length);
                        SearchReplaceUtilities.SelectText(textArea, startPos, endPos);
                        lastResult = result;
                    }
                }
            }
            return(true);
        }