PageRenderTime 21ms CodeModel.GetById 12ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/unmaintained/drills/deployed/deployed.factor

http://github.com/abeaumont/factor
Unknown | 36 lines | 33 code | 3 blank | 0 comment | 0 complexity | e2df91ba04ca6cb08356d915a408f0c7 MD5 | raw file
 1USING: arrays cocoa.dialogs combinators continuations
 2fry grouping io.encodings.utf8 io.files io.styles kernel math
 3math.parser models models.arrow models.history namespaces random
 4sequences splitting ui ui.gadgets.alerts ui.gadgets.book-extras
 5ui.gadgets.books ui.gadgets.buttons ui.gadgets.frames
 6ui.gadgets.grids ui.gadgets.labels ui.gadgets.tracks fonts
 7wrap.strings system ;
 8EXCLUDE: accessors => change-model ;
 9IN: drills.deployed
10SYMBOLS: it startLength ;
11: big ( gadget -- gadget ) T{ font { name "sans-serif" } { size 30 } } >>font ;
12: card ( model quot -- button ) <arrow> <label-control> big [ next ] <book-btn> ;
13: op ( quot str -- gadget ) <label> big swap <book-bevel-btn> ;
14
15: show ( model -- gadget ) dup it set-global [ random ] <arrow>
16   { [ [ first ] card ]
17     [ [ second ] card ]
18     [ '[ |<< it get _ model-changed ] "No" op ]
19          [ '[ |<< [ it get [
20        _ value>> swap remove
21        [ [ it get go-back ] "Drill Complete" alert return ] when-empty
22     ] change-model ] with-return ] "Yes" op ]
23   } cleave
242array { 1 0 } <track> swap [ 0.5 track-add ] each
253array <book*> 3 3 <frame> { 1 1 } >>filled-cell { 450 175 } >>pref-dim swap { 1 1 } grid-add
26it get [ length startLength get swap - number>string "/" startLength get number>string 3append ] <arrow> <label-control> { 1 2 } grid-add ;
27
28: drill ( -- ) [
29   open-panel [
30         [ utf8 file-lines [ "\t" split [ 25 wrap-string ] map ] map dup [ first2 swap 2array ] map append ] map concat
31            [ length startLength set-global ] keep <history> [ add-history ] [ show ] bi
32         "Got it?" open-window
33   ] [ 0 exit ] if*
34] with-ui ;
35
36MAIN: drill