diff --git a/platform/platform-impl/src/com/intellij/ide/AppLifecycleListener.java b/platform/platform-impl/src/com/intellij/ide/AppLifecycleListener.java index 6645f2e9a96c..0a51e070f9f0 100644 --- a/platform/platform-impl/src/com/intellij/ide/AppLifecycleListener.java +++ b/platform/platform-impl/src/com/intellij/ide/AppLifecycleListener.java @@ -32,6 +32,12 @@ public interface AppLifecycleListener { void projectOpenFailed(); void welcomeScreenDisplayed(); + /** + * Fired before saving settings and before final 'can exit?' check. App may end up not closing if some of the 'can exit?' listeners + * return false. + */ + void appClosing(); + abstract class Adapter implements AppLifecycleListener { public void appFrameCreated(final String[] commandLineArgs, @NotNull final Ref willOpenProject) { } @@ -47,5 +53,8 @@ public interface AppLifecycleListener { public void welcomeScreenDisplayed() { } + + public void appClosing() { + } } } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java b/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java index 63fee15836bd..bce74729e587 100644 --- a/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java +++ b/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java @@ -45,6 +45,7 @@ public abstract class RecentProjectsManagerBase implements PersistentStateCompon public static class State { public List recentPaths = new ArrayList(); + public List openPaths = new ArrayList(); public String lastPath; } @@ -123,8 +124,13 @@ public abstract class RecentProjectsManagerBase implements PersistentStateCompon Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); if (openProjects.length == 0) { myState.lastPath = null; + myState.openPaths = Collections.emptyList(); } else { myState.lastPath = getProjectPath(openProjects[openProjects.length - 1]); + myState.openPaths = new ArrayList(); + for (Project openProject : openProjects) { + myState.openPaths.add(getProjectPath(openProject)); + } } } @@ -292,9 +298,17 @@ public abstract class RecentProjectsManagerBase implements PersistentStateCompon if (projectFromCommandLine != null) return; GeneralSettings generalSettings = GeneralSettings.getInstance(); if (generalSettings.isReopenLastProject()) { - String lastProjectPath = getLastProjectPath(); - if (lastProjectPath != null) { - doOpenProject(lastProjectPath, null, false); + List openPaths = myState.openPaths; + if (openPaths.size() > 0) { + for (String openPath : openPaths) { + doOpenProject(openPath, null, true); + } + } + else { + String lastProjectPath = getLastProjectPath(); + if (lastProjectPath != null) { + doOpenProject(lastProjectPath, null, false); + } } } } @@ -306,5 +320,9 @@ public abstract class RecentProjectsManagerBase implements PersistentStateCompon public void projectOpenFailed() { updateLastProjectPath(); } + + public void appClosing() { + updateLastProjectPath(); + } } } diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index f754313ce534..8a18d775c484 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -688,6 +688,8 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application } } + getMessageBus().syncPublisher(AppLifecycleListener.TOPIC).appClosing(); + FileDocumentManager.getInstance().saveAllDocuments(); saveSettings();