diff --git a/platform/configuration-store-impl/src/HeadlessSaveAndSyncHandler.kt b/platform/configuration-store-impl/src/HeadlessSaveAndSyncHandler.kt index 080f7ca924ee..c7d6d2555e12 100644 --- a/platform/configuration-store-impl/src/HeadlessSaveAndSyncHandler.kt +++ b/platform/configuration-store-impl/src/HeadlessSaveAndSyncHandler.kt @@ -1,8 +1,7 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.configurationStore import com.intellij.openapi.application.AccessToken -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.ComponentManager /** @@ -23,13 +22,10 @@ internal class HeadlessSaveAndSyncHandler : BaseSaveAndSyncHandler() { override fun unblockSyncOnFrameActivation() {} - override fun disableAutoSave() = AccessToken.EMPTY_ACCESS_TOKEN + override fun disableAutoSave(): AccessToken = AccessToken.EMPTY_ACCESS_TOKEN - override fun saveSettingsUnderModalProgress(componentManager: ComponentManager, isSaveAppAlso: Boolean): Boolean { + override fun saveSettingsUnderModalProgress(componentManager: ComponentManager): Boolean { StoreUtil.saveSettings(componentManager, forceSavingAllSettings = true) - if (isSaveAppAlso && componentManager !== ApplicationManager.getApplication()) { - StoreUtil.saveSettings(ApplicationManager.getApplication(), forceSavingAllSettings = true) - } return true } } diff --git a/platform/configuration-store-impl/src/SaveAndSyncHandlerImpl.kt b/platform/configuration-store-impl/src/SaveAndSyncHandlerImpl.kt index c73c8109a1c2..67b121f49270 100644 --- a/platform/configuration-store-impl/src/SaveAndSyncHandlerImpl.kt +++ b/platform/configuration-store-impl/src/SaveAndSyncHandlerImpl.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.configurationStore import com.intellij.conversion.ConversionService @@ -200,7 +200,7 @@ internal class SaveAndSyncHandlerImpl : BaseSaveAndSyncHandler(), Disposable { * So, save on app or project closing uses this method to process scheduled for EDT activities - instead of using regular EDT queue special one is used. */ @CalledInAwt - override fun saveSettingsUnderModalProgress(componentManager: ComponentManager, isSaveAppAlso: Boolean): Boolean { + override fun saveSettingsUnderModalProgress(componentManager: ComponentManager): Boolean { if (!ApplicationManager.getApplication().isDispatchThread) { throw IllegalStateException( "saveSettingsUnderModalProgress is intended to be called only in EDT because otherwise wrapping into modal progress task is not required" + @@ -225,9 +225,6 @@ internal class SaveAndSyncHandlerImpl : BaseSaveAndSyncHandler(), Disposable { runBlocking { isSavedSuccessfully = saveSettings(componentManager, forceSavingAllSettings = true) - if (isSaveAppAlso && componentManager !is Application) { - saveSettings(ApplicationManager.getApplication(), forceSavingAllSettings = true) - } } if (project != null && !ApplicationManager.getApplication().isUnitTestMode) { diff --git a/platform/platform-api/src/com/intellij/ide/SaveAndSyncHandler.kt b/platform/platform-api/src/com/intellij/ide/SaveAndSyncHandler.kt index c08274bb14e4..52b231b8acc9 100644 --- a/platform/platform-api/src/com/intellij/ide/SaveAndSyncHandler.kt +++ b/platform/platform-api/src/com/intellij/ide/SaveAndSyncHandler.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide import com.intellij.openapi.application.AccessToken @@ -73,5 +73,5 @@ abstract class SaveAndSyncHandler { } @ApiStatus.Experimental - abstract fun saveSettingsUnderModalProgress(componentManager: ComponentManager, isSaveAppAlso: Boolean = false): Boolean + abstract fun saveSettingsUnderModalProgress(componentManager: ComponentManager): Boolean } 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 13de43d21ebd..956dea3f8ba7 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 @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.application.impl; import com.intellij.BundleBase; @@ -621,7 +621,7 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App LifecycleUsageTriggerCollector.onIdeClose(restart); if (BitUtil.isSet(flags, SAVE)) { - SaveAndSyncHandler.getInstance().saveSettingsUnderModalProgress(this, /* isSaveAppAlso = */ false); + SaveAndSyncHandler.getInstance().saveSettingsUnderModalProgress(this); } boolean success = disposeSelf(!force); diff --git a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java index a7eea7038b36..da348fa30c49 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.project.impl; import com.intellij.configurationStore.StoreReloadManager; @@ -424,7 +424,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable { } catch (ProcessCanceledException e) { GuiUtils.invokeLaterIfNeeded(() -> { - closeProject(project, false, false, /* dispose */ true, true); + closeProject(project, false, /* dispose= */ true, true); notifyProjectOpenFailed(); }, ModalityState.defaultModalityState()); return false; @@ -624,37 +624,32 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable { @Override public final boolean closeProject(@NotNull Project project) { - return closeProject(project, /* isSaveProject = */ true, /* isSaveApp = */ true, /* dispose = */ false, /* checkCanClose = */ true); + return closeProject(project, /* isSaveProject = */ true, /* dispose = */ false, /* checkCanClose = */ true); } @TestOnly public final boolean forceCloseProject(@NotNull Project project, boolean dispose) { - return closeProject(project, /* isSaveProject = */ false, /* isSaveApp = */ false, dispose, /* checkCanClose = */ false); + return closeProject(project, /* isSaveProject = */ false, dispose, /* checkCanClose = */ false); } @Override public boolean forceCloseProject(@NotNull Project project) { - return closeProject(project, /* isSaveProject = */ false, /* isSaveApp = */ false, /* dispose = */ true, /* checkCanClose = */ false); + return closeProject(project, /* isSaveProject = */ false, /* dispose = */ true, /* checkCanClose = */ false); } // return true if successful @Override public boolean closeAndDisposeAllProjects(boolean checkCanClose) { for (Project project : getOpenProjects()) { - if (!closeProject(project, /* isSaveProject = */ true, /* isSaveApp = */ false, /* dispose = */ true, checkCanClose)) { + if (!closeProject(project, /* isSaveProject = */ true, /* dispose = */ true, checkCanClose)) { return false; } } return true; } - // isSaveApp is ignored if saveProject is false @SuppressWarnings("TestOnlyProblems") - private boolean closeProject(@NotNull Project project, - boolean isSaveProject, - boolean isSaveApp, - boolean dispose, - boolean checkCanClose) { + private boolean closeProject(@NotNull Project project, boolean isSaveProject, boolean dispose, boolean checkCanClose) { Application app = ApplicationManager.getApplication(); if (app.isWriteAccessAllowed()) { throw new IllegalStateException( @@ -703,7 +698,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable { if (isSaveProject) { FileDocumentManager.getInstance().saveAllDocuments(); - SaveAndSyncHandler.getInstance().saveSettingsUnderModalProgress(project, isSaveApp); + SaveAndSyncHandler.getInstance().saveSettingsUnderModalProgress(project); } if (checkCanClose && !ensureCouldCloseIfUnableToSave(project)) { @@ -749,7 +744,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable { @Override public boolean closeAndDispose(@NotNull Project project) { - return closeProject(project, true /* save project */, false /* don't save app */, true /* dispose project */, true /* checkCanClose */); + return closeProject(project, true /* save project */, true /* dispose project */, true /* checkCanClose */); } private static void fireProjectClosing(@NotNull Project project) { diff --git a/platform/util/src/com/intellij/openapi/application/AccessToken.java b/platform/util/src/com/intellij/openapi/application/AccessToken.java index 53df1c6e2a10..ef8ea88ea5b8 100644 --- a/platform/util/src/com/intellij/openapi/application/AccessToken.java +++ b/platform/util/src/com/intellij/openapi/application/AccessToken.java @@ -1,6 +1,8 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.application; +import org.jetbrains.annotations.NotNull; + public abstract class AccessToken implements AutoCloseable { @Override public final void close() { @@ -9,6 +11,7 @@ public abstract class AccessToken implements AutoCloseable { public abstract void finish(); + @NotNull public static final AccessToken EMPTY_ACCESS_TOKEN = new AccessToken() { @Override public void finish() {}