Table of Contents

Property SearchGlobal

Namespace
Alternet.Editor
Assembly
Alternet.Editor.v9.dll

SearchGlobal

Gets or sets a value indicating whether search should be global.

public bool SearchGlobal { get; set; }

Property Value

bool

Examples

Here is how to use a SearchGlobal in the C# code:

using System.Collections.Generic;
using System.Windows.Forms;

using Alternet.Editor;

public partial class Form1 : Form
{
    private IDictionary<TabPage, ISyntaxEdit> editors = new Dictionary<TabPage, ISyntaxEdit>();

    private void Form1_Load(object sender, EventArgs e)
    {
        void NewEditor(string fileName)
        {
            TabPage page = new TabPage(fileName);
            tcEditors.TabPages.Add(page);
            ISyntaxEdit edit = new SyntaxEdit();
            editors.Add(page, edit);
            syntaxEdit1.LoadFile(fileName);
            edit.Dock = DockStyle.Fill;
            page.Controls.Add(edit as Control);
        }
        NewEditor("myfile1.txt");
        NewEditor("myfile2.txt");
        NewEditor("myfile3.txt");

        SearchManager.SharedSearch.InitSearch += new InitSearchEvent(DoInitSearch);
        SearchManager.SharedSearch.GetSearch += new GetSearchEvent(DoGetSearch);
    }

    private ISyntaxEdit GetEditor(TabPage key)
    {
        ISyntaxEdit result;
        if (key != null && editors.TryGetValue(key, out result))
            return result;
        return null;
    }

    private void UpdateSearch()
    {
        ISyntaxEdit edit = GetEditor(tcEditors.SelectedTab);
        if (edit != null)
        {
            ISearch search = (ISearch)edit;
            search.SearchGlobal = true;
        }
    }

    private void DoInitSearch(object sender, InitSearchEventArgs e)
    {
        e.Search = GetEditor(tcEditors.SelectedTab);
        foreach (ISyntaxEdit edit in editors.Values)
        {
            edit.SearchGlobal = searchMulti;
            if (edit.Source != null)
                e.SearchList.Add(edit.Source.FileName);
        }
    }

    private void DoGetSearch(object sender, GetSearchEventArgs e)
    {
        foreach (TabPage page in editors.Keys)
        {
            ISyntaxEdit edit = GetEditor(page);
            if (edit != null && string.Compare(edit.Source.FileName, e.FileName, true) == 0)
            {
                tcEditors.SelectedTab = 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.Forms
Imports Alternet.Editor

Partial Public Class Form1
    Inherits Form

    Private editors As IDictionary(Of TabPage, ISyntaxEdit) = New Dictionary(Of TabPage, ISyntaxEdit)()

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        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 Sub NewEditor(ByVal fileName As String)
        Dim page As TabPage = New TabPage(fileName)
        tcEditors.TabPages.Add(page)
        Dim edit As ISyntaxEdit = New SyntaxEdit()
        editors.Add(page, edit)
        syntaxEdit1.LoadFile(fileName)
        edit.Dock = DockStyle.Fill
        page.Controls.Add(TryCast(edit, Control))
    End Sub

    Private Function GetEditor(ByVal key As TabPage) As ISyntaxEdit
        Dim result As ISyntaxEdit
        If key IsNot Nothing AndAlso editors.TryGetValue(key, result) Then
            Return result
        End If
        Return Nothing
    End Function

    Private Sub UpdateSearch()
        Dim edit As ISyntaxEdit = GetEditor(tcEditors.SelectedTab)

        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 InitSearchEventArgs)
        e.Search = GetEditor(tcEditors.SelectedTab)

        For Each edit As ISyntaxEdit In editors.Values
            edit.SearchGlobal = searchMulti
            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 GetSearchEventArgs)
        For Each page As TabPage In editors.Keys
            Dim edit As ISyntaxEdit = GetEditor(page)

            If edit IsNot Nothing AndAlso String.Compare(edit.Source.FileName, e.FileName, True) = 0 Then
                tcEditors.SelectedTab = 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 project files.

Set SearchGlobal to true to enable this feature. In this case, search and replace functionality is provided by the SearchManager instead of the particular SyntaxEdit control instance.