mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
playback — use Promise
This commit is contained in:
9
.idea/codeStyleSettings.xml
generated
9
.idea/codeStyleSettings.xml
generated
@@ -32,15 +32,6 @@
|
||||
<option name="FORMATTER_TAGS_ENABLED" value="true" />
|
||||
<option name="LINE_COMMENT_AT_FIRST_COLUMN" value="false" />
|
||||
<option name="BLOCK_COMMENT_AT_FIRST_COLUMN" value="false" />
|
||||
<JetCodeStyleSettings>
|
||||
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
||||
<value>
|
||||
<package name="java.util" withSubpackages="false" static="false" />
|
||||
<package name="com.intellij.ui.layout" withSubpackages="true" static="false" />
|
||||
<package name="kotlinx.android.synthetic" withSubpackages="true" static="false" />
|
||||
</value>
|
||||
</option>
|
||||
</JetCodeStyleSettings>
|
||||
<XML>
|
||||
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
|
||||
</XML>
|
||||
|
||||
@@ -1,27 +1,12 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback;
|
||||
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
|
||||
public interface PlaybackCommand {
|
||||
ActionCallback execute(PlaybackContext context);
|
||||
Promise<Object> execute(PlaybackContext context);
|
||||
boolean canGoFurther();
|
||||
|
||||
File getScriptDir();
|
||||
|
||||
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback;
|
||||
|
||||
import com.intellij.ide.IdeEventQueue;
|
||||
@@ -29,6 +15,7 @@ import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.wm.IdeFrame;
|
||||
import com.intellij.util.text.StringTokenizer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -183,19 +170,21 @@ public class PlaybackRunner {
|
||||
}
|
||||
}
|
||||
};
|
||||
final ActionCallback cmdCallback = cmd.execute(context);
|
||||
cmdCallback.doWhenDone(() -> {
|
||||
if (cmd.canGoFurther()) {
|
||||
executeFrom(cmdIndex + 1, context.getBaseDir());
|
||||
}
|
||||
else {
|
||||
final Promise<Object> cmdCallback = cmd.execute(context);
|
||||
cmdCallback
|
||||
.onSuccess(it -> {
|
||||
if (cmd.canGoFurther()) {
|
||||
executeFrom(cmdIndex + 1, context.getBaseDir());
|
||||
}
|
||||
else {
|
||||
myCallback.message(null, "Stopped", StatusCallback.Type.message);
|
||||
myActionCallback.setDone();
|
||||
}
|
||||
})
|
||||
.onError(error -> {
|
||||
myCallback.message(null, "Stopped", StatusCallback.Type.message);
|
||||
myActionCallback.setDone();
|
||||
}
|
||||
}).doWhenRejected(() -> {
|
||||
myCallback.message(null, "Stopped", StatusCallback.Type.message);
|
||||
myActionCallback.setRejected();
|
||||
});
|
||||
myActionCallback.setRejected();
|
||||
});
|
||||
}
|
||||
else {
|
||||
myCallback.message(null, "Finished OK " + myPassedStages.size() + " tests", StatusCallback.Type.message);
|
||||
|
||||
@@ -1,32 +1,20 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback.commands;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.ui.playback.PlaybackCommand;
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import org.jetbrains.concurrency.AsyncPromise;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.concurrency.Promises;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
|
||||
public abstract class AbstractCommand implements PlaybackCommand {
|
||||
private static final Logger LOG = Logger.getInstance("#" + AbstractCommand.class.getPackage().getName());
|
||||
|
||||
|
||||
public static final String CMD_PREFIX = "%";
|
||||
|
||||
private final String myText;
|
||||
@@ -34,14 +22,14 @@ public abstract class AbstractCommand implements PlaybackCommand {
|
||||
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;
|
||||
myText = text;
|
||||
myLine = line;
|
||||
}
|
||||
|
||||
@@ -57,28 +45,28 @@ public abstract class AbstractCommand implements PlaybackCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
public final ActionCallback execute(final PlaybackContext context) {
|
||||
public final Promise<Object> execute(final PlaybackContext context) {
|
||||
try {
|
||||
if (isToDumpCommand()) {
|
||||
dumpCommand(context);
|
||||
}
|
||||
final ActionCallback result = new ActionCallback();
|
||||
final AsyncPromise<Object> result = new AsyncPromise<>();
|
||||
Runnable runnable = () -> {
|
||||
try {
|
||||
_execute(context).notify(result);
|
||||
_execute(context).processed(result);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
LOG.error(e);
|
||||
context.error(e.getMessage(), getLine());
|
||||
result.setRejected();
|
||||
result.setError(e);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
if (isAwtThread()) {
|
||||
// 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);
|
||||
}
|
||||
@@ -90,7 +78,7 @@ public abstract class AbstractCommand implements PlaybackCommand {
|
||||
}
|
||||
catch (Throwable e) {
|
||||
context.error(e.getMessage(), getLine());
|
||||
return ActionCallback.REJECTED;
|
||||
return Promises.rejectedPromise(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +90,7 @@ public abstract class AbstractCommand implements PlaybackCommand {
|
||||
return myExecuteInAwt;
|
||||
}
|
||||
|
||||
protected abstract ActionCallback _execute(PlaybackContext context);
|
||||
protected abstract Promise<Object> _execute(PlaybackContext context);
|
||||
|
||||
public void dumpCommand(PlaybackContext context) {
|
||||
context.code(getText(), getLine());
|
||||
|
||||
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback.commands;
|
||||
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
@@ -24,6 +10,8 @@ import com.intellij.openapi.util.ActionCallback;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.TimedOutCallback;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.concurrency.Promises;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.InputEvent;
|
||||
@@ -39,17 +27,16 @@ public class ActionCommand extends TypeCommand {
|
||||
super(text, line, true);
|
||||
}
|
||||
|
||||
protected ActionCallback _execute(final PlaybackContext context) {
|
||||
protected Promise<Object> _execute(final PlaybackContext context) {
|
||||
final String actionName = getText().substring(PREFIX.length()).trim();
|
||||
|
||||
final ActionManager am = ActionManager.getInstance();
|
||||
final AnAction targetAction = am.getAction(actionName);
|
||||
if (targetAction == null) {
|
||||
dumpError(context, "Unknown action: " + actionName);
|
||||
return ActionCallback.REJECTED;
|
||||
return Promises.rejectedPromise();
|
||||
}
|
||||
|
||||
|
||||
if (!context.isUseDirectActionCall()) {
|
||||
final Shortcut[] sc = getActiveKeymapShortcuts(actionName).getShortcuts();
|
||||
KeyStroke stroke = null;
|
||||
@@ -101,7 +88,7 @@ public class ActionCommand extends TypeCommand {
|
||||
context.runPooledThread(() -> type(context.getRobot(), finalStroke));
|
||||
});
|
||||
|
||||
return result;
|
||||
return Promises.toPromise(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +100,7 @@ public class ActionCommand extends TypeCommand {
|
||||
ApplicationManager.getApplication().invokeLater(
|
||||
() -> am.tryToExecute(targetAction, input, null, null, false).doWhenProcessed(result.createSetDoneRunnable()), ModalityState.any());
|
||||
|
||||
return result;
|
||||
return Promises.toPromise(result);
|
||||
}
|
||||
|
||||
public static InputEvent getInputEvent(String actionName) {
|
||||
|
||||
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback.commands;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -20,6 +6,8 @@ import com.intellij.openapi.ui.TypingTarget;
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.concurrency.Promises;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -31,11 +19,11 @@ public class AlphaNumericTypeCommand extends TypeCommand {
|
||||
super(text, line, true);
|
||||
}
|
||||
|
||||
public ActionCallback _execute(PlaybackContext context) {
|
||||
public Promise<Object> _execute(PlaybackContext context) {
|
||||
return type(context, getText());
|
||||
}
|
||||
|
||||
protected ActionCallback type(final PlaybackContext context, final String text) {
|
||||
protected Promise<Object> type(final PlaybackContext context, final String text) {
|
||||
final ActionCallback result = new ActionCallback();
|
||||
|
||||
inWriteSafeContext(() -> {
|
||||
@@ -47,7 +35,7 @@ public class AlphaNumericTypeCommand extends TypeCommand {
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
return Promises.toPromise(result);
|
||||
}
|
||||
|
||||
private ActionCallback typeByRobot(final Robot robot, final String text) {
|
||||
|
||||
@@ -1,24 +1,12 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback.commands;
|
||||
|
||||
import com.intellij.openapi.ui.Queryable;
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import com.intellij.openapi.wm.IdeFocusManager;
|
||||
import org.jetbrains.concurrency.AsyncPromise;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.concurrency.Promises;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
@@ -31,9 +19,7 @@ public class AssertFocused extends AbstractCommand {
|
||||
super(text, line);
|
||||
}
|
||||
|
||||
protected ActionCallback _execute(final PlaybackContext context) {
|
||||
final ActionCallback result = new ActionCallback();
|
||||
|
||||
protected Promise<Object> _execute(final PlaybackContext context) {
|
||||
String text = getText().substring(PREFIX.length()).trim();
|
||||
final Map<String, String> expected = new LinkedHashMap<>();
|
||||
|
||||
@@ -42,23 +28,24 @@ public class AssertFocused extends AbstractCommand {
|
||||
for (String each : keyValue) {
|
||||
final String[] eachPair = each.split("=");
|
||||
if (eachPair.length != 2) {
|
||||
context.error("Syntax error, must be comma-separated pairs key=value", getLine());
|
||||
result.setRejected();
|
||||
return result;
|
||||
String error = "Syntax error, must be comma-separated pairs key=value";
|
||||
context.error(error, getLine());
|
||||
return Promises.rejectedPromise(error);
|
||||
}
|
||||
|
||||
expected.put(eachPair[0], eachPair[1]);
|
||||
}
|
||||
}
|
||||
|
||||
final AsyncPromise<Object> result = new AsyncPromise<>();
|
||||
IdeFocusManager.findInstance().doWhenFocusSettlesDown(() -> {
|
||||
try {
|
||||
doAssert(expected, context);
|
||||
result.setDone();
|
||||
result.setResult(null);
|
||||
}
|
||||
catch (AssertionError error) {
|
||||
context.error("Assertion failed: " + error.getMessage(), getLine());
|
||||
result.setRejected();
|
||||
result.setError(error);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,25 +1,11 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback.commands;
|
||||
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import com.intellij.openapi.util.AsyncResult;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.util.Consumer;
|
||||
import org.jetbrains.concurrency.AsyncPromise;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.concurrency.Promises;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -37,23 +23,20 @@ public class CallCommand extends AbstractCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ActionCallback _execute(final PlaybackContext context) {
|
||||
final ActionCallback cmdResult = new ActionCallback();
|
||||
|
||||
protected Promise<Object> _execute(final PlaybackContext context) {
|
||||
final String cmd = getText().substring(PREFIX.length()).trim();
|
||||
final int open = cmd.indexOf("(");
|
||||
if (open == -1) {
|
||||
context.error("( expected", getLine());
|
||||
return ActionCallback.DONE;
|
||||
return Promises.resolvedPromise();
|
||||
}
|
||||
|
||||
final int close = cmd.lastIndexOf(")");
|
||||
if (close == -1) {
|
||||
context.error(") expected", getLine());
|
||||
return ActionCallback.DONE;
|
||||
return Promises.resolvedPromise();
|
||||
}
|
||||
|
||||
|
||||
final String methodName = cmd.substring(0, open);
|
||||
String[] args = cmd.substring(open + 1, close).split(",");
|
||||
final boolean noArgs = args.length == 1 && args[0].length() == 0;
|
||||
@@ -64,18 +47,19 @@ public class CallCommand extends AbstractCommand {
|
||||
}
|
||||
|
||||
|
||||
final AsyncPromise<Object> cmdResult = new AsyncPromise<>();
|
||||
try {
|
||||
Pair<Method, Class> methodClass = findMethod(context, methodName, types);
|
||||
if (methodClass == null) {
|
||||
context.error("No method \"" + methodName + "\" found in facade classes: " + context.getCallClasses(), getLine());
|
||||
return ActionCallback.REJECTED;
|
||||
return Promises.rejectedPromise();
|
||||
}
|
||||
|
||||
Method m = methodClass.getFirst();
|
||||
|
||||
if (!m.getReturnType().isAssignableFrom(AsyncResult.class)) {
|
||||
context.error("Method " + methodClass.getSecond() + ":" + methodName + " must return AsyncResult object", getLine());
|
||||
return ActionCallback.REJECTED;
|
||||
if (!m.getReturnType().isAssignableFrom(Promise.class)) {
|
||||
context.error("Method " + methodClass.getSecond() + ":" + methodName + " must return Promise object", getLine());
|
||||
return Promises.rejectedPromise();
|
||||
}
|
||||
|
||||
Object[] actualArgs = noArgs ? new Object[1] : new Object[args.length + 1];
|
||||
@@ -83,21 +67,23 @@ public class CallCommand extends AbstractCommand {
|
||||
System.arraycopy(args, 0, actualArgs, 1, actualArgs.length - 1);
|
||||
|
||||
|
||||
AsyncResult result = (AsyncResult<String>)m.invoke(null, actualArgs);
|
||||
Promise<String> result = (Promise<String>)m.invoke(null, actualArgs);
|
||||
if (result == null) {
|
||||
context.error("Method " + methodClass.getSecond() + ":" + methodName + " must return AsyncResult object, but was null", getLine());
|
||||
return ActionCallback.REJECTED;
|
||||
return Promises.rejectedPromise();
|
||||
}
|
||||
|
||||
result.doWhenDone((Consumer<String>)s -> {
|
||||
if (s != null) {
|
||||
context.message(s, getLine());
|
||||
}
|
||||
cmdResult.setDone();
|
||||
}).doWhenRejected(s -> {
|
||||
context.error(s, getLine());
|
||||
cmdResult.setRejected();
|
||||
});
|
||||
result
|
||||
.onSuccess(s -> {
|
||||
if (s != null) {
|
||||
context.message(s, getLine());
|
||||
}
|
||||
cmdResult.setResult(null);
|
||||
})
|
||||
.onError(error -> {
|
||||
context.error(error.getMessage(), getLine());
|
||||
cmdResult.setError(error);
|
||||
});
|
||||
}
|
||||
catch (InvocationTargetException ignored) {
|
||||
context.error("InvocationTargetException while executing command: " + cmd, getLine());
|
||||
|
||||
@@ -1,22 +1,9 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback.commands;
|
||||
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.concurrency.Promises;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -32,11 +19,11 @@ public class CdCommand extends AbstractCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ActionCallback _execute(PlaybackContext context) {
|
||||
protected Promise<Object> _execute(PlaybackContext context) {
|
||||
File file = context.getPathMacro().resolveFile(myDir, context.getBaseDir());
|
||||
if (!file.exists()) {
|
||||
context.message("Cannot cd, directory doesn't exist: " + file.getAbsoluteFile(), getLine());
|
||||
return ActionCallback.REJECTED;
|
||||
return Promises.rejectedPromise();
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -45,8 +32,8 @@ public class CdCommand extends AbstractCommand {
|
||||
catch (IOException e) {
|
||||
context.setBaseDir(file);
|
||||
}
|
||||
|
||||
|
||||
context.message("{base.dir} set to " + context.getBaseDir().getAbsolutePath(), getLine());
|
||||
return ActionCallback.DONE;
|
||||
return Promises.resolvedPromise();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,9 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback.commands;
|
||||
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.concurrency.Promises;
|
||||
|
||||
public class DelayCommand extends AbstractCommand {
|
||||
public static final String PREFIX = CMD_PREFIX + "delay";
|
||||
@@ -25,7 +12,7 @@ public class DelayCommand extends AbstractCommand {
|
||||
super(text, line);
|
||||
}
|
||||
|
||||
public ActionCallback _execute(PlaybackContext context) {
|
||||
public Promise<Object> _execute(PlaybackContext context) {
|
||||
final String s = getText().substring(PREFIX.length()).trim();
|
||||
|
||||
try {
|
||||
@@ -34,9 +21,9 @@ public class DelayCommand extends AbstractCommand {
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
dumpError(context, "Invalid delay value: " + s);
|
||||
return ActionCallback.REJECTED;
|
||||
return Promises.rejectedPromise();
|
||||
}
|
||||
|
||||
return ActionCallback.DONE;
|
||||
return Promises.resolvedPromise();
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,16 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback.commands;
|
||||
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.concurrency.Promises;
|
||||
|
||||
public class EmptyCommand extends AbstractCommand {
|
||||
public EmptyCommand(int line) {
|
||||
super("", line);
|
||||
}
|
||||
|
||||
public ActionCallback _execute(PlaybackContext context) {
|
||||
return ActionCallback.DONE;
|
||||
public Promise<Object> _execute(PlaybackContext context) {
|
||||
return Promises.resolvedPromise();
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,9 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback.commands;
|
||||
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.concurrency.Promises;
|
||||
|
||||
public class ErrorCommand extends AbstractCommand {
|
||||
|
||||
@@ -24,8 +11,8 @@ public class ErrorCommand extends AbstractCommand {
|
||||
super(text, line);
|
||||
}
|
||||
|
||||
public ActionCallback _execute(PlaybackContext context) {
|
||||
public Promise<Object> _execute(PlaybackContext context) {
|
||||
dumpError(context, getText());
|
||||
return ActionCallback.REJECTED;
|
||||
return Promises.rejectedPromise();
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback.commands;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -20,6 +6,8 @@ import com.intellij.openapi.ui.TypingTarget;
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import com.intellij.openapi.util.Couple;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.concurrency.Promises;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -37,11 +25,11 @@ public class KeyCodeTypeCommand extends AlphaNumericTypeCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionCallback _execute(final PlaybackContext context) {
|
||||
public Promise<Object> _execute(final PlaybackContext context) {
|
||||
String text = getText().substring(PREFIX.length()).trim();
|
||||
|
||||
int textDelim = text.indexOf(" ");
|
||||
|
||||
|
||||
final String codes;
|
||||
if (textDelim >= 0) {
|
||||
codes = text.substring(0, textDelim);
|
||||
@@ -57,8 +45,6 @@ public class KeyCodeTypeCommand extends AlphaNumericTypeCommand {
|
||||
}
|
||||
|
||||
final ActionCallback result = new ActionCallback();
|
||||
|
||||
|
||||
inWriteSafeContext(() -> {
|
||||
TypingTarget typingTarget = findTarget(context);
|
||||
if (typingTarget != null) {
|
||||
@@ -68,7 +54,7 @@ public class KeyCodeTypeCommand extends AlphaNumericTypeCommand {
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
return Promises.toPromise(result);
|
||||
}
|
||||
|
||||
private ActionCallback typeCodes(final PlaybackContext context, final Robot robot, final String codes) {
|
||||
|
||||
@@ -1,22 +1,9 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback.commands;
|
||||
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.concurrency.Promises;
|
||||
|
||||
public class KeyShortcutCommand extends TypeCommand {
|
||||
|
||||
@@ -27,15 +14,15 @@ public class KeyShortcutCommand extends TypeCommand {
|
||||
super(text, line, false);
|
||||
}
|
||||
|
||||
public ActionCallback _execute(PlaybackContext context) {
|
||||
public Promise<Object> _execute(PlaybackContext context) {
|
||||
final String one = getText().substring(PREFIX.length());
|
||||
if (!one.endsWith(POSTFIX)) {
|
||||
dumpError(context, "Expected " + "]");
|
||||
return ActionCallback.REJECTED;
|
||||
return Promises.rejectedPromise();
|
||||
}
|
||||
|
||||
type(context.getRobot(), getFromShortcut(one.substring(0, one.length() - 1).trim()));
|
||||
|
||||
return ActionCallback.DONE;
|
||||
return Promises.resolvedPromise();
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,10 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback.commands;
|
||||
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext;
|
||||
import com.intellij.openapi.ui.playback.StageInfo;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.concurrency.Promises;
|
||||
|
||||
public class PopStage extends AbstractCommand {
|
||||
|
||||
@@ -28,13 +15,13 @@ public class PopStage extends AbstractCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ActionCallback _execute(PlaybackContext context) {
|
||||
protected Promise<Object> _execute(PlaybackContext context) {
|
||||
StageInfo stage = context.popStage();
|
||||
if (stage != null) {
|
||||
context.test("Test finished OK: " + stage.getName(), getLine());
|
||||
context.addPassed(stage);
|
||||
}
|
||||
return ActionCallback.DONE;
|
||||
return Promises.resolvedPromise();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,35 +1,22 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback.commands;
|
||||
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.concurrency.Promises;
|
||||
|
||||
public class PrintCommand extends AbstractCommand {
|
||||
|
||||
private final String myText;
|
||||
|
||||
|
||||
public PrintCommand(String text, int line) {
|
||||
super("", line);
|
||||
myText = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ActionCallback _execute(PlaybackContext context) {
|
||||
protected Promise<Object> _execute(PlaybackContext context) {
|
||||
context.code(myText, getLine());
|
||||
return ActionCallback.DONE;
|
||||
return Promises.resolvedPromise();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,25 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback.commands;
|
||||
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext;
|
||||
import com.intellij.openapi.ui.playback.StageInfo;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.concurrency.Promises;
|
||||
|
||||
public class PushStage extends AbstractCommand {
|
||||
|
||||
public static final String PREFIX = CMD_PREFIX + "startTest";
|
||||
|
||||
|
||||
public PushStage(String text, int line) {
|
||||
super(text, line);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ActionCallback _execute(PlaybackContext context) {
|
||||
protected Promise<Object> _execute(PlaybackContext context) {
|
||||
String name = getText().substring(PREFIX.length()).trim();
|
||||
context.test("Test started: " + name, getLine());
|
||||
context.pushStage(new StageInfo(name));
|
||||
return ActionCallback.DONE;
|
||||
return Promises.resolvedPromise();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,23 +1,10 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback.commands;
|
||||
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.concurrency.Promises;
|
||||
|
||||
public class RegistryValueCommand extends AbstractCommand {
|
||||
|
||||
@@ -28,11 +15,11 @@ public class RegistryValueCommand extends AbstractCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ActionCallback _execute(PlaybackContext context) {
|
||||
protected Promise<Object> _execute(PlaybackContext context) {
|
||||
final String[] keyValue = getText().substring(PREFIX.length()).trim().split("=");
|
||||
if (keyValue.length != 2) {
|
||||
context.error("Expected expresstion: " + PREFIX + " key=value", getLine());
|
||||
return ActionCallback.REJECTED;
|
||||
return Promises.rejectedPromise();
|
||||
}
|
||||
|
||||
final String key = keyValue[0];
|
||||
@@ -42,6 +29,6 @@ public class RegistryValueCommand extends AbstractCommand {
|
||||
|
||||
Registry.get(key).setValue(value);
|
||||
|
||||
return ActionCallback.DONE;
|
||||
return Promises.resolvedPromise();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,9 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback.commands;
|
||||
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.concurrency.Promises;
|
||||
|
||||
public class StopCommand extends AbstractCommand {
|
||||
|
||||
@@ -26,9 +13,9 @@ public class StopCommand extends AbstractCommand {
|
||||
super(text, line);
|
||||
}
|
||||
|
||||
protected ActionCallback _execute(PlaybackContext context) {
|
||||
protected Promise<Object> _execute(PlaybackContext context) {
|
||||
context.message("Stopped", getLine());
|
||||
return ActionCallback.DONE;
|
||||
return Promises.resolvedPromise();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.ui.playback.commands;
|
||||
|
||||
import com.intellij.ide.DataManager;
|
||||
@@ -23,30 +9,32 @@ import com.intellij.openapi.ui.playback.PlaybackContext;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.wm.IdeFocusManager;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.concurrency.Promises;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.InputEvent;
|
||||
|
||||
public class ToggleActionCommand extends AbstractCommand {
|
||||
|
||||
|
||||
public static final String PREFIX = CMD_PREFIX + "toggle";
|
||||
|
||||
public static final String ON = "on";
|
||||
public static final String OFF = "off";
|
||||
|
||||
|
||||
public ToggleActionCommand(String text, int line) {
|
||||
super(text, line, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ActionCallback _execute(PlaybackContext context) {
|
||||
protected Promise<Object> _execute(PlaybackContext context) {
|
||||
String[] args = getText().substring(PREFIX.length()).trim().split(" ");
|
||||
String syntaxText = "Syntax error, expected: " + PREFIX + " " + ON + "|" + OFF + " actionName";
|
||||
if (args.length != 2) {
|
||||
context.error(syntaxText, getLine());
|
||||
return ActionCallback.REJECTED;
|
||||
return Promises.rejectedPromise();
|
||||
}
|
||||
|
||||
|
||||
final boolean on;
|
||||
if (ON.equalsIgnoreCase(args[0])) {
|
||||
on = true;
|
||||
@@ -54,19 +42,19 @@ public class ToggleActionCommand extends AbstractCommand {
|
||||
on = false;
|
||||
} else {
|
||||
context.error(syntaxText, getLine());
|
||||
return ActionCallback.REJECTED;
|
||||
return Promises.rejectedPromise();
|
||||
}
|
||||
|
||||
|
||||
String actionId = args[1];
|
||||
final AnAction action = ActionManager.getInstance().getAction(actionId);
|
||||
if (action == null) {
|
||||
context.error("Unknown action id=" + actionId, getLine());
|
||||
return ActionCallback.REJECTED;
|
||||
return Promises.rejectedPromise();
|
||||
}
|
||||
|
||||
if (!(action instanceof ToggleAction)) {
|
||||
context.error("Action is not a toggle action id=" + actionId, getLine());
|
||||
return ActionCallback.REJECTED;
|
||||
return Promises.rejectedPromise();
|
||||
}
|
||||
|
||||
final InputEvent inputEvent = ActionCommand.getInputEvent(actionId);
|
||||
@@ -76,7 +64,7 @@ public class ToggleActionCommand extends AbstractCommand {
|
||||
|
||||
IdeFocusManager fm = IdeFocusManager.getGlobalInstance();
|
||||
fm.doWhenFocusSettlesDown(() -> {
|
||||
final Presentation presentation = (Presentation)action.getTemplatePresentation().clone();
|
||||
final Presentation presentation = action.getTemplatePresentation().clone();
|
||||
AnActionEvent event =
|
||||
new AnActionEvent(inputEvent, DataManager.getInstance()
|
||||
.getDataContext(KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()), ActionPlaces.UNKNOWN,
|
||||
@@ -94,6 +82,6 @@ public class ToggleActionCommand extends AbstractCommand {
|
||||
});
|
||||
|
||||
|
||||
return result;
|
||||
return Promises.toPromise(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,8 +176,8 @@ fun Logger.errorIfNotMessage(e: Throwable): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
fun ActionCallback.toPromise(): Promise<Void?> {
|
||||
val promise = AsyncPromise<Void?>()
|
||||
fun ActionCallback.toPromise(): Promise<Any?> {
|
||||
val promise = AsyncPromise<Any?>()
|
||||
doWhenDone { promise.setResult(null) }
|
||||
.doWhenRejected { error -> promise.setError(createError(error ?: "Internal error")) }
|
||||
return promise
|
||||
|
||||
Reference in New Issue
Block a user