Reputation: 511
In the IntelliJ IDEA plugin action class, I want to get the Java class file name which user is currently viewing. How would I get that?
In IntelliJ IDEA, if we click Analyse -> Inspect Code
, it will show a window to choose scope, in that it will show the current file name also. Similar to that view, I want to get the current file name in plugin action class. How could I do that?
Upvotes: 3
Views: 1621
Reputation: 97168
public class MyAction extends AnAction {
public void actionPerformed(AnActionEvent e) {
VirtualFile vFile = e.getData(PlatformDataKeys.VIRTUAL_FILE);
String fileName = vFile != null ? vFile.getName() : null;
}
}
Upvotes: 10