public void Attach(TextArea textArea, TextEditor editor) { if (textArea == null) { throw new ArgumentNullException("textArea"); } _editor = editor; _textArea = textArea; _currentDocument = textArea.Document; _renderer = new SearchResultBackgroundRenderer { MarkerBrush = new SolidColorBrush(Colors.Yellow) }; _searchTextBox.TextChanged += new TextChangedEventHandler(_searchTextBox_TextChanged); _adorner = new SearchPanelAdorner(textArea, this); if (_currentDocument != null) { _currentDocument.TextChanged += new EventHandler(_currentDocument_TextChanged); } _textArea.DocumentChanged += new EventHandler(_textArea_DocumentChanged); _textArea.PreviewKeyDown += new KeyEventHandler(_textArea_PreviewKeyDown); _searchTextBox.LostFocus += new RoutedEventHandler(_searchTextBox_LostFocus); _replaceTextBox.LostFocus += new RoutedEventHandler(_replaceTextBox_LostFocus); _searchTextBox.GotFocus += new RoutedEventHandler(_searchTextBox_GotFocus); _replaceTextBox.GotFocus += new RoutedEventHandler(_replaceTextBox_GotFocus); KeyDown += new KeyEventHandler(_searchPanel_KeyDown); CommandBindings.Add(new CommandBinding(Find, (sender, e) => Open())); CommandBindings.Add(new CommandBinding(SearchCommands.FindNext, (sender, e) => FindNext())); CommandBindings.Add(new CommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious())); CommandBindings.Add(new CommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close())); textArea.CommandBindings.Add(new CommandBinding(SearchCommands.FindNext, (sender, e) => FindNext())); textArea.CommandBindings.Add(new CommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious())); textArea.CommandBindings.Add(new CommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close())); IsClosed = true; }
void AttachInternal(TextArea textArea) { this.textArea = textArea; adorner = new SearchPanelAdorner(textArea, this); DataContext = this; renderer = new SearchResultBackgroundRenderer(); currentDocument = textArea.Document; if (currentDocument != null) currentDocument.TextChanged += textArea_Document_TextChanged; textArea.DocumentChanged += textArea_DocumentChanged; KeyDown += SearchLayerKeyDown; this.CommandBindings.Add(new CommandBinding(SearchCommands.FindNext, (sender, e) => FindNext())); this.CommandBindings.Add(new CommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious())); this.CommandBindings.Add(new CommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close())); IsClosed = true; }