Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
@trigger 'entry-copied', [@initialPath, newPath]
else
fs.copy @initialPath, newPath, ->
fs.copy @initialPath, newPath, =>
@trigger '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)
@trigger 'entry-moved', [@initialPath, newPath]
if repo = repoForPath(newPath)
repo.getPathStatus(@initialPath)
repo.getPathStatus(newPath)
Expand Down
47 changes: 39 additions & 8 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"
{$, View} = require 'atom-space-pen-views'
fs = require 'fs-plus'
Expand Down Expand Up @@ -32,6 +32,7 @@ class TreeView extends View

initialize: (state) ->
@disposables = new CompositeDisposable
@emitter = new Emitter
@focusAfterAttach = false
@roots = []
@scrollLeftAfterAttach = -1
Expand Down Expand Up @@ -87,6 +88,21 @@ class TreeView extends View
@disposables.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: ->
@on 'dblclick', '.tree-view-resize-handle', =>
@resizeToFitContent()
Expand Down Expand Up @@ -453,6 +469,8 @@ class TreeView extends View
if oldPath
MoveDialog ?= require './move-dialog'
dialog = new MoveDialog(oldPath)
dialog.on 'entry-moved', (event, 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 @@ -533,6 +551,8 @@ class TreeView extends View

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

removeSelectedEntries: ->
Expand All @@ -554,10 +574,12 @@ class TreeView extends View
message: "Are you sure you want to delete the selected #{if selectedPaths.length > 1 then 'items' else 'item'}?"
detailedMessage: "You are deleting:\n#{selectedPaths.join('\n')}"
buttons:
"Move to Trash": ->
"Move to Trash": =>
failedDeletions = []
for selectedPath in selectedPaths
if not shell.moveItemToTrash(selectedPath)
if shell.moveItemToTrash(selectedPath)
@emitter.emit 'entry-deleted', {path: selectedPath}
else
failedDeletions.push "#{selectedPath}"
if repo = repoForPath(selectedPath)
repo.getPathStatus(selectedPath)
Expand Down Expand Up @@ -633,15 +655,21 @@ class TreeView extends View

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 @@ -652,9 +680,11 @@ class TreeView extends View
dialog.on 'directory-created', (event, createdPath) =>
@entryForPath(createdPath)?.reload()
@selectEntryForPath(createdPath)
@emitter.emit 'directory-created', {path: createdPath}
false
dialog.on 'file-created', (event, createdPath) ->
dialog.on 'file-created', (event, createdPath) =>
atom.workspace.open(createdPath)
@emitter.emit 'file-created', {path: createdPath}
false
dialog.attach()

Expand Down Expand Up @@ -725,6 +755,7 @@ class TreeView extends View
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