! Copyright (C) 2006 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. IN: gadgets-search USING: arrays gadgets gadgets-frames gadgets-labels gadgets-panes gadgets-scrolling gadgets-text gadgets-theme generic help tools kernel models sequences words gadgets-borders gadgets-lists namespaces parser hashtables io completion styles ; TUPLE: live-search field list producer action presenter ; : find-live-search [ live-search? ] find-parent ; : find-search-list find-live-search live-search-list ; TUPLE: search-field ; C: search-field ( string -- gadget ) over set-gadget-delegate dup dup set-control-self [ set-editor-text ] keep [ editor-doc-end ] keep ; search-field H{ { T{ key-down f f "UP" } [ find-search-list select-prev ] } { T{ key-down f f "DOWN" } [ find-search-list select-next ] } { T{ key-down f f "RETURN" } [ find-search-list call-action ] } } set-gestures : ( -- model ) gadget get dup live-search-field control-model swap live-search-producer [ "\n" join ] swap append ; : gadget get live-search-presenter [ make-pane ] curry gadget get live-search-action \ first add* ; C: live-search ( string action producer presenter -- gadget ) [ set-live-search-presenter ] keep [ set-live-search-producer ] keep [ set-live-search-action ] keep { { [ ] set-live-search-field f @top } { [ ] set-live-search-list [ ] @center } } make-frame* ; M: live-search focusable-child* live-search-field ; : ( string action -- gadget ) all-words [ word-completions ] curry [ word-completion. ] ; : ( string action -- gadget ) [ search-help ] [ first ($link) ] ; : string-completion. ( pair quot -- ) >r first2 over completion>string swap r> call write-object ; inline : ( string action -- gadget ) source-files get hash-keys natural-sort [ string-completions ] curry [ [ ] string-completion. ] ; : ( string action -- gadget ) vocabs [ string-completions ] curry [ [ ] string-completion. ] ;