diff --git a/extensions/tree/tree-pane.coffee b/extensions/tree/tree-pane.coffee
index b5d52e88f..5d2a2462d 100644
--- a/extensions/tree/tree-pane.coffee
+++ b/extensions/tree/tree-pane.coffee
@@ -32,7 +32,7 @@ class TreePane extends Pane
else
@tree.showDir path
el.addClass 'open'
- list = @createList path
+ list = @createList @tree.findPaths path
el.append list
else
el.addClass 'active'
@@ -47,24 +47,19 @@ class TreePane extends Pane
reload: ->
@html.children('#tree .cwd').text _.last window.path.split '/'
- fileList = @createList window.path
+ fileList = @createList @tree.paths
fileList.addClass 'files'
@html.children('#tree .files').replaceWith fileList
createList: (root) ->
- paths = fs.list root
shownDirs = @tree.shownDirs()
-
list = $('
')
- for path in paths
- continue if @tree.ignorePattern.test path
- filename = path.replace(root, "").substring 1
- type = if fs.isDirectory path then 'dir' else 'file'
+ for {label, path, paths} in root
+ type = if paths then 'dir' else 'file'
encodedPath = encodeURIComponent path
- listItem = $("- #{filename}
")
-
- if path in shownDirs and fs.isDirectory path
- listItem.append @createList path
+ listItem = $("- #{label}
")
+ if path in shownDirs and type is 'dir'
+ listItem.append @createList paths
listItem.addClass "open"
list.append listItem
diff --git a/extensions/tree/tree.coffee b/extensions/tree/tree.coffee
index ca31d8964..353458aca 100644
--- a/extensions/tree/tree.coffee
+++ b/extensions/tree/tree.coffee
@@ -13,6 +13,10 @@ module.exports =
class Tree extends Extension
ignorePattern: /\.git|\.xcodeproj|\.DS_Store/
+ # a path is an object with three keys: label, path, and paths.
+ # paths is an optional Array of other path objects.
+ paths: []
+
constructor: ->
KeyBinder.register "tree", @
KeyBinder.load require.resolve "tree/key-bindings.coffee"
@@ -27,6 +31,7 @@ class Tree extends Extension
else
Watcher.watch dir, @watchDir
+ @paths = @findPaths window.path
@pane = new TreePane @
startup: ->
@@ -52,8 +57,19 @@ class Tree extends Extension
Storage.set @shownDirStorageKey(), dirs
Watcher.watch dir, @watchDir
-
hideDir: (dir) ->
dirs = _.without @shownDirs(), dir
Storage.set @shownDirStorageKey(), dirs
@unwatchDir dir, @watchDir
+
+ findPaths: (root) ->
+ paths = []
+
+ for path in fs.list root
+ continue if @ignorePattern.test path
+ paths.push
+ label: _.last path.split '/'
+ path: path
+ paths: @findPaths path if fs.isDirectory path
+
+ paths