mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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
This commit is contained in:
@@ -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();
|
||||
|
||||
+24
-9
@@ -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);
|
||||
|
||||
+3
-11
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-6
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user