Skip to content

Commit

Permalink
Webview - Add DevTools window (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
Or-Geva authored Jul 24, 2023
1 parent 0194daa commit 8d1d240
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/main/java/com/jfrog/ide/idea/ui/JfrogContextMenuHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.jfrog.ide.idea.ui;

import org.cef.browser.CefBrowser;
import org.cef.browser.CefFrame;
import org.cef.callback.CefContextMenuParams;
import org.cef.callback.CefMenuModel;
import org.cef.handler.CefContextMenuHandler;

import javax.swing.*;
import java.awt.*;

public class JfrogContextMenuHandler implements CefContextMenuHandler {
private static final int DEV_TOOLS_ID = 1;

@Override
public void onBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams params, CefMenuModel model) {
model.clear();
model.addItem(DEV_TOOLS_ID, "Inspect");
}

@Override
public boolean onContextMenuCommand(CefBrowser browser, CefFrame frame, CefContextMenuParams params, int commandId, int eventFlags) {
if (commandId == DEV_TOOLS_ID) {
openDevTools(browser);
return true;
}
return false;
}

private void openDevTools(CefBrowser browser) {
SwingUtilities.invokeLater(() -> {
CefBrowser devToolsBrowser = browser.getDevTools();
JFrame frame = new JFrame("DevTools - JFrog IDE Webview");
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.setSize(800, 600);
frame.getContentPane().add(devToolsBrowser.getUIComponent(), BorderLayout.CENTER);
frame.setVisible(true);
});
}

@Override
public void onContextMenuDismissed(CefBrowser browser, CefFrame frame) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.intellij.openapi.util.Disposer;
import com.intellij.ui.jcef.JBCefBrowser;
import com.jfrog.ide.idea.log.Logger;
import com.jfrog.ide.idea.ui.JfrogContextMenuHandler;
import com.jfrog.ide.idea.ui.jcef.message.MessagePacker;
import com.jfrog.ide.idea.ui.jcef.message.MessageType;
import org.cef.CefApp;
Expand All @@ -28,6 +29,7 @@ public CefBrowser createBrowser(Runnable onLoadEnd) {
streamConsoleMessagesToLog();
handleLoadEvent(onLoadEnd);
messagePacker = new MessagePacker(cefBrowser);
jbCefBrowser.getJBCefClient().addContextMenuHandler(new JfrogContextMenuHandler(), jbCefBrowser.getCefBrowser());
return cefBrowser;
}

Expand Down

0 comments on commit 8d1d240

Please sign in to comment.