1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
4
using ICSharpCode.SharpDevelop.Editor;
6
using ICSharpCode.Core;
8
namespace SearchAndReplace
10
public class Find : AbstractMenuCommand
12
public static void SetSearchPattern()
14
// Get Highlighted value and set it to FindDialog.searchPattern
15
ITextEditor textArea = SearchReplaceUtilities.GetActiveTextEditor();
16
if (textArea != null) {
17
string selectedText = textArea.SelectedText;
18
if (selectedText != null && selectedText.Length > 0 && !IsMultipleLines(selectedText)) {
19
SearchOptions.CurrentFindPattern = selectedText;
24
public override void Run()
27
SearchAndReplaceDialog.ShowSingleInstance(SearchAndReplaceMode.Search);
30
public static bool IsMultipleLines(string text)
32
return text.IndexOf('\n') != -1;
36
public class FindNext : AbstractMenuCommand
38
public override void Run()
40
if (SearchOptions.CurrentFindPattern.Length > 0) {
41
SearchReplaceManager.FindNext(null);
43
Find find = new Find();
50
/// Finds the next text match based on the text currently
51
/// selected. It uses the currently active search options and only changes
52
/// the current find pattern. If the currently active search is inside the
53
/// current text selection then the quick find will change the search so it is
54
/// across the active document, otherwise it will not change the current setting.
57
/// If there is a piece of text selected on a single line then the quick
58
/// find will search for that. If multiple lines of text are selected then
59
/// the word at the start of the selection is determined and searche for.
60
/// If no text is selected then the word next to the caret is used. If
61
/// no text is selected, but the caret is immediately surrounded by whitespace
62
/// then quick find does nothing.
64
public class FindNextSelected : AbstractMenuCommand
66
public override void Run()
68
ITextEditor textArea = SearchReplaceUtilities.GetActiveTextEditor();
69
if (textArea == null) {
73
// Determine what text we should search for.
76
string selectedText = textArea.SelectedText;
77
if (selectedText.Length > 0) {
78
if (Find.IsMultipleLines(selectedText)) {
79
// Locate the nearest word at the selection start.
80
textToFind = textArea.Document.GetWordAt(textArea.SelectionStart);
82
// Search for selected text.
83
textToFind = selectedText;
86
textToFind = textArea.Document.GetWordAt(textArea.Caret.Offset);
89
if (textToFind != null && textToFind.Length > 0) {
90
SearchOptions.CurrentFindPattern = textToFind;
91
if (SearchOptions.DocumentIteratorType == DocumentIteratorType.CurrentSelection) {
92
SearchOptions.DocumentIteratorType = DocumentIteratorType.CurrentDocument;
94
SearchReplaceManager.FindNext(null);
99
public class Replace : AbstractMenuCommand
101
public override void Run()
103
Find.SetSearchPattern();
104
SearchAndReplaceDialog.ShowSingleInstance(SearchAndReplaceMode.Replace);