Plugin saving data PersistentStateComponent
已回答
My plugin needs to save some data to a file whenever a certain change in the project occurs.
- In order to save this data, should I be using PersistentStateComponent instead of simply writing to a txt/xml file as you normally would. I’m not sure what benefits does PersistentStateComponent give me and when should it be used instead of the latter approach.
- I need to be notified of IDE usage (e.g. the user started up the WebStorm application / the user closed the current project etc.). Is there an appropriate Topic I can subscribe to to achieve this (or even better, a list of ALL the topics one can subscribe to so I could deduce what to use myself)?
请先登录再写评论。
1. PersistentStateComponent saves you from trouble of serialization, ensures that everything is persisted on project/application exit, allows to share/import settings, etc.
Usually, it does not drop state on disk immediately (for performance reasons).
2. com.intellij.ide.AppLifecycleListener, com.intellij.openapi.project.ProjectManagerListener, com.intellij.openapi.application.ApplicationActivationListener, com.intellij.ide.PowerSaveMode.Listener, com.intellij.openapi.actionSystem.ex.AnActionListener.
If these are not enough, please share few more examples.
>list of ALL the topics
You can try to trace usages of com.intellij.util.messages.Topic and java.util.EventListener in community sources. This should give a fair share of all available listeners in IDE.