Skip to content

Commit

Permalink
fix: #495 register tool windows later to make IJ 2022.1 happy
Browse files Browse the repository at this point in the history
  • Loading branch information
bjansen committed Mar 6, 2022
1 parent c26ad76 commit 252ac62
Showing 1 changed file with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public class ANTLRv4PluginController implements ProjectComponent {

public Project project;
public ConsoleView console;
public ToolWindow consoleWindow;
private ToolWindow consoleWindow;

public Map<String, PreviewState> grammarToPreviewState =
Collections.synchronizedMap(new HashMap<>());
public ToolWindow previewWindow; // same for all grammar editor
private ToolWindow previewWindow; // same for all grammar editor
public PreviewPanel previewPanel; // same for all grammar editor

public MyVirtualFileAdapter myVirtualFileAdapter = new MyVirtualFileAdapter();
Expand Down Expand Up @@ -128,24 +128,29 @@ public void createToolWindows() {
previewPanel = new PreviewPanel(project);

ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
Content content = contentFactory.createContent(previewPanel, "", false);
content.setCloseable(false);

previewWindow = toolWindowManager.registerToolWindow(PREVIEW_WINDOW_ID, true, ToolWindowAnchor.BOTTOM);
previewWindow.getContentManager().addContent(content);
previewWindow.setIcon(Icons.getToolWindow());
toolWindowManager.invokeLater(() -> {
Content content = contentFactory.createContent(previewPanel, "", false);
content.setCloseable(false);

previewWindow = toolWindowManager.registerToolWindow(PREVIEW_WINDOW_ID, true, ToolWindowAnchor.BOTTOM);
previewWindow.getContentManager().addContent(content);
previewWindow.setIcon(Icons.getToolWindow());
});

TextConsoleBuilderFactory factory = TextConsoleBuilderFactory.getInstance();
TextConsoleBuilder consoleBuilder = factory.createBuilder(project);
this.console = consoleBuilder.getConsole();

JComponent consoleComponent = console.getComponent();
content = contentFactory.createContent(consoleComponent, "", false);
content.setCloseable(false);
toolWindowManager.invokeLater(() -> {
JComponent consoleComponent = console.getComponent();
Content content = contentFactory.createContent(consoleComponent, "", false);
content.setCloseable(false);

consoleWindow = toolWindowManager.registerToolWindow(CONSOLE_WINDOW_ID, true, ToolWindowAnchor.BOTTOM);
consoleWindow.getContentManager().addContent(content);
consoleWindow.setIcon(Icons.getToolWindow());
consoleWindow = toolWindowManager.registerToolWindow(CONSOLE_WINDOW_ID, true, ToolWindowAnchor.BOTTOM);
consoleWindow.getContentManager().addContent(content);
consoleWindow.setIcon(Icons.getToolWindow());
});
}

@Override
Expand Down Expand Up @@ -335,7 +340,9 @@ private void hidePreview() {
if (previewPanel != null) {
previewPanel.setEnabled(false);
}
previewWindow.hide(null);
if (previewWindow != null) {
previewWindow.hide(null);
}
}

/** Make sure to run after updating grammars in previewState */
Expand Down

0 comments on commit 252ac62

Please sign in to comment.