Upgrading from v21 to v25 the vssettings file is ignored

SyntaxEditor for WPF Forum

Posted 2 months ago by Dirk Zellerfeld
Version: 25.1.0
Platform: .NET 9
Environment: Windows 11 (64-bit)
Avatar

We're currently running v21 and we're currently evaluating v25.1. After upgrading, the colors in vssettings file aren't applied.

//calling this after creating the language and registering all the services
using Stream stream = File.Open(path, FileMode.Open);
AmbientHighlightingStyleRegistry.Instance.ImportHighlightingStyles(stream);
 
It only uses colors we've defined in our ClassificationTypeProvider for example
 
public IClassificationType Comment
{
	get
	{
		if ((this.commentValue == null))
		{
			String key = "Comment";
			this.commentValue = this.registryValue.GetClassificationType(key);
			if ((this.commentValue == null))
			{
				this.commentValue = new ClassificationType(key, "Comment");
				this.registryValue.Register(this.commentValue, new HighlightingStyle(Color.FromArgb(255, 71, 156, 70)));
			}
		}
		return this.commentValue;
	}
}

Even trying to overwrite colors have no effect:

var registry = AmbientHighlightingStyleRegistry.Instance;

var ct = registry.GetClassificationType("Comment");
if (ct != null) {
    var style = new HighlightingStyle(
        Colors.LimeGreen,
        null, null, null,
        ActiproSoftware.Windows.Controls.Rendering.LineKind.None
    );
    registry.Register(ct, style, overwriteExisting: true);
}

 I guess somewhere has been a breaking change?

Comments (5)

Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Dirk,

We made some changes in v24 that might be impacting you, especially if you are using a vssettings file just to support dark themes.  If that is the case, please take a look at the v24.1 conversion notes regarding native dark theme support.  We now have a better way to support dark themes without the vssettings file.  More details on dark theme support can be found here.

If this is unrelated to dark themes, is it possible you are loading the vssettings file before the registry and classification types are fully initialized?  Try loading them late in the application startup process to see if that makes an impact.  I do see where you are also trying to customize a color.  Have you verified that the sample for defining the "LimeGreen" color is actually executing that block of code?  I only ask since it is inside an IF block and will only execute if there was not already an existing classification type for a comment.


Actipro Software Support

Posted 2 months ago by Dirk Zellerfeld
Avatar

Thank you, yes it only affects the dark theme. I'm following this suggestion because we have custom keys. Unfortunately this code has also no effect. The key words color doesn't change.

IHighlightingStyleRegistry registry = AmbientHighlightingStyleRegistry.Instance;
registry.DarkColorPalette.SetForeground("Comment", System.Windows.Media.Colors.Yellow);
registry.DarkColorPalette.SetForeground("Number", System.Windows.Media.Colors.Yellow);

This code is applied after ImportHighlightingStyles call (which probably isn't necessary anymore as its ignored), after the language has been created but before any Syntax Editor is visible. Only color changes from our ClassificationTypeProvider are admited.

May I ask why ImportHighlightingStyles is completely ignored? I understand that it isn't necessary anymore but what if we want / need it? Continue making it work wouldn't affect people who are not using this.

Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

It is worth noting that changing the color in the color palette does not automatically transfer to any styles that were already configured before the color was changed (as mentioned here).  When the color palette is changed, all highlighting styles are updated with the colors from the new palette, so make sure the dark colors are configured before changing the registry to the dark palette.

We have tested importing highlighting styles locally and it worked as expected.  When you import highlighting styles, any changes in colors are pushed back to the current color palette.  So if you import styles while the light color palette is active and then switch to dark, you wouldn't see a difference in the dark theme.  Importing styles is the same as if the user had customized their colors, and the color for a light theme is typically not what you'd want for a dark theme.  That's why changes are only applied to the active color palette.  If you are importing dark colors, make sure the dark color palette is active before you import.

If any of the suggestions above do not help, there might be something specific about your scenario that is leading to what you are seeing Could you please try to reproduce in a simple sample project and send to our support email so we can investigate in more detail?  If so, please remove any bin/obj folders from the ZIP before sending or the attachment might be blocked.


Actipro Software Support

Posted 2 months ago by Dirk Zellerfeld
Avatar

Theme is only applied on start of the application. We listen to the CurrentThemeChanged which then creates the language, then imports the vssettings file. This has worked perfectly in v21. In v25, any tries to modify colors after the language has been created doesn't work for dark mode. I just tested light mode and loading vssetting here works fine. Like if I change the colors in the file and launch the app I can see the color changes in the syntax editor. But in dark mode it just doesn't work.

I've created a repro: https://limewire.com/d/vojAg#gogVcMVC5Q

Type anything into the editor and you'll see its yellow because of these lines:

identifierValue = new ClassificationType(key, "Identifier");
registryValue.Register(identifierValue, new HighlightingStyle(Colors.Yellow));

However the vssettings file in bin folder should change the color but its ignored

Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Thank you for providing the sample.  When I run the application, the application is in dark mode and the text is blue, not yellow.  That appears to correspond with the value in the provided vssettings file.  I changed the color in the vssettings file, re-ran the application, and the new color was applied from the file.  For me, everything appears to be working as expected and I used our latest NuGet packages for v25.1.

It is worth noting that your sample is currently managing themes the "old way" where you have to manually change colors when switching between light and dark themes.  If you want to switch to the "new way" that does not require loading styles from a vssettings file, the following changes could be made to your sample project:

Remove the event handler for "ThemeManager.CurrentThemeChanged".  This is tracked automatically by SyntaxEditorThemeManager, so you no longer need to do anything special.

You only have to load the language once, and do not need to re-load it just because a theme changed.  So move your "language.LoadLanguage()" call to the App startup logic.  I tested placing it after you configure the current theme.

Finally, you need to make sure your classification types are initializing colors for the dark palette if you don't like the default colors.  When you register a HighlightingStyle, it assumes the colors you define are for a light theme and attempts to auto-translate the given color to one appropriate for a dark theme.  If you want to set a specific color for the dark theme instead of the automatic one, you just need to make sure the dark color palette is configured before you register the style.  The following is an update to your Identifier classification type that sets the color to Blue like your vssettings file had.

public IClassificationType Identifier
{
    get
    {
        if ((identifierValue == null))
        {
            string key = "Identifier";
            identifierValue = registryValue.GetClassificationType(key);
            if ((identifierValue == null))
            {
                // Make sure dark colors are configured
                var darkColorPalette = registryValue.DarkColorPalette;
                if (darkColorPalette != null)
                    darkColorPalette.SetForeground(key, Colors.Blue);

                // Register default style, which also configures light colors
                identifierValue = new ClassificationType(key, "Identifier");
                registryValue.Register(identifierValue, new HighlightingStyle(Colors.Yellow));
            }
        }
        return identifierValue;
    }
}

You'd want to make the above change to any classification type whose color was not automatically adapting to a dark theme.  You can find more details about color adaptation here. For example, your sample was configured to use Yellow.  That color is automatically adapted to a pale yellow that is more appropriate for a dark theme, so you actually didn't have to do anything to support a dark theme for that color.  You only need to manually define a corresponding color in the dark color palette if you don't like the automatically adapted color.

With the "new way", we tried to remove most of the effort involved in supporting dark themes by automatically watching for theme changes and automatically adapting colors to work with a dark background.  If you want to continue managing themes the "old way", I suggest disabling the new functionality by unmanaging the AmbientHighlightingStyleRegistry from SyntaxEditorThemeManager as discussed here.


Actipro Software Support

The latest build of this product (v25.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.