fixed PY-14819 IPython Notebook: invalid link to settings in popup for missing configuration

This commit is contained in:
Ekaterina Tuzova
2014-12-30 17:01:24 +03:00
parent cece57377b
commit 4b3922203b
@@ -12,6 +12,7 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ProjectFileIndex;
@@ -24,6 +25,7 @@ import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.HyperlinkAdapter;
import com.intellij.util.Alarm;
import com.jetbrains.python.PythonHelpersLocator;
import com.jetbrains.python.packaging.PyPackage;
@@ -37,6 +39,7 @@ import org.jetbrains.plugins.ipnb.format.cells.output.IpnbOutputCell;
import org.jetbrains.plugins.ipnb.protocol.IpnbConnection;
import org.jetbrains.plugins.ipnb.protocol.IpnbConnectionListenerBase;
import javax.swing.event.HyperlinkEvent;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
@@ -69,7 +72,13 @@ public final class IpnbConnectionManager implements ProjectComponent {
if (!myKernels.containsKey(path)) {
String url = IpnbSettings.getInstance(myProject).getURL();
if (StringUtil.isEmptyOrSpaces(url)) {
showWarning(fileEditor, "Please, specify IPython Notebook URL in <a href=\"\">Settings->IPython Notebook</a>");
showWarning(fileEditor, "Please, specify IPython Notebook URL in <a href=\"\">Settings->Tools->IPython Notebook</a>",
new HyperlinkAdapter() {
@Override
protected void hyperlinkActivated(HyperlinkEvent e) {
ShowSettingsUtil.getInstance().showSettingsDialog(myProject, "IPython Notebook");
}
});
return;
}
if (startConnection(codePanel, path, url, false)) {
@@ -119,23 +128,23 @@ public final class IpnbConnectionManager implements ProjectComponent {
private static String showDialogUrl(@NotNull final String initialUrl) {
final String url = Messages.showInputDialog("IPython Notebook URL:", "Start IPython Notebook", null, initialUrl,
new InputValidator() {
@Override
public boolean checkInput(String inputString) {
try {
new URL(inputString);
new InputValidator() {
@Override
public boolean checkInput(String inputString) {
try {
new URL(inputString);
}
catch (MalformedURLException e) {
return false;
}
return !inputString.isEmpty();
}
catch (MalformedURLException e) {
return false;
}
return !inputString.isEmpty();
}
@Override
public boolean canClose(String inputString) {
return true;
}
});
@Override
public boolean canClose(String inputString) {
return true;
}
});
return url == null ? null : StringUtil.trimEnd(url, "/");
}
@@ -164,7 +173,13 @@ public final class IpnbConnectionManager implements ProjectComponent {
}
catch (URISyntaxException e) {
if (showNotification)
showWarning(codePanel.getFileEditor(), "Please, check IPython Notebook URL in Settings->IPython Notebook");
showWarning(codePanel.getFileEditor(), "Please, check IPython Notebook URL in <a href=\"\">Settings->Tools->IPython Notebook</a>",
new HyperlinkAdapter() {
@Override
protected void hyperlinkActivated(HyperlinkEvent e) {
ShowSettingsUtil.getInstance().showSettingsDialog(myProject, "IPython Notebook");
}
});
LOG.warn("IPython Notebook URI Syntax Error: " + e.getMessage());
return false;
}
@@ -177,13 +192,18 @@ public final class IpnbConnectionManager implements ProjectComponent {
return true;
}
private static void showWarning(@NotNull final IpnbFileEditor fileEditor, @NotNull final String message) {
private static void showWarning(@NotNull final IpnbFileEditor fileEditor, @NotNull final String message,
@Nullable final HyperlinkAdapter listener) {
BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(
message, null, MessageType.WARNING.getPopupBackground(), null);
message, null, MessageType.WARNING.getPopupBackground(), listener);
final Balloon balloon = balloonBuilder.createBalloon();
balloon.showInCenterOf(fileEditor.getRunCellButton());
}
private static void showWarning(@NotNull final IpnbFileEditor fileEditor, @NotNull final String message) {
showWarning(fileEditor, message, null);
}
private boolean startIpythonServer(@NotNull final String url, @NotNull final IpnbFileEditor fileEditor) {
final Module module = ProjectFileIndex.SERVICE.getInstance(myProject).getModuleForFile(fileEditor.getVirtualFile());
if (module == null) return false;