String (@NotNull final DataContext dataContext) { final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) { return null; } VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext); if (file == null) { return null; } if (!file.isDirectory()) { file = file.getParent(); if (file == null) { return null; } } VirtualFile contentRoot = ProjectRootManager.getInstance(project).getFileIndex().getContentRootForFile(file); if (contentRoot != null && contentRoot.isDirectory()) { return FileUtil.getRelativePath(getIOFile(contentRoot), getIOFile(file)); } final VirtualFile baseDirectory = BaseProjectDirectories.getInstance(project).getBaseDirectoryFor(file); if (baseDirectory != null) { return FileUtil.getRelativePath(getIOFile(baseDirectory), getIOFile(file)); } return null; }