mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[undo] IJPL-215129 Replace WI assertions with EDT assertions in command processor and undo manager
GitOrigin-RevId: 37c981a0c21065922e165593f23a8d85585d10ae
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b1a7084f6d
commit
d757b335f9
+15
-16
@@ -2,8 +2,7 @@
|
||||
package com.intellij.openapi.command.impl;
|
||||
|
||||
import com.intellij.openapi.application.AccessToken;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.WriteIntentReadAction;
|
||||
import com.intellij.openapi.command.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
@@ -99,8 +98,7 @@ public class CoreCommandProcessor extends CommandProcessorEx {
|
||||
boolean shouldRecordCommandForActiveDocument,
|
||||
@Nullable Document document
|
||||
) {
|
||||
Application application = ApplicationManager.getApplication();
|
||||
application.assertIsDispatchThread();
|
||||
ThreadingAssertions.assertEventDispatchThread();
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(String.format(
|
||||
@@ -119,10 +117,7 @@ public class CoreCommandProcessor extends CommandProcessorEx {
|
||||
}
|
||||
|
||||
if (currentCommand != null) {
|
||||
application.runWriteIntentReadAction(() -> {
|
||||
command.run();
|
||||
return null;
|
||||
});
|
||||
runCommandTask(command);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -136,7 +131,7 @@ public class CoreCommandProcessor extends CommandProcessorEx {
|
||||
document
|
||||
);
|
||||
currentCommand = descriptor;
|
||||
application.runWriteIntentReadAction(() -> {
|
||||
Runnable commandTask = () -> {
|
||||
Throwable throwable = null;
|
||||
try {
|
||||
fireCommandStarted();
|
||||
@@ -154,8 +149,8 @@ public class CoreCommandProcessor extends CommandProcessorEx {
|
||||
throw (ProcessCanceledException)finalThrowable;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
};
|
||||
runCommandTask(commandTask);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -165,7 +160,7 @@ public class CoreCommandProcessor extends CommandProcessorEx {
|
||||
@Nullable Object groupId,
|
||||
@NotNull UndoConfirmationPolicy undoConfirmationPolicy
|
||||
) {
|
||||
ApplicationManager.getApplication().assertWriteIntentLockAcquired();
|
||||
ThreadingAssertions.assertEventDispatchThread();
|
||||
if (project != null && project.isDisposed()) {
|
||||
return null;
|
||||
}
|
||||
@@ -194,7 +189,7 @@ public class CoreCommandProcessor extends CommandProcessorEx {
|
||||
|
||||
@Override
|
||||
public void finishCommand(@NotNull CommandToken command, @Nullable Throwable throwable) {
|
||||
ApplicationManager.getApplication().assertWriteIntentLockAcquired();
|
||||
ThreadingAssertions.assertEventDispatchThread();
|
||||
LOG.assertTrue(currentCommand != null, "no current command in progress");
|
||||
fireCommandFinished();
|
||||
}
|
||||
@@ -220,14 +215,14 @@ public class CoreCommandProcessor extends CommandProcessorEx {
|
||||
|
||||
@Override
|
||||
public void setCurrentCommandName(String name) {
|
||||
ThreadingAssertions.assertWriteIntentReadAccess();
|
||||
ThreadingAssertions.assertEventDispatchThread();
|
||||
LOG.assertTrue(currentCommand != null);
|
||||
currentCommand = currentCommand.withName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentCommandGroupId(Object groupId) {
|
||||
ThreadingAssertions.assertWriteIntentReadAccess();
|
||||
ThreadingAssertions.assertEventDispatchThread();
|
||||
LOG.assertTrue(currentCommand != null);
|
||||
currentCommand = currentCommand.withGroupId(groupId);
|
||||
}
|
||||
@@ -315,7 +310,6 @@ public class CoreCommandProcessor extends CommandProcessorEx {
|
||||
public AccessToken allowMergeGlobalCommands() {
|
||||
ThreadingAssertions.assertWriteIntentReadAccess();
|
||||
allowMergeGlobalCommandsCount++;
|
||||
|
||||
return new AccessToken() {
|
||||
@Override
|
||||
public void finish() {
|
||||
@@ -395,4 +389,9 @@ public class CoreCommandProcessor extends CommandProcessorEx {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void runCommandTask(Runnable commandTask) {
|
||||
// TODO: remove WI within IJPL-215129
|
||||
WriteIntentReadAction.run(commandTask);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,14 +102,14 @@ public class UndoManagerImpl extends UndoManager {
|
||||
|
||||
@Override
|
||||
public void undo(@Nullable FileEditor editor) {
|
||||
ApplicationManager.getApplication().assertWriteIntentLockAcquired();
|
||||
ThreadingAssertions.assertEventDispatchThread();
|
||||
LOG.assertTrue(isUndoAvailable(editor));
|
||||
undoOrRedo(editor, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redo(@Nullable FileEditor editor) {
|
||||
ApplicationManager.getApplication().assertWriteIntentLockAcquired();
|
||||
ThreadingAssertions.assertEventDispatchThread();
|
||||
LOG.assertTrue(isRedoAvailable(editor));
|
||||
undoOrRedo(editor, false);
|
||||
}
|
||||
@@ -128,7 +128,7 @@ public class UndoManagerImpl extends UndoManager {
|
||||
|
||||
@Override
|
||||
public void nonundoableActionPerformed(@NotNull DocumentReference ref, boolean isGlobal) {
|
||||
ApplicationManager.getApplication().assertWriteIntentLockAcquired();
|
||||
ThreadingAssertions.assertEventDispatchThread();
|
||||
if (myProject != null && myProject.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
@@ -137,7 +137,7 @@ public class UndoManagerImpl extends UndoManager {
|
||||
|
||||
@Override
|
||||
public void undoableActionPerformed(@NotNull UndoableAction action) {
|
||||
ApplicationManager.getApplication().assertWriteIntentLockAcquired();
|
||||
ThreadingAssertions.assertEventDispatchThread();
|
||||
if (myProject != null && myProject.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
@@ -198,7 +198,7 @@ public class UndoManagerImpl extends UndoManager {
|
||||
}
|
||||
|
||||
public void invalidateActionsFor(@NotNull DocumentReference ref) {
|
||||
ApplicationManager.getApplication().assertWriteIntentLockAcquired();
|
||||
ThreadingAssertions.assertEventDispatchThread();
|
||||
for (UndoClientState state : getAllClientStates()) {
|
||||
state.invalidateActions(ref);
|
||||
}
|
||||
@@ -478,9 +478,13 @@ public class UndoManagerImpl extends UndoManager {
|
||||
return Pair.create(name.trim(), description.trim());
|
||||
}
|
||||
|
||||
private boolean isUndoRedoAvailable(@Nullable FileEditor editor, boolean undo) {
|
||||
ThreadingAssertions.assertEventDispatchThread();
|
||||
return isUndoRedoAvailableUnsafe(editor, undo);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected boolean isUndoRedoAvailable(@Nullable FileEditor editor, boolean undo) {
|
||||
ApplicationManager.getApplication().assertReadAccessAllowed();
|
||||
protected boolean isUndoRedoAvailableUnsafe(@Nullable FileEditor editor, boolean undo) {
|
||||
UndoClientState state = getClientState(editor);
|
||||
return state != null && state.isUndoRedoAvailable(editor, undo);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user