Skip to content

Commit

Permalink
Add an action to open the dev tools for the JCEF preview
Browse files Browse the repository at this point in the history
  • Loading branch information
ahus1 committed Nov 7, 2022
1 parent 20ce2b4 commit 52efefd
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This document provides a high-level view of the changes introduced by release.
=== 0.37.55

- Require IntelliJ 2021.3.2 as minimum version update deprecated APIs
- Add an action to open the dev tools for the JCEF preview

=== 0.37.54

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,38 +76,62 @@ JCEF preview is an embedded Chrome browser.
After enabling the DevTools, users can right-click on the preview and use "`Open DevTools`".
This opens a fully equipped Chrome developer tools window that allows users to inspect the HTML created in the preview and to view the JavaScript console of the preview.

// https://youtrack.jetbrains.com/issue/IDEA-276906
For IntelliJ 2021.3 and later::
+
--
Set the registry key `ide.browser.jcef.contextMenu.devTools.enabled` to `true` to enable this feature.

The registry is available via menu menu:Help[Find action...], then enter "`Registry`" to search the action, then choose "`Registry...`".
In the dialog that opens, start typing the registry key given above to restrict the list.
Check the checkbox on the right to enable this property.
Press btn:[Close] to close the dialog.
The DevTools are available for all newly opened editors.
For editors already open, close and re-open them to see the DevTools.
No IDE restart is required.

// https://youtrack.jetbrains.com/issue/IDEA-286008
[WARNING]
====
In IntelliJ 2021.3.1, closing the DevTools will also close the IDE.
In IntelliJ 2021.3.1+, closing the DevTools will also close the IDE.
This is tracked in upstream issue https://youtrack.jetbrains.com/issue/IDEA-286008[IDEA-286008].
Possible Workarounds:
* Enable "`Confirm before existing the IDE`" in the IDE's settings.
Once the DevTools have been closed for an editor, the editor needs to be closed and re-opened before DevTools can be opened again.
* Turn off registry option "`ide.browser.jcef.asciidocView.osr.enabled`".
* Turn off registry option `ide.browser.jcef.asciidocView.osr.enabled`.
+
With OSR turned off, the IDE doesn't close any more on closing the DevTools; instead the preview goes blank once dev tools are closed (see https://youtrack.jetbrains.com/issue/IDEA-284130[IDEA-284130]).
Closing and re-opening the editor restores the preview.
+
Once OSR is turned off, unpinned tool windows can no longer show above the preview (see https://youtrack.jetbrains.com/issue/IDEA-252845[IDEA-252845]).
====

For the AsciiDoc plugin 0.37.55+::
+
--
Use the menu item menu:Help[Find Action...] and choose "`Open Devtools Window for the current AsciiDoc Preview`".

Users can define their own shortcut in the Keymap settings entry for this action.
--

For IntelliJ 2022.3 and later::
+
--
Set the registry key `ide.browser.jcef.contextMenu.devTools.enabled` to `true` and set `ide.browser.jcef.asciidocView.osr.enabled` to false to enable this feature.

Once OSR is turned off, unpinned tool windows can no longer show above the preview (see https://youtrack.jetbrains.com/issue/IDEA-252845[IDEA-252845]).

The registry is available via menu menu:Help[Find action...], then enter "`Registry`" to search the action, then choose "`Registry...`".
In the dialog that opens, start typing the registry key given above to restrict the list.
Check the checkbox on the right to enable this property.
Press btn:[Close] to close the dialog.
The DevTools are available for all newly opened editors.
For editors already open, close and re-open them to see the DevTools.
No IDE restart is required.
--

// https://youtrack.jetbrains.com/issue/IDEA-276906
For IntelliJ 2021.3 and later::
+
--
Set the registry key `ide.browser.jcef.contextMenu.devTools.enabled` to `true` to enable this feature.

The registry is available via menu menu:Help[Find action...], then enter "`Registry`" to search the action, then choose "`Registry...`".
In the dialog that opens, start typing the registry key given above to restrict the list.
Check the checkbox on the right to enable this property.
Press btn:[Close] to close the dialog.
The DevTools are available for all newly opened editors.
For editors already open, close and re-open them to see the DevTools.
No IDE restart is required.
--

For IntelliJ 2021.2 and earlier::
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.asciidoc.intellij.actions;

import com.intellij.openapi.actionSystem.AnActionEvent;
import org.asciidoc.intellij.actions.asciidoc.AsciiDocAction;
import org.asciidoc.intellij.editor.AsciiDocHtmlPanel;
import org.asciidoc.intellij.editor.AsciiDocSplitEditor;
import org.asciidoc.intellij.editor.jcef.AsciiDocJCEFHtmlPanel;
import org.asciidoc.intellij.ui.SplitFileEditor;
import org.jetbrains.annotations.NotNull;

public class OpenDevtoolsAction extends AsciiDocAction {
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
SplitFileEditor<?, ?> fileEditor = AsciiDocActionUtil.findSplitEditor(event);
if (fileEditor instanceof AsciiDocSplitEditor) {
AsciiDocHtmlPanel panel = ((AsciiDocSplitEditor) fileEditor).getSecondEditor().getPanel();
if (panel instanceof AsciiDocJCEFHtmlPanel) {
((AsciiDocJCEFHtmlPanel) panel).openDevtools();
}
}
}

@Override
public void update(@NotNull AnActionEvent event) {
boolean visible = false;
SplitFileEditor<?, ?> fileEditor = AsciiDocActionUtil.findSplitEditor(event);
if (fileEditor instanceof AsciiDocSplitEditor) {
AsciiDocHtmlPanel panel = ((AsciiDocSplitEditor) fileEditor).getSecondEditor().getPanel();
if (panel instanceof AsciiDocJCEFHtmlPanel) {
visible = true;
}
}
event.getPresentation().setVisible(visible);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ public JComponent getPreferredFocusedComponent() {
return preferredFocusedComponent;
}

public AsciiDocHtmlPanel getPanel() {
return myPanel;
}

/**
* Get the editor displayable name.
*
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@
<add-to-group group-id="EditorPopupMenu" anchor="first"/>
</group>

<action id="AsciiDocOpenDevtools" text="Open Devtools Window for the current AsciiDoc Preview"
class="org.asciidoc.intellij.actions.OpenDevtoolsAction"/>

<group id="AsciiDocConvert" class="org.asciidoc.intellij.actions.asciidoc.AsciiDocActionGroup">
<action id="asciidoc.convert.document" class="org.asciidoc.intellij.actions.ConvertToAsciiDocAction"
text="Convert to AsciiDoc" description="Convert this document to AsciiDoc">
Expand Down

0 comments on commit 52efefd

Please sign in to comment.