Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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);

            textEditor.Select(startOffset, endOffset - 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);
                }
                textEditor.Select(startOffset, endOffset - startOffset);
            } finally {
                ignoreSelectionChanges = false;
            }
        }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
0
        void ReplaceInSelection()
        {
            int startOffset = Math.Min(selection.Offset, selection.EndOffset);
            int endOffset   = Math.Max(selection.Offset, selection.EndOffset);

            if (findFirst)
            {
                textEditor.Caret.Offset = startOffset;
            }

            try {
                ignoreSelectionChanges = true;
                if (findFirst)
                {
                    findFirst = false;
                    SearchReplaceManager.ReplaceFirstInSelection(startOffset, endOffset - startOffset, null);
                }
                else
                {
                    findFirst = !SearchReplaceManager.ReplaceNextInSelection(null);
                    if (findFirst)
                    {
                        textEditor.Select(startOffset, endOffset - startOffset);
                    }
                }
            } finally {
                ignoreSelectionChanges = false;
            }
        }
Ejemplo n.º 5
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);

            textEditor.Select(startOffset, endOffset - 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)
                {
                    // use anchor for endOffset because the replacement might change the text length
                    var anchor = textEditor.Document.CreateAnchor(endOffset);
                    SearchReplaceManager.ReplaceAll(startOffset, endOffset - startOffset, monitor);
                    endOffset = anchor.Offset;
                }
                textEditor.Select(startOffset, endOffset - startOffset);
            } finally {
                ignoreSelectionChanges = false;
            }
        }
 void CommitSearch()
 {
     if (comboBox.Text.Length > 0)
     {
         LoggingService.Debug("FindComboBox.CommitSearch()");
         SearchOptions.DocumentIteratorType = DocumentIteratorType.CurrentDocument;
         SearchOptions.FindPattern          = comboBox.Text;
         SearchReplaceManager.FindNext(null);
         comboBox.Focus();
     }
 }
Ejemplo n.º 7
0
 public override void Run()
 {
     if (SearchOptions.CurrentFindPattern.Length > 0)
     {
         SearchReplaceManager.FindNext(null);
     }
     else
     {
         Find find = new Find();
         find.Run();
     }
 }
Ejemplo n.º 8
0
 private void Button_ReplaceAll_Click(object sender, EventArgs e)
 {
     WritebackOptions();
     if (IsSelectionSearch)
     {
         if (IsTextSelected(selection))
         {
             RunAllInSelection(2);
         }
     }
     else
     {
         using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search", true))
         {
             SearchReplaceManager.ReplaceAll(monitor);
         }
     }
 }
Ejemplo n.º 9
0
 void BookmarkAllButtonClicked(object sender, EventArgs e)
 {
     WritebackOptions();
     if (IsSelectionSearch)
     {
         if (IsTextSelected(selection))
         {
             RunAllInSelection(1);
         }
     }
     else
     {
         using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search"))
         {
             SearchReplaceManager.MarkAll(monitor);
         }
     }
 }
Ejemplo n.º 10
0
 void ReplaceAllButtonClicked(object sender, EventArgs e)
 {
     WritebackOptions();
     if (IsSelectionSearch)
     {
         if (selection.IsTextSelected)
         {
             RunAllInSelection(2);
         }
     }
     else
     {
         using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search", true))
         {
             monitor.Progress = double.NaN;                     // progress not implemented, use indeterminate progress
             SearchReplaceManager.ReplaceAll(monitor);
         }
     }
 }
Ejemplo n.º 11
0
 void FindNextButtonClicked(object sender, EventArgs e)
 {
     WritebackOptions();
     if (IsSelectionSearch)
     {
         if (IsTextSelected(selection))
         {
             FindNextInSelection();
         }
     }
     else
     {
         using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("Search"))
         {
             SearchReplaceManager.FindNext(monitor);
         }
     }
     Focus();
 }
Ejemplo n.º 12
0
        public override void Run()
        {
            ITextEditor textArea = SearchReplaceUtilities.GetActiveTextEditor();

            if (textArea == null)
            {
                return;
            }

            // Determine what text we should search for.
            string textToFind;

            string selectedText = textArea.SelectedText;

            if (selectedText.Length > 0)
            {
                if (Find.IsMultipleLines(selectedText))
                {
                    // Locate the nearest word at the selection start.
                    textToFind = textArea.Document.GetWordAt(textArea.SelectionStart);
                }
                else
                {
                    // Search for selected text.
                    textToFind = selectedText;
                }
            }
            else
            {
                textToFind = textArea.Document.GetWordAt(textArea.Caret.Offset);
            }

            if (textToFind != null && textToFind.Length > 0)
            {
                SearchOptions.CurrentFindPattern = textToFind;
                if (SearchOptions.DocumentIteratorType == DocumentIteratorType.CurrentSelection)
                {
                    SearchOptions.DocumentIteratorType = DocumentIteratorType.CurrentDocument;
                }
                SearchReplaceManager.FindNext(null);
            }
        }