From 41fc92978afac80d0063879cfbe430eaf2affc4e Mon Sep 17 00:00:00 2001 From: Edem Ibraimov Date: Mon, 13 May 2024 19:59:04 +0000 Subject: [PATCH] IJPL-149223: EOFAction: search for console in the focused component's parents Merge-request: IJ-MR-133695 Merged-by: Edem Ibraimov GitOrigin-RevId: b9dee639395993f7172e2b7a9f306ab94914b696 --- .../intellij/execution/actions/EOFAction.java | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/platform/execution-impl/src/com/intellij/execution/actions/EOFAction.java b/platform/execution-impl/src/com/intellij/execution/actions/EOFAction.java index 4feae23edd8e..635f303de71c 100644 --- a/platform/execution-impl/src/com/intellij/execution/actions/EOFAction.java +++ b/platform/execution-impl/src/com/intellij/execution/actions/EOFAction.java @@ -1,17 +1,18 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.execution.actions; import com.google.common.base.Ascii; import com.intellij.execution.process.ProcessHandler; -import com.intellij.execution.ui.*; -import com.intellij.execution.ui.layout.impl.ViewImpl; +import com.intellij.execution.ui.ConsoleView; +import com.intellij.execution.ui.ConsoleViewContentType; +import com.intellij.execution.ui.RunContentDescriptor; import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.project.DumbAwareAction; +import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.terminal.TerminalExecutionConsole; -import com.intellij.ui.content.Content; -import com.intellij.ui.content.ContentManager; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -24,28 +25,19 @@ public final class EOFAction extends DumbAwareAction { @Override public @NotNull ActionUpdateThread getActionUpdateThread() { - return ActionUpdateThread.BGT; + return ActionUpdateThread.EDT; } @Override public void update(@NotNull AnActionEvent e) { RunContentDescriptor descriptor = StopAction.getRecentlyStartedContentDescriptor(e.getDataContext()); - boolean isConsoleSelected = descriptor != null && isConsoleSelected(descriptor); + ConsoleView console = UIUtil.getParentOfType(ConsoleView.class, IdeFocusManager.findInstance().getFocusOwner()); ProcessHandler handler = descriptor != null ? descriptor.getProcessHandler() : null; - e.getPresentation().setEnabledAndVisible(isConsoleSelected + e.getPresentation().setEnabledAndVisible(console != null && handler != null && !handler.isProcessTerminated()); } - private static boolean isConsoleSelected(@NotNull RunContentDescriptor descriptor) { - RunnerLayoutUi runnerLayoutUi = descriptor.getRunnerLayoutUi(); - if (runnerLayoutUi == null) return false; - ContentManager contentManager = runnerLayoutUi.getContentManager(); - Content selectedContent = contentManager.getSelectedContent(); - return selectedContent != null - && ExecutionConsole.CONSOLE_CONTENT_ID.equals(selectedContent.getUserData(ViewImpl.ID)); - } - @Override public void actionPerformed(@NotNull AnActionEvent e) { RunContentDescriptor descriptor = StopAction.getRecentlyStartedContentDescriptor(e.getDataContext());