Add "Show Web Browser" action for JCEF (internal mode)

GitOrigin-RevId: bca787f7c28e901bf7de4e087889951f3fe18dc8
This commit is contained in:
Anton Tarasov
2019-12-04 12:07:42 +00:00
committed by intellij-monorepo-bot
parent 13b6bac7af
commit ef89b40dd5
2 changed files with 41 additions and 0 deletions
@@ -0,0 +1,40 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.internal;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.wm.impl.IdeFrameImpl;
import com.intellij.ui.jcef.JBCefBrowser;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
/**
* @author tav
*/
public class WebBrowser extends AnAction implements DumbAware {
private static final String URL = "http://maps.google.com";
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Window activeFrame = IdeFrameImpl.getActiveFrame();
if (activeFrame == null) return;
Rectangle bounds = activeFrame.getGraphicsConfiguration().getBounds();
JFrame frame = new IdeFrameImpl();
frame.setTitle("Web Browser - JCEF");
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.setBounds(bounds.width / 4, bounds.height / 4, bounds.width / 2, bounds.height / 2);
frame.setLayout(new BorderLayout());
JBCefBrowser browser = new JBCefBrowser(URL);
frame.add(browser.getComponent(), BorderLayout.CENTER);
JTextField urlBar = new JTextField(URL);
urlBar.addActionListener(event -> browser.loadURL(urlBar.getText()));
frame.add(urlBar, BorderLayout.NORTH);
frame.setVisible(true);
}
}
@@ -1113,6 +1113,7 @@
<action id="DebugMigLayoutAction" internal="true" class="com.intellij.ui.layout.migLayout.DebugMigLayoutAction"
text="UI DSL Debug Mode"/>
<action id="ShowcaseUiDslAction" internal="true" class="com.intellij.ui.layout.ShowcaseUiDslAction" text="UI DSL Showcase"/>
<action id="WebBrowser" class="com.intellij.internal.WebBrowser" text="Show &amp;Web Browser"/>
</group>
<group id="TopAnomalies" internal="true" class="com.intellij.internal.anomalies.TopAnomaliesAction" text="Top Anomalies"
popup="true"/>