Search in sources :

Example 1 with FileEditorManagerListener

use of com.intellij.openapi.fileEditor.FileEditorManagerListener in project intellij-community by JetBrains.

the class StudyBasePluginConfigurator method getFileEditorManagerListener.

@NotNull
@Override
public FileEditorManagerListener getFileEditorManagerListener(@NotNull Project project, @NotNull StudyToolWindow toolWindow) {
    return new FileEditorManagerListener() {

        @Override
        public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
            Task task = getTask(file);
            setTaskText(task, StudyUtils.getTaskDir(file));
            if (task != null) {
                if (task.isChoiceTask()) {
                    final StudyChoiceVariantsPanel choicePanel = new StudyChoiceVariantsPanel(task);
                    toolWindow.setBottomComponent(choicePanel);
                } else {
                    toolWindow.setBottomComponent(null);
                }
            }
        }

        @Override
        public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
            for (VirtualFile openedFile : source.getOpenFiles()) {
                if (StudyUtils.getTaskFile(project, openedFile) != null) {
                    return;
                }
            }
            toolWindow.setEmptyText(project);
        }

        @Override
        public void selectionChanged(@NotNull FileEditorManagerEvent event) {
            VirtualFile file = event.getNewFile();
            if (file != null) {
                Task task = getTask(file);
                setTaskText(task, StudyUtils.getTaskDir(file));
            }
            toolWindow.setBottomComponent(null);
        }

        @Nullable
        private Task getTask(@NotNull VirtualFile file) {
            return StudyUtils.getTaskForFile(project, file);
        }

        private void setTaskText(@Nullable final Task task, @Nullable final VirtualFile taskDirectory) {
            String text = StudyUtils.getTaskTextFromTask(taskDirectory, task);
            if (text == null) {
                toolWindow.setEmptyText(project);
                return;
            }
            toolWindow.setTaskText(text, taskDirectory, project);
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) Task(com.jetbrains.edu.learning.courseFormat.Task) StudyChoiceVariantsPanel(com.jetbrains.edu.learning.editor.StudyChoiceVariantsPanel) FileEditorManagerEvent(com.intellij.openapi.fileEditor.FileEditorManagerEvent) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with FileEditorManagerListener

use of com.intellij.openapi.fileEditor.FileEditorManagerListener in project intellij-community by JetBrains.

the class StepicAdaptiveReactionsPanel method addFileListener.

private void addFileListener() {
    final FileEditorManagerListener editorManagerListener = new FileEditorManagerListener() {

        @Override
        public void selectionChanged(@NotNull FileEditorManagerEvent event) {
            final com.jetbrains.edu.learning.courseFormat.Task task = StudyUtils.getTaskFromSelectedEditor(myProject);
            final boolean isEnabled = task != null && task.getStatus() != StudyStatus.Solved;
            StepicAdaptiveReactionsPanel.this.setEnabledRecursive(isEnabled);
        }
    };
    myProject.getMessageBus().connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, editorManagerListener);
}
Also used : FileEditorManagerEvent(com.intellij.openapi.fileEditor.FileEditorManagerEvent) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with FileEditorManagerListener

use of com.intellij.openapi.fileEditor.FileEditorManagerListener in project intellij-community by JetBrains.

the class GeneratedSourceFileChangeTrackerImpl method projectOpened.

@Override
public void projectOpened() {
    final Update check = new Update("check for changes in generated files") {

        @Override
        public void run() {
            checkFiles();
        }
    };
    EditorFactory.getInstance().getEventMulticaster().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            VirtualFile file = myDocumentManager.getFile(e.getDocument());
            if (file != null) {
                myFilesToCheck.add(file);
                myCheckingQueue.queue(check);
            }
        }
    }, myProject);
    MessageBusConnection connection = myProject.getMessageBus().connect();
    connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() {

        @Override
        public void fileContentReloaded(@NotNull VirtualFile file, @NotNull Document document) {
            myFilesToCheck.remove(file);
            if (myEditedGeneratedFiles.remove(file)) {
                myEditorNotifications.updateNotifications(file);
            }
        }
    });
    connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {

        @Override
        public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
            myEditedGeneratedFiles.remove(file);
        }
    });
    connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {

        @Override
        public void rootsChanged(ModuleRootEvent event) {
            myFilesToCheck.addAll(myEditedGeneratedFiles);
            myEditedGeneratedFiles.clear();
            myCheckingQueue.queue(check);
        }
    });
    myCheckingQueue.activate();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) FileDocumentManagerAdapter(com.intellij.openapi.fileEditor.FileDocumentManagerAdapter) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Update(com.intellij.util.ui.update.Update) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) Document(com.intellij.openapi.editor.Document) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Example 4 with FileEditorManagerListener

use of com.intellij.openapi.fileEditor.FileEditorManagerListener in project intellij-community by JetBrains.

the class ScratchFileServiceImpl method initFileOpenedListener.

private void initFileOpenedListener(MessageBus messageBus) {
    final FileEditorManagerListener editorListener = new FileEditorManagerListener() {

        @Override
        public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
            if (!isEditable(file))
                return;
            RootType rootType = getRootType(file);
            if (rootType == null)
                return;
            rootType.fileOpened(file, source);
        }

        @Override
        public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
            if (Boolean.TRUE.equals(file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN)))
                return;
            if (!isEditable(file))
                return;
            RootType rootType = getRootType(file);
            if (rootType == null)
                return;
            rootType.fileClosed(file, source);
        }

        boolean isEditable(@NotNull VirtualFile file) {
            return FileDocumentManager.getInstance().getDocument(file) != null;
        }
    };
    ProjectManagerAdapter projectListener = new ProjectManagerAdapter() {

        @Override
        public void projectOpened(Project project) {
            project.getMessageBus().connect(project).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, editorListener);
            FileEditorManager editorManager = FileEditorManager.getInstance(project);
            for (VirtualFile virtualFile : editorManager.getOpenFiles()) {
                editorListener.fileOpened(editorManager, virtualFile);
            }
        }
    };
    for (Project project : ProjectManager.getInstance().getOpenProjects()) {
        projectListener.projectOpened(project);
    }
    messageBus.connect().subscribe(ProjectManager.TOPIC, projectListener);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) Project(com.intellij.openapi.project.Project) ProjectManagerAdapter(com.intellij.openapi.project.ProjectManagerAdapter) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with FileEditorManagerListener

use of com.intellij.openapi.fileEditor.FileEditorManagerListener in project intellij-community by JetBrains.

the class AutoScrollFromSourceHandler method install.

public void install() {
    final MessageBusConnection connection = myProject.getMessageBus().connect(myProject);
    connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {

        @Override
        public void selectionChanged(@NotNull FileEditorManagerEvent event) {
            final FileEditor editor = event.getNewEditor();
            if (editor != null && myComponent.isShowing() && isAutoScrollEnabled()) {
                myAlarm.cancelAllRequests();
                myAlarm.addRequest(() -> selectElementFromEditor(editor), getAlarmDelay(), getModalityState());
            }
        }
    });
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) FileEditor(com.intellij.openapi.fileEditor.FileEditor) FileEditorManagerEvent(com.intellij.openapi.fileEditor.FileEditorManagerEvent) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener)

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