use of com.intellij.openapi.fileEditor.FileEditorManagerListener 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;
}
use of com.intellij.openapi.fileEditor.FileEditorManagerListener in project intellij-community by JetBrains.
the class StudyToolWindow method init.
public void init(@NotNull final Project project, final boolean isToolwindow) {
String taskText = StudyUtils.getTaskText(project);
if (taskText == null)
return;
final DefaultActionGroup group = getActionGroup(project);
setActionToolbar(group);
final JPanel panel = new JPanel(new BorderLayout());
final Course course = StudyTaskManager.getInstance(project).getCourse();
if (isToolwindow && course != null && course.isAdaptive()) {
panel.add(new StepicAdaptiveReactionsPanel(project), BorderLayout.NORTH);
}
JComponent taskInfoPanel = createTaskInfoPanel(project);
panel.add(taskInfoPanel, BorderLayout.CENTER);
final JPanel courseProgress = createCourseProgress(project);
if (isToolwindow && course != null && !course.isAdaptive() && EduNames.STUDY.equals(course.getCourseMode())) {
panel.add(courseProgress, BorderLayout.SOUTH);
}
myContentPanel.add(TASK_INFO_ID, panel);
mySplitPane.setFirstComponent(myContentPanel);
addAdditionalPanels(project);
myCardLayout.show(myContentPanel, TASK_INFO_ID);
setContent(mySplitPane);
if (isToolwindow) {
StudyPluginConfigurator configurator = StudyUtils.getConfigurator(project);
if (configurator != null) {
final FileEditorManagerListener listener = configurator.getFileEditorManagerListener(project, this);
project.getMessageBus().connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener);
}
if (StudyTaskManager.getInstance(project).isTurnEditingMode() || StudyTaskManager.getInstance(project).getToolWindowMode() == StudyToolWindowMode.EDITING) {
TaskFile file = StudyUtils.getSelectedTaskFile(project);
if (file != null) {
VirtualFile taskDir = file.getTask().getTaskDir(project);
setTaskText(taskText, taskDir, project);
}
} else {
setTaskText(taskText, null, project);
}
}
}
use of com.intellij.openapi.fileEditor.FileEditorManagerListener in project intellij-plugins by StepicOrg.
the class StudyToolWindow method init.
void init(@NotNull final Project project) {
this.project = project;
final DefaultActionGroup group = getActionGroup(project);
setActionToolbar(group);
final JPanel panel = new JPanel(new BorderLayout());
JComponent stepInfoPanel = createStepInfoPanel(project);
panel.add(stepInfoPanel, BorderLayout.CENTER);
contentPanel.add(STEP_INFO_ID, panel);
splitPane.setFirstComponent(contentPanel);
addAdditionalPanels(project);
cardLayout.show(contentPanel, STEP_INFO_ID);
setContent(splitPane);
StudyPluginConfigurator configurator = StudyUtils.getConfigurator(project);
if (configurator != null) {
final FileEditorManagerListener listener = configurator.getFileEditorManagerListener(project);
project.getMessageBus().connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener);
}
StudyNode<?, ?> stepNode = StepikProjectManager.getSelected(project);
setStepNode(stepNode);
}
Aggregations