77import com .teamdev .jxbrowser .navigation .event .FrameLoadFinished ;
88import com .teamdev .jxbrowser .view .swing .BrowserView ;
99import de .unijena .bioinf .ms .gui .utils .GuiUtils ;
10+ import de .unijena .bioinf .ms .properties .PropertyManager ;
1011import io .sirius .ms .gui .webView .BrowserPanel ;
1112import io .sirius .ms .gui .webView .LinkInterception ;
1213import lombok .extern .slf4j .Slf4j ;
1314import org .jetbrains .annotations .NotNull ;
1415
16+ import javax .swing .*;
1517import java .awt .*;
18+ import java .awt .event .ActionEvent ;
1619import 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