Search in sources :

Example 1 with FileEditorManagerEvent

use of com.intellij.openapi.fileEditor.FileEditorManagerEvent 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 2 with FileEditorManagerEvent

use of com.intellij.openapi.fileEditor.FileEditorManagerEvent 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 3 with FileEditorManagerEvent

use of com.intellij.openapi.fileEditor.FileEditorManagerEvent 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)

Example 4 with FileEditorManagerEvent

use of com.intellij.openapi.fileEditor.FileEditorManagerEvent in project sonarlint-intellij by SonarSource.

the class EditorOpenTriggerTest method should_do_nothing_closed.

@Test
public void should_do_nothing_closed() {
    VirtualFile f1 = mock(VirtualFile.class);
    FileEditorManager mock = mock(FileEditorManager.class);
    editorTrigger.fileClosed(mock, f1);
    editorTrigger.selectionChanged(new FileEditorManagerEvent(mock, null, null, null, null));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditorManagerEvent(com.intellij.openapi.fileEditor.FileEditorManagerEvent) SonarTest(org.sonarlint.intellij.SonarTest) Test(org.junit.Test)

Example 5 with FileEditorManagerEvent

use of com.intellij.openapi.fileEditor.FileEditorManagerEvent in project android by JetBrains.

the class FloatingToolWindowManagerTest method testSwitchingBetweenTwoEditorsWithDifferentFloatingToolWindows.

@Test
@SuppressWarnings("unchecked")
public void testSwitchingBetweenTwoEditorsWithDifferentFloatingToolWindows() {
    when(myKeyboardFocusManager.getFocusOwner()).thenReturn(myWorkBench1, myWorkBench2);
    myListener.fileOpened(myEditorManager, myVirtualFile);
    verify(myFloatingToolWindow1).show(eq(myAttachedToolWindow1));
    myListener.fileOpened(myEditorManager, myVirtualFile);
    verify(myFloatingToolWindow1).hide();
    verify(myFloatingToolWindow2).show(eq(myAttachedToolWindow2));
    FileEditorManagerEvent event1 = new FileEditorManagerEvent(myEditorManager, null, null, null, myFileEditor1);
    FileEditorManagerEvent event2 = new FileEditorManagerEvent(myEditorManager, null, null, null, myFileEditor2);
    myListener.selectionChanged(event1);
    verify(myFloatingToolWindow2).hide();
    verify(myFloatingToolWindow1, times(2)).show(eq(myAttachedToolWindow1));
    myListener.selectionChanged(event2);
    verify(myFloatingToolWindow1, times(2)).hide();
    verify(myFloatingToolWindow2, times(2)).show(eq(myAttachedToolWindow2));
    // Now unregister one of them:
    myManager.unregister(myFileEditor1);
    myListener.selectionChanged(event1);
    verify(myFloatingToolWindow1, times(3)).hide();
    verify(myFloatingToolWindow2, times(2)).hide();
}
Also used : FileEditorManagerEvent(com.intellij.openapi.fileEditor.FileEditorManagerEvent) Test(org.junit.Test)

Aggregations

FileEditorManagerEvent (com.intellij.openapi.fileEditor.FileEditorManagerEvent)11 FileEditorManagerListener (com.intellij.openapi.fileEditor.FileEditorManagerListener)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)3 NotNull (org.jetbrains.annotations.NotNull)3 FileEditorManagerAdapter (com.intellij.openapi.fileEditor.FileEditorManagerAdapter)2 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)2 Test (org.junit.Test)2 Disposable (com.intellij.openapi.Disposable)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 SelectionModel (com.intellij.openapi.editor.SelectionModel)1 EditorEventMulticasterEx (com.intellij.openapi.editor.ex.EditorEventMulticasterEx)1 FocusChangeListener (com.intellij.openapi.editor.ex.FocusChangeListener)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 TextRange (com.intellij.openapi.util.TextRange)1 IdeFrame (com.intellij.openapi.wm.IdeFrame)1 StatusBar (com.intellij.openapi.wm.StatusBar)1 StatusBarWidget (com.intellij.openapi.wm.StatusBarWidget)1 LineSeparatorPanel (com.intellij.openapi.wm.impl.status.LineSeparatorPanel)1