From 8b44f407eee1ec51da3284715cb81ae720bfbacd Mon Sep 17 00:00:00 2001 From: Dmitry Zhuravlev Date: Mon, 9 Sep 2024 17:42:01 +0200 Subject: [PATCH] [lvcs] extract local history isEnabled API (IJPL-161713) GitOrigin-RevId: 18a6bbdf87ff7b1919fdd745870820c5fa4c1826 --- platform/lvcs-api/api-dump.txt | 1 + .../lvcs-api/src/com/intellij/history/LocalHistory.kt | 10 +++++++++- .../intellij/history/integration/LocalHistoryImpl.kt | 6 ++++-- .../integration/ui/actions/LocalHistoryAction.java | 3 ++- .../impl/hotswap/SourceFileChangesCollectorImplTest.kt | 8 +++----- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/platform/lvcs-api/api-dump.txt b/platform/lvcs-api/api-dump.txt index 21979a6b8d3f..a48a95f1bd7e 100644 --- a/platform/lvcs-api/api-dump.txt +++ b/platform/lvcs-api/api-dump.txt @@ -27,6 +27,7 @@ a:com.intellij.history.LocalHistory - ():V - a:getByteContent(com.intellij.openapi.vfs.VirtualFile,com.intellij.history.FileRevisionTimestampComparator):B[] - sf:getInstance():com.intellij.history.LocalHistory +- a:isEnabled():Z - a:isUnderControl(com.intellij.openapi.vfs.VirtualFile):Z - a:putEventLabel(com.intellij.openapi.project.Project,java.lang.String,com.intellij.history.ActivityId):com.intellij.history.Label - f:putSystemLabel(com.intellij.openapi.project.Project,java.lang.String):com.intellij.history.Label diff --git a/platform/lvcs-api/src/com/intellij/history/LocalHistory.kt b/platform/lvcs-api/src/com/intellij/history/LocalHistory.kt index 315a0f74c0d6..36124ad6d705 100644 --- a/platform/lvcs-api/src/com/intellij/history/LocalHistory.kt +++ b/platform/lvcs-api/src/com/intellij/history/LocalHistory.kt @@ -1,4 +1,4 @@ -// 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. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.history import com.intellij.openapi.application.ApplicationManager @@ -37,6 +37,12 @@ import org.jetbrains.annotations.ApiStatus * @see [ActivityId] */ abstract class LocalHistory { + + /** + * Is Local History enabled for all projects. + */ + abstract val isEnabled: Boolean + /** * Starts an action in the local history with the given name and [ActivityId] to indicate the start of file changes. * Call [LocalHistoryAction.finish] after the changes were performed. @@ -120,6 +126,8 @@ abstract class LocalHistory { abstract fun isUnderControl(file: VirtualFile): Boolean private class Dummy : LocalHistory() { + override val isEnabled: Boolean = true + override fun startAction(name: @NlsContexts.Label String?, activityId: ActivityId?): LocalHistoryAction = LocalHistoryAction.NULL override fun putEventLabel(project: Project, name: String, activityId: ActivityId): Label = Label.NULL_INSTANCE override fun putSystemLabel(project: Project, name: @NlsContexts.Label String, color: Int): Label = Label.NULL_INSTANCE diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryImpl.kt b/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryImpl.kt index aaa0694d9ec1..a4e9f647d853 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryImpl.kt +++ b/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryImpl.kt @@ -49,8 +49,10 @@ class LocalHistoryImpl(private val coroutineScope: CoroutineScope) : LocalHistor private var daysToKeep = getInt(DAYS_TO_KEEP) - var isDisabled: Boolean = false - private set + override val isEnabled: Boolean + get() = !isDisabled + + private var isDisabled: Boolean = false var facade: LocalHistoryFacade? = null private set diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/LocalHistoryAction.java b/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/LocalHistoryAction.java index 4375864b1fe9..fccbb6332362 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/LocalHistoryAction.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/LocalHistoryAction.java @@ -2,6 +2,7 @@ package com.intellij.history.integration.ui.actions; +import com.intellij.history.LocalHistory; import com.intellij.history.core.LocalHistoryFacade; import com.intellij.history.integration.IdeaGateway; import com.intellij.history.integration.LocalHistoryImpl; @@ -19,7 +20,7 @@ import org.jetbrains.annotations.Nullable; public abstract class LocalHistoryAction extends AnAction implements DumbAware { @Override public void update(@NotNull AnActionEvent e) { - if (LocalHistoryImpl.getInstanceImpl().isDisabled()) { + if (!LocalHistory.getInstance().isEnabled()) { e.getPresentation().setEnabledAndVisible(false); return; } diff --git a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/impl/hotswap/SourceFileChangesCollectorImplTest.kt b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/impl/hotswap/SourceFileChangesCollectorImplTest.kt index 597db5c00663..ea15887c69df 100644 --- a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/impl/hotswap/SourceFileChangesCollectorImplTest.kt +++ b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/impl/hotswap/SourceFileChangesCollectorImplTest.kt @@ -1,11 +1,7 @@ // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.xdebugger.impl.hotswap -import com.intellij.history.ActivityId -import com.intellij.history.FileRevisionTimestampComparator -import com.intellij.history.Label -import com.intellij.history.LocalHistory -import com.intellij.history.LocalHistoryAction +import com.intellij.history.* import com.intellij.openapi.command.writeCommandAction import com.intellij.openapi.editor.Document import com.intellij.openapi.project.Project @@ -142,6 +138,8 @@ private class MockListener(private val scope: CoroutineScope, private val channe } private class MockLocalHistory(val bytes: ByteArray) : LocalHistory() { + override val isEnabled: Boolean = true + override fun getByteContent(file: VirtualFile, condition: FileRevisionTimestampComparator): ByteArray? = bytes override fun startAction(name: @NlsContexts.Label String?, activityId: ActivityId?): LocalHistoryAction = LocalHistoryAction.NULL override fun putEventLabel(project: Project, name: String, activityId: ActivityId): Label = Label.NULL_INSTANCE