mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-24830 Intellij IDEA 2017 freeze on Macos 10.12.5
This commit is contained in:
@@ -3,6 +3,7 @@ package org.jetbrains.plugins.ipnb;
|
||||
import com.github.rjeschke.txtmark.Configuration;
|
||||
import com.github.rjeschke.txtmark.Processor;
|
||||
import com.intellij.ide.BrowserUtil;
|
||||
import com.intellij.ide.IdeEventQueue;
|
||||
import com.intellij.ide.ui.LafManager;
|
||||
import com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -11,10 +12,10 @@ import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.jetbrains.python.PythonHelpersLocator;
|
||||
import com.sun.javafx.application.PlatformImpl;
|
||||
import com.sun.javafx.webkit.Accessor;
|
||||
import com.sun.webkit.WebPage;
|
||||
import com.sun.webkit.graphics.WCSize;
|
||||
import javafx.application.Platform;
|
||||
import javafx.concurrent.Worker;
|
||||
import javafx.embed.swing.JFXPanel;
|
||||
import javafx.scene.Scene;
|
||||
@@ -67,8 +68,12 @@ public class IpnbJfxUtils {
|
||||
private static final String ourPostfix = "</div></body></html>";
|
||||
private static URL ourStyleUrl;
|
||||
|
||||
public static JComponent createHtmlPanel(@NotNull final String source, int width, boolean repaint) {
|
||||
|
||||
private static void runFX(@NotNull Runnable r) {
|
||||
IdeEventQueue.unsafeNonblockingExecute(r);
|
||||
}
|
||||
|
||||
public static JComponent createHtmlPanel(@NotNull final String source, int width) {
|
||||
final JFXPanel javafxPanel = new JFXPanel() {
|
||||
@Override
|
||||
protected void processMouseWheelEvent(MouseWheelEvent e) {
|
||||
@@ -77,7 +82,7 @@ public class IpnbJfxUtils {
|
||||
parent.dispatchEvent(parentEvent);
|
||||
}
|
||||
};
|
||||
Platform.runLater(() -> {
|
||||
ApplicationManager.getApplication().invokeLater(() -> runFX(() -> PlatformImpl.runLater(() -> {
|
||||
final WebView webView = new WebView();
|
||||
webView.setContextMenuEnabled(false);
|
||||
webView.setOnDragDetected(event -> {
|
||||
@@ -90,14 +95,14 @@ public class IpnbJfxUtils {
|
||||
engine.setOnStatusChanged(event -> {
|
||||
final String data = event.getData();
|
||||
if (data != null && data.isEmpty()) {
|
||||
adjustHeight(webView, javafxPanel, source, repaint);
|
||||
adjustHeight(webView, javafxPanel, source);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
engine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue == Worker.State.SUCCEEDED) {
|
||||
adjustHeight(webView, javafxPanel, source, repaint);
|
||||
adjustHeight(webView, javafxPanel, source);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -117,7 +122,7 @@ public class IpnbJfxUtils {
|
||||
javafxPanel.setScene(scene);
|
||||
updateLaf(LafManager.getInstance().getCurrentLookAndFeel() instanceof DarculaLookAndFeelInfo,
|
||||
engine, javafxPanel);
|
||||
});
|
||||
})));
|
||||
|
||||
return javafxPanel;
|
||||
}
|
||||
@@ -233,7 +238,7 @@ public class IpnbJfxUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static void adjustHeight(final WebView webView, final JFXPanel javafxPanel, String source, boolean repaintCallback) {
|
||||
private static void adjustHeight(final WebView webView, final JFXPanel javafxPanel, String source) {
|
||||
final WebEngine engine = webView.getEngine();
|
||||
final Document document = engine.getDocument();
|
||||
if (document != null) {
|
||||
@@ -275,10 +280,11 @@ public class IpnbJfxUtils {
|
||||
final Dimension size = new Dimension(
|
||||
width, height + count * EditorColorsManager.getInstance().getGlobalScheme().getEditorFontSize());
|
||||
|
||||
ApplicationManager.getApplication().invokeLater(()-> javafxPanel.setPreferredSize(size));
|
||||
if (repaintCallback) {
|
||||
ApplicationManager.getApplication().invokeLater(()->javafxPanel.repaint());
|
||||
}
|
||||
ApplicationManager.getApplication().invokeLater(()->{
|
||||
javafxPanel.setPreferredSize(size);
|
||||
javafxPanel.revalidate();
|
||||
javafxPanel.repaint();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -290,11 +296,11 @@ public class IpnbJfxUtils {
|
||||
}
|
||||
|
||||
private static void updateLafDarcula(WebEngine engine, JFXPanel jfxPanel) {
|
||||
Platform.runLater(() -> {
|
||||
ApplicationManager.getApplication().invokeLater(() -> runFX(() -> PlatformImpl.runLater(() -> {
|
||||
ourStyleUrl = IpnbFileType.class.getResource("/style/javaFXBrowserDarcula.css");
|
||||
engine.setUserStyleSheetLocation(ourStyleUrl.toExternalForm());
|
||||
jfxPanel.getScene().getStylesheets().add(ourStyleUrl.toExternalForm());
|
||||
engine.reload();
|
||||
});
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ public class IpnbUtils {
|
||||
private static final Logger LOG = Logger.getInstance(IpnbUtils.class);
|
||||
private static int hasFx = 0;
|
||||
|
||||
public static JComponent createLatexPane(@NotNull final String source, int width, boolean repaint) {
|
||||
final JComponent panel = createHtmlPanel(source, width, repaint);
|
||||
public static JComponent createLatexPane(@NotNull final String source, int width) {
|
||||
final JComponent panel = createHtmlPanel(source, width);
|
||||
|
||||
panel.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
@@ -52,9 +52,9 @@ public class IpnbUtils {
|
||||
return hasFx == 1;
|
||||
}
|
||||
|
||||
public static JComponent createHtmlPanel(@NotNull final String source, int width, boolean repaint) {
|
||||
public static JComponent createHtmlPanel(@NotNull final String source, int width) {
|
||||
if (hasFx()) {
|
||||
return IpnbJfxUtils.createHtmlPanel(source, width, repaint);
|
||||
return IpnbJfxUtils.createHtmlPanel(source, width);
|
||||
}
|
||||
return createNonJfxPanel(source);
|
||||
}
|
||||
|
||||
@@ -36,13 +36,13 @@ public class IpnbMarkdownPanel extends IpnbEditablePanel<JComponent, IpnbMarkdow
|
||||
@Override
|
||||
protected JComponent createViewPanel() {
|
||||
int width = myParent.getWidth();
|
||||
return IpnbUtils.createLatexPane(myCell.getSourceAsString(), width, false);
|
||||
return IpnbUtils.createLatexPane(myCell.getSourceAsString(), width);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCellView() {
|
||||
int width = myParent.getWidth();
|
||||
myViewPanel = IpnbUtils.createLatexPane(myCell.getSourceAsString(), width,true);
|
||||
myViewPanel = IpnbUtils.createLatexPane(myCell.getSourceAsString(), width);
|
||||
myViewPanel.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
|
||||
@@ -19,6 +19,6 @@ public class IpnbHtmlPanel extends IpnbCodeOutputPanel<IpnbHtmlOutputCell> {
|
||||
@Override
|
||||
protected JComponent createViewPanel() {
|
||||
final int width = myParent.getWidth();
|
||||
return IpnbUtils.createLatexPane(StringUtil.join(myCell.getHtmls(), ""), width, false);
|
||||
return IpnbUtils.createLatexPane(StringUtil.join(myCell.getHtmls(), ""), width);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,6 @@ public class IpnbLatexPanel extends IpnbCodeOutputPanel<IpnbLatexOutputCell> {
|
||||
@Override
|
||||
protected JComponent createViewPanel() {
|
||||
final int width = myParent.getWidth();
|
||||
return IpnbUtils.createLatexPane(StringUtil.join(myCell.getLatex(), ""), width, false);
|
||||
return IpnbUtils.createLatexPane(StringUtil.join(myCell.getLatex(), ""), width);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user