Posted 14 years ago by BTAC Developer
Avatar
Are there any plans to include support for Visual Studio 2005's 'Code Snippet' Technology within SyntaxEditor?

Comments (26)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes, that is on our TODO list. Thanks for the suggestion though!


Actipro Software Support

Posted 14 years ago by Boyd - Automated Software Testing Consultant / Developer, Patterson Consulting, LLC
Avatar
Derek,

If you don't want to wait until the feature is implemented, the latest release of Syntax Editor includes all the features you need to implement this on your own. The KeyTyping event can be used to trap the 'tab' key used to expand and CodeSnippet, and custom SpanIndicators can be used to mark the individual fields.
Posted 14 years ago by BTAC Developer
Avatar
I don't understand. I'm not sure how the SpanIndicator could help me ..I'd need to create a field with a visual border and stuff and make it tabbable ...which doesn't seem possible. I cannot find any useful documentation on the SpanIndicator class either other than the member list, which is useless.
Posted 14 years ago by Boyd - Automated Software Testing Consultant / Developer, Patterson Consulting, LLC
Avatar
You create a custom SpanIndicator class that is used to draw the highlighted background and border. You'll have to handle tab navigation yourself by trapping the Tab key in the KeyTyping event.

You'll need Three SpanIndicators to copy VS 2005:

1) Active Field with colored background and black border
2) Non-active Field with colored background and no border
3) Secondary instances of Active Field with no background and dashed border

Within the KeyTyping event, you'll need to determine if you're currently inside one of your SpanIndicators. If so, you need to cancel the Tab key operation and move the caret to the next SpanIndicator for an active field. You'll also need to trap the Esc key to cancel the CodeSnippet mode.

This process wasn't easy to implement (took me about 12 hours to design and test), but does work. If you're new to SyntaxEditor, you may want to wait on this feature until you're more familiar with the tool (or until it's part of the SyntaxEditor product).
Posted 14 years ago by BTAC Developer
Avatar
Alright. I'm still confused on how to user the SpanIndicator. Is there a sample or tutorial of it somewhere that I can look at to get a feel for how it works?

It's an abstract class, so I've tried inheriting it and it still doesn't like to work. I cannot find any sample usage code of it anywhere, so I'm really stumped.

[Modified at 08/03/2005 09:08 AM]
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
There are some samples on span indicator implementation in this forum. Use the forum search to find them.

The sample app shows how to instantiate some pre-packaged ones like when you click in the indicator margin.


Actipro Software Support

Posted 14 years ago by BTAC Developer
Avatar
I'll keep trying ..but the documentation for it is still pretty poor. I think it could really use some actual documentation in the future. A lot of SyntaxEditor has very weak documentation that makes it very hard to get into..
Posted 14 years ago by BTAC Developer
Avatar
There doesn't seem to be a way to give a border color to the HighlightingStyle method of SpanIndicator. Any suggestions? So far I've got an Inherited SpanIndicator that just highlights the right portion of code. =/
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Right for that you'd have to override the DrawMarks method and just draw a rectangle around the bounds.
/// <summary>
/// Draws the marks associated with the indicator.
/// </summary>
/// <param name="g">The <c>Graphics</c> object to use for drawing.</param>
/// <param name="bounds">A <c>Rectangle</c> specifying the bounds in which to draw.</param>
/// <remarks>This method should be implemented by indicators that have adornments.</remarks>
protected internal abstract void DrawMarks(Graphics g, Rectangle bounds);


Actipro Software Support

Posted 14 years ago by BTAC Developer
Avatar
Yeah, that's what I'm trying ...this is what I've got, but it doesn't seem to do the trick.

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using ActiproSoftware.Drawing;

namespace ActiproSoftware.SyntaxEditor
{

    /// &lt;summary&gt;
    /// Represents a breakpoint indicator.
    /// &lt;/summary&gt;
    public class SelectionIndicator : SpanIndicator
    {

        private static int defaultDisplayPriority;

        private Color backColor;
        private Color foreColor;

        /// &lt;summary&gt;
        /// Initializes a static instance of the &lt;c&gt;BreakpointIndicator&lt;/c&gt; class.
        /// &lt;/summary&gt;
        static SelectionIndicator ( )
        {
            defaultDisplayPriority = 20;
        }

        /// &lt;summary&gt;
        /// Initializes a new instance of the &lt;c&gt;BreakpointIndicator&lt;/c&gt; class.
        /// &lt;/summary&gt;
        public SelectionIndicator ( )
            :
            this ( SelectionIndicator.DefaultName, SelectionIndicator.DefaultDisplayPriority, Color.White, Color.Maroon )
        {
        }

        /// &lt;summary&gt;
        /// Initializes a new instance of the &lt;c&gt;BreakpointIndicator&lt;/c&gt; class with a custom name and color scheme.
        /// &lt;/summary&gt;
        /// &lt;param name="name"&gt;The name to identify the type of indicator.&lt;/param&gt;
        /// &lt;param name="displayPriority"&gt;The priority of display level for the indicator.&lt;/param&gt;
        /// &lt;param name="foreColor"&gt;The &lt;c&gt;Color&lt;/c&gt; to use when drawing the foreground of the indicator.&lt;/param&gt;
        /// &lt;param name="backColor"&gt;The &lt;c&gt;Color&lt;/c&gt; to use when drawing the background of the indicator.&lt;/param&gt;
        public SelectionIndicator ( string name, int displayPriority, Color foreColor, Color backColor )
            :
            base ( name, displayPriority, true, IndicatorMarks.StyleAssignment )
        {

            // Initialize parameters
            this.backColor = backColor;
            this.foreColor = foreColor;
        }

        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// &lt;summary&gt;
        /// Gets or sets the default priority of display level for the newly created indicators of this class.
        /// &lt;/summary&gt;
        /// &lt;value&gt;
        /// The priority of display level for the newly created indicators of this class.
        /// The default value is &lt;c&gt;20&lt;/c&gt;.
        /// &lt;/value&gt;
        /// &lt;remarks&gt;
        /// Indicators with the lowest priority numbers are painted first with other indicators 
        /// painted on top in increasing priority order.
        /// &lt;/remarks&gt;
        public static int DefaultDisplayPriority
        {
            get
            {
                return defaultDisplayPriority;
            }
            set
            {
                defaultDisplayPriority = value;
            }
        }

        /// &lt;summary&gt;
        /// Gets the default name for a breakpoint.
        /// &lt;/summary&gt;
        /// &lt;value&gt;The default name for a breakpoint.&lt;/value&gt;
        public static string DefaultName
        {
            get
            {
                return "Selection";
            }
        }

        /// &lt;summary&gt;
        /// Draws the glyph associated with the indicator.
        /// &lt;/summary&gt;
        /// &lt;param name="g"&gt;The &lt;c&gt;Graphics&lt;/c&gt; object to use for drawing.&lt;/param&gt;
        /// &lt;param name="bounds"&gt;A &lt;c&gt;Rectangle&lt;/c&gt; specifying the bounds in which to draw.&lt;/param&gt;
        protected override void DrawGlyph ( Graphics g, Rectangle bounds )
        {
        } 

        /// &lt;summary&gt;
        /// Draws the marks associated with the indicator.
        /// &lt;/summary&gt;
        /// &lt;param name="g"&gt;The &lt;c&gt;Graphics&lt;/c&gt; object to use for drawing.&lt;/param&gt;
        /// &lt;param name="bounds"&gt;A &lt;c&gt;Rectangle&lt;/c&gt; specifying the bounds in which to draw.&lt;/param&gt;
        protected override void DrawMarks ( Graphics g, Rectangle bounds )
        {
            bounds.Inflate ( 2, 2 );
            g.DrawRectangle ( new Pen(Brushes.Black,5f), bounds );
        }

        /// &lt;summary&gt;
        /// Returns the &lt;see cref="HighlightingStyle"/&gt; to use when drawing text within the indicator.
        /// &lt;/summary&gt;
        /// &lt;returns&gt;The &lt;see cref="HighlightingStyle"/&gt; to use when drawing text within the indicator.&lt;/returns&gt;
        /// &lt;remarks&gt;This method should be implemented by indicators that have a style assignment.&lt;/remarks&gt;
        protected override HighlightingStyle GetHighlightingStyle ( )
        {
            return new HighlightingStyle ( "SelectionStyle", "Selection", foreColor, backColor, false, false, false );
        }
    }
}

Posted 14 years ago by BTAC Developer
Avatar
Alright, making some progress. The Constructor needed the following..

IndicatorMarks.Adornments;

However the problem is that the bounds are too big. Let me try some deflating and stuff.. I'm still not sure if this will work right, but I hope it will.

Hrnm. Well, leaving the bounds at the default size doesn't work. The bottom line is cut off. The rectangle area simply isn't big enough. Any suggestions there?

Nevermind. I got it. I just had to pass each parameter of the rectangle. I was thinking it would be more complex than that. Alright, this should get me started. Thanks a lot for your help, I'll keep trying and post back if I have any more big problems.

[Modified at 08/03/2005 09:52 AM]

[Modified at 08/03/2005 10:00 AM]
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes this is what I consider to be a longstanding bug with GDI. The bounds we pass are the correct bounds. If you call Graphics.FillRectangle and pass the bounds, they fill correctly. However if you call Graphics.DrawRectangle and pass the bounds, it draws the left/top lines correctly but moves the right/bottom lines out one pixel. I have no idea why Microsoft implemented things that way.

So we always end up doing what you found and doing something like:
g.DrawRectangle(bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1);
It's silly that that is necessary but that's how Microsoft chose to make things work.


Actipro Software Support

Posted 14 years ago by BTAC Developer
Avatar
So can I enforce an Indicator on text that is not selected? Ideally, I'd like to be able to 'expand' a segment of code and then tell it what to highlight. Is that possible?
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You should probably override this property... By default it is false. You probably want it true for your situation.
/// <summary>
/// Gets whether to expand the span indicator when typing is performed on the boundary of the indicator.
/// </summary>
/// <value>
/// <c>true</c> if the span indicator should expand; otherwise, <c>false</c>.
/// </value>
/// <remarks>
/// The default value is <c>false</c>.
/// </remarks>
protected internal virtual bool ExpandOnBoundaries {
    get {
        return false;
    }
}


Actipro Software Support

Posted 14 years ago by BTAC Developer
Avatar
Woah, yeah. Thanks. That will help a lot.
Posted 14 years ago by BTAC Developer
Avatar
Alright. This is what I've got so far. I've got three different methods for the "Trigger" event. -.- -- I've got it to do the highlighting, but I'm still very confused about how the Tokens work. I want it to not re-highlight something if the $ is deleted and then re-added, and I want it to track it properly...

using System;
using System.Drawing;
using System.Windows.Forms;

using ActiproSoftware.SyntaxEditor;
using System.Collections.Generic;

namespace System.Windows.Forms.Snippets.Editor
{
    public enum Language
    {
        /// <summary>
        /// Defines the Microsoft C# Language.
        /// </summary>
        CS,

        /// <summary>
        /// Defines the World Wide Web Consortium Cascading Style Sheets Language.
        /// </summary>
        CSS,

        /// <summary>
        /// Defines the World Wide Web Consortium Hypertext Markup Language.
        /// </summary>
        HTML,

        /// <summary>
        /// Defines the Sun Microsystems Java Language.
        /// </summary>
        JAVA,

        /// <summary>
        /// Defines the standard INI Condiguration File Language.
        /// </summary>
        INI,

        /// <summary>
        /// Defines the World Wide Web Consortium JavaScript Language.
        /// </summary>
        JS,

        /// <summary>
        /// Defines the Perl Language.
        /// </summary>
        PERL,

        /// <summary>
        /// Defines the Postback Hypertext Language (PHP).
        /// </summary>
        PHP,

        /// <summary>
        /// Defines the Python Language.
        /// </summary>
        PYTHON,

        /// <summary>
        /// Defines the Server Query Language (MSSQL).
        /// </summary>
        SQL,

        /// <summary>
        /// Defines the Microsoft Visual Basic .NET Language.
        /// </summary>
        VBNET,

        /// <summary>
        /// Defines the World Wide Web Consortium Extensible Markup Language (XML).
        /// </summary>
        XML,

        /// <summary>
        /// Defines the Microsoft Visual Basic Script Language.
        /// </summary>
        VBSCRIPT
    }

    /// <summary>
    /// The Syntax Editor Control is a pre-defined SyntaxEditor with
    /// methods and event handlers predefined for using within class
    /// files.
    /// </summary>
    public sealed partial class SyntaxEditorControl : UserControl
    {
        // ====================================================== //
        //                       CLASS CONSTRUCTORS                  //
        // ====================================================== //

        /// <summary>
        /// Constructs a new SyntaxEditorControl.
        /// </summary>
        public SyntaxEditorControl ( )
        {
            //
            // Required for the Windows Form Designer
            //
            InitializeComponent ( );
            list.Add ( "A" );
            list.Add ( "B" );
            list.Add ( "C" );
        }

        // ====================================================== //
        //                        EVENT HANDLERS                      //
        // ====================================================== //

        private List<string> list = new List<string> ( );

        private void KeyStroke ( object sender, ActiproSoftware.SyntaxEditor.TriggerEventArgs e )
        {
            switch ( e.Trigger.Key )
            {
                case "MemberListTrigger":

                    // Construct the Full Name of the Item -- This is to test
                    // Reflection and Iteration of the DataType in a KeySteam

                    ActiproSoftware.SyntaxEditor.TokenStream ActiproTokenStream =
                        SyntaxEditor.Document.GetTokenStream
                            (
                        // iterate the ActiproTokens of the current view -- select the currently focused ActiproToken and the
                        // ActiproToken next to it for full parsing support.
                                SyntaxEditor.Document.Tokens.IndexOf
                                    ( SyntaxEditor.SelectedView.Selection.EndOffset + 1 )
                            );


                    // Design a String to Hold the Full Lexical Name of the Token
                    // As well as the number of periods in the Token Stream
                    String TokenName = String.Empty; Int32 Periods = 0;

                    // Iterate the Entire Tokenized Stream from Beginning to End
                    while ( ActiproTokenStream.Position > 0 )
                    {
                        // Iterate each Token of the Stream and Assign it
                        ActiproSoftware.SyntaxEditor.Token ActiproToken =
                            ActiproTokenStream.ReadReverse ( );

                        // Determine the Token Key
                        switch ( ActiproToken.Key )
                        {
                            // if the ActiproToken is a punctuation mark, such as a '.', or a ',' then
                            // it should be treated as a delimiter ActiproToken by the syntax editors.
                            case "PunctuationToken":
                                if ( ( ActiproToken.Length == 1 ) && ( SyntaxEditor.Document.GetTokenText ( ActiproToken ) == "$" ) )
                                {
                                    try
                                    {
                                        if ( ActiproTokenStream.Length > 0 && ActiproTokenStream.PeekReverse ( ).IsWhitespace )
                                            TokenName = SyntaxEditor.Document.GetTokenText ( ActiproToken ) + TokenName;
                                        else
                                        {
                                            while ( !ActiproTokenStream.PeekReverse().IsWhitespace )
                                            {
                                                ActiproToken = ActiproTokenStream.ReadReverse ( );
                                                TokenName = SyntaxEditor.Document.GetTokenText ( ActiproToken ) + TokenName;
                                            }

                            
                                            //ActiproTokenStream.Position = 0; // PLACE CODE RIGHT HERE FOR HIGHLIGHTING!!!!
                                            // Add a breakpoint to the line
                                        syntaxEditor.Document.Indicators.Add ( new SelectionIndicator ( ),
                                            ActiproToken.StartOffset , TokenName.Length + 1 );

                                        TokenName = "";
                                        }
                                        
                                    }
                                    catch
                                    {
                                        TokenName = SyntaxEditor.Document.GetTokenText ( ActiproToken ) + TokenName;
                                    }
                                }
                                else
                                    // Return to the Beginning of the Stream
                                    ActiproTokenStream.Position = 0;
                                break;

                            default:
                                // Return to the Beginning of the Stream
                                ActiproTokenStream.Position = 0;
                                break;
                        }
                    }

                    // if a full ActiproToken name is found, then there are a number of options
                    // we can do, such as display the intellisense using reflection list
                    if ( TokenName.Length > 0 )
                    {
                        // Get the MemberList for the IntelliSense ListBox
                        IntelliPromptMemberList intellisenseMemberList =
                            SyntaxEditor.IntelliPrompt.MemberList;

                        // Specify the IntelliPrompt ImageList
                        intellisenseMemberList.ImageList = SyntaxEditor.ReflectionImageList;

                        // Clear the Existing List so that Items can be Added to it Later
                        intellisenseMemberList.Clear ( );

                        foreach ( string s in list )
                            intellisenseMemberList.Add ( new IntelliPromptMemberListItem ( s, 0 ) );

                        // Show the Finalized Member List
                        if ( intellisenseMemberList.Count > 0 )
                            intellisenseMemberList.Show ( );
                    }

                    break;
                default:
                    break;
            }
        }

/*
        /// <summary>
        /// Raised whenever a keystroke is entered in the editor window.
        /// </summary>
        /// <param name="sender">Object that triggered the event.</param>
        /// <param name="e">TriggerEventArgs to handle the event.</param>
        private void KeyStroke ( object sender, ActiproSoftware.SyntaxEditor.TriggerEventArgs e )
        {
            //
            // Determine the Language Key that the Editor Uses
            //
            switch ( SyntaxEditor.Document.Language.Key )
            {
                case "C#":

                    //
                    // Determine the Key that was Pressed
                    // to provide proper intellisense and
                    // syntax controls for the mouse edit
                    //

                    switch ( e.Trigger.Key )
                    {
                        //
                        // Determine if the Key Pressed is a "MemberList" Key, which
                        // means that the key is part of the C# Language Definition.
                        //
                        case "MemberListTrigger":

                            // Construct the Full Name of the Item -- This is to test
                            // Reflection and Iteration of the DataType in a KeySteam

                            ActiproSoftware.SyntaxEditor.TokenStream ActiproTokenStream =
                                SyntaxEditor.Document.GetTokenStream
                                    (
                                // iterate the ActiproTokens of the current view -- select the currently focused ActiproToken and the
                                // ActiproToken next to it for full parsing support.
                                        SyntaxEditor.Document.Tokens.IndexOf
                                            ( SyntaxEditor.SelectedView.Selection.EndOffset + 1 )
                                    );

                            // Design a String to Hold the Full Lexical Name of the Token
                            // As well as the number of periods in the Token Stream
                            String TokenName = String.Empty; Int32 Periods = 0;

                            // Iterate the Entire Tokenized Stream from Beginning to End
                            while ( ActiproTokenStream.Position > 0 )
                            {
                                // Iterate each Token of the Stream and Assign it
                                ActiproSoftware.SyntaxEditor.Token ActiproToken =
                                    ActiproTokenStream.ReadReverse ( );

                                // Determine the Token Key
                                switch ( ActiproToken.Key )
                                {

                                    case "IdentifierToken":
                                        // Return to the Beginning of the Stream
                                        ActiproTokenStream.Position = 0;
                                        break;

                                    case "NativeTypeToken":
                                
                                        // If the Token is an Identifier or a Native .NET Type
                                        // Then Simply Assign the Full Token Text to the TokenName
//                                        TokenName = SyntaxEditor.Document.GetTokenText ( ActiproToken ) + TokenName;
                                        // Return to the Beginning of the Stream
                                        ActiproTokenStream.Position = 0;
                                        MessageBox.Show ( "TEST" );
                                        break;

                                    // if the ActiproToken is a punctuation mark, such as a '.', or a ',' then
                                    // it should be treated as a delimiter ActiproToken by the syntax editors.
                                    case "PunctuationToken":
                                        if ( ( ActiproToken.Length == 1 ) && ( SyntaxEditor.Document.GetTokenText ( ActiproToken ) == "$" ) )
                                        {
                                            try
                                            {
                                                if ( ActiproTokenStream.Length > 0 && ActiproTokenStream.PeekReverse ( ).IsWhitespace )
                                                    TokenName = SyntaxEditor.Document.GetTokenText ( ActiproToken )+TokenName;
                                                else
                                                    break;
                                            }
                                            catch
                                            {
                                                TokenName = SyntaxEditor.Document.GetTokenText ( ActiproToken ) + TokenName;
                                            }
                                        }
                                        else
                                            // Return to the Beginning of the Stream
                                            ActiproTokenStream.Position = 0;
                                        break;

                                    default:
                                        // Return to the Beginning of the Stream
                                        ActiproTokenStream.Position = 0;
                                        break;
                                }

    //                            MessageBox.Show ( TokenName );

                            }


                            // if a full ActiproToken name is found, then there are a number of options
                            // we can do, such as display the intellisense using reflection list
                            if ( TokenName.Length > 0 )
                            {
                                // Get the MemberList for the IntelliSense ListBox
                                IntelliPromptMemberList intellisenseMemberList =
                                    SyntaxEditor.IntelliPrompt.MemberList;

                                // Specify the IntelliPrompt ImageList
                                intellisenseMemberList.ImageList = SyntaxEditor.ReflectionImageList;

                                // Clear the Existing List so that Items can be Added to it Later
                                intellisenseMemberList.Clear ( );

                                foreach ( string s in list )
                                    intellisenseMemberList.Add(new IntelliPromptMemberListItem(s,0));

                                /*
                                // Use Reflection to Get the Assembly Contents
                                Reflection.Assembly[ ] ReflectedAssemblies =
                                    AppDomain.CurrentDomain.GetAssemblies ( );

                                // Iterate the Reflected Assemblies
                                foreach ( Reflection.Assembly ReflectedAssemblyData in ReflectedAssemblies )
                                {
                                    // Retrieve the Assembly Type from Reflection
                                    Type AssemblyType =
                                        ReflectedAssemblyData.GetType ( TokenName, false, false );

                                    if ( AssemblyType != null )
                                    {
                                        intellisenseMemberList.AddReflectionForTypeMembers ( AssemblyType, IntelliPromptTypeMemberFlags.AllMemberTypes |
                                                IntelliPromptTypeMemberFlags.AllAccessTypes | IntelliPromptTypeMemberFlags.Static );
                                        break;
                                    }
                                }
                                
                                // If No Assembly Type can be Found ---
                                if ( intellisenseMemberList.Count == 0 )
                                {
                                    // Then we Assume a Namespace Assembly
                                    System.Collections.Specialized.StringCollection clcNamespaces =
                                        new System.Collections.Specialized.StringCollection ( );

                                    // Append the Token Name to the Namespace Collection
                                    clcNamespaces.Add ( TokenName );

                                    // Create an Array of Flags for Assemblies -- 
                                    IntelliPromptNamespaceAndTypeFlags[ ] intelliFlags =
                                        new IntelliPromptNamespaceAndTypeFlags[ ReflectedAssemblies.Length ];

                                    // This Assumes only Public Namespaces
                                    for ( int index = 0; index < intelliFlags.Length; index++ )
                                        intelliFlags[ index ] = IntelliPromptNamespaceAndTypeFlags.NamespacesAndTypes | IntelliPromptNamespaceAndTypeFlags.Public;

                                    // Use a Reflection Helper Method
                                    intellisenseMemberList.AddReflectionForAssemblyNamespacesAndTypes ( ReflectedAssemblies, intelliFlags, clcNamespaces, null, false );

                                    // Iterate the Items and Add the Descriptions and ToolTip Data
                                    foreach ( IntelliPromptMemberListItem Item in intellisenseMemberList )
                                    {
                                        if ( Item.ImageIndex == ( int )ActiproSoftware.Products.SyntaxEditor.IconResource.Namespace )
                                            Item.Description = String.Format ( "namespace <b>{0}</b>", Item.Tag.ToString ( ) );
                                        else if ( Item.Tag is Type )
                                        {
                                            // Get the Type of Item
                                            Type ItemType = ( Type )Item.Tag;
                                            if ( ItemType.IsEnum )
                                                Item.Description = String.Format ( "enum <b>{0}</b>", ItemType.FullName );
                                            else if ( ItemType.IsInterface )
                                                Item.Description = String.Format ( "interface <b>{0}</b>", ItemType.FullName );
                                            else if ( ItemType.IsValueType )
                                                Item.Description = String.Format ( "struct <b>{0}</b>", ItemType.FullName );
                                            else if ( ItemType.IsSubclassOf ( typeof ( Delegate ) ) )
                                                Item.Description = String.Format ( "delegate <b>{0}</b>", ItemType.FullName );
                                            else
                                                Item.Description = String.Format ( "class <b>{0}</b>", ItemType.FullName );
                                        }
                                    }
                                }

                                // Show the Finalized Member List
                                if ( intellisenseMemberList.Count > 0 )
                                    intellisenseMemberList.Show ( );
                            }
                            break;
                    }
                    break;
            }
        }
/*
        /// <summary>
        /// Raised whenever a keystroke is entered in the editor window.
        /// </summary>
        /// <param name="sender">Object that triggered the event.</param>
        /// <param name="e">TriggerEventArgs to handle the event.</param>
        private void KeyStroke ( object sender, ActiproSoftware.SyntaxEditor.TriggerEventArgs e )
        {
            //
            // Determine the Language Key that the Editor Uses
            //
            switch ( SyntaxEditor.Document.Language.Key )
            {
                case "C#":

                    //
                    // Determine the Key that was Pressed
                    // to provide proper intellisense and
                    // syntax controls for the mouse edit
                    //

                    switch ( e.Trigger.Key )
                    {
                        //
                        // Determine if the Key Pressed is a "MemberList" Key, which
                        // means that the key is part of the C# Language Definition.
                        //
                        case "MemberListTrigger":

                            // Construct the Full Name of the Item -- This is to test
                            // Reflection and Iteration of the DataType in a KeySteam

                            ActiproSoftware.SyntaxEditor.TokenStream ActiproTokenStream =
                                SyntaxEditor.Document.GetTokenStream
                                    (
                                // iterate the ActiproTokens of the current view -- select the currently focused ActiproToken and the
                                // ActiproToken next to it for full parsing support.
                                        SyntaxEditor.Document.Tokens.IndexOf
                                            ( SyntaxEditor.SelectedView.Selection.EndOffset - 1 )
                                    );

                            // Design a String to Hold the Full Lexical Name of the Token
                            // As well as the number of periods in the Token Stream
                            String TokenName = String.Empty; Int32 Periods = 0;

                            // Iterate the Entire Tokenized Stream from Beginning to End
                            while ( ActiproTokenStream.Position > 0 )
                            {
                                // Iterate each Token of the Stream and Assign it
                                ActiproSoftware.SyntaxEditor.Token ActiproToken =
                                    ActiproTokenStream.ReadReverse ( );

                                // Determine the Token Key
                                switch ( ActiproToken.Key )
                                {

                                    case "IdentifierToken":
                                    case "NativeTypeToken":
                                        // If the Token is an Identifier or a Native .NET Type
                                        // Then Simply Assign the Full Token Text to the TokenName
                                        TokenName = SyntaxEditor.Document.GetTokenText ( ActiproToken ) + TokenName;

                                        break;

                                    // if the ActiproToken is a punctuation mark, such as a '.', or a ',' then
                                    // it should be treated as a delimiter ActiproToken by the syntax editors.
                                    case "PunctuationToken":
                                        if ( ( ActiproToken.Length == 1 ) && ( SyntaxEditor.Document.GetTokenText ( ActiproToken ) == "." ) )
                                        {
                                            TokenName = SyntaxEditor.Document.GetTokenText ( ActiproToken ) + TokenName;
                                            // Increment the Period Count
                                            Periods++;
                                        }
                                        else
                                            // Return to the Beginning of the Stream
                                            ActiproTokenStream.Position = 0;
                                        break;

                                    default:
                                        // Return to the Beginning of the Stream
                                        ActiproTokenStream.Position = 0;
                                        break;
                                }

                            }

                            // Convert the FullText Names of Common Token Types
                            if ( ( TokenName.Length > 0 ) && ( Periods == 0 ) )
                            {
                                switch ( TokenName )
                                {
                                    case "bool":
                                        TokenName = "System.Boolean";
                                        break;
                                    case "byte":
                                        TokenName = "System.Byte";
                                        break;
                                    case "char":
                                        TokenName = "System.Char";
                                        break;
                                    case "decimal":
                                        TokenName = "System.Decimal";
                                        break;
                                    case "double":
                                        TokenName = "System.Double";
                                        break;
                                    case "short":
                                        TokenName = "System.Int16";
                                        break;
                                    case "int":
                                        TokenName = "System.Int32";
                                        break;
                                    case "long":
                                        TokenName = "System.Int64";
                                        break;
                                    case "object":
                                        TokenName = "System.Object";
                                        break;
                                    case "sbyte":
                                        TokenName = "System.SByte";
                                        break;
                                    case "float":
                                        TokenName = "System.Single";
                                        break;
                                    case "string":
                                        TokenName = "System.String";
                                        break;
                                    case "ushort":
                                        TokenName = "System.UInt16";
                                        break;
                                    case "uint":
                                        TokenName = "System.UInt32";
                                        break;
                                    case "ulong":
                                        TokenName = "System.UInt64";
                                        break;
                                    case "void":
                                        TokenName = "System.Void";
                                        break;
                                }
                            }

                            // if a full ActiproToken name is found, then there are a number of options
                            // we can do, such as display the intellisense using reflection list
                            if ( TokenName.Length > 0 )
                            {
                                // Get the MemberList for the IntelliSense ListBox
                                IntelliPromptMemberList intellisenseMemberList =
                                    SyntaxEditor.IntelliPrompt.MemberList;

                                // Specify the IntelliPrompt ImageList
                                intellisenseMemberList.ImageList = SyntaxEditor.ReflectionImageList;

                                // Clear the Existing List so that Items can be Added to it Later
                                intellisenseMemberList.Clear ( );

                                // Use Reflection to Get the Assembly Contents
                                Reflection.Assembly[ ] ReflectedAssemblies =
                                    AppDomain.CurrentDomain.GetAssemblies ( );

                                // Iterate the Reflected Assemblies
                                foreach ( Reflection.Assembly ReflectedAssemblyData in ReflectedAssemblies )
                                {
                                    // Retrieve the Assembly Type from Reflection
                                    Type AssemblyType =
                                        ReflectedAssemblyData.GetType ( TokenName, false, false );

                                    if ( AssemblyType != null )
                                    {
                                        intellisenseMemberList.AddReflectionForTypeMembers ( AssemblyType, IntelliPromptTypeMemberFlags.AllMemberTypes |
                                                IntelliPromptTypeMemberFlags.AllAccessTypes | IntelliPromptTypeMemberFlags.Static );
                                        break;
                                    }
                                }

                                // If No Assembly Type can be Found ---
                                if ( intellisenseMemberList.Count == 0 )
                                {
                                    // Then we Assume a Namespace Assembly
                                    System.Collections.Specialized.StringCollection clcNamespaces =
                                        new System.Collections.Specialized.StringCollection ( );

                                    // Append the Token Name to the Namespace Collection
                                    clcNamespaces.Add ( TokenName );

                                    // Create an Array of Flags for Assemblies -- 
                                    IntelliPromptNamespaceAndTypeFlags[ ] intelliFlags =
                                        new IntelliPromptNamespaceAndTypeFlags[ ReflectedAssemblies.Length ];

                                    // This Assumes only Public Namespaces
                                    for ( int index = 0; index < intelliFlags.Length; index++ )
                                        intelliFlags[ index ] = IntelliPromptNamespaceAndTypeFlags.NamespacesAndTypes | IntelliPromptNamespaceAndTypeFlags.Public;

                                    // Use a Reflection Helper Method
                                    intellisenseMemberList.AddReflectionForAssemblyNamespacesAndTypes ( ReflectedAssemblies, intelliFlags, clcNamespaces, null, false );

                                    // Iterate the Items and Add the Descriptions and ToolTip Data
                                    foreach ( IntelliPromptMemberListItem Item in intellisenseMemberList )
                                    {
                                        if ( Item.ImageIndex == ( int )ActiproSoftware.Products.SyntaxEditor.IconResource.Namespace )
                                            Item.Description = String.Format ( "namespace <b>{0}</b>", Item.Tag.ToString ( ) );
                                        else if ( Item.Tag is Type )
                                        {
                                            // Get the Type of Item
                                            Type ItemType = ( Type )Item.Tag;
                                            if ( ItemType.IsEnum )
                                                Item.Description = String.Format ( "enum <b>{0}</b>", ItemType.FullName );
                                            else if ( ItemType.IsInterface )
                                                Item.Description = String.Format ( "interface <b>{0}</b>", ItemType.FullName );
                                            else if ( ItemType.IsValueType )
                                                Item.Description = String.Format ( "struct <b>{0}</b>", ItemType.FullName );
                                            else if ( ItemType.IsSubclassOf ( typeof ( Delegate ) ) )
                                                Item.Description = String.Format ( "delegate <b>{0}</b>", ItemType.FullName );
                                            else
                                                Item.Description = String.Format ( "class <b>{0}</b>", ItemType.FullName );
                                        }
                                    }
                                }

                                // Show the Finalized Member List
                                if ( intellisenseMemberList.Count > 0 )
                                    intellisenseMemberList.Show ( );
                            }
                            break;

                        //
                        // Determine if the Key Pressed is an "XmlComment" Key, which
                        // means that the key belongs to those used for xml comments.
                        //
                        case "XMLCommentTagListTrigger":
                            // Retrieve the IntelliSense Member List
                            IntelliPromptMemberList intelliMemberList =
                                SyntaxEditor.IntelliPrompt.MemberList;

                            // Set IntelliPrompt ImageList
                            intelliMemberList.ImageList =
                                SyntaxEditor.ReflectionImageList;

                            // Append Items to the MemberList
                            int intImageIndex =
                                ( int )ActiproSoftware.Products.SyntaxEditor.IconResource.Keyword;

                            // Clear the Intellisense Member List
                            intelliMemberList.Clear ( );

                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "c", intImageIndex, "Indicates that text within the tag should be marked as code.  Use &lt;code&gt; to indicate multiple lines as code." ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "code", intImageIndex, "Indicates multiple lines as code. Use &lt;c&gt; to indicate that text within a description should be marked as code." ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "example", intImageIndex, "Specifies an example of how to use a method or other library member." ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "exception", intImageIndex, "Specifies which exceptions a class can throw.", "exception cref=\"", "\"" ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "include", intImageIndex, "Refers to comments in another file that describe the types and members in your source code.", "include file='", "' path='[@name=\"\"]'/>" ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "list", intImageIndex, "Provides a container for list items.", "list type=\"", "\"" ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "listheader", intImageIndex, "Defines the heading row of either a table or definition list." ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "item", intImageIndex, "Defines an item in a table or definition list." ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "term", intImageIndex, "A term to define, which will be defined in text." ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "description", intImageIndex, "Either an item in a bullet or numbered list or the definition of a term." ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "para", intImageIndex, "Provides a paragraph container." ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "param", intImageIndex, "Describes one of the parameters for the method.", "param name=\"", "\"/>" ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "paramref", intImageIndex, "Indicates that a word is a parameter.", "paramref name=\"", "\"/>" ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "permission", intImageIndex, "Documents the access of a member.", "permission cref=\"", "\"" ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "remarks", intImageIndex, "Specifies overview information about a class or other type." ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "returns", intImageIndex, "Describes the return value for a method declaration." ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "see", intImageIndex, "Specifies a link from within text.", "see cref=\"", "\"/>" ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "seealso", intImageIndex, "Specifies the text that you might want to appear in a See Also section.", "seealso cref=\"", "\"/>" ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "summary", intImageIndex, "Describes a member for a type." ) );
                            intelliMemberList.Add ( new IntelliPromptMemberListItem ( "value", intImageIndex, "Describes the value for a property declaration." ) );

                            // Display the Completed Member List
                            if ( intelliMemberList.Count > 0 )
                                intelliMemberList.Show ( );
                            break;
                        default:
                            break;
                    }
                    break;
                case "HTML":

                    //
                    // Determine the Key that was Pressed
                    // to provide proper intellisense and
                    // syntax controls for the mouse edit
                    //
                    break;
                default:
                    break;
            }
        }
*/
        /// <summary>
        /// Raised whenever the Document Language and Syntax is Modified
        /// </summary>
        /// <param name="sender">Object that raised the event.</param>
        /// <param name="e">SyntaxLanguageEventArgs to handle the event.</param>
        private void OnChangeDocumentSyntax ( object sender, ActiproSoftware.SyntaxEditor.SyntaxLanguageEventArgs e )
        {
            switch ( e.Language.Key )
            {
                case "C#":
                    // Use the C# semantic parser 
                    e.Language.SemanticParser = new SemanticCSharpParser ( );
                    break;
                case "CSS":
                    // Use the CSS semantic parser
                    e.Language.SemanticParser = new SemanticCssParser ( );
                    break;
                case "HTML":
                    // Use the HTML semantic parser 
                    e.Language.SemanticParser = new SemanticHtmlParser ( );
                    break;
                case "Java":
                    // Use the Java semantic parser 
                    e.Language.SemanticParser = new SemanticJavaParser ( );
                    break;
                case "JScript":
                    // Use the JScript semantic parser 
                    e.Language.SemanticParser = new SemanticJScriptParser ( );
                    break;
                case "SQL":
                    // Use the SQL semantic parser 
                    e.Language.SemanticParser = new SemanticSqlParser ( );
                    break;
                case "VB.NET":
                    // Use the VB.NET semantic parser 
                    e.Language.SemanticParser = new SemanticVBDotNetParser ( );
                    break;
                case "XML":
                    // Use the XML semantic parser 
                    e.Language.SemanticParser = new SemanticXmlParser ( );
                    break;
            }
        }
 

        /// <summary>
        /// Raised whenever indentation is performed.
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">SmartIndentEventArgs to handle the event.</param>
        private void OnSmartIndentation ( object sender, ActiproSoftware.SyntaxEditor.SmartIndentEventArgs e )
        {
            /*
            // By Default, the SyntaxEditor will Initialize the IndentAmount
            // for block formatting.
            switch ( SyntaxEditor.Document.Language.Key )
            {
                case "C#":

                    // Obtain a Reference to the TextEditor Content
                    TextStream strTextStream =
                        SyntaxEditor.Document.GetTextStream
                            ( SyntaxEditor.SelectedView.Selection.FirstOffset );

                    Boolean blnExitLoop = false; // Raise this Value whenever the Loop needs to Exit

                    while ( strTextStream.Position > 0 )
                    {
                        // Increment the Token
                        strTextStream.GoToPreviousToken ( );

                        switch ( strTextStream.CurrentToken.Key )
                        {
                            case "WhitespaceToken":
                                // Ignore all Whitespace
                                break;
                            case "OpenCurlyBraceToken":
                                e.IndentAmount++; blnExitLoop = true;
                                break;
                            default:
                                blnExitLoop = true;
                                break;
                        }

                        if ( blnExitLoop )
                            break;
                    }
                    break;
            }
             * */
        }

        // ====================================================== //
        //                       CLASS PROPERTIES                      //
        // ====================================================== //

        /// <summary>
        /// Gets or Sets the ActiproSyntax Editor Control
        /// </summary>
        public ActiproSoftware.SyntaxEditor.SyntaxEditor SyntaxEditor
        {
            get { return syntaxEditor; }
            set { syntaxEditor = value; }
        }

        /// <summary>
        /// Gets or Sets the Programming Language
        /// </summary>
        [System.ComponentModel.Browsable ( true )]
        public Language Language
        {
            get { return _csLanguage; }
            set
            {
                // Specify the Language
                _csLanguage = value;

                if ( DesignMode )
                    return;

                // Switch the Template
                SelectLanguage ( value );
            }
        }

        /// <summary>
        /// Occurs when the indicator margin is clicked.
        /// </summary>
        /// <param name="sender">Sender of the event.</param>
        /// <param name="e">Event arguments.</param>
        private void editor_IndicatorMarginClick ( object sender, IndicatorMarginClickEventArgs e )
        {
            // Make sure text is selected
            if ( syntaxEditor.SelectedView.Selection.Length == 0 )
            {
                //MessageBox.Show ( "Please select some text and re-click within the indicator margin to set a breakpoint over the selected text." );
                return;
            }

            // Add status message
    //        this.WriteLine ( "IndicatorMarginClick: " + e.ToString ( ) );

            if ( Control.ModifierKeys == Keys.Shift )
            {
                // A breakpoint is already on the line... remove all breakpoints from the line
                syntaxEditor.SelectedView.CurrentDocumentLine.Indicators.Clear ( );
            }
            else if ( syntaxEditor.SelectedView.CurrentDocumentLine.Indicators.Contains ( BreakpointIndicator.DefaultName ) )
            {
                // Add a second indicator to the line
                syntaxEditor.Document.Indicators.Add ( new DisappearingIndicator ( 2000 ), syntaxEditor.SelectedView.Selection.FirstOffset, syntaxEditor.SelectedView.Selection.Length );
            }
            else
            {
                // Add a breakpoint to the line
                syntaxEditor.Document.Indicators.Add ( new SelectionIndicator( ),
                    syntaxEditor.SelectedView.Selection.FirstOffset, syntaxEditor.SelectedView.Selection.Length );
            }
        }

        private void syntaxEditor_IntelliPromptMemberListClosed ( object sender, System.ComponentModel.CancelEventArgs e )
        {
            
        }
    }
}
[Modified at 08/03/2005 03:16 PM]
Posted 14 years ago by BTAC Developer
Avatar
Alright. I've got some of the functionality I'm looking for .. My code is posted below. This does the general highlighting, but it still has some trouble. Can you offer any suggestions for how to make it more real-time and keep track of the literals enclosed within $[A-Z]$?

        /// <summary>
        /// Raised whenever the Trigger Event is raised to display declaration intellisense.
        /// </summary>
        /// <param name="e">TriggerEventArgs to handle the event.</param>
        private void OnTriggerIntellisense ( ActiproSoftware.SyntaxEditor.TriggerEventArgs e )
        {
            switch ( e.Trigger.Key )
            {
                case "MemberListTrigger":

                    // Construct the Full Name of the Item -- This is to test
                    // Reflection and Iteration of the DataType in a KeySteam

                    ActiproSoftware.SyntaxEditor.TokenStream ActiproTokenStream =
                        Document.GetTokenStream
                            (
                        // iterate the ActiproTokens of the current view -- select the currently focused ActiproToken and the
                        // ActiproToken next to it for full parsing support.
                                Document.Tokens.IndexOf
                                    ( SelectedView.Selection.EndOffset + 1 )
                            );


                    // Design a String to Hold the Full Lexical Name of the Token
                    // As well as the number of periods in the Token Stream
                    String TokenName = String.Empty;

                    // Iterate the Entire Tokenized Stream from Beginning to End
                    while ( ActiproTokenStream.Position > 0 )
                    {
                        // Iterate each Token of the Stream and Assign it
                        ActiproSoftware.SyntaxEditor.Token ActiproToken =
                            ActiproTokenStream.ReadReverse ( );

                        // Determine the Token Key
                        switch ( ActiproToken.Key )
                        {
                            // if the ActiproToken is a punctuation mark, such as a '.', or a ',' then
                            // it should be treated as a delimiter ActiproToken by the syntax editors.
                            case "PunctuationToken":
                                if ( ( ActiproToken.Length == 1 ) && ( Document.GetTokenText ( ActiproToken ) == "$" ) )
                                {
                                    try
                                    {
                                        if ( ActiproTokenStream.Length > 0 && ActiproTokenStream.PeekReverse ( ).IsWhitespace )
                                            TokenName = Document.GetTokenText ( ActiproToken ) + TokenName;
                                        else
                                        {
                                            while ( !ActiproTokenStream.PeekReverse ( ).IsWhitespace )
                                            {
                                                ActiproToken = ActiproTokenStream.ReadReverse ( );
                                                TokenName = Document.GetTokenText ( ActiproToken ) + TokenName;
                                            }
                                            //ActiproTokenStream.Position = 0; // PLACE CODE RIGHT HERE FOR HIGHLIGHTING!!!!
                                            // Add a breakpoint to the line
                                            Document.Indicators.Add ( new HighlightIndicator ( ),
                                                ActiproToken.StartOffset, TokenName.Length + 1 );

                                            TokenName = "";
                                        }
                                    }
                                    catch
                                    {
                                        TokenName = Document.GetTokenText ( ActiproToken ) + TokenName;
                                    }
                                }
                                else
                                    // Return to the Beginning of the Stream
                                    ActiproTokenStream.Position = 0;
                                break;

                            default:
                                // Return to the Beginning of the Stream
                                ActiproTokenStream.Position = 0;
                                break;
                        }
                    }

                    // if a full ActiproToken name is found, then there are a number of options
                    // we can do, such as display the intellisense using reflection list
                    if ( TokenName.Length > 0 )
                    {
                        // Get the MemberList for the IntelliSense ListBox
                        IntelliPromptMemberList intellisenseMemberList =
                            IntelliPrompt.MemberList;

                        // Specify the IntelliPrompt ImageList
                        intellisenseMemberList.ImageList = ReflectionImageList;

                        // Clear the Existing List so that Items can be Added to it Later
                        intellisenseMemberList.Clear ( );

                        foreach ( Snippets.CodeSnippetDeclaration Literal in Snippets.Program.ActiveSnippet.CodeSnippet.Snippet.Declarations )
                            intellisenseMemberList.Add ( new IntelliPromptMemberListItem ( Literal.ID, 0 ) );

                        // Show the Finalized Member List
                        if ( intellisenseMemberList.Count > 0 )
                            intellisenseMemberList.Show ( );
                    }

                    break;
                default:
                    break;
            }
        }
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I'm sorry... not really following what you are trying to accomplish. Can you summarize?


Actipro Software Support

Posted 14 years ago by BTAC Developer
Avatar
Certainly ---
Just a review of how the snippets work to make sure we're on the same page -- forgive me if this is moot.

I've got a class called "CodeSnippetDeclaration", which represents a literal declaration within a code snippet. The object of a declaration is that it is a variable that, when the snippet is pasted, the cursor is placed within and you can tab between the various declarations. Declarations are defined with a $[A-Z]$ syntax.

Declarations is a Generic Collection List<CodeSnippetDeclaration>.

What I am trying to do is, in the 'code' view, when a user types a "$" symbol, it will populate the intellisense window with a list of the current declarations for the code snippet (this is a code snippet DESIGNER tool). Which I have semi-successfully done in the code above, as you can see. I'm not really happy with it, but it works okay.

When they select one of the valid declarations, and end it with a "$", it will encapsulate that declaration in a HighlightingIndicator.

My problem is this -- it does do the above functionality, but it has many bugs
1. It cannot seem to highlight the declaration if the first "$" is the first character on a line
2. HighlightIndicators can easily 'overlap' each other. If the user tries it. For instance
$literal$$literal, while not what the user would want to type in, is still valid text, and
if inputted, it screws up the highlighting. I want to try and safeguard against this.
3. When I open a snippet from a file, I want the highlighting to resume, so I need to be able
to iterate the document and find all of the declarations and highlight them.
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Question... instead of using span indicators to highlight declarations, can you just make a lexical pattern with the custom highlighting within the XML language definition itself? That way the lexical parser will identify tokens that are declarations for you.


Actipro Software Support

Posted 14 years ago by BTAC Developer
Avatar
But I need the window to be in the C# or VB.NET language, so a lexical pattern wouldn't work. I can't seperate things with the <script> tag like in the examples either. I'm not sure how one would go about that. Furthermore, I need to be able to tab between the different highlighted fields.

This is what I'm trying, but it's not working. I've been looking at the Regular Expressions Documentation and it isn't helping much ...I'm still very confused.

<RegexPatternGroup TokenKey="DeclarationToken" Style="ReservedWordStyle" PatternValue="$({AlphaMacro})*$" />
just using the lexical parser -- I just want to highlight things between $ and $. How can this be accomplished? It isn't seeming to respond to anything I put in for "PatternValue".
[Modified at 08/07/2005 09:23 AM]

[Modified at 08/07/2005 09:44 AM]

[Modified at 08/07/2005 10:37 AM]
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Well $ is a reserved character so as the documentation says, you can escape reseved regex characters by putting a backslash before them like: \$

I've seen Boyd's implementation of snippets and he intercepts the KeyTyping event so that when snippets are active, instead of allowing characters to be typed, he starts an undo group and uses Document.UndoableInsert to insert the typed character in any indicator for the declaration that the selection is currently in. He also is using span indicators to track the declarations and highlight them.

For finding other instances of declarations when you open a file, use the regular expression find capabilities in the Document.FindReplace object model.


Actipro Software Support

Posted 14 years ago by BTAC Developer
Avatar
I'm sorry, but the \$ doesn't work.

<RegexPatternGroup TokenKey="DeclarationToken" Style="HighlightIndicatorStyle" PatternValue="@? \$(_ | {AlphaMacro})({WordMacro})*\$" />

is my syntax. Replacing the \$ with &amp; works fine using & and &, but when I use \$, it does not work at all.
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I pasted your exact line in the C# sample language def at the beginning of the DefaultState pattern groups and changed the highlighting style to one of the styles defined above (since yours wasn't defined in our C# def). When I type $a$ in the document, it highlights as expected.


Actipro Software Support

Posted 14 years ago by Alan C - Owner, Savian
Avatar
Can you provide an idea as to when we should see snippets? We were going to code it ourselves but it would be nice to have it supported directly instead.
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Not sure, but I would imagine it would be one of the next major features to be implemented since we have a clearer idea of how it should work.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.