From acbb1015a4aec945c9faf451dc73a69084314780 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Tue, 11 Nov 2008 14:37:29 +0300 Subject: [PATCH] intercept project closing event while compilation is in progress --- .../intellij/compiler/actions/CompileProjectAction.java | 8 +++++--- .../impl/com/intellij/compiler/progress/CompilerTask.java | 14 +++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/compiler/impl/com/intellij/compiler/actions/CompileProjectAction.java b/compiler/impl/com/intellij/compiler/actions/CompileProjectAction.java index 4a3830c8c8..8cecc5b5c0 100644 --- a/compiler/impl/com/intellij/compiler/actions/CompileProjectAction.java +++ b/compiler/impl/com/intellij/compiler/actions/CompileProjectAction.java @@ -21,9 +21,11 @@ public class CompileProjectAction extends CompileActionBase { public void finished(boolean aborted, int errors, int warnings, final CompileContext compileContext) { if (!aborted && LocalHistoryConfiguration.getInstance().ADD_LABEL_ON_PROJECT_COMPILATION) { String text = getTemplatePresentation().getText(); - LocalHistory.putSystemLabel(project, errors == 0 - ? CompilerBundle.message("rebuild.lvcs.label.no.errors", text) - : CompilerBundle.message("rebuild.lvcs.label.with.errors", text)); + if (!project.isDisposed()) { + LocalHistory.putSystemLabel(project, errors == 0 + ? CompilerBundle.message("rebuild.lvcs.label.no.errors", text) + : CompilerBundle.message("rebuild.lvcs.label.with.errors", text)); + } } } }); diff --git a/compiler/impl/com/intellij/compiler/progress/CompilerTask.java b/compiler/impl/com/intellij/compiler/progress/CompilerTask.java index d950eaa2ec..1ce9271a6d 100644 --- a/compiler/impl/com/intellij/compiler/progress/CompilerTask.java +++ b/compiler/impl/com/intellij/compiler/progress/CompilerTask.java @@ -27,8 +27,8 @@ import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.Task; import com.intellij.openapi.progress.util.ProgressIndicatorBase; import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.project.ProjectManagerListener; -import com.intellij.openapi.project.ex.ProjectManagerEx; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Computable; @@ -105,9 +105,14 @@ public class CompilerTask extends Task.Backgroundable { return new NotificationInfo("Compiler", "Compilation Finished", myErrorCount + " Errors, " + myWarningCount + " Warnings", true); } + private CloseListener myCloseListener; + public void run(@NotNull final ProgressIndicator indicator) { myIndicator = indicator; + final ProjectManager projectManager = ProjectManager.getInstance(); + projectManager.addProjectManagerListener(myProject, myCloseListener = new CloseListener()); + final Semaphore semaphore = ((CompilerManagerImpl)CompilerManager.getInstance(myProject)).getCompilationSemaphore(); semaphore.acquireUninterruptibly(); try { @@ -118,6 +123,7 @@ public class CompilerTask extends Task.Backgroundable { } finally { indicator.stop(); + projectManager.removeProjectManagerListener(myProject, myCloseListener); semaphore.release(); } } @@ -382,7 +388,7 @@ public class CompilerTask extends Task.Backgroundable { final Content content = PeerFactory.getInstance().getContentFactory().createContent(component, myContentName, true); content.putUserData(CONTENT_ID_KEY, myContentId); messageView.getContentManager().addContent(content); - new CloseListener(content, messageView.getContentManager()); + myCloseListener.setContent(content, messageView.getContentManager()); removeAllContents(myProject, content); messageView.getContentManager().setSelectedContent(content); updateProgressText(); @@ -546,11 +552,10 @@ public class CompilerTask extends Task.Backgroundable { return !myIndicator.isRunning(); } - public CloseListener(Content content, ContentManager contentManager) { + public void setContent(Content content, ContentManager contentManager) { myContent = content; myContentManager = contentManager; contentManager.addContentManagerListener(this); - ProjectManagerEx.getInstanceEx().addProjectManagerListener(myProject, this); } public void contentRemoved(ContentManagerEvent event) { @@ -565,7 +570,6 @@ public class CompilerTask extends Task.Backgroundable { } } myContentManager.removeContentManagerListener(this); - ProjectManagerEx.getInstanceEx().removeProjectManagerListener(myProject, this); myContent.release(); myContent = null; } -- 2.11.4.GIT