Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 540afa1

Browse files
committed
refactor: removeSelectedEntriesPermanently
1 parent a51d998 commit 540afa1

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

lib/tree-view.coffee

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,8 @@ class TreeView
638638
buttons: [(if shouldDeletePermanently then 'Permanently Delete ⚠️' else 'Move to Trash'), 'Cancel']
639639
}, (response) =>
640640
if response is 0 # Move to Trash
641+
if shouldDeletePermanently
642+
return @removeSelectedPathsPermanently(selectedPaths, selectedEntries)
641643
failedDeletions = []
642644
for selectedPath in selectedPaths
643645
# Don't delete entries which no longer exist. This can happen, for example, when:
@@ -647,39 +649,22 @@ class TreeView
647649
continue unless fs.existsSync(selectedPath)
648650

649651
@emitter.emit 'will-delete-entry', {pathToDelete: selectedPath}
650-
if shell.moveItemToTrash(selectedPath, shouldDeletePermanently)
652+
if shell.moveItemToTrash(selectedPath)
651653
@emitter.emit 'entry-deleted', {pathToDelete: selectedPath}
652654
else
653-
if not shouldDeletePermanently
654-
@emitter.emit 'delete-entry-failed', {pathToDelete: selectedPath}
655+
@emitter.emit 'delete-entry-failed', {pathToDelete: selectedPath}
655656
failedDeletions.push selectedPath
656657

657658
if repo = repoForPath(selectedPath)
658659
repo.getPathStatus(selectedPath)
659660

660661
if failedDeletions.length > 0
661-
if shouldDeletePermanently
662-
del(selectedPaths, {force: true})
663-
.then( (deletedPaths) ->
664-
for deletedPath in deletedPaths
665-
@emitter.emit 'entry-deleted', {pathToDelete: deletedPath}
666-
)
667-
.catch((err) ->
668-
atom.notifications.addError @formatTrashFailureMessage(failedDeletions, true),
669-
description: err
670-
dismissable: true
671-
for selectedPath in selectedPaths
672-
@emitter.emit 'delete-entry-failed', {pathToDelete: selectedPath}
673-
)
674-
.finally( -> @finishRemoval(selectedEntries[0]))
675-
else
676-
atom.notifications.addError @formatTrashFailureMessage(failedDeletions, false),
677-
description: @formatTrashEnabledMessage()
678-
detail: "#{failedDeletions.join('\n')}"
679-
dismissable: true
662+
atom.notifications.addError @formatTrashFailureMessage(failedDeletions, false),
663+
description: @formatTrashEnabledMessage()
664+
detail: "#{failedDeletions.join('\n')}"
665+
dismissable: true
680666

681-
if not shouldDeletePermanently
682-
@finishRemoval(selectedEntries[0])
667+
@finishRemoval(selectedEntries[0])
683668
)
684669

685670
formatTrashFailureMessage: (failedDeletions, shouldDeletePermanently = false) ->
@@ -699,6 +684,21 @@ class TreeView
699684
@selectEntry(firstSelectedEntry.closest('.directory:not(.selected)'))
700685
@updateRoots() if atom.config.get('tree-view.squashDirectoryNames')
701686

687+
removeSelectedPathsPermanently: (selectedPaths, selectedEntries) ->
688+
del(selectedPaths, {force: true})
689+
.then( (deletedPaths) ->
690+
for deletedPath in deletedPaths
691+
@emitter.emit 'entry-deleted', {pathToDelete: deletedPath}
692+
)
693+
.catch((err) ->
694+
atom.notifications.addError @formatTrashFailureMessage(selectedPaths, true),
695+
description: err
696+
dismissable: true
697+
for selectedPath in selectedPaths
698+
@emitter.emit 'delete-entry-failed', {pathToDelete: selectedPath}
699+
)
700+
.finally( -> @finishRemoval(selectedEntries[0]))
701+
702702
# Public: Copy the path of the selected entry element.
703703
# Save the path in localStorage, so that copying from 2 different
704704
# instances of atom works as intended

0 commit comments

Comments
 (0)