Add Buffer.save

This commit is contained in:
Corey Johnson & Nathan Sobo
2011-12-15 15:59:32 -08:00
parent 5fbb320957
commit a07daf26ca
4 changed files with 59 additions and 9 deletions

View File

@@ -7,9 +7,18 @@ class Buffer
url: null
constructor: (@url) ->
text = if @url then fs.read(@url) else ""
text = if @url and fs.exists(@url)
fs.read(@url)
else
""
@aceDocument = new Document text
getText: ->
@aceDocument.getValue()
setText: (text) ->
@aceDocument.setValue text
save: ->
if not @url then throw new Error("Tried to save buffer with no url")
fs.write @url, @getText()

View File

@@ -25,4 +25,3 @@ class Editor
getAceSession: ->
@aceEditor.getSession()

View File

@@ -67,6 +67,12 @@ module.exports =
listDirectoryTree: (path) ->
@list path, true
# Remove a file at the given path. Throws an error if path is not a
# file or a symbolic link to a file.
remove: (path) ->
fm = OSX.NSFileManager.defaultManager
paths = fm.removeItemAtPath_error path, null
# Open, read, and close a file, returning the file's contents.
read: (path) ->
path = @absolute path