From c9cb2c65b710d3aa22aa20e5753a082e6a2e12ed Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Fri, 23 Sep 2016 14:08:33 +0200 Subject: [PATCH] IDEA-119826 Do not require confirmation each time I open an IPR file CPP-7665 Cannot open *.cmake/CMakeLists.txt using File | Open - project is opened instead --- .../intellij/ide/actions/OpenFileAction.java | 22 +++++++++++++++---- .../src/messages/IdeBundle.properties | 3 +++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/actions/OpenFileAction.java b/platform/platform-impl/src/com/intellij/ide/actions/OpenFileAction.java index a9cf0aeeefe3..3ccf199c0dab 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/OpenFileAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/OpenFileAction.java @@ -17,6 +17,7 @@ package com.intellij.ide.actions; import com.intellij.icons.AllIcons; import com.intellij.ide.IdeBundle; +import com.intellij.ide.highlighter.ProjectFileType; import com.intellij.ide.impl.ProjectUtil; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; @@ -90,10 +91,23 @@ public class OpenFileAction extends AnAction implements DumbAware { // try to open as a project - unless the file is an .ipr of the current one if ((project == null || !file.equals(project.getProjectFile())) && OpenProjectFileChooserDescriptor.isProjectFile(file)) { - Project openedProject = ProjectUtil.openOrImport(file.getPath(), project, false); - if (openedProject != null) { - FileChooserUtil.setLastOpenedFile(openedProject, file); - return; + int answer = file.getFileType() instanceof ProjectFileType + ? Messages.YES + : Messages.showYesNoCancelDialog(project, + IdeBundle.message("message.open.file.is.project", file.getName()), + IdeBundle.message("title.open.project"), + IdeBundle.message("message.open.file.is.project.open.as.project"), + IdeBundle.message("message.open.file.is.project.open.as.file"), + IdeBundle.message("button.cancel"), + Messages.getQuestionIcon()); + if (answer == Messages.CANCEL) return; + + if (answer == Messages.YES) { + Project openedProject = ProjectUtil.openOrImport(file.getPath(), project, false); + if (openedProject != null) { + FileChooserUtil.setLastOpenedFile(openedProject, file); + return; + } } } diff --git a/platform/platform-resources-en/src/messages/IdeBundle.properties b/platform/platform-resources-en/src/messages/IdeBundle.properties index 042e343e10c8..632eedaa0687 100644 --- a/platform/platform-resources-en/src/messages/IdeBundle.properties +++ b/platform/platform-resources-en/src/messages/IdeBundle.properties @@ -427,6 +427,9 @@ title.popup.new.element.same.place=New in This Directory command.go.to.next.split=Go to next split message.occurrence.N.of.M=Occurrence {0} of {1} error.dir.contains.no.project=''{0}'' does not contain a project +message.open.file.is.project={0} is a project file.\nWould you like to open this project? +message.open.file.is.project.open.as.project=Open as &Project +message.open.file.is.project.open.as.file=Open as &File error.files.of.this.type.cannot.be.opened=Files of this type cannot be opened in {0} title.cannot.open.file=Cannot Open File title.cannot.open.project=Cannot Open Project