Tree.paths

This commit is contained in:
Chris Wanstrath
2011-11-06 21:05:34 -08:00
parent 5e19f70cbc
commit b13dcaece1
2 changed files with 24 additions and 13 deletions

View File

@@ -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 = $('<ul>')
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 = $("<li class='#{type}' data-path='#{encodedPath}'>#{filename}</li>")
if path in shownDirs and fs.isDirectory path
listItem.append @createList path
listItem = $("<li class='#{type}' data-path='#{encodedPath}'>#{label}</li>")
if path in shownDirs and type is 'dir'
listItem.append @createList paths
listItem.addClass "open"
list.append listItem

View File

@@ -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