mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-08 16:19:17 +03:00
Flash red and show an error message when there's an error on moving a file
This commit is contained in:
parent
b528196d1b
commit
a59c96d3a9
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
||||
|
@ -25,3 +25,8 @@ $.fn.preempt = (eventName, handler) ->
|
||||
|
||||
$.fn.hasParent = ->
|
||||
@parent()[0]?
|
||||
|
||||
$.fn.flashError = ->
|
||||
@addClass 'error'
|
||||
removeErrorClass = => @removeClass 'error'
|
||||
window.setTimeout(removeErrorClass, 200)
|
||||
|
@ -58,3 +58,8 @@ body {
|
||||
border-top: 5px solid #515151;
|
||||
}
|
||||
|
||||
.error {
|
||||
background: #991212;
|
||||
-webkit-transition: background 200ms ease-out;
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user