perform macro playback typing and action invocation in write-safe context (EA-89146 - assert: PsiDocumentManagerBase.commitAllDocuments)

This commit is contained in:
peter
2016-10-10 19:02:26 +02:00
parent 69375e6833
commit 9424d2691f
5 changed files with 19 additions and 15 deletions
@@ -17,6 +17,8 @@ package com.intellij.openapi.ui.playback.commands;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.ex.AnActionListener;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.keymap.KeymapManager;
import com.intellij.openapi.ui.playback.PlaybackContext;
import com.intellij.openapi.util.ActionCallback;
@@ -31,11 +33,10 @@ import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
public class ActionCommand extends TypeCommand {
public static String PREFIX = CMD_PREFIX + "action";
public static final String PREFIX = CMD_PREFIX + "action";
public ActionCommand(String text, int line) {
super(text, line);
super(text, line, true);
}
protected ActionCallback _execute(final PlaybackContext context) {
@@ -81,7 +82,7 @@ public class ActionCommand extends TypeCommand {
@Override
public void beforeActionPerformed(final AnAction action, DataContext dataContext, AnActionEvent event) {
SwingUtilities.invokeLater(() -> {
ApplicationManager.getApplication().invokeLater(() -> {
if (context.isDisposed()) {
am.removeAnActionListener(listener.get());
return;
@@ -92,13 +93,13 @@ public class ActionCommand extends TypeCommand {
am.removeAnActionListener(listener.get());
result.setDone();
}
});
}, ModalityState.any());
}
});
am.addAnActionListener(listener.get());
context.runPooledThread(() -> type(context.getRobot(), finalStroke));
});
}, ModalityState.current());
return result;
}
@@ -109,8 +110,8 @@ public class ActionCommand extends TypeCommand {
final ActionCallback result = new ActionCallback();
context.getRobot().delay(Registry.intValue("actionSystem.playback.delay"));
SwingUtilities.invokeLater(
() -> am.tryToExecute(targetAction, input, null, null, false).doWhenProcessed(result.createSetDoneRunnable()));
ApplicationManager.getApplication().invokeLater(
() -> am.tryToExecute(targetAction, input, null, null, false).doWhenProcessed(result.createSetDoneRunnable()), ModalityState.any());
return result;
}
@@ -16,6 +16,7 @@
package com.intellij.openapi.ui.playback.commands;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.ui.TypingTarget;
import com.intellij.openapi.ui.playback.PlaybackContext;
import com.intellij.openapi.util.ActionCallback;
@@ -29,7 +30,7 @@ import java.awt.event.KeyEvent;
public class AlphaNumericTypeCommand extends TypeCommand {
public AlphaNumericTypeCommand(String text, int line) {
super(text, line);
super(text, line, true);
}
public ActionCallback _execute(PlaybackContext context) {
@@ -46,7 +47,7 @@ public class AlphaNumericTypeCommand extends TypeCommand {
} else {
typeByRobot(context.getRobot(), text).notify(result);
}
});
}, ModalityState.current());
return result;
}
@@ -16,6 +16,7 @@
package com.intellij.openapi.ui.playback.commands;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.ui.TypingTarget;
import com.intellij.openapi.ui.playback.PlaybackContext;
import com.intellij.openapi.util.ActionCallback;
@@ -67,7 +68,7 @@ public class KeyCodeTypeCommand extends AlphaNumericTypeCommand {
} else {
typeCodes(context, context.getRobot(), codes).notify(result);
}
});
}, ModalityState.current());
return result;
}
@@ -82,6 +83,7 @@ public class KeyCodeTypeCommand extends AlphaNumericTypeCommand {
String[] splits = eachPair.split(MODIFIER_DELIMITER);
Integer code = Integer.valueOf(splits[0]);
Integer modifier = Integer.valueOf(splits[1]);
//noinspection MagicConstant
type(robot, code.intValue(), modifier.intValue());
}
catch (NumberFormatException e) {
@@ -24,7 +24,7 @@ public class KeyShortcutCommand extends TypeCommand {
public static final String POSTFIX = "]";
public KeyShortcutCommand(String text, int line) {
super(text, line);
super(text, line, false);
}
public ActionCallback _execute(PlaybackContext context) {
@@ -27,9 +27,9 @@ public abstract class TypeCommand extends AbstractCommand {
private static final KeyStrokeMap ourMap = new KeyStrokeMap();
public TypeCommand(String text, int line) {
super(text, line);
}
public TypeCommand(String text, int line, boolean executeInAwt) {
super(text, line, executeInAwt);
}
protected void type(Robot robot, int code, @JdkConstants.InputEventMask int modifiers) {
type(robot, KeyStroke.getKeyStroke(code, modifiers));