mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Tree.paths
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user