Flash red and show an error message when there's an error on moving a file

This commit is contained in:
Nathan Sobo 2012-05-08 14:18:21 -06:00
parent b528196d1b
commit a59c96d3a9
7 changed files with 36 additions and 11 deletions

View File

@ -554,6 +554,20 @@ describe "TreeView", ->
expect(fs.exists(newPath)).toBeTruthy()
expect(fs.exists(filePath)).toBeFalsy()
describe "when a file or directory already exists at the target path", ->
it "shows an error message and does not close the dialog", ->
runs ->
fs.write(fs.join(rootDirPath, 'target.txt'), '')
newPath = fs.join(rootDirPath, 'target.txt')
moveDialog.miniEditor.setText(newPath)
moveDialog.trigger 'tree-view:confirm'
expect(moveDialog.prompt.text()).toContain 'Error'
expect(moveDialog.prompt.text()).toContain 'already exists'
expect(moveDialog.prompt).toHaveClass('error')
expect(moveDialog.hasParent()).toBeTruthy()
describe "when 'tree-view:cancel' is triggered on the move dialog", ->
it "removes the dialog and focuses the tree view", ->
treeView.attachToDom()

View File

@ -47,9 +47,7 @@ class CommandPanel extends View
@commandInterpreter.eval(@rootView.activeEditor(), command)
catch error
if error instanceof SyntaxError
@addClass 'error'
removeErrorClass = => @removeClass 'error'
window.setTimeout(removeErrorClass, 200)
@flashError()
return
else
throw error

View File

@ -25,10 +25,14 @@ class Dialog extends View
@miniEditor.setSelectionBufferRange(range)
confirm: ->
@onConfirm(@miniEditor.getText())
return if @onConfirm(@miniEditor.getText()) is false
@remove()
$('#root-view').focus()
cancel: ->
@remove()
$('.tree-view').focus()
showError: (message) ->
@prompt.text(message)
@prompt.flashError()

View File

@ -151,8 +151,12 @@ class TreeView extends View
onConfirm: (newPath) =>
newPath = @rootView.project.resolve(newPath)
directoryPath = fs.directory(newPath)
fs.makeDirectory(directoryPath) unless fs.exists(directoryPath)
fs.move(oldPath, newPath)
try
fs.makeDirectory(directoryPath) unless fs.exists(directoryPath)
fs.move(oldPath, newPath)
catch e
dialog.showError("Error: " + e.message + " Try a different path:")
return false
@rootView.append(dialog)

View File

@ -25,3 +25,8 @@ $.fn.preempt = (eventName, handler) ->
$.fn.hasParent = ->
@parent()[0]?
$.fn.flashError = ->
@addClass 'error'
removeErrorClass = => @removeClass 'error'
window.setTimeout(removeErrorClass, 200)

View File

@ -58,3 +58,8 @@ body {
border-top: 5px solid #515151;
}
.error {
background: #991212;
-webkit-transition: background 200ms ease-out;
}

View File

@ -4,11 +4,6 @@
background: #515151;
display: -webkit-box;
padding: 3px;
-webkit-transition: background 200ms ease-out;
}
.command-panel.error {
background: #991212;
}
.command-panel .prompt {