Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webview - Add DevTools window #372

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading