! Copyright (C) 2005 Slava Pestov. ! See http://factor.sf.net/license.txt for BSD license. IN: gadgets-panes USING: arrays gadgets gadgets-buttons gadgets-editors gadgets-labels gadgets-scrolling gadgets-theme generic hashtables io kernel line-editor math namespaces prettyprint sequences strings styles threads ; ! A pane is an area that can display text. ! output: pile ! current: shelf ! input: editor TUPLE: pane output active current input prototype continuation ; : add-output 2dup set-pane-output add-gadget ; : ( current input -- line ) { { [ ] f @center } { [ ] f @left } } make-frame ; : init-line ( pane -- ) dup pane-prototype clone swap set-pane-current ; : prepare-line ( pane -- ) dup init-line dup pane-active unparent [ dup pane-current swap pane-input ] keep 2dup set-pane-active add-gadget ; : pop-continuation ( pane -- quot ) dup pane-continuation f rot set-pane-continuation ; : pane-eval ( string pane -- ) pop-continuation dup [ [ continue-with ] in-thread ] when 2drop ; SYMBOL: structured-input : pane-call ( quot pane -- ) dup [ "Command: " write over short. ] with-stream* >r structured-input set-global "\"structured-input\" \"gadgets-panes\" lookup get-global call" r> pane-eval ; : replace-input ( string pane -- ) pane-input set-editor-text ; : print-input ( string pane -- ) [ dup [ presented set bold font-style set ] make-hash format terpri ] with-stream* ; : pane-commit ( pane -- ) dup pane-input commit-editor-text swap 2dup print-input pane-eval ; : pane-clear ( pane -- ) dup pane-output clear-incremental pane-current clear-gadget ; C: pane ( -- pane ) over set-delegate 1 over set-pack-fill over set-pane-prototype over add-output dup prepare-line ; M: pane gadget-gestures pane-input [ H{ { T{ key-down f f "RETURN" } [ pane-commit ] } { T{ key-down f f "UP" } [ pane-input [ history-prev ] with-editor ] } { T{ key-down f f "DOWN" } [ pane-input [ history-next ] with-editor ] } { T{ key-down f { C+ } "l" } [ pane-clear ] } } ] [ H{ } ] if ; : ( -- pane ) "" over set-pane-input ; M: pane focusable-child* ( pane -- editor ) pane-input [ t ] unless* ; : prepare-print ( current -- gadget ) #! Optimization: if line has 1 child, add the child. dup gadget-children { { [ dup empty? ] [ 2drop ""