Please consider editing your post and mark it as obsolete instead. Do you want to delete post?
How to get the folder of currenctly selected file
Permanently deleted user
Created
I need to get the folder of the currently selected file ( when ProjectViewPopupMenu is clicked ). I tried to get it from the Project , but not succeeded.
B> I need to get the folder of the currently selected file ( when B> ProjectViewPopupMenu is clicked ). B> I tried to get it from the Project , but not succeeded.
Please note that there is a possible case that more than one element is selected at the project view. You can use PlatformDataKeys.VIRTUAL_FILE_ARRAY for obtaining all of them then.
Hello Buminda,
B> I need to get the folder of the currently selected file ( when
B> ProjectViewPopupMenu is clicked ).
B> I tried to get it from the Project , but not succeeded.
public void actionPerformed(AnActionEvent e) {
VirtualFile file = (VirtualFile) e.getDataContext().getData(DataConstants.VIRTUAL_FILE);
VirtualFile folder = file.getParent();
}
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"
Looks like the new way to do this is:
e.getData(DataKeys.VIRTUAL_FILE) is better because it's shorter.
Hi George,
Please note that there is a possible case that more than one element is selected at the project view. You can use PlatformDataKeys.VIRTUAL_FILE_ARRAY for obtaining all of them then.
Denis