I am building a more advanced editor for VS 2017 / 2019. However, one of the things which is important is to maintain the same colours as defined by the user / theme the user has chosen.
Now, for all the environment colours (that is, all aspects of VS which are not the contents of the editor window), these are easily obtained via the method
VSColorTheme.GetThemedColor(themeResourceKey);
Using the predefined themeResourceKeys as defined in
Microsoft.VisualStudio.PlatformUI.EnvironmentColors
So, for example, to retrieve the background color key for the tool window background, you call the following
VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey);
What I am after is the keys of the colors being used by VS to color class names, comments, line number, privates, publics, statics, etc, all colors used in the editor. With these color keys, I'd like to then use these code keys to call a VS extensibility class or method to retrieve the actual colours being used.
Does anyone have any knowledge on how the editor is retrieving these actual color keys, and how I can use these to retrieve the currently set color?
Thanks
Related
I'm looking for a reference as to what each color of syntax highlighting in Visual Studio Code actually means. I'm currently using the dark default theme Dark+. I've gotten used to recognizing a few of the highlight colors and I get the gist of what I'm looking at, but I'm looking for a more detailed reference of what each color means.
I've searched for a while for this and can not find any reference guide or glossary/index listing the colors and meanings. Not sure if it matters, but I am solely writing in JavaScript.
Thank you in advance.
edit: I have included a screenshot of the type of syntax highlighting I am referring to.
The meaning of the syntax highlight colors comes in two parts:
How are the characters in the file organized into meaningful tokens?
How are those tokens assigned a particular color and font style?
Partitioning text to tokens
The first part is determined by a grammar description built in to VSCode. VSCode uses a system based on TextMate grammars. The grammars are defined in the VSCode sources (e.g., JavaScript.tmLanguage.json), but in that form have gone through a couple stages of postprocessing, making them nearly unreadable. There is no documentation of the intent of these grammar files. They tend to at least roughly follow the relevant language specification, but with plenty of ad-hoc deviations.
The most practical way to understand what tokens are defined is to use the "Developer: Inspect TM Scopes" tool available in the Command Palette (Ctrl+Shift+P). When you put your cursor on a token, it will show you the "scope labels" that describe that token. These labels are more or less human-readable.
Edit 2020-07-24: As of VSCode 1.47 (and possibly a little earlier) the command is called "Developer: Inspect Editor Tokens and Scopes".
Example:
Above, we can see that the return keyword is most specifically classified as keyword.control.flow.js. It is within a brace-enclosed code block (meta.block.js), within a function definition (meta.function.js), within Javascript source code (source.js).
That sequence of scope labels is the closest thing there is to a "meaning" for a token in VSCode.
Assigning colors to tokens
Next, there is the process of mapping that sequence of scope labels to a color and font style. That is done by the theme. In my case I am using Visual Studio Light, defined in the VSCode sources in light_vs.json. In the case of the return keyword, this is the applicable fragment:
{
"scope": "keyword.control",
"settings": {
"foreground": "#0000ff"
}
},
This says, basically, that anything with a scope label beginning with "keyword.control" shall have a blue color. But other fragments may override this one; the rules are somewhat complex. Why blue? It's an arbitrary aesthetic choice.
Why do function and NaN have the same color? The grammar assigns them different scope labels (storage.type.function.js versus constant.language.nan.js), but it just happens that the theme you are using (Dark+) assigns them the same color (as does mine). I find that an odd choice, but can only speculate about the reason.
Customizing the colors
You didn't ask, but an obvious follow-on question would be how to customize these colors, for example giving function and NaN different colors. See this answer.
Is there a way to have a custom color that has been set in the Windows color picker to be persistent? When I use Adobe LiveCycle and want to change a color to a color that I use all the time, I have to create it every time, and I figured since it's accessing the default Windows color picker, there might be a way to add the color and make it persistent.
IMHO, there is no way of doing so. Microsoft allows to redefine the default colors and it also allows for a hook to remember the user selected colors, but it has to happen in the source of the program. See http://msdn.microsoft.com/en-us/library/windows/desktop/ms646375%28v=vs.85%29.aspx#custom_template on how to set default colors when compiling a program.
Even the Microsoft default Paint program is dumb enough to forget any user defined colors.
Cheers,
p.s. For others, who are programming their own application and what to allow for saving user-defined colors: http://vbcity.com/forums/t/112635.aspx
In Windows 7 and Windows XP you can find the "Window Color and Appearance" dialog under "Control Panel\Appearance and Personalization\Personalization".
Changing "Color1" of item "3D-Border" will result in a change of the following entries in the registry key
[HKEY_CURRENT_USER\Control Panel\Colors]
containing the resulting rgb-values:
Group1 (same values):
InactiveTitle, AppWorkspace, ButtonShadow, Graytext
Group2 (same values, different to those of group1):
Scrollbar, ButtonHilight
Does anyone know how these value are being calculated from the given rgb-values of "Color1"?
After searching the web without results and playing around with many values I did not happen to find a plausible way of how to do this.
Does anyone know the rules for this?
Any help would be appreciated.
I uploaded some demo values, systematically dealing with values in the lower parts. Also a text file comparing the affected registry key [HKEY_CURRENT_USER\Control Panel\Colors] after change of Color to Red (255 0 0).
When you set the "3D Border" color to red, it changed the "Button Face" color to red and interpolated this color to generate various lighter and darker shades of red, which were used to set some related color values.
The point is to create a consistent-looking theme with minimal effort. All you need to do is set the "base" color for 3D objects, and all of the other colors are automatically calculated to ensure that objects have the appropriate 3D appearance.
Some of these values, like the highlight and shadow colors used for 3D objects, are not directly configurable from the control panel applet. However, they can be set manually in the registry, and you can call the SetSysColors function to update currently running applications.
Why do you think you need to know the actual algorithm that Windows is using? What problem are you trying to solve? What are you going to use this information to do?
I do not imagine that the exact algorithm is documented anywhere. The code has been part of the OS since at least Windows 95.
I'm wondering if there is a way to change the colors for a specific code? I'd like have a different color scheme for C# than I do for JS?
Another question is there an easy way to find out what the "display items:" name is within the Options > Enviroment > Fonts and Colors? For many of the of the code items it's difficult to know exactly what MS is calling object types.
if you want to change the code highlighting I would recommend:
http://studiostyl.es/
What are the recommended colors for an application's background, button faces, etc.?
In the past I've just chosen a color scheme but I'd like to be more compatible with the Windows Accessibility Options, etc.
I see that VB6 has System Colors like Application Workspace.
Edit: I'd like to find an explanation of all of those colors (like what's the difference between Application Workspace and Window Background?
In my opinion, you should leave the colors as they are if you are using standard controls; they'll get the right color according to che current color scheme by themselves. You need to use the color constants only if you have to draw your own UI elements; in that case, the meaning of those constants is explained briefly in their documentation.
This PDF http://www.johnsmiley.com/cis18/Smiley009.pdf [ explanation of VB6 System Color values ]should help you. It lists all the system color constants and what they mean. For instance vbApplicationWorkspace is the "Background color of multipledocument interface (MDI) applications."
If you're interested in the whole MS Windows UI/UX guidelines, they are available online here and for download here. Page 618 deals with how to "Use theme or system Colors"
It depends on the language and framework you use. .Net for example has an entire SystemColors class full of static properties like SystemColors.Control that are 'changed' to the corresponding system color in runtime.
I think most office applications conform to the system colors, while most graphics intensive applications (e.g. games) use their own color scheme.
It is best if you try to use the colors of the current system (like the .NET SystemColors), that way if the user changes his settings (for example if he uses a high-contrast color scheme or some fancy black theme he likes) your application will adapt those colors and that way conforms to the users preferences/needs.