Fixes #327. Only show beautify progress view when actually beautifying

- Beautifiers extends event emitter
This commit is contained in:
Glavin Wiechert 2015-06-10 10:34:51 -03:00
parent bf1c7fc0e2
commit dcddf71346
2 changed files with 19 additions and 7 deletions

View File

@ -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")

View File

@ -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!'