CreateDirectoryOrPackageHandler (@NotNull Project project, @NotNull PsiDirectory directory, @NotNull SmartPsiElementPointer<PsiDirectory> directoryPointer, @NotNull Module module) { return new CreateDirectoryOrPackageHandler(project, directory, false, ".") { @Override protected void createDirectories(String subDirName) { super.createDirectories(subDirName); final PsiDirectory restoredDirectory = directoryPointer.getElement(); if (restoredDirectory == null) return; PsiFileSystemItem element = getCreatedElement(); PsiFileSystemItem lastElement = element; while (element != null && !element.equals(restoredDirectory)) { lastElement = element; element = element.getParent(); } if (element == null) return; VirtualFile topmostCreatedDirectory = lastElement.getVirtualFile(); if (topmostCreatedDirectory == null) return; PyNamespacePackagesService.getInstance(module).toggleMarkingAsNamespacePackage(topmostCreatedDirectory); } }; }