FileTreeEntityController.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* eslint-disable
  2. chai-friendly/no-unused-expressions,
  3. max-len,
  4. no-return-assign,
  5. no-undef,
  6. */
  7. // TODO: This file was created by bulk-decaffeinate.
  8. // Fix any style issues and re-enable lint.
  9. /*
  10. * decaffeinate suggestions:
  11. * DS101: Remove unnecessary use of Array.from
  12. * DS102: Remove unnecessary code created because of implicit returns
  13. * DS207: Consider shorter variations of null checks
  14. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  15. */
  16. define(['base', 'ide/file-tree/util/iconTypeFromName'], function(
  17. App,
  18. iconTypeFromName
  19. ) {
  20. App.controller('FileTreeEntityController', function($scope, ide, $modal) {
  21. $scope.select = function(e) {
  22. if (e.ctrlKey || e.metaKey) {
  23. e.stopPropagation()
  24. const initialMultiSelectCount = ide.fileTreeManager.multiSelectedCount()
  25. ide.fileTreeManager.toggleMultiSelectEntity($scope.entity) === 0
  26. if (initialMultiSelectCount === 0) {
  27. // On first multi selection, also include the current active/open file.
  28. return ide.fileTreeManager.multiSelectSelectedEntity()
  29. }
  30. } else {
  31. ide.fileTreeManager.selectEntity($scope.entity)
  32. return $scope.$emit('entity:selected', $scope.entity)
  33. }
  34. }
  35. $scope.draggableHelper = function() {
  36. if (ide.fileTreeManager.multiSelectedCount() > 0) {
  37. return $(
  38. `<strong style='z-index:100'>${ide.fileTreeManager.multiSelectedCount()} Files</strong>`
  39. )
  40. } else {
  41. return $(`<strong style='z-index:100'>${$scope.entity.name}</strong>`)
  42. }
  43. }
  44. $scope.inputs = { name: $scope.entity.name }
  45. $scope.startRenaming = () => ($scope.entity.renaming = true)
  46. let invalidModalShowing = false
  47. $scope.finishRenaming = function() {
  48. // avoid double events when blur and on-enter fire together
  49. if (!$scope.entity.renaming) {
  50. return
  51. }
  52. const { name } = $scope.inputs
  53. // validator will set name to undefined for invalid filenames
  54. if (name == null) {
  55. // Showing the modal blurs the rename box which calls us again
  56. // so track this with the invalidModalShowing flag
  57. if (invalidModalShowing) {
  58. return
  59. }
  60. invalidModalShowing = true
  61. const modal = $modal.open({
  62. templateUrl: 'invalidFileNameModalTemplate'
  63. })
  64. modal.result.then(() => (invalidModalShowing = false))
  65. return
  66. }
  67. delete $scope.entity.renaming
  68. if (name == null || name.length === 0) {
  69. $scope.inputs.name = $scope.entity.name
  70. return
  71. }
  72. return ide.fileTreeManager.renameEntity($scope.entity, name)
  73. }
  74. $scope.$on('rename:selected', function() {
  75. if ($scope.entity.selected) {
  76. return $scope.startRenaming()
  77. }
  78. })
  79. $scope.openDeleteModal = function() {
  80. let entities
  81. if (ide.fileTreeManager.multiSelectedCount() > 0) {
  82. entities = ide.fileTreeManager.getMultiSelectedEntityChildNodes()
  83. } else {
  84. entities = [$scope.entity]
  85. }
  86. return $modal.open({
  87. templateUrl: 'deleteEntityModalTemplate',
  88. controller: 'DeleteEntityModalController',
  89. resolve: {
  90. entities() {
  91. return entities
  92. }
  93. }
  94. })
  95. }
  96. $scope.$on('delete:selected', function() {
  97. if ($scope.entity.selected) {
  98. return $scope.openDeleteModal()
  99. }
  100. })
  101. return ($scope.iconTypeFromName = iconTypeFromName)
  102. })
  103. return App.controller('DeleteEntityModalController', function(
  104. $scope,
  105. ide,
  106. $modalInstance,
  107. entities
  108. ) {
  109. $scope.state = { inflight: false }
  110. $scope.entities = entities
  111. $scope.delete = function() {
  112. $scope.state.inflight = true
  113. for (let entity of Array.from($scope.entities)) {
  114. ide.fileTreeManager.deleteEntity(entity)
  115. }
  116. return $modalInstance.close()
  117. }
  118. return ($scope.cancel = () => $modalInstance.dismiss('cancel'))
  119. })
  120. })