mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Don't show the tree view until the project has a path
This commit is contained in:
@@ -14,7 +14,7 @@ describe "TreeView", ->
|
||||
project = rootView.project
|
||||
|
||||
atom.loadPackage("tree-view")
|
||||
treeView = rootView.find(".tree-view").view()
|
||||
treeView = TreeView.instance
|
||||
treeView.root = treeView.find('> li:first').view()
|
||||
sampleJs = treeView.find('.file:contains(tree-view.js)')
|
||||
sampleTxt = treeView.find('.file:contains(tree-view.txt)')
|
||||
@@ -52,24 +52,34 @@ describe "TreeView", ->
|
||||
|
||||
rootView = new RootView
|
||||
atom.loadPackage 'tree-view'
|
||||
treeView = rootView.find(".tree-view").view()
|
||||
treeView = TreeView.instance
|
||||
|
||||
it "does not create a root node", ->
|
||||
it "does not attach or create a root node", ->
|
||||
expect(treeView.hasParent()).toBeFalsy()
|
||||
expect(treeView.root).not.toExist()
|
||||
|
||||
it "serializes without throwing an exception", ->
|
||||
expect(-> treeView.serialize()).not.toThrow()
|
||||
|
||||
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")
|
||||
describe "when the project is assigned a path because a buffer is opened", ->
|
||||
it "attaches the tree and creates a root directory view", ->
|
||||
rootView.open(require.resolve('fixtures/sample.js'))
|
||||
expect(treeView.hasParent()).toBeTruthy()
|
||||
expect(treeView.root.getPath()).toBe require.resolve('fixtures')
|
||||
expect(treeView.root.parent()).toMatchSelector(".tree-view")
|
||||
|
||||
oldRoot = treeView.root
|
||||
oldRoot = treeView.root
|
||||
|
||||
rootView.project.setPath('/tmp')
|
||||
expect(treeView.root).not.toEqual oldRoot
|
||||
expect(oldRoot.hasParent()).toBeFalsy()
|
||||
rootView.project.setPath('/tmp')
|
||||
expect(treeView.root).not.toEqual oldRoot
|
||||
expect(oldRoot.hasParent()).toBeFalsy()
|
||||
|
||||
describe "when the project is assigned a path because a new buffer is saved", ->
|
||||
it "attaches the tree and creates a root directory view", ->
|
||||
rootView.getActiveEditSession().saveAs("/tmp/test.txt")
|
||||
expect(treeView.hasParent()).toBeTruthy()
|
||||
expect(treeView.root.getPath()).toBe require.resolve('/tmp')
|
||||
expect(treeView.root.parent()).toMatchSelector(".tree-view")
|
||||
|
||||
describe "serialization", ->
|
||||
[newRootView, newTreeView] = []
|
||||
|
||||
@@ -16,7 +16,12 @@ class TreeView extends ScrollView
|
||||
@instance = TreeView.deserialize(state, rootView)
|
||||
else
|
||||
@instance = new TreeView(rootView)
|
||||
@instance.attach()
|
||||
|
||||
if rootView.project.getPath()
|
||||
@instance.attach()
|
||||
else
|
||||
rootView.project.one "path-changed", =>
|
||||
@instance.attach()
|
||||
|
||||
@deactivate: ->
|
||||
@instance.deactivate()
|
||||
@@ -118,8 +123,8 @@ class TreeView extends ScrollView
|
||||
|
||||
updateRoot: ->
|
||||
@root?.remove()
|
||||
if @rootView.project.getRootDirectory()
|
||||
@root = new DirectoryView(directory: @rootView.project.getRootDirectory(), isExpanded: true, project: @rootView.project)
|
||||
if rootDirectory = @rootView.project.getRootDirectory()
|
||||
@root = new DirectoryView(directory: rootDirectory, isExpanded: true, project: @rootView.project)
|
||||
@append(@root)
|
||||
else
|
||||
@root = null
|
||||
|
||||
Reference in New Issue
Block a user