Skip to content

Commit 84fd348

Browse files
Flanker32wangmingliang-ms
authored andcommitted
Show survey monkey in intellij editor
1 parent c0ca9e9 commit 84fd348

File tree

7 files changed

+150
-4
lines changed

7 files changed

+150
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*/
5+
6+
package com.microsoft.azure.toolkit.intellij.common.feedback;
7+
8+
import com.intellij.openapi.actionSystem.AnAction;
9+
import com.intellij.openapi.actionSystem.AnActionEvent;
10+
import com.intellij.openapi.fileEditor.FileEditorManager;
11+
import com.intellij.openapi.project.DumbAware;
12+
import com.intellij.openapi.util.Key;
13+
import com.intellij.openapi.vfs.VirtualFile;
14+
import com.intellij.testFramework.LightVirtualFile;
15+
import com.microsoft.azure.toolkit.ide.common.icon.AzureIcons;
16+
import com.microsoft.azure.toolkit.intellij.common.AzureFileType;
17+
import com.microsoft.azure.toolkit.intellij.common.IntelliJAzureIcons;
18+
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
19+
import org.jetbrains.annotations.NotNull;
20+
21+
public class ProvideFeedbackAction extends AnAction implements DumbAware {
22+
public static final Key<String> ID = new Key<>("ProvideFeedbackAction");
23+
24+
@Override
25+
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
26+
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(anActionEvent.getProject());
27+
if (fileEditorManager == null) {
28+
return;
29+
}
30+
LightVirtualFile itemVirtualFile = searchExistingFile(fileEditorManager);
31+
if (itemVirtualFile == null) {
32+
itemVirtualFile = new LightVirtualFile("Provide Feedback");
33+
itemVirtualFile.putUserData(ID, ProvideFeedbackAction.class.getCanonicalName());
34+
itemVirtualFile.setFileType(new AzureFileType(ProvideFeedbackEditorProvider.TYPE, IntelliJAzureIcons.getIcon(AzureIcons.Common.AZURE)));
35+
}
36+
final LightVirtualFile finalItemVirtualFile = itemVirtualFile;
37+
AzureTaskManager.getInstance().runLater(() -> fileEditorManager.openFile(finalItemVirtualFile, true /*focusEditor*/, true /*searchForOpen*/));
38+
}
39+
40+
private LightVirtualFile searchExistingFile(FileEditorManager fileEditorManager) {
41+
LightVirtualFile virtualFile = null;
42+
for (VirtualFile editedFile : fileEditorManager.getOpenFiles()) {
43+
String fileResourceId = editedFile.getUserData(ID);
44+
if (fileResourceId != null && fileResourceId.equals(ProvideFeedbackAction.class.getCanonicalName()) &&
45+
editedFile.getFileType().getName().equals(ProvideFeedbackEditorProvider.TYPE)) {
46+
virtualFile = (LightVirtualFile) editedFile;
47+
break;
48+
}
49+
}
50+
return virtualFile;
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.microsoft.azure.toolkit.intellij.common.feedback.ProvideFeedbackEditor">
3+
<grid id="27dc6" binding="pnlRoot" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="0" left="0" bottom="0" right="0"/>
5+
<constraints>
6+
<xy x="20" y="20" width="524" height="400"/>
7+
</constraints>
8+
<properties/>
9+
<border type="none"/>
10+
<children/>
11+
</grid>
12+
</form>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*/
5+
6+
package com.microsoft.azure.toolkit.intellij.common.feedback;
7+
8+
import com.intellij.openapi.project.DumbAware;
9+
import com.intellij.openapi.project.Project;
10+
import com.intellij.openapi.vfs.VirtualFile;
11+
import com.intellij.ui.jcef.JBCefBrowser;
12+
import com.intellij.uiDesigner.core.GridConstraints;
13+
import com.microsoft.azure.toolkit.intellij.common.BaseEditor;
14+
import org.jetbrains.annotations.Nls;
15+
import org.jetbrains.annotations.NotNull;
16+
17+
import javax.swing.*;
18+
19+
public class ProvideFeedbackEditor extends BaseEditor implements DumbAware {
20+
private JPanel pnlRoot;
21+
22+
public ProvideFeedbackEditor(final Project project, VirtualFile virtualFile) {
23+
super(virtualFile);
24+
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+
28+
}
29+
30+
@Override
31+
public @NotNull JComponent getComponent() {
32+
return pnlRoot;
33+
}
34+
35+
@Override
36+
public @Nls(capitalization = Nls.Capitalization.Title) @NotNull String getName() {
37+
return "Provide Feedback";
38+
}
39+
40+
@Override
41+
public void dispose() {
42+
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.microsoft.azure.toolkit.intellij.common.feedback;
2+
3+
import com.intellij.openapi.fileEditor.FileEditor;
4+
import com.intellij.openapi.fileEditor.FileEditorPolicy;
5+
import com.intellij.openapi.fileEditor.FileEditorProvider;
6+
import com.intellij.openapi.project.DumbAware;
7+
import com.intellij.openapi.project.Project;
8+
import com.intellij.openapi.vfs.VirtualFile;
9+
10+
import javax.annotation.Nonnull;
11+
12+
public class ProvideFeedbackEditorProvider implements FileEditorProvider, DumbAware {
13+
public static final String TYPE = "Microsoft.Customer_Survey";
14+
15+
@Override
16+
public boolean accept(@Nonnull Project project, @Nonnull VirtualFile virtualFile) {
17+
return virtualFile.getFileType().getName().equals(getEditorTypeId());
18+
}
19+
20+
@Nonnull
21+
@Override
22+
public FileEditor createEditor(@Nonnull Project project, @Nonnull VirtualFile virtualFile) {
23+
return new ProvideFeedbackEditor(project, virtualFile);
24+
}
25+
26+
@Nonnull
27+
@Override
28+
public String getEditorTypeId() {
29+
return TYPE;
30+
}
31+
32+
@Nonnull
33+
@Override
34+
public FileEditorPolicy getPolicy() {
35+
return FileEditorPolicy.HIDE_DEFAULT_EDITOR;
36+
}
37+
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/resources/META-INF/azure-intellij-plugin-lib.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
id="Azure Streaming Log" canCloseContents="true"/>
1616
<webHelpProvider implementation="com.microsoft.azure.toolkit.intellij.common.help.AzureWebHelpProvider"/>
1717
<applicationService serviceImplementation="com.microsoft.azure.toolkit.intellij.common.settings.IntellijStore"/>
18+
<fileEditorProvider implementation="com.microsoft.azure.toolkit.intellij.common.feedback.ProvideFeedbackEditorProvider" />
1819
</extensions>
1920
<actions>
2021
<action id="Actions.WhatsNew"
@@ -25,5 +26,7 @@
2526
text="Never Show Again"
2627
description="Never show again">
2728
</action>
29+
<action id="Actions.ProvideFeedback" class="com.microsoft.azure.toolkit.intellij.common.feedback.ProvideFeedbackAction"
30+
text="Provide Feedback" icon="/icons/Common/feedback.svg"/>
2831
</actions>
2932
</idea-plugin>

PluginsAndFeatures/azure-toolkit-for-intellij/src/main/java/com/microsoft/intellij/ui/ServerExplorerToolWindowFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ public void paintComponent(Graphics g) {
440440

441441
private void addToolbarItems(ToolWindow toolWindow, final Project project, final AzureModule azureModule) {
442442
final AnAction refreshAction = new RefreshAllAction(azureModule);
443-
final AnAction feedbackAction = ActionManager.getInstance().getAction("AzureToolkit.Survey");
443+
final AnAction feedbackAction = ActionManager.getInstance().getAction("Actions.ProvideFeedback");
444444
final AnAction signInAction = ActionManager.getInstance().getAction("AzureToolkit.AzureSignIn");
445445
final AnAction selectSubscriptionsAction = ActionManager.getInstance().getAction("AzureToolkit.SelectSubscriptions");
446446
toolWindow.setTitleActions(Arrays.asList(refreshAction, selectSubscriptionsAction, signInAction, Separator.create(), feedbackAction));

PluginsAndFeatures/azure-toolkit-for-intellij/src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@
195195
</group>
196196
<action class="com.microsoft.intellij.actions.NewCustomerIssueFeedbackAction" id="AzureToolkit.GithubIssue" text="Report Issues" />
197197
<action class="com.microsoft.intellij.actions.NewFeatureRequestFeedbackAction" id="AzureToolkit.FeatureRequest" text="Request Feature" />
198-
<action class="com.microsoft.intellij.actions.QualtricsSurveyAction" id="AzureToolkit.Survey" text="Provide Feedback"
199-
icon="/icons/Common/feedback.svg"/>
200198
<action id="Actions.SparkJobDisconnect" class="com.microsoft.azure.hdinsight.spark.run.action.SparkBatchJobDisconnectAction"
201199
text="Disconnect" description="Disconnect the log view from remote Spark Job"
202200
icon="/icons/SparkJobDisconnect.png">
@@ -271,7 +269,7 @@
271269
<separator/>
272270
<reference ref="AzureToolkit.GithubIssue"/>
273271
<reference ref="AzureToolkit.FeatureRequest"/>
274-
<reference ref="AzureToolkit.Survey"/>
272+
<reference ref="Actions.ProvideFeedback"/>
275273
<reference ref="Actions.WhatsNew"/>
276274
</group>
277275

0 commit comments

Comments
 (0)