diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index 77e3581..818af10 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -4,6 +4,7 @@ Promise = require('bluebird') Languages = require('../languages/') path = require('path') logger = require('../logger')(__filename) +{EventEmitter} = require 'events' # Lazy loaded dependencies extend = null @@ -25,7 +26,7 @@ analyticsWriteKey = "u3c26xkae8" ### Register all supported beautifiers ### -module.exports = class Beautifiers +module.exports = class Beautifiers extends EventEmitter ### List of beautifier names @@ -419,9 +420,13 @@ module.exports = class Beautifiers options = transformOptions(beautifier, language.name, options) # Beautify text with language options + @emit "beautify::start" beautifier.beautify(text, language.name, options) .then(resolve) .catch(reject) + .finally(=> + @emit "beautify::end" + ) # Check if Analytics is enabled if atom.config.get("atom-beautify.analytics") diff --git a/src/beautify.coffee b/src/beautify.coffee index 9d118e3..cc44611 100644 --- a/src/beautify.coffee +++ b/src/beautify.coffee @@ -19,6 +19,7 @@ yaml = null async = null dir = null # Node-Dir LoadingView = null +loadingView = null $ = null # function cleanOptions(data, types) { @@ -44,6 +45,17 @@ setCursors = (editor, posArray) -> continue editor.addCursorAtBufferPosition bufferPosition return + +# Show beautification progress/loading view +beautifier.on('beautify::start', -> + LoadingView ?= require "./views/loading-view" + loadingView ?= new LoadingView() + loadingView.show() +) +beautifier.on('beautify::end', -> + loadingView?.hide() +) + beautify = ({onSave}) -> # Deprecation warning for beautify on save if atom.config.get("atom-beautify.beautifyOnSave") is true @@ -63,15 +75,11 @@ beautify = ({onSave}) -> # Continue beautifying path ?= require("path") - LoadingView ?= require "./views/loading-view" - @loadingView ?= new LoadingView() - @loadingView.show() forceEntireFile = onSave and atom.config.get("atom-beautify.beautifyEntireFileOnSave") # Show error - showError = (error)=> - @loadingView.hide() + showError = (error) => if not atom.config.get("atom-beautify.muteAllErrors") # console.log(e) @@ -140,7 +148,6 @@ beautify = ({onSave}) -> # else # console.log "Already Beautiful!" - @loadingView.hide() return # console.log 'Beautify time!'