2018-11-05 05:06:39 -05:00
|
|
|
/* eslint-disable
|
|
|
|
chai-friendly/no-unused-expressions,
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
no-undef,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
define(['base', 'ide/file-tree/util/iconTypeFromName'], function(
|
|
|
|
App,
|
|
|
|
iconTypeFromName
|
|
|
|
) {
|
2020-01-02 14:21:45 -05:00
|
|
|
App.controller('FileTreeEntityController', function(
|
|
|
|
$scope,
|
|
|
|
ide,
|
|
|
|
$modal,
|
|
|
|
$element
|
|
|
|
) {
|
2019-07-16 05:13:18 -04:00
|
|
|
$scope.select = function(e) {
|
|
|
|
if (e.ctrlKey || e.metaKey) {
|
|
|
|
e.stopPropagation()
|
|
|
|
const initialMultiSelectCount = ide.fileTreeManager.multiSelectedCount()
|
|
|
|
ide.fileTreeManager.toggleMultiSelectEntity($scope.entity) === 0
|
|
|
|
if (initialMultiSelectCount === 0) {
|
|
|
|
// On first multi selection, also include the current active/open file.
|
|
|
|
return ide.fileTreeManager.multiSelectSelectedEntity()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
} else {
|
|
|
|
ide.fileTreeManager.selectEntity($scope.entity)
|
|
|
|
return $scope.$emit('entity:selected', $scope.entity)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-01-02 14:21:45 -05:00
|
|
|
if ($scope.entity.type === 'doc') {
|
|
|
|
$scope.$watch('entity.selected', function(isSelected) {
|
|
|
|
if (isSelected) {
|
|
|
|
$scope.$emit('entity-file:selected', $scope.entity)
|
|
|
|
$scope.$applyAsync(function() {
|
|
|
|
$element[0].scrollIntoView()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
$scope.draggableHelper = function() {
|
|
|
|
if (ide.fileTreeManager.multiSelectedCount() > 0) {
|
|
|
|
return $(
|
|
|
|
`<strong style='z-index:100'>${ide.fileTreeManager.multiSelectedCount()} Files</strong>`
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return $(`<strong style='z-index:100'>${$scope.entity.name}</strong>`)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
$scope.inputs = { name: $scope.entity.name }
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
$scope.startRenaming = () => ($scope.entity.renaming = true)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
let invalidModalShowing = false
|
|
|
|
$scope.finishRenaming = function() {
|
|
|
|
// avoid double events when blur and on-enter fire together
|
|
|
|
if (!$scope.entity.renaming) {
|
|
|
|
return
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
const { name } = $scope.inputs
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
// validator will set name to undefined for invalid filenames
|
|
|
|
if (name == null) {
|
|
|
|
// Showing the modal blurs the rename box which calls us again
|
|
|
|
// so track this with the invalidModalShowing flag
|
|
|
|
if (invalidModalShowing) {
|
2018-11-05 05:06:39 -05:00
|
|
|
return
|
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
invalidModalShowing = true
|
|
|
|
const modal = $modal.open({
|
|
|
|
templateUrl: 'invalidFileNameModalTemplate'
|
|
|
|
})
|
|
|
|
modal.result.then(() => (invalidModalShowing = false))
|
|
|
|
return
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
delete $scope.entity.renaming
|
|
|
|
if (name == null || name.length === 0) {
|
|
|
|
$scope.inputs.name = $scope.entity.name
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return ide.fileTreeManager.renameEntity($scope.entity, name)
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
$scope.$on('rename:selected', function() {
|
|
|
|
if ($scope.entity.selected) {
|
|
|
|
return $scope.startRenaming()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
$scope.openDeleteModal = function() {
|
|
|
|
let entities
|
|
|
|
if (ide.fileTreeManager.multiSelectedCount() > 0) {
|
|
|
|
entities = ide.fileTreeManager.getMultiSelectedEntityChildNodes()
|
|
|
|
} else {
|
|
|
|
entities = [$scope.entity]
|
|
|
|
}
|
|
|
|
return $modal.open({
|
|
|
|
templateUrl: 'deleteEntityModalTemplate',
|
|
|
|
controller: 'DeleteEntityModalController',
|
|
|
|
resolve: {
|
|
|
|
entities() {
|
|
|
|
return entities
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
$scope.$on('delete:selected', function() {
|
|
|
|
if ($scope.entity.selected) {
|
|
|
|
return $scope.openDeleteModal()
|
|
|
|
}
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
return ($scope.iconTypeFromName = iconTypeFromName)
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
return App.controller('DeleteEntityModalController', function(
|
|
|
|
$scope,
|
|
|
|
ide,
|
|
|
|
$modalInstance,
|
|
|
|
entities
|
|
|
|
) {
|
|
|
|
$scope.state = { inflight: false }
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
$scope.entities = entities
|
|
|
|
|
|
|
|
$scope.delete = function() {
|
|
|
|
$scope.state.inflight = true
|
|
|
|
for (let entity of Array.from($scope.entities)) {
|
|
|
|
ide.fileTreeManager.deleteEntity(entity)
|
|
|
|
}
|
|
|
|
return $modalInstance.close()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
|
|
|
|
return ($scope.cancel = () => $modalInstance.dismiss('cancel'))
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|