Merge branch 'master' of github.com:probablycorey/Atomicity

This commit is contained in:
Nathan Sobo
2012-01-06 19:57:35 -08:00
9 changed files with 117 additions and 59 deletions

View File

@@ -12,11 +12,11 @@ class Editor extends Template
viewProperties:
aceEditor: null
buffer: null
editorElement: null
initialize: () ->
@aceSessions = {}
@buildAceEditor()
@open()
@setBuffer(new Buffer)
shutdown: ->
@destroy()
@@ -24,10 +24,11 @@ class Editor extends Template
destroy: ->
@aceEditor.destroy()
open: (url) ->
@buffer = new Buffer(url)
session = new EditSession(@buffer.aceDocument, @buffer.getMode())
@aceEditor.setSession(session)
setBuffer: (@buffer) ->
@aceEditor.setSession @getAceSessionForBuffer(buffer)
getAceSessionForBuffer: (buffer) ->
@aceSessions[@buffer.url] ?= new EditSession(@buffer.aceDocument, @buffer.getMode())
buildAceEditor: ->
@aceEditor = ace.edit this[0]

View File

@@ -1,9 +1,13 @@
fs = require 'fs'
Buffer = require 'buffer'
module.exports =
class Project
buffers: null
constructor: (@url) ->
@buffers = {}
getFilePaths: ->
projectUrl = @url
@@ -11,3 +15,11 @@ class Project
urls = (url.replace(projectUrl, "") for url in urls when fs.isFile(url))
urls
open: (filePath) ->
filePath = @resolve filePath
@buffers[filePath] ?= new Buffer(filePath)
resolve: (filePath) ->
filePath = fs.join(@url, filePath) unless filePath[0] == '/'
fs.absolute filePath

View File

@@ -2,6 +2,7 @@ $ = require 'jquery'
fs = require 'fs'
Template = require 'template'
Buffer = require 'buffer'
Editor = require 'editor'
FileFinder = require 'file-finder'
Project = require 'project'
@@ -23,7 +24,7 @@ class RootView extends Template
if url
@project = new Project(fs.directory(url))
@editor.open(url) if fs.isFile(url)
@editor.setBuffer(@project.open(url)) if fs.isFile(url)
addPane: (view) ->
pane = $('<div class="pane">')
@@ -37,7 +38,10 @@ class RootView extends Template
@fileFinder.remove()
@fileFinder = null
else
@project.getFilePaths().done (urls) =>
@fileFinder = FileFinder.build({urls, selected: (url) => @editor.open(url)})
@addPane(@fileFinder)
@project.getFilePaths().done (paths) =>
relativePaths = (path.replace(@project.url, "") for path in paths)
@fileFinder = FileFinder.build
urls: relativePaths
selected: (relativePath) => @editor.setBuffer(@project.open(relativePath))
@addPane @fileFinder
@fileFinder.input.focus()

View File

@@ -35,6 +35,11 @@ module.exports =
exists: (path) ->
OSX.NSFileManager.defaultManager.fileExistsAtPath_isDirectory path, null
join: (paths...) ->
return paths[0] if paths.length == 1
[first, rest...] = paths
first.replace(/\/?$/, "/") + @join(rest...)
# Returns true if the file specified by path exists and is a
# directory.
isDirectory: (path) ->