]> gitweb.factorcode.org Git - factor.git/blob - basis/ui/tools/browser/history/history.factor
f80189c7838916dfca8abf1b9c7d0f3c8db43cbe
[factor.git] / basis / ui / tools / browser / history / history.factor
1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel accessors sequences locals ;
4 IN: ui.tools.browser.history
5
6 TUPLE: history owner back forward ;
7
8 : <history> ( owner -- history )
9     V{ } clone V{ } clone history boa ;
10
11 GENERIC: history-value ( object -- value )
12
13 GENERIC: set-history-value ( value object -- )
14
15 : (add-history) ( history to -- )
16     swap owner>> history-value dup [ swap push ] [ 2drop ] if ;
17
18 :: go-back/forward ( history to from -- )
19     from empty? [
20         history to (add-history)
21         from pop history owner>> set-history-value
22     ] unless ;
23
24 : go-back ( history -- )
25     dup [ forward>> ] [ back>> ] bi go-back/forward ;
26
27 : go-forward ( history -- )
28     dup [ back>> ] [ forward>> ] bi go-back/forward ;
29
30 : add-history ( history -- )
31     dup forward>> delete-all
32     dup back>> (add-history) ;