From 95d2147dd5a1233306f9deaffec67daea183c20b Mon Sep 17 00:00:00 2001
From: Sam Anklesaria <sam@Tintin.local>
Date: Sun, 7 Jun 2009 17:43:07 -0500
Subject: [PATCH] frp books automatically add models

---
 extra/ui/frp/layout/layout.factor | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/extra/ui/frp/layout/layout.factor b/extra/ui/frp/layout/layout.factor
index 48cb0398e0..a4f0b09409 100644
--- a/extra/ui/frp/layout/layout.factor
+++ b/extra/ui/frp/layout/layout.factor
@@ -5,6 +5,7 @@ words tools.continuations ;
 IN: ui.frp.layout
 
 TUPLE: layout gadget size ; C: <layout> layout
+ERROR: no-models models ;
 
 SYNTAX: ,% scan string>number [ <layout> , ] curry over push-all ;
 SYNTAX: ->% scan string>number '[ [ _ <layout> , ] [ output-model ] bi ] over push-all ;
@@ -31,7 +32,8 @@ SYMBOL: wordnames
 : <hbox> ( gadgets -- track ) horizontal <box> ; inline
 : <vbox> ( gadgets -- track ) vertical <box> ; inline
 
-: <frp-book> ( gadgets -- book ) f make-layout f <book> handle-words ; inline
+: <frp-book> ( quot: ( -- model ) -- book ) f make-layout roll dup activate-model <book> handle-words
+   swap [ no-models ] unless-empty ; inline
 
 SYNTAX: $ CREATE-WORD dup [ , ] curry (( -- )) define-declared "$" expect
    word [ [ building get length swap wordnames get set-at ] [ , ] bi ] curry over push-all ;
@@ -42,7 +44,7 @@ GENERIC# insert-item 1 ( item location -- )
 M: gadget insert-item dup first book? [ first2 spin [ add-gadget ] keep insert-gadget ]
    [ [ f <layout> ] dip insert-item ] if ;
 M: layout insert-item first2 spin [ insert-layout ] keep gadget>> insert-gadget ;
-M: model insert-item dup first book? [ "Books can't contain models" throw ]
+M: model insert-item dup first book? [ no-models ]
    [ first model>> swap add-connection ] if ;
 
 : insert-items ( makelist -- ) f swap [ dup word?