From 0ec085684321bfcfb3af62846482c0bdc84f589a Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Wed, 8 Feb 2017 20:13:32 +0300 Subject: [PATCH] passing correct projectToClose --- .../projectWizard/AbstractNewProjectStep.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/util/projectWizard/AbstractNewProjectStep.java b/platform/lang-impl/src/com/intellij/ide/util/projectWizard/AbstractNewProjectStep.java index ee7aa7d53398..58faec49bf5a 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/projectWizard/AbstractNewProjectStep.java +++ b/platform/lang-impl/src/com/intellij/ide/util/projectWizard/AbstractNewProjectStep.java @@ -28,13 +28,14 @@ import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.wm.IdeFocusManager; +import com.intellij.openapi.wm.IdeFrame; import com.intellij.platform.CustomStepProjectGenerator; import com.intellij.platform.DirectoryProjectGenerator; import com.intellij.platform.PlatformProjectOpenProcessor; @@ -158,9 +159,11 @@ public class AbstractNewProjectStep extends DefaultActionGroup implements DumbAw public void consume(@Nullable final ProjectSettingsStepBase settings) { if (settings == null) return; - final Project project = ProjectManager.getInstance().getDefaultProject(); + // todo projectToClose should be passed from calling action, this is just a quick workaround + IdeFrame frame = IdeFocusManager.getGlobalInstance().getLastFocusedFrame(); + final Project projectToClose = frame != null ? frame.getProject() : null; final DirectoryProjectGenerator generator = settings.getProjectGenerator(); - doGenerateProject(project, settings.getProjectLocation(), generator, + doGenerateProject(projectToClose, settings.getProjectLocation(), generator, file -> getProjectSettings(generator)); } @@ -168,14 +171,14 @@ public class AbstractNewProjectStep extends DefaultActionGroup implements DumbAw abstract protected Object getProjectSettings(@NotNull DirectoryProjectGenerator generator); } - public static Project doGenerateProject(@Nullable final Project project, + public static Project doGenerateProject(@Nullable final Project projectToClose, @NotNull final String locationString, @Nullable final DirectoryProjectGenerator generator, @NotNull final Function settingsComputable) { final File location = new File(FileUtil.toSystemDependentName(locationString)); if (!location.exists() && !location.mkdirs()) { String message = ActionsBundle.message("action.NewDirectoryProject.cannot.create.dir", location.getAbsolutePath()); - Messages.showErrorDialog(project, message, ActionsBundle.message("action.NewDirectoryProject.title")); + Messages.showErrorDialog(projectToClose, message, ActionsBundle.message("action.NewDirectoryProject.title")); return null; } @@ -188,7 +191,7 @@ public class AbstractNewProjectStep extends DefaultActionGroup implements DumbAw if (baseDir.getChildren().length > 0) { String message = ActionsBundle.message("action.NewDirectoryProject.not.empty", location.getAbsolutePath()); - int rc = Messages.showYesNoDialog(project, message, ActionsBundle.message("action.NewDirectoryProject.title"), Messages.getQuestionIcon()); + int rc = Messages.showYesNoDialog(projectToClose, message, ActionsBundle.message("action.NewDirectoryProject.title"), Messages.getQuestionIcon()); if (rc == Messages.YES) { return PlatformProjectOpenProcessor.getInstance().doOpenProject(baseDir, null, false); } @@ -221,6 +224,6 @@ public class AbstractNewProjectStep extends DefaultActionGroup implements DumbAw }; } EnumSet options = EnumSet.noneOf(PlatformProjectOpenProcessor.Option.class); - return PlatformProjectOpenProcessor.doOpenProject(baseDir, null, -1, callback, options); + return PlatformProjectOpenProcessor.doOpenProject(baseDir, projectToClose, -1, callback, options); } } \ No newline at end of file