[Editing]

Gregor.Editing

Sunday, April 27, 2003

Gregor.Editing namespace

Utilities

Then, there are wrappers to keyboard APIs, as well as the infamous token lists used by the auto text namespace. Then, there is the CCharManager class, which is used by the syntax parsers from the Coloring sub namespace as well as the CAutoText class.

The CTextBoxPrinter class wraps up various objects needed for a rich printing experience (page setup, print preview, printer selection), and deals with writing the text contents from a text box into the printing DC (handling string drawing, line wrapping, page breaking - these things aren't done automatically anymore in .NET).

Extending RichTextBox

Mainly, this offers an extension of the RichTextBox control, incorporating methods that wrap edit messages, add special text introspection, allow cumulative text searches (with result lists), and so on. There's also a feature to add or remove indents on several lines (tabs or spaces, optionally). A property governs whether tabs the user enters are replaced by spaces. An instance of XRichEditor is needed in order to use the other functionality provided by this assembly.

More Enhancements

The sub namespaces under Gregor.Editing offer various editing helpers. These are, listed in order of growing intrusiveness:

Gregor.Editing.AutoConversion namespace

Automagic Text Mucking

Auto-converters assist the user while entering text by automatically completing code blocks or fixing typos. This is in the early stages: there's just a test implementation which completes VB.NET code blocks, but note that in an WebEdit.NET AddIn, you can readily extend the CAutoConverterBase class, filling the gaps.

Gregor.Editing.AutoText namespace

AutoText: like IntelliSense

This offers auto text functionality (lists that pop up on a rich text control). Entries are saved in a special list (which can be persisted). This feature can be used so as to record words the user enters, or simply suggest predefined entries.

Gregor.Editing.Coloring namespace

Syntax Coloring

Offers syntax parsing and coloring of the text. Syntax parsers are extensible, and can be obtained from a factory (based on file name extensions). Formatting info is separated from the parsing code (a parser will return a list of text ranges, which associate what I call a "range kind" object with a given section of text; there is a number of predefined range kinds, which may be extended - see the NRangeKinds collection).

Parser Class Hierarchy

The class hierarchy for parsers is as follows:

CSyntaxParserBase (abstract)
    CCommonSyntaxParser (abstract)
        CBasicSyntaxParser (abstract)
           CVbClassicSyntaxParser
           CVbnetSyntaxParser
        CCurlySyntaxParser (abstract)
            CCppSyntaxParser
            CCsSyntaxParser
            CJavaSyntaxParser
            CJsSyntaxParser
            CPlainCSyntaxParser
        CShellSyntaxParser
        CStyleSheetSyntaxParser
    CKeywordParser
    CLineParser
    CMarkupSyntaxParser (abstract)
        CHtmlSyntaxParser
        CXmlSyntaxParser

The CKeywordParser interface denotes a parser that supports keyword recognition, including the possibility to map keywords to different range kinds (thus using special formatting for different keywords). The difference between CCommonSyntaxParser and CKeywordParser is that the former knows about common programming language syntax features, such as preprocessor directives, block/line comments, and string literals, whereas the latter is suitable for highlighting keywords in any arbitrary text document in various ways.

The CLineParser class applies formats the entire lines in a text document, depending on the characters at the start of each line (configurable). It is useful for marking record-style documents. WebEdit.NET uses this for the "ToDo List" language, in which lines starting with hyphens, sharp signs, backslashes, and so on are assigned various stati, and colored accordingly.

The C++ syntax parser distinguishes between standard and vendor-defined keywords, with the option of ignoring the latter. In the future, the HTML syntax parser will support parsing embedded scripts or styles, by delegating to an appropriate parser buddy.

Gregor.Editing.EditAssistance namespace

High-Level Text Generation

Editing assistants help with generating text. The CCodeAssistantBase class works with code model classes provided by Gregor.Core, such as CMemberInfoEx and CTypeInfoEx. It provides certain methods for code generation (and possibly refactoring) that an application can call, such as ImlementInterface or OverrideMember. Note that, unlike the other editing helpers, code assistants are not directly tied to the XRichEditor control: it's up to the application to further process the generated text. Likewise, any GUI for a code assistant, if needed, must be provided by the application. WebEdit.NET lets the user set up code assistants through the languages configuration file, and invokes them through context menu items on the built-in assembly browser's control, provided by the CCodeAssistanceContextMenuProvider.

Gregor.Editing.Outlining namespace

Provides objects that create hierarchical outline of textual documents of certain types, such as XML documents or C# or VB.NET source files.