Disable the Presentation of AnAction

Hi,

I have a DefaultActionGroup to which I have added a bunch AnAction instances. This DefaultActionGroup has been added to a toolbar. Depending on certain conditions I need to enable/disable these actions. I looked up in the Forum and found the following thread.
http://intellij.net/forums/thread.jspa?messageID=559794&#559794

But using the AnActionEvent instance I can only get the Presentation of the associated UI component on which the event occured. How can I enable/disable other toolbar buttons that I need to modify?

thanks
Dhwani

3 comments
Comment actions Permalink

Hello Dhwani,

I have a DefaultActionGroup to which I have added a bunch AnAction
instances. This DefaultActionGroup has been added to a toolbar.
Depending on certain conditions I need to enable/disable these
actions. I looked up in the Forum and found the following thread.

http://intellij.net/forums/thread.jspa?messageID=559794&#559794

But using the AnActionEvent instance I can only get the Presentation
of the associated UI component on which the event occured. How can I
enable/disable other toolbar buttons that I need to modify?


In IntelliJ IDEA, you do not disable or enable actions explicitly from other
places of the code. Instead, you override AnAction.update(), check the conditions
which determine whether the action should be enabled, and enable or disable
the presentation of that action.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Hi Dmitry,

Thanks for confirming that. Thats how I had attempted to do it. I have implemented it as follows.

group.add(new AnAction("Action1", "Action1 description", null) {

public void actionPerformed(AnActionEvent e) {
// TODO
}

public void update(AnActionEvent e) {
e.getPresentation().setEnabled(Action1EnabledFlag);
}
});

The Action1EnabledFlag is a boolean whose value can be set anywhere in the code.

Thanks
dk

0

Please sign in to leave a comment.