Skip to content

Commit 40c9605

Browse files
committed
implement shortcut to open jxbrowser devtools to JxBrowserPanel
(cherry picked from commit ee2f3ff)
1 parent 533f5d8 commit 40c9605

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

sirius_cli/src/main/resources/sirius.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,6 @@ de.unijena.bioinf.spec_viewer.sirius.anopanel = false
9696

9797

9898
de.unijena.bioinf.webservice.infopanel = true
99-
de.unijena.bioinf.webservice.login.terms = false
99+
de.unijena.bioinf.webservice.login.terms = false
100+
101+
io.sirius-ms.browser.devtools.allow = false

sirius_gui/src/main/java/io/sirius/ms/gui/webView/BrowserPanel.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,7 @@ public Dimension getPreferredSize() {
5959
public Dimension getMinimumSize() {
6060
return new Dimension(50,20);
6161
}
62+
63+
public abstract void showDevTools();
64+
6265
}

sirius_gui/src/main/java/io/sirius/ms/gui/webView/jxbrowser/JxBrowserPanel.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
import com.teamdev.jxbrowser.navigation.event.FrameLoadFinished;
88
import com.teamdev.jxbrowser.view.swing.BrowserView;
99
import de.unijena.bioinf.ms.gui.utils.GuiUtils;
10+
import de.unijena.bioinf.ms.properties.PropertyManager;
1011
import io.sirius.ms.gui.webView.BrowserPanel;
1112
import io.sirius.ms.gui.webView.LinkInterception;
1213
import lombok.extern.slf4j.Slf4j;
1314
import org.jetbrains.annotations.NotNull;
1415

16+
import javax.swing.*;
1517
import java.awt.*;
18+
import java.awt.event.ActionEvent;
1619
import java.net.URI;
1720

1821
@Slf4j
@@ -26,6 +29,7 @@ public JxBrowserPanel(String url, @NotNull Browser browser, LinkInterception lin
2629
this.browser = browser;
2730
this.linkInterception = linkInterception;
2831
initialize(url);
32+
addDevToolsKeybinding();
2933
}
3034

3135
private void initialize(@NotNull String url) {
@@ -127,4 +131,34 @@ public void cleanupResources() {
127131
if (browser != null && !browser.isClosed())
128132
browser.close();
129133
}
134+
135+
@Override
136+
public void showDevTools() {
137+
browser.devTools().show();
138+
}
139+
140+
private void addDevToolsKeybinding() {
141+
if (PropertyManager.getBoolean("io.sirius-ms.browser.devtools.allow", false)) {
142+
// Create the action to be performed
143+
Action f12Action = new AbstractAction() {
144+
@Override
145+
public void actionPerformed(ActionEvent e) {
146+
showDevTools();
147+
}
148+
};
149+
150+
// Get the InputMap and ActionMap for the panel
151+
InputMap inputMap = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
152+
ActionMap actionMap = getActionMap();
153+
154+
// Define a name for the action
155+
String actionKey = "doF12Action";
156+
157+
// Link the KeyStroke to the action name in the InputMap
158+
inputMap.put(KeyStroke.getKeyStroke("F12"), actionKey);
159+
160+
// Link the action name to the actual Action in the ActionMap
161+
actionMap.put(actionKey, f12Action);
162+
}
163+
}
130164
}

0 commit comments

Comments
 (0)