Search in sources :

Example 1 with PlaybackRunner

use of com.intellij.openapi.ui.playback.PlaybackRunner in project intellij-community by JetBrains.

the class PlaybackDebugger method startWhenFrameActive.

private void startWhenFrameActive() {
    myLog.setText(null);
    addInfo("Waiting for IDE frame activation", -1, MESSAGE_COLOR, 0);
    myRunner = new PlaybackRunner(myCodeEditor.getText(), this, false, true, false);
    VirtualFile file = pathToFile();
    if (file != null) {
        VirtualFile scriptDir = file.getParent();
        if (scriptDir != null) {
            myRunner.setScriptDir(new File(scriptDir.getPresentableUrl()));
        }
    }
    new Thread("playback debugger") {

        @Override
        public void run() {
            new WaitFor(60000) {

                @Override
                protected boolean condition() {
                    return KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow() instanceof IdeFrame || myRunner == null;
                }
            };
            if (myRunner == null) {
                message(null, "Script stopped", -1, Type.message, true);
                return;
            }
            message(null, "Starting script...", -1, Type.message, true);
            TimeoutUtil.sleep(1000);
            if (myRunner == null) {
                message(null, "Script stopped", -1, Type.message, true);
                return;
            }
            final PlaybackRunner runner = myRunner;
            myRunner.run().doWhenProcessed(() -> {
                if (runner == myRunner) {
                    SwingUtilities.invokeLater(() -> myRunner = null);
                }
            });
        }
    }.start();
}
Also used : PlaybackRunner(com.intellij.openapi.ui.playback.PlaybackRunner) WaitFor(com.intellij.util.WaitFor) File(java.io.File) IdeFrame(com.intellij.openapi.wm.IdeFrame)

Example 2 with PlaybackRunner

use of com.intellij.openapi.ui.playback.PlaybackRunner in project intellij-community by JetBrains.

the class ActionMacroManager method playbackMacro.

private void playbackMacro(ActionMacro macro) {
    final IdeFrame frame = WindowManager.getInstance().getIdeFrame(null);
    assert frame != null;
    StringBuffer script = new StringBuffer();
    ActionMacro.ActionDescriptor[] actions = macro.getActions();
    for (ActionMacro.ActionDescriptor each : actions) {
        each.generateTo(script);
    }
    final PlaybackRunner runner = new PlaybackRunner(script.toString(), new PlaybackRunner.StatusCallback.Edt() {

        @Override
        public void messageEdt(PlaybackContext context, String text, Type type) {
            if (type == Type.message || type == Type.error) {
                StatusBar statusBar = frame.getStatusBar();
                if (statusBar != null) {
                    if (context != null) {
                        text = "Line " + context.getCurrentLine() + ": " + text;
                    }
                    statusBar.setInfo(text);
                }
            }
        }
    }, Registry.is("actionSystem.playback.useDirectActionCall"), true, Registry.is("actionSystem.playback.useTypingTargets"));
    myIsPlaying = true;
    runner.run().doWhenDone(() -> {
        StatusBar statusBar = frame.getStatusBar();
        statusBar.setInfo("Script execution finished");
    }).doWhenProcessed(() -> myIsPlaying = false);
}
Also used : PlaybackRunner(com.intellij.openapi.ui.playback.PlaybackRunner) IdeFrame(com.intellij.openapi.wm.IdeFrame) StatusBar(com.intellij.openapi.wm.StatusBar) PlaybackContext(com.intellij.openapi.ui.playback.PlaybackContext)

Aggregations

PlaybackRunner (com.intellij.openapi.ui.playback.PlaybackRunner)2 IdeFrame (com.intellij.openapi.wm.IdeFrame)2 PlaybackContext (com.intellij.openapi.ui.playback.PlaybackContext)1 StatusBar (com.intellij.openapi.wm.StatusBar)1 WaitFor (com.intellij.util.WaitFor)1 File (java.io.File)1