Is it a good idea to store Presentation as a field?

Answered

I have my own AnAction class and I'd like to update the icon of it at any given moment of time. This is not possible, because the icon can only be updated when update(AnActionEvent e) is called. Is it a bad idea to get the Presentation object from the AnActionEvent event and than store it somewhere else as a field? This works, I can update the Presentation at any time, but I am not sure if this is a good idea (maybe it prevents some objects from being disposed etc.)

0
2 comments

That's not a good idea. Please check the AnAction class JavaDocs:

* If the action is added to a toolbar, its "update" can be called twice a second, but only if there was
* any user activity or a focus transfer. If your action's availability is changed
* in absence of any of these events, please call {@code ActivityTracker.getInstance().inc()} to notify
* action subsystem to update all toolbar actions when your subsystem's determines that its actions' visibility might be affected.
0
Avatar
Permanently deleted user

Thank you!

ActivityTracker.getInstance().inc()

works well. I don't need to store Presentation at all.

0

Please sign in to leave a comment.