commit
bf0f492740
1 changed files with 7 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
path = require 'path'
|
path = require 'path'
|
||||||
CommandError = require './command-error'
|
CommandError = require './command-error'
|
||||||
|
fs = require 'fs'
|
||||||
|
|
||||||
trySave = (func) ->
|
trySave = (func) ->
|
||||||
deferred = Promise.defer()
|
deferred = Promise.defer()
|
||||||
|
|
@ -30,6 +31,10 @@ trySave = (func) ->
|
||||||
|
|
||||||
deferred.promise
|
deferred.promise
|
||||||
|
|
||||||
|
saveAs = (filePath) ->
|
||||||
|
editor = atom.workspace.getActiveTextEditor()
|
||||||
|
fs.writeFileSync(filePath, editor.getText())
|
||||||
|
|
||||||
getFullPath = (filePath) ->
|
getFullPath = (filePath) ->
|
||||||
return filePath if path.isAbsolute(filePath)
|
return filePath if path.isAbsolute(filePath)
|
||||||
return path.join(atom.project.getPath(), filePath)
|
return path.join(atom.project.getPath(), filePath)
|
||||||
|
|
@ -119,7 +124,7 @@ class Ex
|
||||||
if filePath.length > 0
|
if filePath.length > 0
|
||||||
editorPath = editor.getPath()
|
editorPath = editor.getPath()
|
||||||
fullPath = getFullPath(filePath)
|
fullPath = getFullPath(filePath)
|
||||||
trySave(-> editor.saveAs(fullPath))
|
trySave(-> saveAs(fullPath))
|
||||||
.then ->
|
.then ->
|
||||||
deferred.resolve()
|
deferred.resolve()
|
||||||
editor.buffer.setPath(editorPath)
|
editor.buffer.setPath(editorPath)
|
||||||
|
|
@ -129,7 +134,7 @@ class Ex
|
||||||
else
|
else
|
||||||
if filePath.length > 0
|
if filePath.length > 0
|
||||||
fullPath = getFullPath(filePath)
|
fullPath = getFullPath(filePath)
|
||||||
trySave(-> editor.saveAs(fullPath))
|
trySave(-> saveAs(fullPath))
|
||||||
.then deferred.resolve
|
.then deferred.resolve
|
||||||
else
|
else
|
||||||
fullPath = atom.showSaveDialogSync()
|
fullPath = atom.showSaveDialogSync()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue