Skip to content

Commit

Permalink
feat:添加浏览器tabBar
Browse files Browse the repository at this point in the history
  • Loading branch information
darksheep committed Jul 26, 2023
1 parent e221db1 commit 005c95a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.darksheep.sheepnote.ui.swing.editor.utils.EditorHelper;
import com.darksheep.sheepnote.ui.swing.toolWindow.divider.CustomSplitPaneUI;
import com.darksheep.sheepnote.ui.web.brower.JBCefBrowserSingleton;
import com.darksheep.sheepnote.ui.web.container.BrowserPanel;
import com.darksheep.sheepnote.utils.LocalHtmlHelper;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnActionEvent;
Expand Down Expand Up @@ -96,12 +97,16 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo
Content mainContent = contentFactory.createContent(mainPanel, "NoteList", false);

// 第二个 Content,包含 FlowchartPanel
Content flowchartContent = contentFactory.createContent(flowchartPanel, "NoteFlowchart", false);
Content flowchartContent = contentFactory.createContent(jbCefBrowser.getComponent(), "NoteFlowchart", false);

//第三个 浏览器
Content browserContent = contentFactory.createContent(new BrowserPanel(), "Browser", false);



toolWindow.getContentManager().addContent(mainContent);
toolWindow.getContentManager().addContent(flowchartContent);
toolWindow.getContentManager().addContent(browserContent);
toolWindow.getContentManager().setSelectedContent(mainContent);
}
@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.darksheep.sheepnote.ui.web.container;

import com.darksheep.sheepnote.ui.web.container.actions.GBackAction;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.ActionPlaces;
import com.intellij.openapi.actionSystem.ActionToolbar;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.ui.SimpleToolWindowPanel;
import com.intellij.ui.jcef.JBCefBrowser;

public class BrowserPanel extends SimpleToolWindowPanel {

private JBCefBrowser jbCefBrowser;

public BrowserPanel() {
super(true, true);
jbCefBrowser = new JBCefBrowser("bing.com");
ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.CONTEXT_TOOLBAR, buildToolbar(), true);
setContent(jbCefBrowser.getComponent());
setToolbar(actionToolbar.getComponent());

}
private DefaultActionGroup buildToolbar() {
DefaultActionGroup toolbar = new DefaultActionGroup();
GBackAction backButton = new GBackAction(jbCefBrowser, AllIcons.Actions.Back);
toolbar.add(backButton);
return toolbar;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.darksheep.sheepnote.ui.web.container.actions;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.DumbAware;
import com.intellij.ui.jcef.JBCefBrowser;

import javax.swing.*;

public class GBackAction extends AnAction implements DumbAware {
private JBCefBrowser jbCefBrowser;

public GBackAction(JBCefBrowser jbCefBrowser, Icon icon) {
super(icon);
this.jbCefBrowser = jbCefBrowser;
}

@Override
public void update(AnActionEvent e) {
if (!jbCefBrowser.getCefBrowser().canGoBack()) {
e.getPresentation().setEnabled(false);
return;
}
super.update(e);
}

@Override
public void actionPerformed(AnActionEvent e) {
jbCefBrowser.getCefBrowser().canGoBack();
}
}

0 comments on commit 005c95a

Please sign in to comment.