factor/basis/ui/tools/browser/browser.factor

92 lines
2.7 KiB
Factor
Raw Normal View History

! Copyright (C) 2006, 2008 Slava Pestov.
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
USING: debugger ui.tools.workspace help help.topics kernel
2008-12-11 17:47:38 -05:00
models models.history tools.apropos ui.commands ui.gadgets
ui.gadgets.panes ui.gadgets.scrollers ui.gadgets.tracks
ui.gestures ui.gadgets.buttons ui.gadgets.packs
ui.gadgets.editors ui.gadgets.labels models compiler.units
assocs words vocabs accessors fry combinators.short-circuit ;
2007-09-20 18:09:08 -04:00
IN: ui.tools.browser
TUPLE: browser-gadget < track pane history ;
2007-09-20 18:09:08 -04:00
2008-12-11 17:47:38 -05:00
: show-help ( link browser-gadget -- )
2008-11-20 21:34:49 -05:00
history>> dup add-history
[ >link ] dip set-model ;
2007-09-20 18:09:08 -04:00
: <help-pane> ( browser-gadget -- gadget )
2008-11-20 21:34:49 -05:00
history>> [ '[ _ print-topic ] try ] <pane-control> ;
2007-09-20 18:09:08 -04:00
: init-history ( browser-gadget -- )
2008-06-08 16:32:55 -04:00
"handbook" >link <history> >>history drop ;
2007-09-20 18:09:08 -04:00
2008-12-11 17:47:38 -05:00
: search-browser ( string browser -- )
[ <apropos> ] dip show-help ;
: <search-field> ( browser -- field )
'[ _ search-browser ] <action-field> 10 >>min-width 10 >>max-width ;
: <browser-toolbar> ( browser -- toolbar )
<shelf>
{ 5 5 } >>gap
over <toolbar> add-gadget
"Search:" <label> add-gadget
swap <search-field> add-gadget ;
2007-09-20 18:09:08 -04:00
: <browser-gadget> ( -- gadget )
{ 0 1 } browser-gadget new-track
dup init-history
2008-12-11 17:47:38 -05:00
dup <browser-toolbar> f track-add
dup <help-pane> >>pane
dup pane>> <scroller> 1 track-add ;
2007-09-20 18:09:08 -04:00
M: browser-gadget call-tool* show-help ;
M: browser-gadget tool-scroller
2008-06-08 16:32:55 -04:00
pane>> find-scroller ;
2007-09-20 18:09:08 -04:00
M: browser-gadget graft*
[ add-definition-observer ] [ call-next-method ] bi ;
M: browser-gadget ungraft*
[ call-next-method ] [ remove-definition-observer ] bi ;
: showing-definition? ( defspec assoc -- ? )
2008-11-20 21:34:49 -05:00
{
[ key? ]
[ [ dup word-link? [ name>> ] when ] dip key? ]
[ [ dup vocab-link? [ vocab ] when ] dip key? ]
} 2|| ;
M: browser-gadget definitions-changed ( assoc browser -- )
2008-06-08 16:32:55 -04:00
history>>
2008-08-31 17:17:46 -04:00
dup value>> rot showing-definition?
[ notify-connections ] [ drop ] if ;
2007-09-20 18:09:08 -04:00
: help-action ( browser-gadget -- link )
2008-08-31 17:17:46 -04:00
history>> value>> >link ;
2007-09-20 18:09:08 -04:00
2008-06-08 16:32:55 -04:00
: com-follow ( link -- ) browser-gadget call-tool ;
2007-09-20 18:09:08 -04:00
2008-06-08 16:32:55 -04:00
: com-back ( browser -- ) history>> go-back ;
2007-09-20 18:09:08 -04:00
2008-06-08 16:32:55 -04:00
: com-forward ( browser -- ) history>> go-forward ;
2007-09-20 18:09:08 -04:00
2008-06-08 16:32:55 -04:00
: com-documentation ( browser -- ) "handbook" swap show-help ;
2007-09-20 18:09:08 -04:00
2008-06-08 16:32:55 -04:00
: browser-help ( -- ) "ui-browser" help-window ;
2007-09-20 18:09:08 -04:00
\ browser-help H{ { +nullary+ t } } define-command
browser-gadget "toolbar" f {
{ T{ key-down f { A+ } "LEFT" } com-back }
{ T{ key-down f { A+ } "RIGHT" } com-forward }
{ f com-documentation }
2007-09-20 18:09:08 -04:00
{ T{ key-down f f "F1" } browser-help }
} define-command-map
2008-04-11 23:33:01 -04:00
browser-gadget "multi-touch" f {
{ T{ left-action } com-back }
{ T{ right-action } com-forward }
} define-command-map