Access ToggleAction state from Listener
已回答
I am trying to write a little plugin. Within this plugin I created a ToggleAction registered in the Vew Menu.
On the other hand i have some Listener classes that should do stuff when some file was changed AND the ToggleAction state is selected.
My questions is, how can i retrieve the state of the ToggleAction from within my Listener classes?
Thanks in advance and best regards
Daniel Haak
请先登录再写评论。
Your AnAction instance should not hold any state, so you'll have to extract it as you did. A simple, persistent solution would be using `PropertiesComponent` https://plugins.jetbrains.com/docs/intellij/persisting-state-of-components.html
There's no generic "default". Using a singleton is fine if it's really application-global. Otherwise, a project-level Service is another (non-persisting) variant to Project-level PropertiesComponent
Short update I build a workaround by using a singleton service as data storage.
Thanks for the response. As it turns out my little workaround works better in my scenario than the originally thought after solution. However because I have to stick to intellij plugins at least for a little while I take every information I can get hold upon. So Is 'PropertiesComponent' the default solution for storing 'ToggleAction' states or is there another default.
Thanks for clarification.