Skip to content

Commit c7b4cea

Browse files
authored
Disconnect the message bus connection when resource template editor is closed (#3185)
1 parent 46af808 commit c7b4cea

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/helpers/arm/ResourceTemplateView.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.intellij.openapi.wm.WindowManager;
3838
import com.intellij.testFramework.LightVirtualFile;
3939
import com.intellij.uiDesigner.core.GridConstraints;
40+
import com.intellij.util.messages.MessageBusConnection;
4041
import com.microsoft.azure.management.resources.DeploymentMode;
4142
import com.microsoft.azuretools.azurecommons.util.Utils;
4243
import com.microsoft.azuretools.telemetrywrapper.EventUtil;
@@ -80,19 +81,23 @@ public void loadTemplate(DeploymentNode node, String template) {
8081
constraints.setAnchor(GridConstraints.ANCHOR_WEST);
8182
editorPanel.add(fileEditor.getComponent(), constraints);
8283

83-
project.getMessageBus().connect(fileEditor).
84-
subscribe(FileEditorManagerListener.Before.FILE_EDITOR_MANAGER, new FileEditorManagerListener.Before() {
84+
final MessageBusConnection messageBusConnection = project.getMessageBus().connect(fileEditor);
85+
messageBusConnection.subscribe(FileEditorManagerListener.Before.FILE_EDITOR_MANAGER, new FileEditorManagerListener.Before() {
8586
@Override
8687
public void beforeFileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
8788
if (file.getFileType().getName().equals(ResourceTemplateViewProvider.TYPE) &&
8889
file.getName().equals(node.getName())) {
89-
String editorText = ((PsiAwareTextEditorImpl) fileEditor).getEditor().getDocument().getText();
90-
if (editorText.equals(prettyTemplate)) {
91-
return;
92-
}
93-
if (DefaultLoader.getUIHelper().showConfirmation(PROMPT_MESSAGE_SAVE_TEMPALTE, "Azure Explorer",
94-
new String[]{"Yes", "No"}, null)) {
95-
new ExportTemplate(node).doExport(editorText);
90+
try {
91+
String editorText = ((PsiAwareTextEditorImpl) fileEditor).getEditor().getDocument().getText();
92+
if (editorText.equals(prettyTemplate)) {
93+
return;
94+
}
95+
if (DefaultLoader.getUIHelper().showConfirmation(PROMPT_MESSAGE_SAVE_TEMPALTE, "Azure Explorer",
96+
new String[]{"Yes", "No"}, null)) {
97+
new ExportTemplate(node).doExport(editorText);
98+
}
99+
} finally {
100+
messageBusConnection.disconnect();
96101
}
97102
}
98103
}

0 commit comments

Comments
 (0)