ItemPresentation () { return new ItemPresentation() { @Override public String getPresentableText() { return getModuleName(PyFileImpl.this); } @Override public String getLocationString() { final String name = getLocationName(); return name != null ? "(" + name + ")" : null; } @Override public Icon getIcon(final boolean open) { if (PyUtil.isPackage(PyFileImpl.this)) { return AllIcons.Nodes.Package; } return PyFileImpl.this.getIcon(0); } @NotNull private static String getModuleName(@NotNull PyFile file) { if (PyUtil.isPackage(file)) { final PsiDirectory dir = file.getContainingDirectory(); if (dir != null) { return dir.getName(); } } return FileUtilRt.getNameWithoutExtension(file.getName()); } @Nullable private String getLocationName() { final QualifiedName name = QualifiedNameFinder.findShortestImportableQName(PyFileImpl.this); if (name != null) { final QualifiedName prefix = name.removeTail(1); if (prefix.getComponentCount() > 0) { return prefix.toString(); } } final String relativePath = getRelativeContainerPath(); if (relativePath != null) { return relativePath; } final PsiDirectory psiDirectory = getParent(); if (psiDirectory != null) { return psiDirectory.getVirtualFile().getPresentableUrl(); } return null; } @Nullable private String getRelativeContainerPath() { final PsiDirectory psiDirectory = getParent(); if (psiDirectory != null) { final VirtualFile virtualFile = getVirtualFile(); if (virtualFile != null) { final VirtualFile root = ProjectFileIndex.getInstance(getProject()).getContentRootForFile(virtualFile); if (root != null) { final VirtualFile parent = virtualFile.getParent(); final VirtualFile rootParent = root.getParent(); if (rootParent != null && parent != null) { return VfsUtilCore.getRelativePath(parent, rootParent, File.separatorChar); } } } } return null; } }; }