FileTreeEntityController.coffee 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 if ext in ['bib']
  56. return 'book'
  57. else
  58. return "file"
  59. ]
  60. App.controller "DeleteEntityModalController", [
  61. "$scope", "ide", "$modalInstance", "entities"
  62. ($scope, ide, $modalInstance, entities) ->
  63. $scope.state =
  64. inflight: false
  65. $scope.entities = entities
  66. $scope.delete = () ->
  67. $scope.state.inflight = true
  68. for entity in $scope.entities
  69. ide.fileTreeManager.deleteEntity(entity)
  70. $modalInstance.close()
  71. $scope.cancel = () ->
  72. $modalInstance.dismiss('cancel')
  73. ]