|
87 | 87 | public class AsciiDocPreviewEditor extends UserDataHolderBase implements FileEditor {
|
88 | 88 |
|
89 | 89 | private static final Logger LOG = Logger.getInstance(AsciiDocPreviewEditor.class);
|
90 |
| - private static final String EMPTY_HTML = "<html></html>"; |
91 |
| - private static final String JCEF_HTML = "<html>If you can read this and not the content of your document, your preview does not show. One possible reason is that you are using a remote desktop and " + |
92 |
| - "GPU rendered content is not shown.<p>" + |
93 |
| - "To fix this, update the IDE's registry and set the key 'ide.browser.jcef.gpu.disable' to the value 'true'.<p>" + |
94 |
| - "To access the registry, open the menu 'Help | Find Action...' and then choose the action 'Registry...'. " + |
95 |
| - "Once the registry opens, type the key to find the entry, and enable the checkbox to set the value to 'true'. " + |
96 |
| - "Once you changed the value, restart the IDE for the setting to become effective.</html>"; |
97 | 90 | private final AsciiDocExtensionService extensionService = ApplicationManager.getApplication().getService(AsciiDocExtensionService.class);
|
98 | 91 | /**
|
99 | 92 | * single threaded with one task queue (one for each editor window).
|
@@ -219,6 +212,9 @@ private AsciiDocWrapper getAsciiDocInstance() {
|
219 | 212 | void renderIfVisible() {
|
220 | 213 | // visible = preview is enabled
|
221 | 214 | // displayable = editor window is visible as it is the active editor in a group
|
| 215 | + if (myPanel == null && getComponent().isVisible() && getComponent().isDisplayable()) { |
| 216 | + setupPanel(); |
| 217 | + } |
222 | 218 | if (myPanel != null && getComponent().isVisible() && getComponent().isDisplayable()) {
|
223 | 219 | render();
|
224 | 220 | }
|
@@ -298,13 +294,13 @@ public AsciiDocPreviewEditor(final Document document, Project project) {
|
298 | 294 | myHtmlPanelWrapper = new JPanel();
|
299 | 295 | LayoutManager overlay = new OverlayLayout(myHtmlPanelWrapper);
|
300 | 296 | myHtmlPanelWrapper.setLayout(overlay);
|
301 |
| - hint = new JLabel(EMPTY_HTML); |
| 297 | + hint = new JLabel(); |
302 | 298 | myHtmlPanelWrapper.add(hint);
|
303 | 299 |
|
304 | 300 | myHtmlPanelWrapper.addComponentListener(new ComponentAdapter() {
|
305 | 301 | @Override
|
306 | 302 | public void componentShown(ComponentEvent e) {
|
307 |
| - setupPanel(); |
| 303 | + renderIfVisible(); |
308 | 304 | }
|
309 | 305 |
|
310 | 306 | @Override
|
@@ -467,10 +463,15 @@ private static AsciiDocHtmlPanel detachOldPanelAndCreateAndAttachNewOne(Document
|
467 | 463 | }
|
468 | 464 | panelWrapper.add(newPanel.getComponent(), BorderLayout.CENTER, 0);
|
469 | 465 |
|
470 |
| - String hintText = newPanel instanceof AsciiDocJCEFHtmlPanel ? JCEF_HTML : EMPTY_HTML; |
471 |
| - if (!Objects.equals(hint.getText(), hintText)) { |
472 |
| - // defer UI update to avoid flicking of the shown text |
473 |
| - ApplicationManager.getApplication().invokeLater(() -> hint.setText(hintText)); |
| 466 | + if (newPanel instanceof AsciiDocJCEFHtmlPanel) { |
| 467 | + hint.setText("<html>If you can read this and not the content of your document, your preview does not show. One possible reason is that you are using a remote desktop and " + |
| 468 | + "GPU rendered content is not shown.<p>" + |
| 469 | + "To fix this, update the IDE's registry and set the key 'ide.browser.jcef.gpu.disable' to the value 'true'.<p>" + |
| 470 | + "To access the registry, open the menu 'Help | Find Action...' and then choose the action 'Registry...'. " + |
| 471 | + "Once the registry opens, type the key to find the entry, and enable the checkbox to set the value to 'true'. " + |
| 472 | + "Once you changed the value, restart the IDE for the setting to become effective."); |
| 473 | + } else { |
| 474 | + hint.setText("<html></html>"); |
474 | 475 | }
|
475 | 476 |
|
476 | 477 | return newPanel;
|
@@ -571,9 +572,7 @@ public boolean isValid() {
|
571 | 572 | */
|
572 | 573 | @Override
|
573 | 574 | public void selectNotify() {
|
574 |
| - if (myPanel == null) { |
575 |
| - setupPanel(); |
576 |
| - } |
| 575 | + renderIfVisible(); |
577 | 576 | if (FileDocumentManager.getInstance().getUnsavedDocuments().length > 0) {
|
578 | 577 | ApplicationManager.getApplication().invokeLater(() -> {
|
579 | 578 | // don't try to run save-all in parallel, therefore synchronize
|
|
0 commit comments