Auto setting code style scheme from plugin
Answered
I want to auto-import and select my own code style scheme on IDE level from plugin.
I found the API in these posts: 1 2
My code like this:
final VirtualFile selectedXml = VfsUtil.findFileByIoFile(mySchemeXmlFile, true);
CodeStyleSchemesUIConfiguration.Util.setRecentImportFile(selectedXml);
final CodeStyleScheme schemeImported = new CodeStyleSchemeImpl("GoogleStyle", false, null);
final SchemeImporter<CodeStyleScheme> importer = SchemeImporterEP.getImporter("IntelliJ IDEA code style XML", CodeStyleScheme.class);
assert importer != null;
importer.importScheme(project, selectedXml, schemeImported, new SchemeFactory<CodeStyleScheme>() {
@Override
public @NotNull CodeStyleScheme createNewScheme(@Nullable String name) {
return schemeImported;
}
});
CodeStyleSchemesModel codeStyleSchemesModel = new CodeStyleSchemesModel(project);
codeStyleSchemesModel.addScheme(schemeImported, true);
codeStyleSchemesModel.apply();
After run the codes, I found two problems:
1. Use SchemeImporter API, the "Import Scheme" dialog will open, is there any API can import schemes quietly?
2. When I quit IDE and restarted, reopen Settings-editor-code style panel, the imported scheme was lost. Is there something wrong?
Thanks.
Please sign in to leave a comment.
Waiting for answer from responsible developer.
OK…
For 1, I have no idea… ignored.
For 2, finally I save the scheme like this:
Hello,
1. To get around the dialog, you can use CodeStyleSettingsLoader, which the XML importer uses behind the scenes:
2. CodeStyleSettingsManager#notifyCodeStyleSettingsChanged should be called after making these changes, so that other parts of the system can update properly. codeStyleSchemesConfigurable.apply(); calls it, among other things. (Note that this code should run on the EDT.)
Hey Miaoze612,
you dont create a code style for Apache Camel ?
thanks