mirror of
https://github.com/atom/atom.git
synced 2026-02-08 21:55:05 -05:00
Merge branch 'master' of github.com:probablycorey/Atomicity
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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) ->
|
||||
|
||||
Reference in New Issue
Block a user