This commit is contained in:
Alexey Kudravtsev
2018-10-09 14:57:35 +03:00
parent a97a6cb271
commit 59e663447f
3 changed files with 36 additions and 29 deletions
@@ -1046,12 +1046,14 @@ public class PsiTreeUtil {
return nextLeaf(parent);
}
@NotNull
public static PsiElement lastChild(@NotNull PsiElement element) {
PsiElement lastChild = element.getLastChild();
if (lastChild != null) return lastChild(lastChild);
return element;
}
@NotNull
public static PsiElement firstChild(@NotNull final PsiElement element) {
PsiElement child = element.getFirstChild();
if (child != null) return firstChild(child);
@@ -1079,35 +1079,43 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
return null;
}
public static class ClearAllAction extends DumbAwareAction {
private static class ClearThisConsoleAction extends ClearAllAction {
private final ConsoleView myConsoleView;
@SuppressWarnings("unused") // in LangActions.xml
public ClearAllAction() {
this(null);
}
ClearAllAction(ConsoleView consoleView) {
super(ExecutionBundle.message("clear.all.from.console.action.name"), "Clear the contents of the console", AllIcons.Actions.GC);
ClearThisConsoleAction(@NotNull ConsoleView consoleView) {
myConsoleView = consoleView;
}
@Override
public void update(@NotNull AnActionEvent e) {
boolean enabled = myConsoleView != null && myConsoleView.getContentSize() > 0;
if (!enabled) {
enabled = e.getData(LangDataKeys.CONSOLE_VIEW) != null;
Editor editor = e.getData(CommonDataKeys.EDITOR);
if (editor != null && editor.getDocument().getTextLength() == 0) {
enabled = false;
}
boolean enabled = myConsoleView.getContentSize() > 0;
e.getPresentation().setEnabled(enabled);
}
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
myConsoleView.clear();
}
}
public static class ClearAllAction extends DumbAwareAction {
public ClearAllAction() {
super(ExecutionBundle.message("clear.all.from.console.action.name"), "Clear the contents of the console", AllIcons.Actions.GC);
}
@Override
public void update(@NotNull AnActionEvent e) {
boolean enabled = e.getData(LangDataKeys.CONSOLE_VIEW) != null;
Editor editor = e.getData(CommonDataKeys.EDITOR);
if (editor != null && editor.getDocument().getTextLength() == 0) {
enabled = false;
}
e.getPresentation().setEnabled(enabled);
}
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
final ConsoleView consoleView = myConsoleView != null ? myConsoleView : e.getData(LangDataKeys.CONSOLE_VIEW);
final ConsoleView consoleView = e.getData(LangDataKeys.CONSOLE_VIEW);
if (consoleView != null) {
consoleView.clear();
}
@@ -1387,19 +1395,16 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
};
final AnAction autoScrollToTheEndAction = new ScrollToTheEndToolbarAction(myEditor);
//Initializing custom actions
final AnAction[] consoleActions = new AnAction[6 + customActions.size()];
consoleActions[0] = prevAction;
consoleActions[1] = nextAction;
consoleActions[2] = switchSoftWrapsAction;
consoleActions[3] = autoScrollToTheEndAction;
consoleActions[4] = ActionManager.getInstance().getAction("Print");
consoleActions[5] = new ClearAllAction(this);
for (int i = 0; i < customActions.size(); ++i) {
consoleActions[i + 6] = customActions.get(i);
}
List<AnAction> consoleActions = new ArrayList<>();
consoleActions.add(prevAction);
consoleActions.add(nextAction);
consoleActions.add(switchSoftWrapsAction);
consoleActions.add(autoScrollToTheEndAction);
consoleActions.add(ActionManager.getInstance().getAction("Print"));
consoleActions.add(new ClearThisConsoleAction(this));
consoleActions.addAll(customActions);
List<ConsoleActionsPostProcessor> postProcessors = ConsoleActionsPostProcessor.EP_NAME.getExtensionList();
AnAction[] result = consoleActions;
AnAction[] result = consoleActions.toArray(AnAction.EMPTY_ARRAY);
for (ConsoleActionsPostProcessor postProcessor : postProcessors) {
result = postProcessor.postProcess(this, result);
}
@@ -105,7 +105,7 @@ public class DuplexConsoleActionsTest extends LightPlatformTestCase {
private static void assertHasActions(AnAction[] mergedActions, String... actionNames) {
for (String name : actionNames) {
assertNotNull(findAction(mergedActions, name));
assertNotNull(name + " in " + Arrays.toString(mergedActions), findAction(mergedActions, name));
}
}