Project.proto.open emits a 'new-buffer' event if a new buffer is created

RootView.proto.open always uses Project's open method now. RootView creates a project with no path when editing a new buffer, so there's always a project.
This commit is contained in:
Nathan Sobo
2012-04-17 17:15:19 -06:00
parent 5b67feff54
commit 331984148f
4 changed files with 51 additions and 26 deletions

View File

@@ -1,8 +1,9 @@
fs = require 'fs'
Buffer = require 'buffer'
_ = require 'underscore'
EventEmitter = require 'event-emitter'
module.exports =
class Project
buffers: null
@@ -15,10 +16,19 @@ class Project
path.replace(projectPath, "") for path in paths when fs.isFile(path)
open: (filePath) ->
filePath = @resolve filePath
@buffers[filePath] ?= new Buffer(filePath)
if filePath?
filePath = @resolve(filePath)
buffer = @buffers[filePath]
unless buffer
@buffers[filePath] = buffer = new Buffer(filePath)
@trigger 'new-buffer', buffer
else
buffer = new Buffer
@trigger 'new-buffer', buffer
buffer
resolve: (filePath) ->
filePath = fs.join(@path, filePath) unless filePath[0] == '/'
fs.absolute filePath
_.extend Project.prototype, EventEmitter

View File

@@ -42,6 +42,7 @@ class RootView extends View
@project = new Project(fs.directory(pathToOpen))
@open(pathToOpen) if fs.isFile(pathToOpen)
else if not panesViewState?
@project = new Project
@open()
@deserializePanes(panesViewState) if panesViewState
@@ -65,7 +66,7 @@ class RootView extends View
when 'Editor' then Editor.deserialize(viewState)
open: (path) ->
buffer = if path then @project.open(path) else new Buffer
buffer = @project.open(path)
if @activeEditor()
@activeEditor().setBuffer(buffer)
@@ -86,7 +87,7 @@ class RootView extends View
.on 'buffer-path-change.root-view', =>
path = editor.buffer.path
@setTitle(path)
@project ?= new Project(fs.directory(path)) if path
@project.path ?= fs.directory(path) if path
@setTitle(editor.buffer.path)
@@ -108,7 +109,7 @@ class RootView extends View
rootPane?.adjustDimensions()
toggleFileFinder: ->
return unless @project
return unless @project.path?
if @fileFinder and @fileFinder.parent()[0]
@fileFinder.remove()