Destroy editSession by calling a method on the project instead of triggering a destroy event that the project listens to.

This commit is contained in:
Corey Johnson
2012-06-29 11:21:14 -07:00
parent 2ff1cc9baf
commit 98393a653e
2 changed files with 11 additions and 7 deletions

View File

@@ -83,21 +83,25 @@ class Project
buffer = @buildBuffer()
editSession = new EditSession
project: this
buffer: buffer
tabText: @getTabText()
autoIndent: @getAutoIndent()
softTabs: @getSoftTabs()
softWrap: @getSoftWrap()
editSession.on 'destroy', =>
@editSessions = _.without(@editSessions, editSession)
bufferIsOrphaned = not _.find @editSessions, (e) -> e.buffer == editSession.buffer
editSession.buffer.destroy() if bufferIsOrphaned
@editSessions.push editSession
@trigger 'new-edit-session', editSession
editSession
removeEditSession: (editSession) ->
_.remove(@editSessions, editSession)
@destroyBufferIfOrphaned(editSession.buffer)
destroyBufferIfOrphaned: (buffer) ->
unless _.find(@editSessions, (editSession) -> editSession.buffer == buffer)
buffer.destroy()
buildBuffer: (filePath) ->
buffer = new Buffer(filePath)
@trigger 'new-buffer', buffer