BinaryFilesManager.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* eslint-disable
  2. max-len,
  3. no-unused-vars,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. let BinaryFilesManager
  13. export default BinaryFilesManager = class BinaryFilesManager {
  14. constructor(ide, $scope) {
  15. this.ide = ide
  16. this.$scope = $scope
  17. this.$scope.$on('entity:selected', (event, entity) => {
  18. if (this.$scope.ui.view !== 'track-changes' && entity.type === 'file') {
  19. return this.openFile(entity)
  20. } else if (entity.type === 'doc') {
  21. return this.closeFile()
  22. }
  23. })
  24. }
  25. openFile(file) {
  26. if (this.$scope.ui.view === 'editor') {
  27. // store position before switching to binary view
  28. this.$scope.$broadcast('store-doc-position')
  29. }
  30. this.ide.fileTreeManager.selectEntity(file)
  31. if (this.$scope.ui.view !== 'history') {
  32. this.$scope.ui.view = 'file'
  33. }
  34. this.$scope.openFile = null
  35. this.$scope.$apply()
  36. return window.setTimeout(
  37. () => {
  38. this.$scope.openFile = file
  39. this.$scope.$apply()
  40. this.$scope.$broadcast('file-view:file-opened')
  41. window.dispatchEvent(new Event('file-view:file-opened'))
  42. },
  43. 0,
  44. this
  45. )
  46. }
  47. openFileWithId(id) {
  48. const entity = this.ide.fileTreeManager.findEntityById(id)
  49. if (entity?.type === 'file') {
  50. this.openFile(entity)
  51. }
  52. }
  53. closeFile() {
  54. return window.setTimeout(
  55. () => {
  56. this.$scope.openFile = null
  57. if (this.$scope.ui.view !== 'history') {
  58. this.$scope.ui.view = 'editor'
  59. }
  60. this.$scope.$apply()
  61. },
  62. 0,
  63. this
  64. )
  65. }
  66. }