Setting code style scheme from plugin
I want to read/set code style scheme from plugin.
Tried to use CodeStyleSchemes.getInstance().getCurrentScheme() and CodeStyleSchemes.getInstance().setCurrentScheme() but it seemed that what was returned by getCurrentScheme was not the same as in the settings dialog.
Why is that? Am I using wrong API?
Please sign in to leave a comment.
Could you please clarify "was not the same as in the settings dialog"?
The API is correct but more actions may be needed depending on what you are trying to achieve eventually.
What I saw was that if CodeStyleSchemes.getInstance().getCurrentScheme().getName() returned e.g. 'CompanyStyle' and then I went into normal IDEA settings dialog it showed 'Default' for code style scheme.
So it was like there was a mismatch between the API and what was shown in IDEA settings dialog.
com.intellij.psi.codeStyle.CodeStyleSettingsManager#getSettings(Project)
It also depends on the currently selected project. You can choose a different IDE scheme for every project. Assuming that it's a global (IDE) scheme, not "Project", you can find it using the following code:
Or simply use CodeStyleSchemesModel as follows:
You can also add/remove/select schemes via CodeStyleSchemesMdoel and the use apply() at the end.