When the project's path changes, the TreeView's root directory updates.

This commit is contained in:
Corey Johnson 2012-05-08 09:56:56 -07:00
parent f4c5536391
commit 8a921d2799
2 changed files with 26 additions and 6 deletions

View File

@ -43,13 +43,27 @@ describe "TreeView", ->
expect(rootEntries.find('> .file:contains(sample.js)')).toExist()
expect(rootEntries.find('> .file:contains(sample.txt)')).toExist()
it "is empty when the project has not path", ->
treeView.deactivate()
describe "when the project has not path", ->
beforeEach ->
treeView.deactivate()
rootView = new RootView
rootView.activateExtension(TreeView)
treeView = rootView.find(".tree-view").view()
expect(treeView.root).not.toExist()
rootView = new RootView
rootView.activateExtension(TreeView)
treeView = rootView.find(".tree-view").view()
it "does not create a root node", ->
expect(treeView.root).not.toExist()
it "creates a root view when the project path is created", ->
rootView.open(require.resolve('fixtures/sample.js'))
expect(treeView.root.getPath()).toBe require.resolve('fixtures')
expect(treeView.root.parent()).toMatchSelector(".tree-view")
oldRoot = treeView.root
rootView.project.setPath('/tmp')
expect(treeView.root).not.toEqual oldRoot
expect(oldRoot.hasParent()).toBeFalsy()
describe "serialization", ->
newTreeView = null

View File

@ -51,6 +51,7 @@ class TreeView extends View
@on 'tree-view:remove', => @removeSelectedEntry()
@on 'tree-view:directory-modified', => @selectActiveFile()
@rootView.on 'active-editor-path-change', => @selectActiveFile()
@rootView.project.on 'path-change', => @updateRoot()
@on 'tree-view:unfocus', => @rootView.activeEditor()?.focus()
@rootView.on 'tree-view:focus', => this.focus()
@ -80,6 +81,11 @@ class TreeView extends View
false
updateRoot: ->
@root?.remove()
@root = new DirectoryView(directory: @rootView.project.getRootDirectory(), isExpanded: true)
@append(@root)
selectActiveFile: ->
activeFilePath = @rootView.activeEditor()?.buffer.path
@selectEntryForPath(activeFilePath)