Handle save errors in Pane

Esse commit está contido em:
Kevin Sawicki
2015-02-05 14:42:21 -08:00
commit 3850550345
2 arquivos alterados com 27 adições e 2 exclusões
+25 -2
Ver Arquivo
@@ -481,7 +481,10 @@ class Pane extends Model
itemURI = item.getUri()
if itemURI?
item.save?()
try
item.save?()
catch
@handleSaveError(error)
nextAction?()
else
@saveItemAs(item, nextAction)
@@ -498,7 +501,10 @@ class Pane extends Model
itemPath = item.getPath?()
newItemPath = atom.showSaveDialogSync(itemPath)
if newItemPath
item.saveAs(newItemPath)
try
item.saveAs(newItemPath)
catch error
@handleSaveError(error)
nextAction?()
# Public: Save all items.
@@ -667,3 +673,20 @@ class Pane extends Model
for item in @getItems()
return false unless @promptToSaveItem(item)
true
handleSaveError: (error) ->
if error.message.endsWith('is a directory')
atom.notifications.addWarning("Unable to save file: #{error.message}")
else if error.code is 'EACCES' and error.path?
atom.notifications.addWarning("Unable to save file: Permission denied '#{error.path}'")
else if error.code is 'EPERM' and error.path?
atom.notifications.addWarning("Unable to save file '#{error.path}'", detail: error.message)
else if error.code is 'EBUSY' and error.path?
atom.notifications.addWarning("Unable to save file '#{error.path}'", detail: error.message)
else if error.code is 'EROFS' and error.path?
atom.notifications.addWarning("Unable to save file: Read-only file system '#{error.path}'")
else if errorMatch = /ENOTDIR, not a directory '([^']+)'/.exec(error.message)
fileName = errorMatch[1]
atom.notifications.addWarning("Unable to save file: A directory in the path '#{fileName}' could not be written to")
else
throw error
+2
Ver Arquivo
@@ -1,10 +1,12 @@
# Like sands through the hourglass, so are the days of our lives.
console.profile('loading')
require './window'
Atom = require './atom'
window.atom = Atom.loadOrCreate('editor')
atom.initialize()
atom.startEditorWindow()
console.profileEnd('loading')
# Workaround for focus getting cleared upon window creation
windowFocused = ->