From 86420977b328ca1e3a4874fdd189e6dc19a44292 Mon Sep 17 00:00:00 2001 From: slava Date: Fri, 6 Oct 2006 21:07:13 +0000 Subject: [PATCH] Minor completion UI cleanups --- TODO.FACTOR.txt | 5 ----- library/help/search.factor | 6 +++++- library/help/search.facts | 6 +----- library/load.factor | 2 +- library/ui/tools/listener.factor | 15 +++++++++++++++ library/ui/tools/operations.factor | 12 ++++++++++++ library/ui/tools/search.factor | 26 +++++++++++++++----------- 7 files changed, 49 insertions(+), 23 deletions(-) diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 2fc37b933c..1e2299056e 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -12,11 +12,6 @@ - minibuffer should show a title - clean up listener's minibuffer-related code - help search looks funny -- vocab completer -- vocab operations: - - browse - - insert IN: -- or just 'become in' - - insert USE: -- 'use' + ui: diff --git a/library/help/search.factor b/library/help/search.factor index 1c9179e78a..fbf300c968 100644 --- a/library/help/search.factor +++ b/library/help/search.factor @@ -2,7 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. IN: help USING: arrays definitions graphs hashtables help io kernel math -namespaces porter-stemmer prettyprint sequences strings words ; +namespaces porter-stemmer prettyprint sequences strings words +completion ; ! Right now this code is specific to the help. It will be ! generalized to an abstract full text search engine later. @@ -46,6 +47,9 @@ SYMBOL: term-index tokenize [ term-index get hash ] map [ ] subset count-occurrences hash>alist rank-completions ; +: search-help. ( phrase -- ) + search-help [ first ] map help-outliner ; + : index-help ( -- ) term-index get [ dup clear-hash diff --git a/library/help/search.facts b/library/help/search.facts index 87c978ae50..14513ec41f 100644 --- a/library/help/search.facts +++ b/library/help/search.facts @@ -23,10 +23,6 @@ $terpri "The " { $link search-help } " word searches the term index and the " { $link index-help } " word updates it." } { $see-also help } ; -HELP: discard-irrelevant -{ $values { "results" "a sequence" } { "newresults" "a new sequence" } } -{ $description "Discard search results which rank in the lower 33% compared to the top scoring result, since they are most likely irrelevant." } ; - HELP: count-occurrences { $values { "seq" "a sequence of hashtables" } { "hash" "a hashtable" } } { $description "Collates all keys from the hashtables in " { $snippet "seq" } " and sums their values, which must be numbers." } ; @@ -36,7 +32,7 @@ HELP: search-help { $description "Performs a full-text search in the term index for help topics relating to " { $snippet "phrase" } ". The result is an association list of topic names paired with scores, sorted by decreasing score." } ; HELP: index-help -{ $description "Updates the full-text search term index for use by " { $link search-help } "." } ; +{ $description "Updates the full-text search term index for use by " { $link search-help. } " and " { $link search-help } "." } ; HELP: search-help. { $values { "phrase" "a string" } } diff --git a/library/load.factor b/library/load.factor index 2054a4d7bd..235d0ee138 100644 --- a/library/load.factor +++ b/library/load.factor @@ -77,6 +77,7 @@ PROVIDE: library { "tools/definitions.factor" "tools/describe.factor" + "tools/completion.factor" "help/stylesheet.factor" "help/topics.factor" @@ -94,7 +95,6 @@ PROVIDE: library { "tools/memory.factor" "tools/listener.factor" "tools/inspector.factor" - "tools/completion.factor" "tools/word-tools.factor" "tools/test.factor" diff --git a/library/ui/tools/listener.factor b/library/ui/tools/listener.factor index 5386ebf72f..c30749e7c9 100644 --- a/library/ui/tools/listener.factor +++ b/library/ui/tools/listener.factor @@ -114,6 +114,10 @@ M: listener-gadget tool-help : show-source-files-search ( listener action -- ) "" swap swap show-minibuffer ; +: show-vocabs-search ( listener action -- ) + >r dup listener-gadget-input selected-word r> + swap show-minibuffer ; + : show-list ( seq presenter action listener -- ) >r >r >r r> r> r> show-minibuffer ; @@ -168,6 +172,17 @@ listener-gadget "Listener commands" { show-source-files-search ] } + { + "Use vocabulary" + T{ key-down f { C+ } "u" } + [ + [ + find-listener hide-minibuffer + [ use+ ] curry call-listener + ] + show-vocabs-search + ] + } { "Hide minibuffer" T{ key-down f f "ESCAPE" } diff --git a/library/ui/tools/operations.factor b/library/ui/tools/operations.factor index 91fbde372b..a09183790f 100644 --- a/library/ui/tools/operations.factor +++ b/library/ui/tools/operations.factor @@ -123,6 +123,18 @@ M: operation invoke-command ( target operation -- ) { +quot+ [ browser call-tool ] } } define-operation +[ vocab-link? ] H{ + { +mouse+ T{ button-up f f 2 } } + { +name+ "Enter in" } + { +quot+ [ [ in set ] curry call-listener ] } +} define-operation + +[ vocab-link? ] H{ + { +mouse+ T{ button-up f f 3 } } + { +name+ "Use" } + { +quot+ [ [ use+ ] curry call-listener ] } +} define-operation + ! Link [ link? ] H{ { +mouse+ T{ button-up f f 1 } } diff --git a/library/ui/tools/search.factor b/library/ui/tools/search.factor index d826c887de..5e8166526a 100644 --- a/library/ui/tools/search.factor +++ b/library/ui/tools/search.factor @@ -5,7 +5,7 @@ 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 ; +completion styles ; TUPLE: live-search field list model producer action presenter ; @@ -34,8 +34,8 @@ search-field H{ : - gadget get live-search-presenter - gadget get live-search-action + gadget get live-search-presenter [ make-pane ] curry + gadget get live-search-action \ first add* ; C: live-search ( string action producer presenter -- gadget ) @@ -60,24 +60,28 @@ C: live-search ( string action producer presenter -- gadget ) M: live-search focusable-child* live-search-field ; : ( string action -- gadget ) - \ first add* all-words [ word-completions ] curry - [ [ word-completion. ] make-pane ] + [ word-completion. ] ; : ( string action -- gadget ) - \ first add* [ search-help ] - [ [ first ($link) ] make-pane ] + [ first ($link) ] ; -: file-completion. ( pair -- ) - first2 over completion>string swap write-object ; +: string-completion. ( pair quot -- ) + >r first2 over completion>string swap r> write-object ; + inline : ( string action -- gadget ) - \ first add* source-files get hash-keys natural-sort [ string-completions ] curry - [ [ file-completion. ] make-pane ] + [ [ ] string-completion. ] + ; + +: ( string action -- gadget ) + vocabs + [ string-completions ] curry + [ [ ] string-completion. ] ;