}
public OpenEditorTracker startTracking() {
ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerAdapter() {
@Override public void projectOpened(final Project project) {
MessageBusConnection connection = project.getMessageBus().connect();
connection.subscribe(FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() {
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
VirtualFile virtualFile = event.getNewFile();
if (virtualFile == null) return;
if (fileSystem.isScratch(virtualFile)) {
allowAccessToNonProjectFile_HACK(virtualFile, project);
mrScratchManager.userOpenedScratch(virtualFile.getName());
}
}
});
connectionsByProject.put(project, connection);
}
@Override public void projectClosed(Project project) {
MessageBusConnection connection = connectionsByProject.remove(project);
if (connection != null) connection.disconnect();
}
});
return this;
}