use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class RunIdeConsoleAction method executeQuery.
private static void executeQuery(@NotNull Project project, @NotNull VirtualFile file, @NotNull Editor editor, @NotNull IdeScriptEngine engine) {
String command = getCommandText(project, editor);
if (StringUtil.isEmptyOrSpaces(command))
return;
String profile = getProfileText(file);
RunContentDescriptor descriptor = getConsoleView(project, file);
ConsoleViewImpl consoleView = (ConsoleViewImpl) descriptor.getExecutionConsole();
prepareEngine(project, engine, descriptor);
try {
long ts = System.currentTimeMillis();
//myHistoryController.getModel().addToHistory(command);
consoleView.print("> " + command, ConsoleViewContentType.USER_INPUT);
consoleView.print("\n", ConsoleViewContentType.USER_INPUT);
String script = profile == null ? command : profile + "\n" + command;
Object o = engine.eval(script);
String prefix = "[" + (StringUtil.formatDuration(System.currentTimeMillis() - ts)) + "]";
consoleView.print(prefix + "=> " + o, ConsoleViewContentType.NORMAL_OUTPUT);
consoleView.print("\n", ConsoleViewContentType.NORMAL_OUTPUT);
} catch (Throwable e) {
//noinspection ThrowableResultOfMethodCallIgnored
Throwable ex = ExceptionUtil.getRootCause(e);
consoleView.print(ex.getClass().getSimpleName() + ": " + ex.getMessage(), ConsoleViewContentType.ERROR_OUTPUT);
consoleView.print("\n", ConsoleViewContentType.ERROR_OUTPUT);
}
selectContent(descriptor);
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class ExecutionManagerImpl method restartRunProfile.
@Override
public void restartRunProfile(@NotNull final ExecutionEnvironment environment) {
RunnerAndConfigurationSettings configuration = environment.getRunnerAndConfigurationSettings();
List<RunContentDescriptor> runningIncompatible;
if (configuration == null) {
runningIncompatible = Collections.emptyList();
} else {
runningIncompatible = getIncompatibleRunningDescriptors(configuration);
}
RunContentDescriptor contentToReuse = environment.getContentToReuse();
final List<RunContentDescriptor> runningOfTheSameType = new SmartList<>();
if (configuration != null && configuration.isSingleton()) {
runningOfTheSameType.addAll(getRunningDescriptorsOfTheSameConfigType(configuration));
} else if (isProcessRunning(contentToReuse)) {
runningOfTheSameType.add(contentToReuse);
}
List<RunContentDescriptor> runningToStop = ContainerUtil.concat(runningOfTheSameType, runningIncompatible);
if (!runningToStop.isEmpty()) {
if (configuration != null) {
if (!runningOfTheSameType.isEmpty() && (runningOfTheSameType.size() > 1 || contentToReuse == null || runningOfTheSameType.get(0) != contentToReuse) && !userApprovesStopForSameTypeConfigurations(environment.getProject(), configuration.getName(), runningOfTheSameType.size())) {
return;
}
if (!runningIncompatible.isEmpty() && !userApprovesStopForIncompatibleConfigurations(myProject, configuration.getName(), runningIncompatible)) {
return;
}
}
for (RunContentDescriptor descriptor : runningToStop) {
stopProcess(descriptor);
}
}
if (myAwaitingRunProfiles.get(environment.getRunProfile()) == environment) {
// defense from rerunning exactly the same ExecutionEnvironment
return;
}
myAwaitingRunProfiles.put(environment.getRunProfile(), environment);
awaitTermination(new Runnable() {
@Override
public void run() {
if (myAwaitingRunProfiles.get(environment.getRunProfile()) != environment) {
// a new rerun has been requested before starting this one, ignore this rerun
return;
}
if ((DumbService.getInstance(myProject).isDumb() && !Registry.is("dumb.aware.run.configurations")) || ExecutorRegistry.getInstance().isStarting(environment)) {
awaitTermination(this, 100);
return;
}
for (RunContentDescriptor descriptor : runningOfTheSameType) {
ProcessHandler processHandler = descriptor.getProcessHandler();
if (processHandler != null && !processHandler.isProcessTerminated()) {
awaitTermination(this, 100);
return;
}
}
myAwaitingRunProfiles.remove(environment.getRunProfile());
start(environment);
}
}, 50);
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class CloseAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final RunContentDescriptor contentDescriptor = getContentDescriptor();
if (contentDescriptor == null) {
return;
}
final boolean removedOk = ExecutionManager.getInstance(myProject).getContentManager().removeRunContent(getExecutor(), contentDescriptor);
if (removedOk) {
myContentDescriptor = null;
myExecutor = null;
}
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class RunConfigurationsComboBoxAction method setConfigurationIcon.
private static void setConfigurationIcon(final Presentation presentation, final RunnerAndConfigurationSettings settings, final Project project) {
try {
Icon icon = RunManagerEx.getInstanceEx(project).getConfigurationIcon(settings);
ExecutionManagerImpl executionManager = ExecutionManagerImpl.getInstance(project);
List<RunContentDescriptor> runningDescriptors = executionManager.getRunningDescriptors(s -> s == settings);
if (runningDescriptors.size() == 1) {
icon = ExecutionUtil.getLiveIndicator(icon);
}
if (runningDescriptors.size() > 1) {
icon = IconUtil.addText(icon, String.valueOf(runningDescriptors.size()));
}
presentation.setIcon(icon);
} catch (IndexNotReadyException ignored) {
}
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class ShowRunningListAction method actionPerformed.
@Override
public void actionPerformed(final AnActionEvent e) {
final Project project = e.getProject();
if (project == null || project.isDisposed())
return;
final Ref<Pair<? extends JComponent, String>> stateRef = new Ref<>();
final Ref<Balloon> balloonRef = new Ref<>();
final Timer timer = UIUtil.createNamedTimer("runningLists", 250);
ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
Balloon balloon = balloonRef.get();
if (project.isDisposed() || (balloon != null && balloon.isDisposed())) {
timer.stop();
return;
}
ArrayList<Project> projects = new ArrayList<>(Arrays.asList(ProjectManager.getInstance().getOpenProjects()));
//List should begin with current project
projects.remove(project);
projects.add(0, project);
Pair<? extends JComponent, String> state = getCurrentState(projects);
Pair<? extends JComponent, String> prevState = stateRef.get();
if (prevState != null && prevState.getSecond().equals(state.getSecond()))
return;
stateRef.set(state);
BalloonBuilder builder = JBPopupFactory.getInstance().createBalloonBuilder(state.getFirst());
builder.setShowCallout(false).setTitle(ExecutionBundle.message("show.running.list.balloon.title")).setBlockClicksThroughBalloon(true).setDialogMode(true).setHideOnKeyOutside(false);
IdeFrame frame = IdeFrame.KEY.getData(e.getDataContext());
if (frame == null) {
frame = WindowManagerEx.getInstanceEx().getFrame(project);
}
if (balloon != null) {
balloon.hide();
}
builder.setClickHandler(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof MouseEvent) {
MouseEvent mouseEvent = (MouseEvent) e.getSource();
Component component = mouseEvent.getComponent();
component = SwingUtilities.getDeepestComponentAt(component, mouseEvent.getX(), mouseEvent.getY());
Object value = ((JComponent) component).getClientProperty(KEY);
if (value instanceof Trinity) {
Project aProject = (Project) ((Trinity) value).first;
JFrame aFrame = WindowManager.getInstance().getFrame(aProject);
if (aFrame != null && !aFrame.isActive()) {
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(aFrame, true);
});
}
ExecutionManagerImpl.getInstance(aProject).getContentManager().toFrontRunContent((Executor) ((Trinity) value).second, (RunContentDescriptor) ((Trinity) value).third);
}
}
}
}, false);
balloon = builder.createBalloon();
balloonRef.set(balloon);
JComponent component = frame.getComponent();
RelativePoint point = new RelativePoint(component, new Point(component.getWidth(), 0));
balloon.show(point, Balloon.Position.below);
}
};
timer.addActionListener(actionListener);
timer.setInitialDelay(0);
timer.start();
}
Aggregations