How to dynamically add/remove actions from a menu?

"Add as Ant build file" is only present in menu for some files. I'd like
an action of mine to be similarly only present in some cases. How do I
do this?

3 comments

Thanks, it works!

Maas van den Berg wrote:

 public class SomeAction extends AnAction {
>   private static boolean flag;
> 
>   public SomeAction() {
>     super("SomeAction");
>   }
> 
>   public void actionPerformed(AnActionEvent e) {
>   }
> 
>   public void update(AnActionEvent e) {
>     boolean someSpecialCondition = flag = !flag;
>     e.getPresentation().setVisible(someSpecialCondition);
>   }
> }
> ]]>

0

Thanks, it works!

Maas van den Berg wrote:

 public class SomeAction extends AnAction {
>   private static boolean flag;
> 
>   public SomeAction() {
>     super("SomeAction");
>   }
> 
>   public void actionPerformed(AnActionEvent e) {
>   }
> 
>   public void update(AnActionEvent e) {
>     boolean someSpecialCondition = flag = !flag;
>     e.getPresentation().setVisible(someSpecialCondition);
>   }
> }
> ]]>

0

Please sign in to leave a comment.