Load action in code?

I'm trying to create a plugin it will be showed in Tools menu but only when a project is opened. How can I do it? I need create a project component, then load the action in projectOpened() of that component? Can I do it by specifying in plugin.xml? Or I must do it in code?

Thanks

3 comments

Hello t800t8,

t> I'm trying to create a plugin it will be showed in Tools menu but
t> only when a project is opened. How can I do it? I need create a
t> project component, then load the action in projectOpened() of that
t> component? Can I do it by specifying in plugin.xml? Or I must do it
t> in code?

You should register the action in the regular way, and hide it if the project
is not loaded.

public class MyAction extends AnAction {
public void actionPerformed(AnActionEvent e) {
// your code here
}

public void update(AnActionEvent e) {
boolean projectOpened = e.getDataContext().getData(DataConstants.PROJECT)
!= null;
e.getPresentation().setVisible(projectOpened);
}
}

--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Hi Dmitry,

Quick answer. Thanks again :)

0

Please sign in to leave a comment.