diff --git a/platform/core-api/src/com/intellij/openapi/command/undo/UndoConstants.kt b/platform/core-api/src/com/intellij/openapi/command/undo/UndoConstants.kt index b3f1cf73996c..e7c032f1327b 100644 --- a/platform/core-api/src/com/intellij/openapi/command/undo/UndoConstants.kt +++ b/platform/core-api/src/com/intellij/openapi/command/undo/UndoConstants.kt @@ -19,7 +19,7 @@ import com.intellij.openapi.util.Key import org.jetbrains.annotations.ApiStatus @ApiStatus.ScheduledForRemoval -@Deprecated("Use {@link UndoUtil} instead") +@Deprecated("Use {@link UndoUtil} instead", level = DeprecationLevel.HIDDEN) interface UndoConstants { companion object { @@ -27,11 +27,11 @@ interface UndoConstants { @JvmField @ApiStatus.ScheduledForRemoval @Deprecated("Use {@link UndoUtil#forceUndoIn(VirtualFile, Runnable)} instead") - val FORCE_RECORD_UNDO: Key = Key.create("FORCE_RECORD_UNDO") + val FORCE_RECORD_UNDO: Key = UndoUtil.FORCE_RECORD_UNDO @JvmField @ApiStatus.ScheduledForRemoval @Deprecated("Use {@link UndoUtil#disableUndoIn(Document, Runnable)} instead") - val DONT_RECORD_UNDO: Key = Key.create("DONT_RECORD_UNDO") + val DONT_RECORD_UNDO: Key = UndoUtil.DONT_RECORD_UNDO } } diff --git a/platform/core-api/src/com/intellij/openapi/command/undo/UndoUtil.java b/platform/core-api/src/com/intellij/openapi/command/undo/UndoUtil.java index 963778eb247d..125c2cdbb877 100644 --- a/platform/core-api/src/com/intellij/openapi/command/undo/UndoUtil.java +++ b/platform/core-api/src/com/intellij/openapi/command/undo/UndoUtil.java @@ -4,12 +4,17 @@ package com.intellij.openapi.command.undo; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.editor.Document; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; public final class UndoUtil { + + static Key FORCE_RECORD_UNDO = Key.create("FORCE_RECORD_UNDO"); + static Key DONT_RECORD_UNDO = Key.create("DONT_RECORD_UNDO"); + private UndoUtil() { } @@ -26,43 +31,50 @@ public final class UndoUtil { } public static void disableUndoFor(@NotNull Document document) { - document.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE); + document.putUserData(DONT_RECORD_UNDO, Boolean.TRUE); } + public static void disableUndoIn(@NotNull Document document, @NotNull Runnable runnable) { - document.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE); + document.putUserData(DONT_RECORD_UNDO, Boolean.TRUE); try { runnable.run(); } finally { - document.putUserData(UndoConstants.DONT_RECORD_UNDO, null); + document.putUserData(DONT_RECORD_UNDO, null); } } + public static void disableUndoFor(@NotNull VirtualFile file) { - file.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE); + file.putUserData(DONT_RECORD_UNDO, Boolean.TRUE); } + public static void enableUndoFor(@NotNull Document document) { - document.putUserData(UndoConstants.DONT_RECORD_UNDO, null); + document.putUserData(DONT_RECORD_UNDO, null); } public static boolean isUndoDisabledFor(@NotNull Document document) { - return Boolean.TRUE.equals(document.getUserData(UndoConstants.DONT_RECORD_UNDO)); + return Boolean.TRUE.equals(document.getUserData(DONT_RECORD_UNDO)); } + public static boolean isUndoDisabledFor(@NotNull VirtualFile file) { - return Boolean.TRUE.equals(file.getUserData(UndoConstants.DONT_RECORD_UNDO)); + return Boolean.TRUE.equals(file.getUserData(DONT_RECORD_UNDO)); } + public static void forceUndoIn(@NotNull VirtualFile file, @NotNull Runnable runnable) { - file.putUserData(UndoConstants.FORCE_RECORD_UNDO, Boolean.TRUE); + file.putUserData(FORCE_RECORD_UNDO, Boolean.TRUE); try { runnable.run(); } finally { - file.putUserData(UndoConstants.FORCE_RECORD_UNDO, null); + file.putUserData(FORCE_RECORD_UNDO, null); } } + public static void setForceUndoFlag(@NotNull VirtualFile file, boolean flag) { - file.putUserData(UndoConstants.FORCE_RECORD_UNDO, flag ? Boolean.TRUE : null); + file.putUserData(FORCE_RECORD_UNDO, flag ? Boolean.TRUE : null); } + public static boolean isForceUndoFlagSet(@NotNull VirtualFile file) { - return file.getUserData(UndoConstants.FORCE_RECORD_UNDO) == Boolean.TRUE; + return file.getUserData(FORCE_RECORD_UNDO) == Boolean.TRUE; } }