FileTreeEntityController.coffee 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. define [
  2. "base"
  3. ], (App) ->
  4. App.controller "FileTreeEntityController", ["$scope", "ide", "$modal", ($scope, ide, $modal) ->
  5. $scope.select = (e) ->
  6. if e.ctrlKey or e.metaKey
  7. e.stopPropagation()
  8. ide.fileTreeManager.toggleMultiSelectEntity($scope.entity)
  9. else
  10. ide.fileTreeManager.selectEntity($scope.entity)
  11. $scope.$emit "entity:selected", $scope.entity
  12. $scope.draggableHelper = () ->
  13. if ide.fileTreeManager.multiSelectedCount() > 0
  14. return $("<div style='z-index:100'>#{ide.fileTreeManager.multiSelectedCount()} Files</div>")
  15. else
  16. return $("<div style='z-index:100'>#{$scope.entity.name}</div>")
  17. $scope.inputs =
  18. name: $scope.entity.name
  19. $scope.startRenaming = () ->
  20. $scope.entity.renaming = true
  21. $scope.finishRenaming = () ->
  22. delete $scope.entity.renaming
  23. name = $scope.inputs.name
  24. if !name? or name.length == 0
  25. $scope.inputs.name = $scope.entity.name
  26. return
  27. ide.fileTreeManager.renameEntity($scope.entity, name)
  28. $scope.$on "rename:selected", () ->
  29. $scope.startRenaming() if $scope.entity.selected
  30. $scope.openDeleteModal = () ->
  31. if ide.fileTreeManager.multiSelectedCount() > 0
  32. entities = ide.fileTreeManager.getMultiSelectedEntityChildNodes()
  33. else
  34. entities = [$scope.entity]
  35. $modal.open(
  36. templateUrl: "deleteEntityModalTemplate"
  37. controller: "DeleteEntityModalController"
  38. resolve:
  39. entities: () -> entities
  40. )
  41. $scope.$on "delete:selected", () ->
  42. $scope.openDeleteModal() if $scope.entity.selected
  43. ]
  44. App.controller "DeleteEntityModalController", [
  45. "$scope", "ide", "$modalInstance", "entities"
  46. ($scope, ide, $modalInstance, entities) ->
  47. $scope.state =
  48. inflight: false
  49. $scope.entities = entities
  50. $scope.delete = () ->
  51. $scope.state.inflight = true
  52. for entity in $scope.entities
  53. ide.fileTreeManager.deleteEntity(entity)
  54. $modalInstance.close()
  55. $scope.cancel = () ->
  56. $modalInstance.dismiss('cancel')
  57. ]