|
37 | 37 | import com.intellij.openapi.wm.WindowManager; |
38 | 38 | import com.intellij.testFramework.LightVirtualFile; |
39 | 39 | import com.intellij.uiDesigner.core.GridConstraints; |
| 40 | +import com.intellij.util.messages.MessageBusConnection; |
40 | 41 | import com.microsoft.azure.management.resources.DeploymentMode; |
41 | 42 | import com.microsoft.azuretools.azurecommons.util.Utils; |
42 | 43 | import com.microsoft.azuretools.telemetrywrapper.EventUtil; |
@@ -80,19 +81,23 @@ public void loadTemplate(DeploymentNode node, String template) { |
80 | 81 | constraints.setAnchor(GridConstraints.ANCHOR_WEST); |
81 | 82 | editorPanel.add(fileEditor.getComponent(), constraints); |
82 | 83 |
|
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() { |
85 | 86 | @Override |
86 | 87 | public void beforeFileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) { |
87 | 88 | if (file.getFileType().getName().equals(ResourceTemplateViewProvider.TYPE) && |
88 | 89 | 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(); |
96 | 101 | } |
97 | 102 | } |
98 | 103 | } |
|
0 commit comments