Property SearchGlobal
SearchGlobal
Gets or sets a value indicating whether search should be global.
public bool SearchGlobal { get; set; }
Property Value
Examples
Here is how to use a SearchGlobal in the C# code:
using System.Collections.Generic;
using System.Windows.Controls;
using Alternet.Editor;
public partial class MainWindow : Window
{
private IDictionary<TabItem, TextEditor> editors = new Dictionary<TabItem, TextEditor>();
private void Window_Loadeded(object sender, System.Windows.RoutedEventArgs e)
{
void NewEditor(string fileName)
{
TabItem page = new TabItem();
page.Header = fileName;
tcEditors.Items.Add(page);
TextEditor edit = new TextEditor();
editors.Add(page, edit);
page.Content = edit;
edit.LoadFile(fileName);
}
NewEditor("myfile1.txt");
NewEditor("myfile2.txt");
NewEditor("myfile3.txt");
SearchManager.SharedSearch.InitSearch += new InitSearchEvent(DoInitSearch);
SearchManager.SharedSearch.GetSearch += new GetSearchEvent(DoGetSearch);
}
private TextEditor GetEditor(TabItem key)
{
TextEditor result;
if (key != null && editors.TryGetValue(key, out result))
return result;
return null;
}
private void UpdateSearch()
{
TextEditor edit = GetEditor(tcEditors.SelectedItem as TabItem);
if (edit != null)
{
ISearch search = (ISearch)edit;
search.SearchGlobal = true;
}
}
private void DoInitSearch(object sender, InitSearchRoutedEventArgs e)
{
e.Search = GetEditor(tcEditors.SelectedItem as TabItem);
foreach (TextEditor edit in editors.Values)
{
edit.SearchGlobal = true;
if (edit.Source != null)
e.SearchList.Add(edit.Source.FileName);
}
}
private void DoGetSearch(object sender, GetSearchRoutedEventArgs e)
{
foreach (TabItem page in editors.Keys)
{
TextEditor edit = GetEditor(page);
if (edit != null && string.Compare(edit.Source.FileName, e.FileName, true) == 0)
{
tcEditors.SelectedItem = page;
UpdateSearch();
e.Search = (ISearch)edit;
break;
}
}
}
}
Here is how to use a SearchGlobal in the Visual Basic code:
Imports System.Collections.Generic
Imports System.Windows.Controls
Imports Alternet.Editor
Partial Public Class MainWindow
Private editors As IDictionary(Of TabItem, TextEditor) = New Dictionary(Of TabItem, TextEditor)()
Private Sub NewEditor(ByVal fileName As String)
Dim page As TabItem = New TabItem()
page.Header = fileName
tcEditors.Items.Add(page)
Dim edit As TextEditor = New TextEditor()
editors.Add(page, edit)
page.Content = edit
edit.LoadFile(fileName)
End Sub
Private Sub Window_Loadeded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
NewEditor("myfile1.txt")
NewEditor("myfile2.txt")
NewEditor("myfile3.txt")
AddHandler SearchManager.SharedSearch.InitSearch, New InitSearchEvent(AddressOf DoInitSearch)
AddHandler SearchManager.SharedSearch.GetSearch, New GetSearchEvent(AddressOf DoGetSearch)
End Sub
Private Function GetEditor(ByVal key As TabItem) As TextEditor
Dim result As TextEditor
If key IsNot Nothing AndAlso editors.TryGetValue(key, result) Then Return result
Return Nothing
End Function
Private Sub UpdateSearch()
Dim edit As TextEditor = GetEditor(TryCast(tcEditors.SelectedItem, TabItem))
If edit IsNot Nothing Then
Dim search As ISearch = CType(edit, ISearch)
search.SearchGlobal = True
End If
End Sub
Private Sub DoInitSearch(ByVal sender As Object, ByVal e As InitSearchRoutedEventArgs)
e.Search = GetEditor(TryCast(tcEditors.SelectedItem, TabItem))
For Each edit As TextEditor In editors.Values
edit.SearchGlobal = True
If edit.Source IsNot Nothing Then e.SearchList.Add(edit.Source.FileName)
Next
End Sub
Private Sub DoGetSearch(ByVal sender As Object, ByVal e As GetSearchRoutedEventArgs)
For Each page As TabItem In editors.Keys
Dim edit As TextEditor = GetEditor(page)
If edit IsNot Nothing AndAlso String.Compare(edit.Source.FileName, e.FileName, True) = 0 Then
tcEditors.SelectedItem = page
UpdateSearch()
e.Search = CType(edit, ISearch)
Exit For
End If
Next
End Sub
End Class
Remarks
Search and replace operations may be configured to be across multiple text documents. It's beneficial for searching for occurrences of the text within all files in the projects.
Set SearchGlobal to true to enable this feature. In this case, search and replace functionality is provided by the SearchManager instead of the particular TextEditor control instance.