2009-05-03 13:29:29 -04:00
|
|
|
USING: accessors arrays delegate delegate.protocols
|
2009-05-06 22:36:06 -04:00
|
|
|
io.pathnames kernel locals models.arrow namespaces prettyprint sequences
|
2009-05-06 22:39:13 -04:00
|
|
|
ui.frp vectors make ;
|
2009-05-01 12:06:20 -04:00
|
|
|
IN: file-trees
|
|
|
|
|
2009-05-06 22:36:06 -04:00
|
|
|
TUPLE: walkable-vector vector father ;
|
|
|
|
CONSULT: sequence-protocol walkable-vector vector>> ;
|
|
|
|
|
|
|
|
M: walkable-vector set-nth [ vector>> set-nth ] 3keep nip
|
|
|
|
father>> swap children>> vector>> push ;
|
|
|
|
|
|
|
|
TUPLE: tree node comment children ;
|
2009-05-03 13:29:29 -04:00
|
|
|
CONSULT: sequence-protocol tree children>> ;
|
2009-05-01 12:06:20 -04:00
|
|
|
|
2009-05-06 22:36:06 -04:00
|
|
|
: <dir-tree> ( {start,comment} -- tree ) first2 walkable-vector new vector new >>vector
|
|
|
|
[ tree boa dup children>> ] [ ".." -rot tree boa ] 2bi swap (>>father) ;
|
|
|
|
|
2009-05-01 12:06:20 -04:00
|
|
|
DEFER: (tree-insert)
|
|
|
|
|
2009-05-06 22:36:06 -04:00
|
|
|
: tree-insert ( path tree -- ) [ unclip <dir-tree> ] [ children>> ] bi* (tree-insert) ;
|
2009-05-01 12:06:20 -04:00
|
|
|
:: (tree-insert) ( path-rest path-head tree-children -- )
|
|
|
|
tree-children [ node>> path-head node>> = ] find nip
|
|
|
|
[ path-rest swap tree-insert ]
|
|
|
|
[
|
|
|
|
path-head tree-children push
|
|
|
|
path-rest [ path-head tree-insert ] unless-empty
|
|
|
|
] if* ;
|
2009-05-06 22:36:06 -04:00
|
|
|
|
|
|
|
! Use an accumulator for this
|
|
|
|
: add-paths ( pathseq -- {{name,path}} )
|
|
|
|
"" [ [ "/" glue dup ] keep swap 2array , ] [ reduce drop ] f make ;
|
|
|
|
|
|
|
|
: create-tree ( file-list -- tree ) [ path-components add-paths ] map
|
|
|
|
{ "/" "/" } <dir-tree> [ [ tree-insert ] curry each ] keep ;
|
2009-05-03 13:29:29 -04:00
|
|
|
|
|
|
|
: <dir-table> ( tree-model -- table )
|
|
|
|
<frp-list*> [ node>> 1array ] >>quot
|
2009-05-06 22:36:06 -04:00
|
|
|
[ selected-value>> [ dup [ first ] when ] <arrow> <switch> ]
|
|
|
|
[ swap >>model ] bi
|
|
|
|
[ dup comment>> 2array ] >>val-quot ;
|