Skip to content

Commit a163366

Browse files
change label of close button to Close from Submit and close the editor when close button in webview is clicked.
1 parent 84fd348 commit a163366

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/java/com/microsoft/azure/toolkit/intellij/common/feedback/ProvideFeedbackAction.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
import com.microsoft.azure.toolkit.intellij.common.AzureFileType;
1717
import com.microsoft.azure.toolkit.intellij.common.IntelliJAzureIcons;
1818
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
19-
import org.jetbrains.annotations.NotNull;
19+
20+
import javax.annotation.Nonnull;
21+
import java.util.Objects;
2022

2123
public class ProvideFeedbackAction extends AnAction implements DumbAware {
2224
public static final Key<String> ID = new Key<>("ProvideFeedbackAction");
2325

2426
@Override
25-
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
26-
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(anActionEvent.getProject());
27+
public void actionPerformed(@Nonnull AnActionEvent anActionEvent) {
28+
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(Objects.requireNonNull(anActionEvent.getProject()));
2729
if (fileEditorManager == null) {
2830
return;
2931
}
@@ -39,10 +41,10 @@ public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
3941

4042
private LightVirtualFile searchExistingFile(FileEditorManager fileEditorManager) {
4143
LightVirtualFile virtualFile = null;
42-
for (VirtualFile editedFile : fileEditorManager.getOpenFiles()) {
43-
String fileResourceId = editedFile.getUserData(ID);
44+
for (final VirtualFile editedFile : fileEditorManager.getOpenFiles()) {
45+
final String fileResourceId = editedFile.getUserData(ID);
4446
if (fileResourceId != null && fileResourceId.equals(ProvideFeedbackAction.class.getCanonicalName()) &&
45-
editedFile.getFileType().getName().equals(ProvideFeedbackEditorProvider.TYPE)) {
47+
editedFile.getFileType().getName().equals(ProvideFeedbackEditorProvider.TYPE)) {
4648
virtualFile = (LightVirtualFile) editedFile;
4749
break;
4850
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/java/com/microsoft/azure/toolkit/intellij/common/feedback/ProvideFeedbackEditor.java

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,79 @@
55

66
package com.microsoft.azure.toolkit.intellij.common.feedback;
77

8+
import com.intellij.openapi.fileEditor.FileEditorManager;
89
import com.intellij.openapi.project.DumbAware;
910
import com.intellij.openapi.project.Project;
11+
import com.intellij.openapi.util.Disposer;
1012
import com.intellij.openapi.vfs.VirtualFile;
1113
import com.intellij.ui.jcef.JBCefBrowser;
14+
import com.intellij.ui.jcef.JBCefBrowserBase;
15+
import com.intellij.ui.jcef.JBCefJSQuery;
1216
import com.intellij.uiDesigner.core.GridConstraints;
1317
import com.microsoft.azure.toolkit.intellij.common.BaseEditor;
18+
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
19+
import org.cef.browser.CefBrowser;
20+
import org.cef.browser.CefFrame;
21+
import org.cef.handler.CefLoadHandlerAdapter;
1422
import org.jetbrains.annotations.Nls;
15-
import org.jetbrains.annotations.NotNull;
1623

24+
import javax.annotation.Nonnull;
1725
import javax.swing.*;
1826

1927
public class ProvideFeedbackEditor extends BaseEditor implements DumbAware {
28+
private final JBCefJSQuery myJSQueryOpenInBrowser;
2029
private JPanel pnlRoot;
2130

2231
public ProvideFeedbackEditor(final Project project, VirtualFile virtualFile) {
2332
super(virtualFile);
33+
final JBCefBrowser jbCefBrowser = new JBCefBrowser("https://www.surveymonkey.com/r/PNB5NBL?mode=simple");
34+
final CefBrowser browser = jbCefBrowser.getCefBrowser();
35+
pnlRoot.add(jbCefBrowser.getComponent(), new GridConstraints(0, 0, 1, 1, 0, GridConstraints.FILL_BOTH, 3, 3, null, null, null, 0));
36+
// Create a JS query instance
37+
this.myJSQueryOpenInBrowser = JBCefJSQuery.create((JBCefBrowserBase) jbCefBrowser);
38+
myJSQueryOpenInBrowser.addHandler((e) -> {
39+
AzureTaskManager.getInstance().runLater(() -> {
40+
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
41+
fileEditorManager.closeFile(virtualFile);
42+
});
43+
return new JBCefJSQuery.Response("ok!");
44+
});
2445

25-
final JBCefBrowser browser = new JBCefBrowser("https://www.surveymonkey.com/r/PNB5NBL?mode=simple");
26-
pnlRoot.add(browser.getComponent(), new GridConstraints(0, 0, 1, 1, 0, GridConstraints.FILL_BOTH, 3, 3, null, null, null, 0));
27-
46+
jbCefBrowser.getJBCefClient().addLoadHandler(new CefLoadHandlerAdapter() {
47+
@Override
48+
public void onLoadEnd(CefBrowser browser, CefFrame frame, int httpStatusCode) {
49+
if (!browser.getURL().contains("https://www.surveymonkey.com/r/PNB5NBL")) {
50+
return;
51+
}
52+
final String js = "window.JavaPanelBridge = {\n" +
53+
" closeTab: function (e) {\n" +
54+
" " + myJSQueryOpenInBrowser.inject("e") +
55+
" }\n" +
56+
"};\n" +
57+
"var azToolkitCloseBtn = document.querySelector('.thank-you-page-container.survey-submit-actions a.survey-page-button.btn');\n" +
58+
"if (azToolkitCloseBtn) {\n" +
59+
" azToolkitCloseBtn.innerHTML='Close';" +
60+
" azToolkitCloseBtn.addEventListener('click', () => {\n" +
61+
" window.JavaPanelBridge.closeTab();\n" +
62+
" });\n" +
63+
"}";
64+
browser.executeJavaScript(js, browser.getURL(), 0);
65+
}
66+
}, browser);
2867
}
2968

3069
@Override
31-
public @NotNull JComponent getComponent() {
70+
public JComponent getComponent() {
3271
return pnlRoot;
3372
}
3473

3574
@Override
36-
public @Nls(capitalization = Nls.Capitalization.Title) @NotNull String getName() {
75+
public @Nls(capitalization = Nls.Capitalization.Title) @Nonnull String getName() {
3776
return "Provide Feedback";
3877
}
3978

4079
@Override
4180
public void dispose() {
42-
81+
Disposer.dispose(myJSQueryOpenInBrowser);
4382
}
4483
}

0 commit comments

Comments
 (0)