• Products
  • Download
  • Purchase
  • Support
  • Company
Actipro Software company logo
Twitter Follow Actipro RSS Subscribe (RSS Feed)

The Actipro Blog

Tag Cloud

  • aero
  • blog
  • docking
  • editors
  • gauge
  • intelliprompt
  • navigation
  • propertygrid
  • ribbon
  • shared library
  • silverlight
  • syntaxeditor
  • themes
  • views
  • winforms
  • wpf

Latest Twitter News

November 21, 2011 at 11:14 AM
#WPF Studio 2011.2 is out now! Includes enhanced themes for native WPF conrtols and new SyntaxEditor features. http://t.co/uEMCaGPG

September 26, 2011 at 1:25 PM
If you'd like to see our #WPF / #Silverlight SyntaxEditor code editor control ported to Metro, provide feedback here: http://t.co/xXBNIDTi

September 15, 2011 at 8:31 PM
If you want to see SyntaxEditor eventually show up in Win8's #xaml UI, be sure to add your support to this MS thread: http://t.co/FBjz6TuC

August 15, 2011 at 1:47 PM
New SyntaxEditor IntelliPrompt parameter info feature docs/samples ready for the 2011.2 #WPF and #Silverlight releases. http://t.co/ezoYIjv

August 2, 2011 at 2:40 PM
First look at new automated IntelliPrompt parameter info coming to our C#/VB editor control in #WPF / #Silverlight http://t.co/CUz6O1T

Twitter Follow us on Twitter

Month List

  • 2012
    • February (3)
    • January (2)
  • 2011
    • December (2)
    • November (7)
    • October (2)
    • September (1)
    • August (5)
    • July (3)
    • June (6)
    • May (5)
    • April (8)
    • March (4)
    • February (5)
    • January (9)
  • 2010
    • December (9)
    • November (10)
    • October (4)
    • September (8)
    • August (12)
    • July (9)
    • June (7)
    • May (6)
    • April (7)
    • March (6)
    • February (6)
    • January (4)
  • 2009
    • December (2)
    • November (2)
    • October (12)
    • September (3)
    • August (11)
    • July (10)
    • June (6)
    • May (3)
    • April (7)
    • March (6)
    • February (8)
    • January (10)
  • 2008
    • December (10)
    • November (2)
    • October (3)
    • September (5)
    • August (5)
    • July (8)
    • June (4)
    • May (4)
    • April (10)
    • March (8)
    • February (1)
    • January (2)

Category List

  • RSS feed for ActiproActipro (289)
  • RSS feed for Blog SummaryBlog Summary (13)
  • RSS feed for GeneralGeneral (34)
  • RSS feed for In developmentIn development (150)
  • RSS feed for New featuresNew features (140)
  • RSS feed for New productNew product (30)
  • RSS feed for PromotionPromotion (2)
  • RSS feed for SilverlightSilverlight (71)
  • RSS feed for Tips and tricksTips and tricks (4)
  • RSS feed for Visual Studio 2008Visual Studio 2008 (2)
  • RSS feed for Windows FormsWindows Forms (20)
  • RSS feed for Windows VistaWindows Vista (10)
  • RSS feed for WPFWPF (235)
  • RSS feed for XAMLXAML (23)

About Us

Actipro Software is a leading provider of .NET user interface controls for the WPF, Silverlight, and WinForms frameworks, and is most well-known for their SyntaxEditor syntax-highlighting code editor control.

Please take some time to learn more about us and our product offerings.

SyntaxEditor for WPF - Need input on highlighting style configuration

March 25, 2009 at 1:57 AM
by Bill Henning (Actipro)

Sorry we haven’t made any new SyntaxEditor for WPF posts recently.  We’ve been hammering away at the TODO items in code.  We also have made a ton of performance improvements so that everything from document loading to scrolling is very fast.  It’s cool stuff, but nothing we can show in a screenshot. :)

We’re now on the home stretch towards code completion of the SyntaxEditor for WPF public beta.  Just a few outstanding areas left to work out before it will be ready.

One portion we need to finalize is how best to support highlighting style configuration from your side as a language developer.  Let me describe how highlighting styles work in SyntaxEditor for WPF, they are a little different in concept than in SyntaxEditor 4.0. 

In SyntaxEditor for WPF, we have achieved true separation of text/parsing and UI.  In SyntaxEditor 4.0, you would assign highlighting styles directly to tokens.  However in the WPF version, this wouldn’t match our separation design since highlighting styles are UI-related.  Therefore what we have instead is something call classifications.

You define a set of classification types (implementing IClassificationType).  We provide some common implementations such as classification types for general comments, identifiers, strings, etc.  An IClassifier looks at tokens that were lexical parsed from your document and converts those into classified ranges, meaning a certain range of text has a certain classification type.

Take this line for example:

   1: int foo;

 

In a C# classifier, the first three letters will be assigned a Keyword classification type.  The foo range can be assigned an Identifier classification type and so on.

The classification type is purely logical and doesn’t provide any highlighting information.  So how does the SyntaxEditor control know what text to highlight as what?  It uses a registry to map from a classification type to a related highlighting style.  Therefore if our registry is configured properly, the Keyword classification type will return a blue foreground style from the registry.

Please give your feedback on the following…

Now here is where we’d love to get your input.  Please provide some comments on any of the rest of this post because it’s still a bit up in the air as to how we’ll keep the implementation.

Right now, we have two registries.  The first is a classification type registry.  This basically just stores instances of IClassificationType that are keyed on their string Key.  There is an ambient version of this registry out there so that say there are two languages that both use the classification for Comment.  They can check to see if a classification type keyed as Comment is already registered, and reuse it if so.

The idea here is that an options dialog that allows customization of highlighting styles could enumerate the classification type registry and list each one in a ListBox.  As the end user clicks the ListBox, the second registry (described earlier in this article that maps from classification type to highlighting style) would be checked to grab the highlighting style for the classification type and allow customization of it.

IClassificationType is currently defined like this:

   1: public interface IClassificationType {
   2:     string Description { get; }
   3:     string Key { get; }
   4: }

The Key is a constant key that uniquely identifies the classification type.  The description is more of a description that could be localized in your application.  For instance an XML comment classification type might have a Key of “XMLComment” but a Description of “XML Comment” where the latter may have been pulled from localized resources.  The Description is what would show up in the ListBox.

Here is how a classification type instance can be registered with the ambient classification type registry:

   1: AmbientClassificationTypeRegistry.Instance.Register(ClassificationTypes.Comment);

 

Note that ClassificationTypes static class provides some built-in common IClassificationType instances.  In this case, we registered the Comment one.

Next we need to configure the classification type to highlighting style mapping before a language is created.

   1: AmbientHighlightingStyleRegistry.Instance.Register(ClassificationTypes.Comment.Key, 
   2:     new HighlightingStyle(ClassificationTypes.Comment.Key, Colors.Green, Colors.Transparent));

This added a mapping in AmbientHighlightingStyleRegistry, from a classification type to a green foreground style.

When a language is created that would use a Comment classification type, it would look it up in the registry like this:

   1: IClassificationType commentCT = 
   2:     AmbientClassificationTypeRegistry.Instance[ClassificationTypes.Comment.Key];

Thus the commentCT variable would end up with an instance of ClassificationTypes.Comment.  When any text is classified with a classification type of Comment, it will end up being green in the editor.

You may be asking why we bother doing the registry lookup in that last code snippet instead of assigning commentCT directly to ClassificationTypes.Comment.  Well assume that multiple languages you make are creating a new IClassificationType called Operator.  The first IClassificationType with the key Operator will be the one that is used in the registry.  If another IClassificationType keyed Operator is attempted to be registered, it will be ignored.  Thus, the lookup in the code snippet above ensures that we get the instance that is registered.

Questions, issues, thoughts

The registries all need to be set up in your application before languages are loaded that use them.  Also if you will have a highlighting style customization page in your options dialog, all of the classification types and styles should be set up before loading that.

So our question to you as a language designer is, where should the code to set up the registries be?  Should you have to create an instance of a language to register that info and then just dispose the language if you don’t need it right away?  Or should there be smaller classes that accomplish this?  In that case you’d have to create those at app startup to do your registering but at least you wouldn’t be loading full-blown language classes.  We could also have language classes auto call a related registrar class to ensure they are registered by the time the language is used.

 

 

 

If you are a SyntaxEditor alpha tester and have the latest build from today, you can see one implementation idea of a registrar class in the second Getting Started QuickStart.

Please post your comments now, thanks!

Tags: wpf, syntaxeditor
Filed under: Actipro, In development, WPF
Submit to DotNetKicks...
Permalink | Comments (5)

Related posts

SyntaxEditor for WPF - Highlighting style configuration part 2Thanks for your comments on this post and via email on yesterday’s post about getting input on...SyntaxEditor for WPF - Advanced themes and highlighting style featuresThe past several days we’ve been cleaning up code (running code analysis, fixing XML comment e...Integrating MGrammar DSL parsers with SyntaxEditor to implement syntax highlightingNow that the public beta of SyntaxEditor for WPF has been released, I’d like to show off a really ne...

Comments

March 23, 2009 at 14:20  

Jesper

Not everything is perfect in SyntaxEditor for Windows Forms, but the way it works right now with parsing and language smarts initialization explicit and UI initialization implicit seems like a good model. This is sort of both, unless I misread the post. But it is weird, since the language should keep one of the registries, and the control should keep the other. The language can surely keep around a recommended implementation of the UI-related registry for easy retrieval and application. That should even be what happens by default.

The ambient approach to styling is good, but I think it's missing something. There's a Mac OS X text editor named TextMate, which has a good idea about labelling the tokens in this way; it keeps a stack of "scopes", which for all intents and purposes seem pretty well identical to the classifications. (These scopes are also named in namespace fashion, to distinguish between code, strings, comments, preprocessor...) Under this scheme, the attribute value in an XML tag in a documentation comment could be labelled as a string, attribute value, XML stuff, documentation comment and comment and get the styling from all of these.

It's probably a little late to make this change right now, but now you know. And for what it's worth - the new separation and the new structure is still fantastic. There's plenty of cake and plenty of icing, and I'm looking forward to hearing more.

Jesper

March 23, 2009 at 19:26  

Boyd Patterson

My initial thoughts are to keep the registration separate from the language.  These likely need to be loaded at app startup or at least before presenting an option dialog for customization.  I do not like the idea of loading a full language and disposing it just to get the registrations in place.

Boyd Patterson

March 24, 2009 at 00:32  

Jesper, thanks for the comments.  Here's a problem with SE4's highlighting style model that we've had a lot of customers complain about, thus some of the ideas in the post.  In SE4, highlighting styles are specific to a particular language.  This means that to make an options dialog, say you'd want to just use a different color for comments in general across the board for any language.  That wasn't really feasible since languages stored their own highlighting style data.

With this newer design we're trying to decouple things a bit.  So that multiple languages can use the same logical classification types and those classification types are mapped to certain highlighting styles.

This allows you to have an options dialog that lists all the classification types, and then make highlighting style changes for those types.  Of course the downside as mentioned above is that they need to be registered ahead of time somehow.

You had mentioned "since the language should keep one of the registries, and the control should keep the other".  Actually both default registries are ambient, meaning that any language would use the same ones.  I wanted to make sure I explained that correctly.  The language, or the registrar class (the small class that just does the registration for the language) if it was used instead, would operate on those ambient registries.

One other thing I should have mentioned is that similar to your TextMate idea, we do have the possibility of classification types being based on other classification types and inheriting style data from those too when resolving style data.  That is something we have a TODO marker for in our code, although as of now it is not implemented yet.  However we have things set up so it can be added in the future.

Bill Henning (Actipro)

March 24, 2009 at 15:49  

Jesper

"Actually both default registries are ambient, meaning that any language would use the same ones."

Ah, yes. What I meant was that one of the registries maps the context to a key (which is something the language should do, no question) and the other maps the key/classification to a UI decision. Something connected to the language should certainly be able to prescribe default advice of sorts for the UI, but if using the language unconditionally means having it poking around in the UI for you to do that, that seems weird from a separation of concerns standpoint. It also sounds like it's entirely up to ordering at that point who gets to decide what color something is when you're loading a few languages. (Some HTML pages have HTML, CSS, JavaScript and server code, all of which might define "block comments".) That's how it sounds to me like the language's interaction with the registrar class works, but I wouldn't know exactly, and maybe I'm reading it all wrong.

As far as the language registering the classification types ahead of time goes (which I understand is more the question that's being asked), that's just what needs to be done, I agree with that, and I think that it should be lazily done whenever it's first needed on an event basis.

Jesper

March 25, 2009 at 08:59  

Thanks for your comments, today we've implemented a simpler solution that is very effective.  Check out the latest blog post here for details:
blog.actiprosoftware.com/.../...ration-part-2.aspx

Bill Henning (Actipro)

Comments are closed
Copyright © 1999-2012 Actipro Software LLC. All rights reserved.
Home Actipro Software | Products | Download | Contact Us