use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class StopAction method getActiveStoppableDescriptors.
@NotNull
private static List<RunContentDescriptor> getActiveStoppableDescriptors(final DataContext dataContext) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null) {
return Collections.emptyList();
}
final List<RunContentDescriptor> runningProcesses = ExecutionManager.getInstance(project).getContentManager().getAllDescriptors();
if (runningProcesses.isEmpty()) {
return Collections.emptyList();
}
final List<RunContentDescriptor> activeDescriptors = new ArrayList<>();
for (RunContentDescriptor descriptor : runningProcesses) {
if (canBeStopped(descriptor)) {
activeDescriptors.add(descriptor);
}
}
return activeDescriptors;
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class StopAction method actionPerformed.
@Override
public void actionPerformed(final AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
Project project = e.getProject();
List<Pair<TaskInfo, ProgressIndicator>> cancellableProcesses = getCancellableProcesses(project);
List<RunContentDescriptor> stoppableDescriptors = getActiveStoppableDescriptors(dataContext);
if (isPlaceGlobal(e)) {
int todoSize = cancellableProcesses.size() + stoppableDescriptors.size();
if (todoSize == 1) {
if (!stoppableDescriptors.isEmpty()) {
ExecutionManagerImpl.stopProcess(stoppableDescriptors.get(0));
} else {
cancellableProcesses.get(0).second.cancel();
}
return;
}
Pair<List<HandlerItem>, HandlerItem> handlerItems = getItemsList(cancellableProcesses, stoppableDescriptors, getRecentlyStartedContentDescriptor(dataContext));
if (handlerItems == null || handlerItems.first.isEmpty()) {
return;
}
final JBList list = new JBList(handlerItems.first);
if (handlerItems.second != null)
list.setSelectedValue(handlerItems.second, true);
list.setCellRenderer(new GroupedItemsListRenderer(new ListItemDescriptorAdapter() {
@Nullable
@Override
public String getTextFor(Object value) {
return value instanceof HandlerItem ? ((HandlerItem) value).displayName : null;
}
@Nullable
@Override
public Icon getIconFor(Object value) {
return value instanceof HandlerItem ? ((HandlerItem) value).icon : null;
}
@Override
public boolean hasSeparatorAboveOf(Object value) {
return value instanceof HandlerItem && ((HandlerItem) value).hasSeparator;
}
}));
JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setMovable(true).setTitle(handlerItems.first.size() == 1 ? "Confirm process stop" : "Stop process").setFilteringEnabled(o -> ((HandlerItem) o).displayName).setItemChoosenCallback(() -> {
List valuesList = list.getSelectedValuesList();
for (Object o : valuesList) {
if (o instanceof HandlerItem)
((HandlerItem) o).stop();
}
}).setRequestFocus(true).createPopup();
InputEvent inputEvent = e.getInputEvent();
Component component = inputEvent != null ? inputEvent.getComponent() : null;
if (component != null && ActionPlaces.MAIN_TOOLBAR.equals(e.getPlace())) {
popup.showUnderneathOf(component);
} else if (project == null) {
popup.showInBestPositionFor(dataContext);
} else {
popup.showCenteredInCurrentWindow(project);
}
} else {
ExecutionManagerImpl.stopProcess(getRecentlyStartedContentDescriptor(dataContext));
}
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class ExecutionHelper method findRunningConsole.
public static Collection<RunContentDescriptor> findRunningConsole(@NotNull Project project, @NotNull NotNullFunction<RunContentDescriptor, Boolean> descriptorMatcher) {
RunContentManager contentManager = ExecutionManager.getInstance(project).getContentManager();
final RunContentDescriptor selectedContent = contentManager.getSelectedContent();
if (selectedContent != null) {
final ToolWindow toolWindow = contentManager.getToolWindowByDescriptor(selectedContent);
if (toolWindow != null && toolWindow.isVisible()) {
if (descriptorMatcher.fun(selectedContent)) {
return Collections.singletonList(selectedContent);
}
}
}
final ArrayList<RunContentDescriptor> result = ContainerUtil.newArrayList();
for (RunContentDescriptor runContentDescriptor : contentManager.getAllDescriptors()) {
if (descriptorMatcher.fun(runContentDescriptor)) {
result.add(runContentDescriptor);
}
}
return result;
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class EOFAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
RunContentDescriptor descriptor = StopAction.getRecentlyStartedContentDescriptor(e.getDataContext());
ProcessHandler activeProcessHandler = descriptor != null ? descriptor.getProcessHandler() : null;
if (activeProcessHandler == null || activeProcessHandler.isProcessTerminated())
return;
try {
OutputStream input = activeProcessHandler.getProcessInput();
if (input != null) {
ConsoleView console = e.getData(LangDataKeys.CONSOLE_VIEW);
if (console != null) {
console.print("^D\n", ConsoleViewContentType.SYSTEM_OUTPUT);
}
input.close();
}
} catch (IOException ignored) {
}
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class GroovyConsole method createConsole.
@Nullable
public static GroovyConsole createConsole(@NotNull final Project project, @NotNull final VirtualFile contentFile, @NotNull Module module) {
final ProcessHandler processHandler = createProcessHandler(module);
if (processHandler == null)
return null;
final GroovyConsoleStateService consoleStateService = GroovyConsoleStateService.getInstance(project);
consoleStateService.setFileModule(contentFile, module);
final String title = consoleStateService.getSelectedModuleTitle(contentFile);
final ConsoleViewImpl consoleView = new ConsoleViewImpl(project, true);
final RunContentDescriptor descriptor = new RunContentDescriptor(consoleView, processHandler, new JPanel(new BorderLayout()), title);
final GroovyConsole console = new GroovyConsole(project, descriptor, consoleView, processHandler);
// must call getComponent before createConsoleActions()
final JComponent consoleViewComponent = consoleView.getComponent();
final DefaultActionGroup actionGroup = new DefaultActionGroup();
actionGroup.add(new BuildAndRestartConsoleAction(module, project, defaultExecutor, descriptor, restarter(project, contentFile)));
actionGroup.addSeparator();
actionGroup.addAll(consoleView.createConsoleActions());
actionGroup.add(new CloseAction(defaultExecutor, descriptor, project) {
@Override
public void actionPerformed(AnActionEvent e) {
// use force
processHandler.destroyProcess();
super.actionPerformed(e);
}
});
final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, actionGroup, false);
toolbar.setTargetComponent(consoleViewComponent);
final JComponent ui = descriptor.getComponent();
ui.add(consoleViewComponent, BorderLayout.CENTER);
ui.add(toolbar.getComponent(), BorderLayout.WEST);
project.getMessageBus().connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
@Override
public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
if (file.equals(contentFile)) {
// if file was closed then kill process and hide console content
console.stop();
}
}
});
processHandler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
if (contentFile.getUserData(GROOVY_CONSOLE) == console) {
// process terminated either by closing file or by close action
contentFile.putUserData(GROOVY_CONSOLE, null);
}
}
});
contentFile.putUserData(GROOVY_CONSOLE, console);
consoleView.attachToProcess(processHandler);
processHandler.startNotify();
ExecutionManager.getInstance(project).getContentManager().showRunContent(defaultExecutor, descriptor);
return console;
}
Aggregations