]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://github.com/bogiebro/factor
authorDoug Coleman <erg@jobim.local>
Sun, 3 May 2009 17:57:16 +0000 (12:57 -0500)
committerDoug Coleman <erg@jobim.local>
Sun, 3 May 2009 17:57:16 +0000 (12:57 -0500)
extra/file-trees/file-trees.factor
extra/str-fry/str-fry.factor
extra/ui/frp/frp-docs.factor
extra/ui/frp/frp.factor

index 788291c0a23bdc3a0d77a0f3c64db6fb04e9962f..eadfccdc4c0adfabb5372e49404786254749d329 100644 (file)
@@ -1,10 +1,10 @@
-USING: accessors delegate delegate.protocols io.pathnames
-kernel locals namespaces sequences vectors
-tools.annotations prettyprint ;
+USING: accessors arrays delegate delegate.protocols
+io.pathnames kernel locals namespaces prettyprint sequences
+ui.frp vectors ;
 IN: file-trees
 
 TUPLE: tree node children ;
-CONSULT: sequence-protocol tree children>> [ node>> ] map ;
+CONSULT: sequence-protocol tree children>> ;
 
 : <tree> ( start -- tree ) V{ } clone
    [ tree boa dup children>> ] [ ".." swap tree boa ] bi swap push ;
@@ -20,4 +20,9 @@ DEFER: (tree-insert)
       path-rest [ path-head tree-insert ] unless-empty
    ] if* ;
 : create-tree ( file-list -- tree ) [ path-components ] map
-   t <tree> [ [ tree-insert ] curry each ] keep ;
\ No newline at end of file
+   t <tree> [ [ tree-insert ] curry each ] keep ;
+
+: <dir-table> ( tree-model -- table )
+   <frp-list*> [ node>> 1array ] >>quot
+   [ selected-value>> <switch> ]
+   [ swap >>model ] bi ;
\ No newline at end of file
index aafdaa95d932b0c99be5f00196b44b72c105b031..bfe74f37eb9b279a4f2ad66c6feb2b9b1fe51592 100644 (file)
@@ -1,4 +1,7 @@
-USING: kernel sequences splitting strings.parser ;
+USING: combinators effects kernel math sequences splitting
+strings.parser ;
 IN: str-fry
-: str-fry ( str -- quot ) "_" split unclip [ [ rot glue ] reduce ] 2curry ;
+: str-fry ( str -- quot ) "_" split
+    [ unclip [ [ rot glue ] reduce ] 2curry ]
+    [ length 1 - 1 <effect> [ call-effect ] 2curry ] bi ;
 SYNTAX: I" parse-string rest str-fry over push-all ;
\ No newline at end of file
index af44567e4621720ea3f8ea401a19b51c1384e962..479a56e513af0b3eac934d859fc71b572951bce2 100644 (file)
@@ -36,7 +36,7 @@ HELP: <fold>
 { $values { "oldval" "starting value" } { "quot" "applied to update and previous values" } { "model" model } { "model'" model } }
 { $description "Similar to " { $link reduce } " but works on models, applying a quotation to the previous and new values at each update" } ;
 
-HELP: switch
+HELP: <switch>
 { $values { "signal1" model } { "signal2" model } { "signal'" model } }
 { $description "Creates a model that starts with the behavior of model1 and switches to the behavior of model2 on its update" } ;
 
index aa7c44ee0384d6aca863a3a0b4aea7326f246ef9..699d034c72794a15a9736f5be54c3993329d711d 100644 (file)
@@ -1,7 +1,7 @@
-USING: accessors arrays colors fonts fry kernel models
+USING: accessors arrays colors fonts kernel models
 models.product monads sequences ui.gadgets ui.gadgets.buttons
 ui.gadgets.editors ui.gadgets.line-support ui.gadgets.tables
-ui.gadgets.tracks ui.render ;
+ui.gadgets.tracks ui.render ui.gadgets.scrollers ;
 QUALIFIED: make
 IN: ui.frp
 
@@ -18,8 +18,11 @@ M: frp-table row-color color-quot>> [ call( a -- b ) ]  [ drop f ] if* ;
     frp-table new-line-gadget dup >>renderer [ ] >>quot swap >>model
     f <model> >>selected-value sans-serif-font >>font
     focus-border-color >>focus-border-color
-    transparent >>column-line-color ;
+    transparent >>column-line-color [ ] >>val-quot ;
+: <frp-table*> ( -- table ) f <model> <frp-table> ;
 : <frp-list> ( model -- table ) <frp-table> [ 1array ] >>quot ;
+: <frp-list*> ( -- table ) f <model> <frp-list> ;
+
 : <frp-field> ( -- field ) f <model> <model-field> ;
 
 ! Layout utilities
@@ -27,6 +30,8 @@ M: frp-table row-color color-quot>> [ call( a -- b ) ]  [ drop f ] if* ;
 GENERIC: output-model ( gadget -- model )
 M: gadget output-model model>> ;
 M: frp-table output-model selected-value>> ;
+M: model-field output-model field-model>> ;
+M: scroller output-model children>> first model>> ;
 
 GENERIC: , ( uiitem -- )
 M: gadget , make:, ;
@@ -41,13 +46,16 @@ M: table -> dup , selected-value>> ;
    [ { } make:make ] dip <track> swap [ f track-add ] each ; inline
 : <box*> ( gadgets type -- track ) [ <box> ] [ [ model>> ] map <product> ] bi >>model ; inline
 : <hbox> ( gadgets -- track ) horizontal <box> ; inline
+: <hbox*> ( gadgets -- track ) horizontal <box*> ; inline
 : <vbox> ( gadgets -- track ) vertical <box> ; inline
+: <vbox*> ( gadgets -- track ) vertical <box*> ; inline
 
-! Model utilities
+! !!! Model utilities
 TUPLE: multi-model < model ;
-! M: multi-model model-activated dup model-changed ;
 : <multi-model> ( models kind -- model ) f swap new-model [ [ add-dependency ] curry each ] keep ;
 
+! Events- discrete model utilities
+
 TUPLE: merge-model < multi-model ;
 M: merge-model model-changed [ value>> ] dip set-model ;
 : <merge> ( models -- model ) merge-model <multi-model> ;
@@ -57,15 +65,21 @@ M: filter-model model-changed [ value>> ] dip [ quot>> call( val -- bool ) ] 2ke
    [ set-model ] [ 2drop ] if ;
 : <filter> ( model quot -- filter-model ) [ 1array filter-model <multi-model> ] dip >>quot ;
 
+! Behaviors - continuous model utilities
+
 TUPLE: fold-model < multi-model oldval quot ;
 M: fold-model model-changed [ [ value>> ] [ [ oldval>> ] [ quot>> ] bi ] bi*
    call( val oldval -- newval ) ] keep set-model ;
-: <fold> ( oldval quot model -- model' ) 1array fold-model <multi-model> swap >>quot swap >>oldval ;
+: <fold> ( oldval quot model -- model' ) 1array fold-model <multi-model> swap >>quot
+   swap [ >>oldval ] [ >>value ] bi ;
 
-TUPLE: switch-model < multi-model switcher on ;
-M: switch-model model-changed tuck [ switcher>> = ] 2keep
-   '[ on>> [ _ value>> _ set-model ] when ] [ t swap (>>on) ] if ;
-: switch ( signal1 signal2 -- signal' ) [ 2array switch-model <multi-model> ] keep >>switcher ;
+TUPLE: switch-model < multi-model original switcher on ;
+M: switch-model model-changed 2dup switcher>> =
+   [ over value>> [ [ value>> ] [ t >>on ] bi* set-model ] [ 2drop ] if ]
+   [ dup on>> [ 2drop ] [ [ value>> ] dip set-model ] if ] if ;
+M: switch-model model-activated [ original>> ] keep model-changed ;
+: <switch> ( signal1 signal2 -- signal' ) [ 2array switch-model <multi-model> ] 2keep
+   [ >>original ] [ >>switcher ] bi* ;
 
 TUPLE: mapped < model model quot ;
 
@@ -87,4 +101,4 @@ INSTANCE: gadget-monad monad
 INSTANCE: gadget monad
 M: gadget monad-of drop gadget-monad ;
 M: gadget-monad return drop <gadget> swap >>model ;
-M: gadget >>= model>> '[ _ swap call( x -- y ) ] ; 
\ No newline at end of file
+M: gadget >>= output-model [ swap call( x -- y ) ] curry ; 
\ No newline at end of file