From 5093010bcf95aedbe4c4e1370f0494a0844b4fd2 Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Tue, 2 Dec 2014 11:33:14 +0100 Subject: [PATCH] Platform: * creation of playback actions for awt-thread simplified * when previos action ends in write action, new action should not be executed in write action --- .../openapi/ui/playback/PlaybackRunner.java | 4 +-- .../ui/playback/commands/AbstractCommand.java | 33 ++++++++++++++----- .../ui/playback/commands/CallCommand.java | 14 ++------ .../commands/ToggleActionCommand.java | 7 +--- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackRunner.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackRunner.java index 7de5fc0d30e0..c0f642196bec 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackRunner.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/PlaybackRunner.java @@ -20,10 +20,8 @@ import com.intellij.ide.UiActivityMonitor; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationActivationListener; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.ui.playback.commands.AssertFocused; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.ui.playback.commands.*; -import com.intellij.openapi.ui.playback.commands.ActionCommand; import com.intellij.openapi.util.ActionCallback; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.io.FileUtil; @@ -96,7 +94,7 @@ public class PlaybackRunner { myPassedStages.clear(); myContextTimestamp++; - ApplicationManager.getApplication().getMessageBus().connect(myOnStop).subscribe(ApplicationActivationListener.TOPIC, myAppListener); + ApplicationManager.getApplication().getMessageBus().connect(ApplicationManager.getApplication()).subscribe(ApplicationActivationListener.TOPIC, myAppListener); try { myActionCallback = new ActionCallback(); diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/AbstractCommand.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/AbstractCommand.java index da4ac90fa448..fb4d031fe4f3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/AbstractCommand.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/AbstractCommand.java @@ -20,6 +20,7 @@ import com.intellij.openapi.ui.playback.PlaybackCommand; import com.intellij.openapi.ui.playback.PlaybackContext; import com.intellij.openapi.util.ActionCallback; +import javax.swing.*; import java.io.File; public abstract class AbstractCommand implements PlaybackCommand { @@ -28,10 +29,16 @@ public abstract class AbstractCommand implements PlaybackCommand { private final String myText; private final int myLine; + private final boolean myExecuteInAwt; private File myScriptDir; public AbstractCommand(String text, int line) { + this(text, line, false); + } + + public AbstractCommand(String text, int line, boolean executeInAwt) { + myExecuteInAwt = executeInAwt; myText = text != null ? text : null; myLine = line; } @@ -54,15 +61,23 @@ public abstract class AbstractCommand implements PlaybackCommand { dumpCommand(context); } final ActionCallback result = new ActionCallback(); + Runnable runnable = new Runnable() { + @Override + public void run() { + _execute(context).notify(result); + } + }; + if (isAwtThread()) { - _execute(context).notify(result); - } else { - ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { - @Override - public void run() { - _execute(context).notify(result); - } - }); + // prevent previous action context affecting next action. + // E.g. previous action may have called callback.setDone from inside write action, while + // next action may not expect that + + //noinspection SSBasedInspection + SwingUtilities.invokeLater(runnable); + } + else { + ApplicationManager.getApplication().executeOnPooledThread(runnable); } return result; @@ -78,7 +93,7 @@ public abstract class AbstractCommand implements PlaybackCommand { } protected boolean isAwtThread() { - return false; + return myExecuteInAwt; } protected abstract ActionCallback _execute(PlaybackContext context); diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/CallCommand.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/CallCommand.java index eeb1dd8a62bd..910c44d8f9a1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/CallCommand.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/CallCommand.java @@ -26,18 +26,15 @@ import java.lang.reflect.Method; import java.util.Set; /** - * Created by IntelliJ IDEA. - * User: kirillk - * Date: 8/3/11 - * Time: 4:08 PM - * To change this template use File | Settings | File Templates. + * Author: kirillk + * Date: 8/3/11 4:08 PM */ public class CallCommand extends AbstractCommand { public static final String PREFIX = CMD_PREFIX + "call"; public CallCommand(String text, int line) { - super(text, line); + super(text, line, true); } @Override @@ -132,9 +129,4 @@ public class CallCommand extends AbstractCommand { return null; } - - @Override - protected boolean isAwtThread() { - return true; - } } diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/ToggleActionCommand.java b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/ToggleActionCommand.java index 4a169bcf53ff..8f8e9e09b1ee 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/ToggleActionCommand.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/playback/commands/ToggleActionCommand.java @@ -41,12 +41,7 @@ public class ToggleActionCommand extends AbstractCommand { public static final String OFF = "off"; public ToggleActionCommand(String text, int line) { - super(text, line); - } - - @Override - protected boolean isAwtThread() { - return true; + super(text, line, true); } @Override