[Journal - Searching for Text in WebEdit.NET]

Searching for Text in WebEdit.NET

Wednesday, January 18, 2006

I've reworked the text searching features in WebEdit.NET. So far, searching text was limited to the current document (using the Find Text tool window), or given folders in the file system (with the Find Files tool window).

The new approach is more generalized, with the ultimate aim of replacing the Find File window altogether. Everything is based on the classes in the new Gregor.Editing.Searching namespace, which abstract the concept of file/document to "Search Source", and the concept of directories (or any group of files) to "Search Scope". Thus, the whole thing is extensible.

For now, WebEdit.NET provides search scopes including:

For obtaining the text, the standard extension point of Document Storage Providers is used. This means, for example, if you have the DataDocs AddIn installed, you can search for text in databases.

Document storage providers are also used for obtaining additional search scopes. For now, the built-in Local Storage Provider provides a scope for the folder currently selected in the File Manager window.

Search operations include finding and replacing text, either in batch mode ("Find All"), or incrementally. The Find Text tool window looks rather slick by default for simply finding text in the current document. Additional toolbars appear for advanced options and scope selection.

Replacements are applied to storage items (ie., files are updated) as well as any open documents that correspond to them (ie., open files will reflect these changes right away). However, if the scope is one that always consists of open documents exclusively (as with the "Active Document" and "Open Documents" scopes), then changes are applied to these open documents only, marking them as changed. I figured this to be the most intelligent choice, so there are no other options, at least not now.

In addition to the "Match Case" and "Whole Word" options, there are some other search options:

Here's a little RegEx example for inserting properties for fields in C# classes:

// search text:
private ([\w]+) m_([\w]+);

// replacement:
$& public $1{ get{ return m_$2; } }

Note that character escapes, such as \n, do not seem to work in .NET RegEx substitution patterns, although they're supposed to; can you help me here?

Scope selection includes the following:

When using "Find All" or "Replace All", the results list provides details such as file names, line numbers, line texts (both new and original in the case of "Replace All"). Results may be grouped by line or by file. Results from previous searches can be retained, so it's possible to compile search results step-by-step.

There is also a list of recent search criteria and options, the last twenty or so of that list are persisted (WebEditSearches.xml). This means it's easy, for example, to redo a certain replacement, because both search string and replacement string as well as any options are bundled together.