From ef89b40dd5a732ff68e8d68d1e897286d553bff4 Mon Sep 17 00:00:00 2001 From: Anton Tarasov Date: Wed, 4 Dec 2019 15:02:37 +0300 Subject: [PATCH] Add "Show Web Browser" action for JCEF (internal mode) GitOrigin-RevId: bca787f7c28e901bf7de4e087889951f3fe18dc8 --- .../src/com/intellij/internal/WebBrowser.java | 40 +++++++++++++++++++ .../src/idea/PlatformActions.xml | 1 + 2 files changed, 41 insertions(+) create mode 100644 platform/platform-impl/src/com/intellij/internal/WebBrowser.java diff --git a/platform/platform-impl/src/com/intellij/internal/WebBrowser.java b/platform/platform-impl/src/com/intellij/internal/WebBrowser.java new file mode 100644 index 000000000000..688b06606cfb --- /dev/null +++ b/platform/platform-impl/src/com/intellij/internal/WebBrowser.java @@ -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); + } +} diff --git a/platform/platform-resources/src/idea/PlatformActions.xml b/platform/platform-resources/src/idea/PlatformActions.xml index b1a26053c130..cf5ef0726ad6 100644 --- a/platform/platform-resources/src/idea/PlatformActions.xml +++ b/platform/platform-resources/src/idea/PlatformActions.xml @@ -1113,6 +1113,7 @@ +