Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
4 changes: 3 additions & 1 deletion lib/copy-dialog.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ class CopyDialog extends Dialog
try
if fs.isDirectorySync(@initialPath)
fs.copySync(@initialPath, newPath)
@emitter.emit 'entry-copied', [@initialPath, newPath]
else
fs.copy @initialPath, newPath, ->
fs.copy @initialPath, newPath, =>
@emitter.emit 'entry-copied', [@initialPath, newPath]
atom.workspace.open newPath,
activatePane: true
initialLine: activeEditor?.getLastCursor().getBufferRow()
Expand Down
1 change: 1 addition & 0 deletions lib/move-dialog.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MoveDialog extends Dialog
try
fs.makeTreeSync(directoryPath) unless fs.existsSync(directoryPath)
fs.moveSync(@initialPath, newPath)
@emitter.emit 'entry-moved', [@initialPath, newPath]
if repo = repoForPath(newPath)
repo.getPathStatus(@initialPath)
repo.getPathStatus(newPath)
Expand Down
40 changes: 35 additions & 5 deletions lib/tree-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ path = require 'path'
{shell} = require 'electron'

_ = require 'underscore-plus'
{BufferedProcess, CompositeDisposable} = require 'atom'
{BufferedProcess, CompositeDisposable, Emitter} = require 'atom'
{repoForPath, getStyleObject, getFullExtension} = require "./helpers"
fs = require 'fs-plus'

Expand Down Expand Up @@ -41,6 +41,7 @@ class TreeView
@element.appendChild(@resizeHandle)

@disposables = new CompositeDisposable
@emitter = new Emitter
@focusAfterAttach = false
@roots = []
@scrollLeftAfterAttach = -1
Expand Down Expand Up @@ -90,6 +91,21 @@ class TreeView
@rootDragAndDrop.dispose()
@detach() if @panel?

onDirectoryCreated: (callback) ->
@emitter.on('directory-created', callback)

onEntryCopied: (callback) ->
@emitter.on('entry-copied', callback)

onEntryDeleted: (callback) ->
@emitter.on('entry-deleted', callback)

onEntryMoved: (callback) ->
@emitter.on('entry-moved', callback)

onFileCreated: (callback) ->
@emitter.on('file-created', callback)

handleEvents: ->
@resizeHandle.addEventListener 'dblclick', => @resizeToFitContent()
@resizeHandle.addEventListener 'mousedown', (e) => @resizeStarted(e)
Expand Down Expand Up @@ -494,6 +510,8 @@ class TreeView

if oldPath
dialog = new MoveDialog(oldPath)
dialog.emitter.on 'entry-moved', ([oldPath, newPath]) =>
@emitter.emit 'entry-moved', {oldPath, newPath}
dialog.attach()

# Get the outline of a system call to the current platform's file manager.
Expand Down Expand Up @@ -581,6 +599,8 @@ class TreeView
return unless oldPath

dialog = new CopyDialog(oldPath)
dialog.emitter.on 'entry-copied', (oldPath, newPath) =>
@emitter.emit 'entry-copied', {oldPath, newPath}
dialog.attach()

removeSelectedEntries: ->
Expand All @@ -606,6 +626,7 @@ class TreeView
failedDeletions = []
for selectedPath in selectedPaths
if shell.moveItemToTrash(selectedPath)
@emitter.emit 'entry-deleted', {path: selectedPath}
for editor in atom.workspace.getTextEditors()
if editor?.getPath() is selectedPath
editor.destroy()
Expand Down Expand Up @@ -698,15 +719,21 @@ class TreeView

if fs.isDirectorySync(initialPath)
# use fs.copy to copy directories since read/write will fail for directories
catchAndShowFileErrors -> fs.copySync(initialPath, newPath)
catchAndShowFileErrors =>
fs.copySync(initialPath, newPath)
@emitter.emit 'entry-copied', {oldPath: initialPath, newPath}
else
# read the old file and write a new one at target location
catchAndShowFileErrors -> fs.writeFileSync(newPath, fs.readFileSync(initialPath))
catchAndShowFileErrors =>
fs.writeFileSync(newPath, fs.readFileSync(initialPath))
@emitter.emit 'entry-copied', {oldPath: initialPath, newPath}
else if cutPaths
# Only move the target if the cut target doesn't exists and if the newPath
# Only move the target if the cut target doesn't exist and if the newPath
# is not within the initial path
unless fs.existsSync(newPath) or newPath.startsWith(initialPath)
catchAndShowFileErrors -> fs.moveSync(initialPath, newPath)
catchAndShowFileErrors =>
fs.moveSync(initialPath, newPath)
@emitter.emit 'entry-moved', {oldPath: initialPath, newPath}

add: (isCreatingFile) ->
selectedEntry = @selectedEntry() ? @roots[0]
Expand All @@ -717,9 +744,11 @@ class TreeView
@entryForPath(createdPath)?.reload()
@selectEntryForPath(createdPath)
@updateRoots() if atom.config.get('tree-view.squashDirectoryNames')
@emitter.emit 'directory-created', {path: createdPath}
dialog.onDidCreateFile (createdPath) =>
atom.workspace.open(createdPath)
@updateRoots() if atom.config.get('tree-view.squashDirectoryNames')
@emitter.emit 'file-created', {path: createdPath}
dialog.attach()

removeProjectFolder: (e) ->
Expand Down Expand Up @@ -795,6 +824,7 @@ class TreeView
try
fs.makeTreeSync(newDirectoryPath) unless fs.existsSync(newDirectoryPath)
fs.moveSync(initialPath, newPath)
@emitter.emit 'entry-moved', {oldPath: initialPath, newPath}

if repo = repoForPath(newPath)
repo.getPathStatus(initialPath)
Expand Down
Loading