Project wise settings with PersistentStateComponent

Answered

Hi, I need to save settings separately for every project.

I tried various combinations of annotations, but all the time settings are visible to all projects.
How to save settings for every project separately? Thanks

Example code:

@State(name = "Yii2Support", storages = {@Storage()})
public class Yii2SupportSettings implements ApplicationComponent, PersistentStateComponent<Yii2SupportSettings> {

}
0
2 comments

I'm having the exact same problem. I am trying to persist some data from a plugin on a per-project basis.

I started my IDE in plugin test mode, opened a project, it loads my persisted data just fine. I open a new window, from the same instance as the debugged IDE (so the other project window also have my plugin) and try to read the persisted state and getting the same data that was saved in the other window.

I tried debugging and put a breakpoint where I return the object in getInstance() and both windows have different instances of the PersistentStateComponent. I don't understand how the data gets crossed like that.

Is there a way to save that state to be "sandboxed" to that workspace? Anyway, here's my code:

@State(
name = "MyCoolPlugin",
storages = [Storage(StoragePathMacros.WORKSPACE_FILE)]
)
object MyProjectState: PersistentStateComponent<MyProjectState.State> {

data class State(
var storyNumber: String? = null,
var storyType: String? = null)

private var myState: State = State()

fun getInstance(project: Project): MyProjectState{
val service = ServiceManager.getService(project, MyProjectState::class.java)
return service
}

override fun getState(): State = myState

override fun loadState(state: State) {
XmlSerializerUtil.copyBean(state, myState)
}
}
0

Simon, please create new threads and provide full sources of your plugin as there could be various factors contributing to such behavior. Thanks.

0

Please sign in to leave a comment.