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);
}
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);
}
};
}
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());
}
}
});
}
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));
}
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();
}
Aggregations