This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Trigger events when moving, creating or deleting files/directories #938
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There's currently no reliable way to detect when a user's renamed or moved a file in the tree-view. Filesystem events such as
did-destroy
are by no means fit for detecting a file's deletion; such events are also triggered onFile
objects when draggingFileView
objects between folders.Furthermore, it's difficult to determine a file or directory's previous path when responding to a path change. Short of individually monitoring every file and directory's status, package authors have no easy way to respond to user-directed changes in the filesystem.
This PR addresses this matter by introducing a number of events that're emitted at certain points in the
tree-view
's lifecycle:directory-created
path
: Resolved/normalised path of the directoryentry-copied
oldPath
: Path to source file/directorynewPath
: Path of newly-created file/directoryentry-deleted
path
: Last-known path of a deleted resourceentry-moved
: Self-explanatory. Invoked by both cut-and-paste as well as drag-and-drop/rename.oldPath
newPath
file-created
path
: Resolved/normalised path of the fileThese events are emitted on the main
tree-view
instance, which is accessible through both the DOM as well as viaatom.packages.activePackages["tree-view"].mainModule.treeView
.