FileTreeEntityController.coffee 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. $scope.iconTypeFromName = (name) ->
  48. ext = name.split(".").pop()?.toLowerCase()
  49. if ext in ["png", "pdf", "jpg", "jpeg", "gif"]
  50. return "image"
  51. else if ext in ["csv", "xls", "xlsx"]
  52. return "table"
  53. else if ext in ["py", "r"]
  54. return "file-text"
  55. else
  56. return "file"
  57. ]
  58. App.controller "DeleteEntityModalController", [
  59. "$scope", "ide", "$modalInstance", "entities"
  60. ($scope, ide, $modalInstance, entities) ->
  61. $scope.state =
  62. inflight: false
  63. $scope.entities = entities
  64. $scope.delete = () ->
  65. $scope.state.inflight = true
  66. for entity in $scope.entities
  67. ide.fileTreeManager.deleteEntity(entity)
  68. $modalInstance.close()
  69. $scope.cancel = () ->
  70. $modalInstance.dismiss('cancel')
  71. ]