diff --git a/platform/core-api/src/com/intellij/psi/util/PsiTreeUtil.java b/platform/core-api/src/com/intellij/psi/util/PsiTreeUtil.java index 8fbb364a1269..d630ed5c6b5f 100644 --- a/platform/core-api/src/com/intellij/psi/util/PsiTreeUtil.java +++ b/platform/core-api/src/com/intellij/psi/util/PsiTreeUtil.java @@ -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); diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java index 3188d902438b..b17274bd83cd 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java @@ -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 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 postProcessors = ConsoleActionsPostProcessor.EP_NAME.getExtensionList(); - AnAction[] result = consoleActions; + AnAction[] result = consoleActions.toArray(AnAction.EMPTY_ARRAY); for (ConsoleActionsPostProcessor postProcessor : postProcessors) { result = postProcessor.postProcess(this, result); } diff --git a/platform/platform-tests/testSrc/com/intellij/execution/impl/DuplexConsoleActionsTest.java b/platform/platform-tests/testSrc/com/intellij/execution/impl/DuplexConsoleActionsTest.java index c514a5abc471..495be52ed834 100644 --- a/platform/platform-tests/testSrc/com/intellij/execution/impl/DuplexConsoleActionsTest.java +++ b/platform/platform-tests/testSrc/com/intellij/execution/impl/DuplexConsoleActionsTest.java @@ -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)); } }