How to save plugin project settings

已回答

Hello,

I'm trying to save the settings of a project but nothing happen.

The following project does nothing. It only have the configurable, the persistentState for the settings and a tab window.

Code is pretty straight forward.

Upload id: 2023_02_07_9QxVhWwN7JSuxu8UtaPt89 (file: plugin.zip)

 

Can someone have a look ? 

 

thanks

0

Hi,

Since you are configurable at a project level, so every opened project will create an object RobotProjectSettings , so that your code

private static RobotProjectSettings robotProjectSettings = new RobotProjectSettings();

will make no sense. This class should be created by the IDEA project module itself.

Please try to change your code RobotProjectSettings a bit:

@State(name = "RobotProjectSettings", storages = @Storage(value = "exygen.xml"))
public class RobotProjectSettings implements PersistentStateComponent<RobotProjectSettings.State> {
// private static RobotProjectSettings robotProjectSettings = new RobotProjectSettings();
private State state= new State();


// public static RobotProjectSettings getInstance() {
// return robotProjectSettings;
// }

public static RobotProjectSettings getInstance(@NotNull Project project) {
return project.getService(RobotProjectSettings.class);
}
// ... other code no needs to change
}

and fix the corresponding errors which call this method, and pass a project parameter to it, like this:

. I've tried the fixed code and it works well.

Also, this document might be helpful: https://plugins.jetbrains.com/docs/intellij/plugin-services.html

0

Thank you. It works.

The key is point I haven't found was:

project.getService(RobotProjectSettings.class);
0

请先登录再写评论。