See #36. Add right-click Beautification of single files in Tree view
This commit is contained in:
parent
19c6046cd8
commit
e678fdf759
|
@ -8,4 +8,4 @@
|
||||||
# For more detailed documentation see
|
# For more detailed documentation see
|
||||||
# https://atom.io/docs/latest/advanced/keymaps
|
# https://atom.io/docs/latest/advanced/keymaps
|
||||||
'.workspace .editor:not(.mini)':
|
'.workspace .editor:not(.mini)':
|
||||||
'ctrl-alt-b': 'beautify'
|
'ctrl-alt-b': 'beautify:editor'
|
||||||
|
|
|
@ -7,6 +7,7 @@ _ = require("lodash")
|
||||||
beautifier = require("./language-options")
|
beautifier = require("./language-options")
|
||||||
languages = beautifier.languages
|
languages = beautifier.languages
|
||||||
defaultLanguageOptions = beautifier.defaultLanguageOptions
|
defaultLanguageOptions = beautifier.defaultLanguageOptions
|
||||||
|
options = require "./options"
|
||||||
# Lazy loaded dependencies
|
# Lazy loaded dependencies
|
||||||
fs = null
|
fs = null
|
||||||
path = require("path")
|
path = require("path")
|
||||||
|
@ -16,6 +17,8 @@ LoadingView = null
|
||||||
MessagePanelView = null
|
MessagePanelView = null
|
||||||
PlainMessageView = null
|
PlainMessageView = null
|
||||||
editorconfig = null
|
editorconfig = null
|
||||||
|
$ = null
|
||||||
|
|
||||||
#MessageView = require "./message-view"
|
#MessageView = require "./message-view"
|
||||||
findFileResults = {}
|
findFileResults = {}
|
||||||
|
|
||||||
|
@ -300,6 +303,44 @@ beautify = ({onSave})->
|
||||||
showError(e)
|
showError(e)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
beautifyFile = (event)->
|
||||||
|
# console.log('beautifyFile', arguments)
|
||||||
|
entry = event.target
|
||||||
|
# console.log('entry', entry)
|
||||||
|
return unless entry
|
||||||
|
$ ?= (require "space-pen").$
|
||||||
|
$entry = $(entry)
|
||||||
|
if $entry.prop("tagName") is "LI"
|
||||||
|
$entry = $("span.name", $entry)
|
||||||
|
# console.log($entry)
|
||||||
|
filePath = $entry.data('path')
|
||||||
|
# console.log('filePath', filePath)
|
||||||
|
# Get contents of file
|
||||||
|
fs ?= require "fs"
|
||||||
|
fs.readFile(filePath, (err, data) ->
|
||||||
|
throw error if err
|
||||||
|
input = data?.toString()
|
||||||
|
grammar = atom.grammars.selectGrammar(filePath, input)
|
||||||
|
grammarName = grammar.name
|
||||||
|
# Get the options
|
||||||
|
allOptions = options.getOptionsForPath(filePath)
|
||||||
|
# Beautify File
|
||||||
|
completionFun = (output) ->
|
||||||
|
if output instanceof Error
|
||||||
|
throw output # output == Error
|
||||||
|
else if typeof output is "string"
|
||||||
|
fs.writeFile(filePath, output, (err) ->
|
||||||
|
throw err if err
|
||||||
|
)
|
||||||
|
else
|
||||||
|
console.log(output)
|
||||||
|
try
|
||||||
|
beautifier.beautify input, grammarName, allOptions, completionFun
|
||||||
|
catch e
|
||||||
|
console.error(e)
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
handleSaveEvent = =>
|
handleSaveEvent = =>
|
||||||
atom.workspace.eachEditor (editor) =>
|
atom.workspace.eachEditor (editor) =>
|
||||||
buffer = editor.getBuffer()
|
buffer = editor.getBuffer()
|
||||||
|
@ -323,4 +364,5 @@ plugin.configDefaults = _.merge(
|
||||||
plugin.activate = ->
|
plugin.activate = ->
|
||||||
handleSaveEvent()
|
handleSaveEvent()
|
||||||
plugin.subscribe atom.config.observe("atom-beautify.beautifyOnSave", handleSaveEvent)
|
plugin.subscribe atom.config.observe("atom-beautify.beautifyOnSave", handleSaveEvent)
|
||||||
atom.workspaceView.command "beautify", beautify
|
atom.workspaceView.command "beautify:editor", beautify
|
||||||
|
atom.workspaceView.command "beautify:file", beautifyFile
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
# See https://atom.io/docs/latest/creating-a-package#menus for more details
|
# See https://atom.io/docs/latest/creating-a-package#menus for more details
|
||||||
'context-menu':
|
'context-menu':
|
||||||
'.workspace .editor:not(.mini)':
|
'.workspace .editor:not(.mini)':
|
||||||
'Enable atom-beautify': 'beautify'
|
'Enable atom-beautify': 'beautify:editor'
|
||||||
|
'.tree-view li[is="tree-view-file"].file.entry':
|
||||||
|
'Beautify File': 'beautify:file'
|
||||||
|
|
||||||
'menu': [
|
'menu': [
|
||||||
{
|
{
|
||||||
'label': 'Packages'
|
'label': 'Packages'
|
||||||
'submenu': [
|
'submenu': [
|
||||||
'label': 'Beautify'
|
'label': 'Beautify'
|
||||||
'command': 'beautify'
|
'command': 'beautify:editor'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
22
package.json
22
package.json
|
@ -83,24 +83,26 @@
|
||||||
"atom": ">0.50.0"
|
"atom": ">0.50.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"analytics-node": "^1.0.2",
|
||||||
|
"atom-message-panel": "^1.1.1",
|
||||||
|
"coffee-formatter": "^0.1.0",
|
||||||
|
"editorconfig": "^0.11.4",
|
||||||
"emissary": "^1.0.0",
|
"emissary": "^1.0.0",
|
||||||
"extend": "^1.2.1",
|
"extend": "^1.2.1",
|
||||||
"js-beautify": "^1.5.4",
|
"js-beautify": "^1.5.4",
|
||||||
"lodash": "2.4.1",
|
|
||||||
"strip-json-comments": "^0.1.3",
|
|
||||||
"js-yaml": "^3.0.2",
|
"js-yaml": "^3.0.2",
|
||||||
"temp": "^0.8.0",
|
"lodash": "2.4.1",
|
||||||
"prettydiff": "^1.6.11",
|
|
||||||
"node-uuid": "^1.4.1",
|
|
||||||
"analytics-node": "^1.0.2",
|
|
||||||
"coffee-formatter": "^0.1.0",
|
|
||||||
"atom-message-panel": "^1.1.1",
|
|
||||||
"editorconfig": "^0.11.4",
|
|
||||||
"loophole": "^1.0.0",
|
"loophole": "^1.0.0",
|
||||||
|
"node-uuid": "^1.4.1",
|
||||||
|
"prettydiff": "^1.6.11",
|
||||||
|
"space-pen": "^4.3.0",
|
||||||
|
"strip-json-comments": "^0.1.3",
|
||||||
|
"temp": "^0.8.0",
|
||||||
"typescript-formatter": "~0.1.4"
|
"typescript-formatter": "~0.1.4"
|
||||||
},
|
},
|
||||||
"activationEvents": [
|
"activationEvents": [
|
||||||
"beautify",
|
"beautify:editor",
|
||||||
|
"beautify:file",
|
||||||
"core:save",
|
"core:save",
|
||||||
"core:save-as"
|
"core:save-as"
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue