Search in sources :

Example 11 with FileEditorManagerListener

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ConsoleViewImpl(com.intellij.execution.impl.ConsoleViewImpl) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) CloseAction(com.intellij.execution.ui.actions.CloseAction) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with FileEditorManagerListener

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);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StepicAdaptiveReactionsPanel(com.jetbrains.edu.learning.stepic.StepicAdaptiveReactionsPanel) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener)

Example 13 with FileEditorManagerListener

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);
}
Also used : DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) StudyPluginConfigurator(org.stepik.core.StudyPluginConfigurator)

Aggregations

FileEditorManagerListener (com.intellij.openapi.fileEditor.FileEditorManagerListener)13 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)5 FileEditorManagerEvent (com.intellij.openapi.fileEditor.FileEditorManagerEvent)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Project (com.intellij.openapi.project.Project)3 NotNull (org.jetbrains.annotations.NotNull)3 Document (com.intellij.openapi.editor.Document)2 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)2 Nullable (org.jetbrains.annotations.Nullable)2 ConsoleViewImpl (com.intellij.execution.impl.ConsoleViewImpl)1 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)1 CloseAction (com.intellij.execution.ui.actions.CloseAction)1 Disposable (com.intellij.openapi.Disposable)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 Editor (com.intellij.openapi.editor.Editor)1 SelectionModel (com.intellij.openapi.editor.SelectionModel)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 EditorEventMulticasterEx (com.intellij.openapi.editor.ex.EditorEventMulticasterEx)1 FocusChangeListener (com.intellij.openapi.editor.ex.FocusChangeListener)1