Restore assignment of @project ivar in TextBuffer

Because TextBuffers need a reference to `project` during deserialization,
and because the project global deserializes text buffers while it itself
is being deserialized (which happens before the global is actually
assigned), we have to pass a project reference into TextBuffer. This is
really annoying and makes me want to store the references to open buffers 
elsewhere. But for now it's the only way to break the circularity.
This commit is contained in:
Nathan Sobo
2013-08-14 10:49:48 -06:00
parent 3c166edd26
commit fa6ea01bfc

View File

@@ -33,12 +33,13 @@ class TextBuffer
# initialText - A {String} setting the starting text
constructor: (optionsOrState={}, params={}) ->
if optionsOrState instanceof telepath.Document
{@project} = params
@state = optionsOrState
@text = @state.get('text')
filePath = @state.get('relativePath')
@id = @state.get('id')
else
{filePath, initialText} = optionsOrState
{@project, filePath, initialText} = optionsOrState
@text = site.createDocument(initialText, shareStrings: true) if initialText
@id = guid.create().toString()
@state = site.createDocument
@@ -47,7 +48,7 @@ class TextBuffer
version: @constructor.version
if filePath
@setPath(project.resolve(filePath))
@setPath(@project.resolve(filePath))
if @text
@updateCachedDiskContents()
else
@@ -74,7 +75,7 @@ class TextBuffer
unless @destroyed
@file?.off()
@destroyed = true
project?.removeBuffer(this)
@project?.removeBuffer(this)
retain: ->
@refcount++
@@ -156,7 +157,7 @@ class TextBuffer
@state.get('relativePath')
setRelativePath: (relativePath) ->
@setPath(project.resolve(relativePath))
@setPath(@project.resolve(relativePath))
# Sets the path for the file.
#
@@ -168,7 +169,7 @@ class TextBuffer
@file = new File(path)
@file.read() if @file.exists()
@subscribeToFile()
@state.set('relativePath', project.relativize(path))
@state.set('relativePath', @project.relativize(path))
@trigger "path-changed", this
# Retrieves the current buffer's file extension.
@@ -593,7 +594,7 @@ class TextBuffer
checkoutHead: ->
path = @getPath()
return unless path
project.getRepo()?.checkoutHead(path)
@project.getRepo()?.checkoutHead(path)
# Checks to see if a file exists.
#