! Copyright (C) 2006 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. IN: gadgets-search USING: arrays gadgets 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 strings modules ; TUPLE: live-search field list ; : find-live-search [ live-search? ] find-parent ; : find-search-list find-live-search live-search-list ; TUPLE: search-field ; C: search-field ( -- gadget ) over set-gadget-delegate dup dup set-control-self [ 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 : ( producer -- model ) gadget get live-search-field control-model 200 [ "\n" join ] swap ; : ( action seq producer presenter -- gadget ) -rot curry ; C: live-search ( string action seq producer presenter -- gadget ) { { [ ] set-live-search-field f @top } { [ ] set-live-search-list [ ] @center } } make-frame* [ live-search-field set-editor-text ] keep ; M: live-search focusable-child* live-search-field ; : ( string action -- gadget ) all-words [ word-completions ] [ word-name ] ; : help-completions ( str pairs -- seq ) >r >lower r> [ second >lower ] swap completions [ first ] map ; : ( string action -- gadget ) all-articles [ dup article-title 2array ] map [ help-completions ] [ article-title ] ; : ( string action -- gadget ) source-files get hash-keys natural-sort [ string-completions [ ] map ] [ pathname-string ] ; : module-completions ( str modules -- seq ) [ module-name ] swap completions ; : ( string action -- gadget ) available-modules [ module-completions ] [ module-name ] ; : ( string action -- gadget ) vocabs [ string-completions [ ] map ] [ vocab-link-name ] ; : ( string action seq -- gadget ) [ string-completions [ ] map ] [ input-string ] ;