mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
simplify — closeProject must not save application (and in the whole codebase it is already so)
GitOrigin-RevId: bf905ea4825b330c2ae9983b776000b9b124b05e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5c294f73b9
commit
d3f45401ae
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+2
-2
@@ -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);
|
||||
|
||||
+9
-14
@@ -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) {
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
Reference in New Issue
Block a user