TreeView's add and move create intermediate directories as needed

This commit is contained in:
Corey Johnson 2012-07-03 15:34:34 -07:00
parent 4cf4456635
commit 3aaa8ad8f0
2 changed files with 13 additions and 13 deletions

View File

@ -488,15 +488,15 @@ describe "TreeView", ->
describe "when the path with a trailing '/' is changed and confirmed", -> describe "when the path with a trailing '/' is changed and confirmed", ->
describe "when no file or directory exists at the given path", -> describe "when no file or directory exists at the given path", ->
it "adds a directory and closes the dialog", -> it "adds a directory and closes the dialog", ->
newPath = fs.join(dirPath, "new-dir") newPath = fs.join(dirPath, "new/dir")
addDialog.miniEditor.insertText("new-dir/") addDialog.miniEditor.insertText("new/dir/")
addDialog.trigger 'tree-view:confirm' addDialog.trigger 'tree-view:confirm'
expect(fs.exists(newPath)).toBeTruthy() expect(fs.exists(newPath)).toBeTruthy()
expect(fs.isDirectory(newPath)).toBeTruthy() expect(fs.isDirectory(newPath)).toBeTruthy()
expect(addDialog.parent()).not.toExist() expect(addDialog.parent()).not.toExist()
expect(rootView.getActiveEditor().buffer.getPath()).not.toBe newPath expect(rootView.getActiveEditor().buffer.getPath()).not.toBe newPath
describe "when a or directory already exists at the given path", -> describe "when a file or directory already exists at the given path", ->
it "shows an error message and does not close the dialog", -> it "shows an error message and does not close the dialog", ->
newPath = fs.join(dirPath, "new-dir") newPath = fs.join(dirPath, "new-dir")
fs.makeDirectory(newPath) fs.makeDirectory(newPath)
@ -587,7 +587,7 @@ describe "TreeView", ->
describe "when the directories along the new path don't exist", -> describe "when the directories along the new path don't exist", ->
it "creates the target directory before moving the file", -> it "creates the target directory before moving the file", ->
runs -> runs ->
newPath = fs.join(rootDirPath, 'new-directory', 'renamed-test-file.txt') newPath = fs.join(rootDirPath, 'new/directory', 'renamed-test-file.txt')
moveDialog.miniEditor.setText(newPath) moveDialog.miniEditor.setText(newPath)
moveDialog.trigger 'tree-view:confirm' moveDialog.trigger 'tree-view:confirm'

View File

@ -171,7 +171,7 @@ class TreeView extends View
newPath = @rootView.project.resolve(newPath) newPath = @rootView.project.resolve(newPath)
directoryPath = fs.directory(newPath) directoryPath = fs.directory(newPath)
try try
fs.makeDirectory(directoryPath) unless fs.exists(directoryPath) fs.makeTree(directoryPath) unless fs.exists(directoryPath)
fs.move(oldPath, newPath) fs.move(oldPath, newPath)
catch e catch e
dialog.showError("Error: " + e.message + " Try a different path:") dialog.showError("Error: " + e.message + " Try a different path:")
@ -208,15 +208,15 @@ class TreeView extends View
endsWithDirectorySeperator = /\/$/.test(relativePath) endsWithDirectorySeperator = /\/$/.test(relativePath)
path = @rootView.project.resolve(relativePath) path = @rootView.project.resolve(relativePath)
try try
if endsWithDirectorySeperator if fs.exists(path)
fs.makeDirectory(path) pathType = if fs.isFile(path) then "file" else "directory"
dialog.showError("Error: A #{pathType} already exists at path '#{path}'. Try a different path:")
false
else if endsWithDirectorySeperator
fs.makeTree(path)
else else
if fs.exists(path) fs.write(path, "")
dialog.showError("Error: A file already exists at path '#{path}'. Try a different path:") @rootView.open(path)
false
else
fs.write(path, "")
@rootView.open(path)
catch e catch e
dialog.showError("Error: " + e.message + " Try a different path:") dialog.showError("Error: " + e.message + " Try a different path:")
return false return false