2014-07-08 07:02:26 -04:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
|
|
|
App.controller "FileTreeEntityController", ["$scope", "ide", "$modal", ($scope, ide, $modal) ->
|
2016-02-09 10:13:58 -05:00
|
|
|
$scope.select = (e) ->
|
|
|
|
if e.ctrlKey or e.metaKey
|
|
|
|
e.stopPropagation()
|
2016-02-10 10:59:51 -05:00
|
|
|
initialMultiSelectCount = ide.fileTreeManager.multiSelectedCount()
|
|
|
|
ide.fileTreeManager.toggleMultiSelectEntity($scope.entity) == 0
|
|
|
|
if initialMultiSelectCount == 0
|
|
|
|
# On first multi selection, also include the current active/open file.
|
|
|
|
ide.fileTreeManager.multiSelectSelectedEntity()
|
2016-02-09 10:13:58 -05:00
|
|
|
else
|
|
|
|
ide.fileTreeManager.selectEntity($scope.entity)
|
|
|
|
$scope.$emit "entity:selected", $scope.entity
|
|
|
|
|
|
|
|
$scope.draggableHelper = () ->
|
|
|
|
if ide.fileTreeManager.multiSelectedCount() > 0
|
2016-02-10 10:59:51 -05:00
|
|
|
return $("<strong style='z-index:100'>#{ide.fileTreeManager.multiSelectedCount()} Files</strong>")
|
2016-02-09 10:13:58 -05:00
|
|
|
else
|
2016-02-10 10:59:51 -05:00
|
|
|
return $("<strong style='z-index:100'>#{$scope.entity.name}</strong>")
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
$scope.inputs =
|
|
|
|
name: $scope.entity.name
|
|
|
|
|
|
|
|
$scope.startRenaming = () ->
|
|
|
|
$scope.entity.renaming = true
|
|
|
|
|
2016-09-21 11:31:02 -04:00
|
|
|
invalidModalShowing = false
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.finishRenaming = () ->
|
2018-01-29 11:06:56 -05:00
|
|
|
# avoid double events when blur and on-enter fire together
|
|
|
|
return if !$scope.entity.renaming
|
|
|
|
|
2015-03-02 07:46:02 -05:00
|
|
|
name = $scope.inputs.name
|
2016-09-21 11:31:02 -04:00
|
|
|
|
2016-09-22 09:57:59 -04:00
|
|
|
if !name.match(new RegExp(ide.validFileRegex))
|
2016-09-21 11:31:02 -04:00
|
|
|
# Showing the modal blurs the rename box which calls us again
|
|
|
|
# so track this with the invalidModalShowing flag
|
|
|
|
return if invalidModalShowing
|
|
|
|
invalidModalShowing = true
|
|
|
|
modal = $modal.open(
|
|
|
|
templateUrl: "invalidFileNameModalTemplate"
|
|
|
|
)
|
|
|
|
modal.result.then () ->
|
|
|
|
invalidModalShowing = false
|
|
|
|
return
|
|
|
|
|
|
|
|
delete $scope.entity.renaming
|
2015-03-02 07:46:02 -05:00
|
|
|
if !name? or name.length == 0
|
2015-03-04 09:19:47 -05:00
|
|
|
$scope.inputs.name = $scope.entity.name
|
2015-03-02 07:46:02 -05:00
|
|
|
return
|
|
|
|
ide.fileTreeManager.renameEntity($scope.entity, name)
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
$scope.$on "rename:selected", () ->
|
|
|
|
$scope.startRenaming() if $scope.entity.selected
|
|
|
|
|
|
|
|
$scope.openDeleteModal = () ->
|
2016-02-09 10:13:58 -05:00
|
|
|
if ide.fileTreeManager.multiSelectedCount() > 0
|
|
|
|
entities = ide.fileTreeManager.getMultiSelectedEntityChildNodes()
|
|
|
|
else
|
|
|
|
entities = [$scope.entity]
|
2014-07-08 07:02:26 -04:00
|
|
|
$modal.open(
|
|
|
|
templateUrl: "deleteEntityModalTemplate"
|
|
|
|
controller: "DeleteEntityModalController"
|
2016-02-09 10:13:58 -05:00
|
|
|
resolve:
|
|
|
|
entities: () -> entities
|
2014-07-08 07:02:26 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
$scope.$on "delete:selected", () ->
|
|
|
|
$scope.openDeleteModal() if $scope.entity.selected
|
2015-07-17 11:30:04 -04:00
|
|
|
|
|
|
|
$scope.iconTypeFromName = (name) ->
|
|
|
|
ext = name.split(".").pop()?.toLowerCase()
|
|
|
|
if ext in ["png", "pdf", "jpg", "jpeg", "gif"]
|
|
|
|
return "image"
|
|
|
|
else if ext in ["csv", "xls", "xlsx"]
|
|
|
|
return "table"
|
|
|
|
else if ext in ["py", "r"]
|
|
|
|
return "file-text"
|
2016-05-18 10:58:24 -04:00
|
|
|
else if ext in ['bib']
|
|
|
|
return 'book'
|
2015-07-17 11:30:04 -04:00
|
|
|
else
|
|
|
|
return "file"
|
2014-07-08 07:02:26 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
App.controller "DeleteEntityModalController", [
|
2016-02-09 10:13:58 -05:00
|
|
|
"$scope", "ide", "$modalInstance", "entities"
|
|
|
|
($scope, ide, $modalInstance, entities) ->
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.state =
|
|
|
|
inflight: false
|
2016-02-09 10:13:58 -05:00
|
|
|
|
|
|
|
$scope.entities = entities
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
$scope.delete = () ->
|
|
|
|
$scope.state.inflight = true
|
2016-02-09 10:13:58 -05:00
|
|
|
for entity in $scope.entities
|
|
|
|
ide.fileTreeManager.deleteEntity(entity)
|
|
|
|
$modalInstance.close()
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
$scope.cancel = () ->
|
|
|
|
$modalInstance.dismiss('cancel')
|
|
|
|
]
|