Skip to content

Commit

Permalink
Closes #84. Improve the error message panel to only appear on new error
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavin001 committed Sep 10, 2014
1 parent 2c4202b commit 31b2178
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
23 changes: 14 additions & 9 deletions lib/beautify.coffee
Expand Up @@ -130,11 +130,19 @@ beautify = ->
MessagePanelView ?= require('atom-message-panel').MessagePanelView
PlainMessageView ?= require('atom-message-panel').PlainMessageView
LoadingView ?= require "./loading-view"
@messagePanel ?= new MessagePanelView title: 'Atom Beautify'
@messagePanel.attach() ;
@messagePanel ?= new MessagePanelView title: 'Atom Beautify Error Messages'
@loadingView ?= new LoadingView()
@loadingView.show()
forceEntireFile = atom.config.get("atom-beautify.beautifyEntireFileOnSave")
# Show error
showError = (e) =>
# console.log(e)
@loadingView.hide()
@messagePanel.attach()
@messagePanel.add(new PlainMessageView({
message: e.message,
className: 'text-error'
}))
# Look for .jsbeautifierrc in file and home path, check env variables
getConfig = (startPath, upwards=true) ->
# Verify that startPath is a string
Expand Down Expand Up @@ -177,7 +185,9 @@ beautify = ->
# Asynchronously and callback-style
beautifyCompleted = (text) =>
# console.log 'beautifyCompleted'
if oldText isnt text
if text instanceof Error
showError(text)
else if oldText isnt text
# console.log "Replacing current editor's text with new text"
posArray = getCursors(editor)
# console.log "posArray: #{posArray}"
Expand Down Expand Up @@ -284,12 +294,7 @@ beautify = ->
try
beautifier.beautify text, grammarName, allOptions, beautifyCompleted
catch e
console.log(e)
@loadingView.hide()
@messagePanel.add(new PlainMessageView({
message: e.message,
className: 'text-error'
} )) ;
showError(e)
return

handleSaveEvent = =>
Expand Down
5 changes: 2 additions & 3 deletions lib/langs/cli-beautify.coffee
Expand Up @@ -21,15 +21,12 @@ module.exports = (getCmd, isStdout) ->
outputPath = temp.path()
deleteOutputFile = ->
temp.cleanup()

# Delete the output path
fs.unlink outputPath, (err) ->
console.log "Deleting output file", err if err
return

return


# Process the command
processCmd = (cmd) ->
if cmd
Expand Down Expand Up @@ -72,11 +69,13 @@ module.exports = (getCmd, isStdout) ->

else
console.log "Beautifcation Error: ", err
callback err
deleteOutputFile()
return

else
console.log "Beautify CLI command not valid."
callback(new Error("Beautify CLI command not valid."))
return


Expand Down

0 comments on commit 31b2178

Please sign in to comment.