FileTreeEntityController.coffee 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. invalidModalShowing = false
  26. $scope.finishRenaming = () ->
  27. name = $scope.inputs.name
  28. if !name.match(new RegExp(ide.validFileRegex))
  29. # Showing the modal blurs the rename box which calls us again
  30. # so track this with the invalidModalShowing flag
  31. return if invalidModalShowing
  32. invalidModalShowing = true
  33. modal = $modal.open(
  34. templateUrl: "invalidFileNameModalTemplate"
  35. )
  36. modal.result.then () ->
  37. invalidModalShowing = false
  38. return
  39. delete $scope.entity.renaming
  40. if !name? or name.length == 0
  41. $scope.inputs.name = $scope.entity.name
  42. return
  43. ide.fileTreeManager.renameEntity($scope.entity, name)
  44. $scope.$on "rename:selected", () ->
  45. $scope.startRenaming() if $scope.entity.selected
  46. $scope.openDeleteModal = () ->
  47. if ide.fileTreeManager.multiSelectedCount() > 0
  48. entities = ide.fileTreeManager.getMultiSelectedEntityChildNodes()
  49. else
  50. entities = [$scope.entity]
  51. $modal.open(
  52. templateUrl: "deleteEntityModalTemplate"
  53. controller: "DeleteEntityModalController"
  54. resolve:
  55. entities: () -> entities
  56. )
  57. $scope.$on "delete:selected", () ->
  58. $scope.openDeleteModal() if $scope.entity.selected
  59. $scope.iconTypeFromName = (name) ->
  60. ext = name.split(".").pop()?.toLowerCase()
  61. if ext in ["png", "pdf", "jpg", "jpeg", "gif"]
  62. return "image"
  63. else if ext in ["csv", "xls", "xlsx"]
  64. return "table"
  65. else if ext in ["py", "r"]
  66. return "file-text"
  67. else if ext in ['bib']
  68. return 'book'
  69. else
  70. return "file"
  71. ]
  72. App.controller "DeleteEntityModalController", [
  73. "$scope", "ide", "$modalInstance", "entities"
  74. ($scope, ide, $modalInstance, entities) ->
  75. $scope.state =
  76. inflight: false
  77. $scope.entities = entities
  78. $scope.delete = () ->
  79. $scope.state.inflight = true
  80. for entity in $scope.entities
  81. ide.fileTreeManager.deleteEntity(entity)
  82. $modalInstance.close()
  83. $scope.cancel = () ->
  84. $modalInstance.dismiss('cancel')
  85. ]