diff --git a/platform/built-in-server/src/org/jetbrains/ide/OpenFileHttpService.java b/platform/built-in-server/src/org/jetbrains/ide/OpenFileHttpService.java index 20dc8d0e7cc5..c800f14ddeb2 100644 --- a/platform/built-in-server/src/org/jetbrains/ide/OpenFileHttpService.java +++ b/platform/built-in-server/src/org/jetbrains/ide/OpenFileHttpService.java @@ -23,6 +23,7 @@ import com.intellij.openapi.fileEditor.OpenFileDescriptor; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.project.ProjectUtil; +import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.util.text.StringUtilRt; @@ -44,6 +45,7 @@ import org.jetbrains.builtInWebServer.WebServerPathToFileManager; import org.jetbrains.concurrency.AsyncPromise; import org.jetbrains.concurrency.Promise; +import javax.swing.*; import java.io.File; import java.io.IOException; import java.util.concurrent.ConcurrentLinkedQueue; @@ -169,16 +171,33 @@ class OpenFileHttpService extends RestService { @NotNull Promise openFile(@NotNull OpenFileRequest request) { - String path = FileUtil.expandUserHome(request.file); - final File file = new File(FileUtil.toSystemDependentName(path)); + String systemIndependentName = FileUtil.toSystemIndependentName(FileUtil.expandUserHome(request.file)); + final File file = new File(systemIndependentName); + if (file.isAbsolute()) { + if (com.intellij.ide.impl.ProjectUtil.isRemotePath(systemIndependentName)) { + Ref confirmLoadingRemoteFile = new Ref<>(); + try { + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + boolean value = com.intellij.ide.impl.ProjectUtil + .confirmLoadingFromRemotePath(systemIndependentName, "warning.load.file.from.share", "title.load.file.from.share"); + confirmLoadingRemoteFile.set(value); + } + }); + } catch (Throwable ignored) {} + if (confirmLoadingRemoteFile.get() != Boolean.TRUE) { + return Promise.reject(NOT_FOUND); + } + } return openAbsolutePath(file, request); } // we don't want to call refresh for each attempt on findFileByRelativePath call, so, we do what ourSaveAndSyncHandlerImpl does on frame activation RefreshQueue queue = RefreshQueue.getInstance(); queue.cancelSession(refreshSessionId); - OpenFileTask task = new OpenFileTask(FileUtil.toCanonicalPath(FileUtil.toSystemIndependentName(path), '/'), request); + OpenFileTask task = new OpenFileTask(FileUtil.toCanonicalPath(systemIndependentName, '/'), request); requests.offer(task); RefreshSession session = queue.createSession(true, true, new Runnable() { @Override diff --git a/platform/built-in-server/src/org/jetbrains/ide/ProjectSetRequestHandler.java b/platform/built-in-server/src/org/jetbrains/ide/ProjectSetRequestHandler.java index 351ac3483cd9..a469f05b1c6d 100644 --- a/platform/built-in-server/src/org/jetbrains/ide/ProjectSetRequestHandler.java +++ b/platform/built-in-server/src/org/jetbrains/ide/ProjectSetRequestHandler.java @@ -18,6 +18,7 @@ package org.jetbrains.ide; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ModalityState; import com.intellij.platform.ProjectSetReader; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.FullHttpRequest; @@ -63,13 +64,13 @@ public class ProjectSetRequestHandler extends RestService { @Override public String execute(@NotNull QueryStringDecoder urlDecoder, @NotNull FullHttpRequest request, @NotNull ChannelHandlerContext context) throws IOException { final JsonObject descriptor = new JsonParser().parse(createJsonReader(request)).getAsJsonObject(); - ApplicationManager.getApplication().invokeLater(new Runnable() { + ApplicationManager.getApplication().invokeAndWait(new Runnable() { @Override public void run() { new ProjectSetReader().readDescriptor(descriptor, null); activateLastFocusedFrame(); } - }); + }, ModalityState.any()); sendOk(request, context); return null; } diff --git a/platform/core-api/src/com/intellij/ide/IdeBundle.java b/platform/core-api/src/com/intellij/ide/IdeBundle.java index 51e4c1b66aac..368a4f55c2a4 100644 --- a/platform/core-api/src/com/intellij/ide/IdeBundle.java +++ b/platform/core-api/src/com/intellij/ide/IdeBundle.java @@ -35,7 +35,7 @@ public class IdeBundle { } private static Reference ourBundle; - @NonNls private static final String BUNDLE = "messages.IdeBundle"; + @NonNls public static final String BUNDLE = "messages.IdeBundle"; private IdeBundle() { } diff --git a/platform/platform-impl/src/com/intellij/ide/impl/ProjectUtil.java b/platform/platform-impl/src/com/intellij/ide/impl/ProjectUtil.java index aeacbe6726c7..f9e99a488e43 100644 --- a/platform/platform-impl/src/com/intellij/ide/impl/ProjectUtil.java +++ b/platform/platform-impl/src/com/intellij/ide/impl/ProjectUtil.java @@ -44,6 +44,7 @@ import com.intellij.util.SystemProperties; import org.jdom.JDOMException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.PropertyKey; import javax.swing.*; import java.awt.*; @@ -178,12 +179,7 @@ public class ProjectUtil { } if (isRemotePath(path) && !RecentProjectsManager.getInstance().hasPath(path)) { - final Window window = getActiveFrameOrWelcomeScreen(); - final String msg = IdeBundle.message("warning.load.project.from.share", path); - final String title = IdeBundle.message("title.load.project.from.share"); - final Icon icon = Messages.getWarningIcon(); - final int answer = window == null ? Messages.showYesNoDialog(msg, title, icon) : Messages.showYesNoDialog(window, msg, title, icon); - if (answer != Messages.YES) { + if (!confirmLoadingFromRemotePath(path, "warning.load.project.from.share", "title.load.project.from.share")) { return null; } } @@ -210,6 +206,17 @@ public class ProjectUtil { return project; } + public static boolean confirmLoadingFromRemotePath(@NotNull String path, + @NotNull @PropertyKey(resourceBundle = IdeBundle.BUNDLE) String msgKey, + @NotNull @PropertyKey(resourceBundle = IdeBundle.BUNDLE) String titleKey) { + final Window window = getActiveFrameOrWelcomeScreen(); + final String msg = IdeBundle.message(msgKey, path); + final String title = IdeBundle.message(titleKey); + final Icon icon = Messages.getWarningIcon(); + final int answer = window == null ? Messages.showYesNoDialog(msg, title, icon) : Messages.showYesNoDialog(window, msg, title, icon); + return answer == Messages.YES; + } + private static Window getActiveFrameOrWelcomeScreen() { Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow(); if (window != null) return window; @@ -223,7 +230,7 @@ public class ProjectUtil { return null; } - private static boolean isRemotePath(@NotNull String path) { + public static boolean isRemotePath(@NotNull String path) { return path.contains("//") || path.contains("\\\\"); } diff --git a/platform/platform-resources-en/src/messages/IdeBundle.properties b/platform/platform-resources-en/src/messages/IdeBundle.properties index 17fecbc68fcf..88607e0eaf70 100644 --- a/platform/platform-resources-en/src/messages/IdeBundle.properties +++ b/platform/platform-resources-en/src/messages/IdeBundle.properties @@ -1193,4 +1193,6 @@ go.to.class.dumb.mode.message=Go To Class action is not available until indices edit.custom.settings.confirm=File \n''{0}''\n does not exist. Create? warning.load.project.from.share=You are opening a project from a network share. Do you trust this location?\n{0} -title.load.project.from.share=Loading Project From Network \ No newline at end of file +title.load.project.from.share=Loading Project From Network +warning.load.file.from.share=You are opening a file from a network share. Do you want to continue?\n{0} +title.load.file.from.share=Loading File From Network \ No newline at end of file