FileTreeEntityController.coffee 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. initialMultiSelectCount = ide.fileTreeManager.multiSelectedCount()
  9. ide.fileTreeManager.toggleMultiSelectEntity($scope.entity) == 0
  10. if initialMultiSelectCount == 0
  11. # On first multi selection, also include the current active/open file.
  12. ide.fileTreeManager.multiSelectSelectedEntity()
  13. else
  14. ide.fileTreeManager.selectEntity($scope.entity)
  15. $scope.$emit "entity:selected", $scope.entity
  16. $scope.draggableHelper = () ->
  17. if ide.fileTreeManager.multiSelectedCount() > 0
  18. return $("<strong style='z-index:100'>#{ide.fileTreeManager.multiSelectedCount()} Files</strong>")
  19. else
  20. return $("<strong style='z-index:100'>#{$scope.entity.name}</strong>")
  21. $scope.inputs =
  22. name: $scope.entity.name
  23. $scope.startRenaming = () ->
  24. $scope.entity.renaming = true
  25. $scope.finishRenaming = () ->
  26. delete $scope.entity.renaming
  27. name = $scope.inputs.name
  28. if !name? or name.length == 0
  29. $scope.inputs.name = $scope.entity.name
  30. return
  31. ide.fileTreeManager.renameEntity($scope.entity, name)
  32. $scope.$on "rename:selected", () ->
  33. $scope.startRenaming() if $scope.entity.selected
  34. $scope.openDeleteModal = () ->
  35. if ide.fileTreeManager.multiSelectedCount() > 0
  36. entities = ide.fileTreeManager.getMultiSelectedEntityChildNodes()
  37. else
  38. entities = [$scope.entity]
  39. $modal.open(
  40. templateUrl: "deleteEntityModalTemplate"
  41. controller: "DeleteEntityModalController"
  42. resolve:
  43. entities: () -> entities
  44. )
  45. $scope.$on "delete:selected", () ->
  46. $scope.openDeleteModal() if $scope.entity.selected
  47. ]
  48. App.controller "DeleteEntityModalController", [
  49. "$scope", "ide", "$modalInstance", "entities"
  50. ($scope, ide, $modalInstance, entities) ->
  51. $scope.state =
  52. inflight: false
  53. $scope.entities = entities
  54. $scope.delete = () ->
  55. $scope.state.inflight = true
  56. for entity in $scope.entities
  57. ide.fileTreeManager.deleteEntity(entity)
  58. $modalInstance.close()
  59. $scope.cancel = () ->
  60. $modalInstance.dismiss('cancel')
  61. ]