From 3db7af1edf15ff9b7d97e0e7c40f34b476738b3d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki & Nathan Sobo Date: Wed, 9 Jan 2013 19:24:47 -0700 Subject: [PATCH] Don't show the tree view until the project has a path --- src/app/root-view.coffee | 2 +- .../tree-view/spec/tree-view-spec.coffee | 32 ++++++++++++------- src/packages/tree-view/src/tree-view.coffee | 11 +++++-- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index c62bc7c90..ed0a88124 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -82,8 +82,8 @@ class RootView extends View @handleFocus(e) if document.activeElement is document.body @on 'root-view:active-path-changed', (e, path) => - @project.setPath(path) unless @project.getRootDirectory() if path + @project.setPath(path) unless @project.getRootDirectory() @setTitle(fs.base(path)) else @setTitle("untitled") diff --git a/src/packages/tree-view/spec/tree-view-spec.coffee b/src/packages/tree-view/spec/tree-view-spec.coffee index 664022285..2606ba92f 100644 --- a/src/packages/tree-view/spec/tree-view-spec.coffee +++ b/src/packages/tree-view/spec/tree-view-spec.coffee @@ -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] = [] diff --git a/src/packages/tree-view/src/tree-view.coffee b/src/packages/tree-view/src/tree-view.coffee index 7f8470b7c..c3c57bfc2 100644 --- a/src/packages/tree-view/src/tree-view.coffee +++ b/src/packages/tree-view/src/tree-view.coffee @@ -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