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