Removing delegation support from UI

db4
Slava Pestov 2008-08-22 23:27:25 -05:00
parent a4ac751605
commit d8ede92dfb
6 changed files with 25 additions and 32 deletions

View File

@ -6,18 +6,16 @@ HELP: set-gestures
{ $values { "class" "a class word" } { "hash" hashtable } }
{ $description "Sets the gestures a gadget class responds to. The hashtable maps gestures to quotations with stack effect " { $snippet "( gadget -- )" } "." } ;
HELP: handle-gesture*
{ $values { "gadget" "the receiver of the gesture" } { "gesture" "a gesture" } { "delegate" "an object" } { "?" "a boolean" } }
{ $contract "Handles a gesture sent to a gadget. As the delegation chain is traversed, this generic word is called with every delegate of the gadget at the top of the stack, however the front-most delegate remains fixed as the " { $snippet "gadget" } " parameter."
HELP: handle-gesture
{ $values { "gesture" "a gesture" } { "gadget" "the receiver of the gesture" } { "?" "a boolean" } }
{ $contract "Handles a gesture sent to a gadget."
$nl
"Outputs " { $link f } " if the gesture was handled, and " { $link t } " if the gesture should be passed on to the gadget's delegate." }
"Outputs " { $link f } " if the gesture was handled, and " { $link t } " if the gesture should be passed on to the gadget's parent."
$nl
"The default implementation looks at the " { $snippet "\"gestures\"" } " word property of each superclass of the gadget's class." }
{ $notes "Methods should be defined on this word if you desire to handle an arbitrary set of gestures. To define handlers for a fixed set, it is easier to use " { $link set-gestures } "." } ;
HELP: handle-gesture
{ $values { "gesture" "a gesture" } { "gadget" gadget } { "?" "a boolean" } }
{ $description "Calls " { $link handle-gesture* } " on every delegate of " { $snippet "gadget" } ". Outputs " { $link f } " if some delegate handled the gesture, else outputs " { $link t } "." } ;
{ send-gesture handle-gesture handle-gesture* set-gestures } related-words
{ send-gesture handle-gesture set-gestures } related-words
HELP: send-gesture
{ $values { "gesture" "a gesture" } { "gadget" gadget } { "?" "a boolean" } }
@ -203,7 +201,7 @@ $nl
"There are two ways to define gesture handling logic. The simplest way is to associate a fixed set of gestures with a class:"
{ $subsection set-gestures }
"Another way is to define a generic word on a class which handles all gestures sent to gadgets of that class:"
{ $subsection handle-gesture* }
{ $subsection handle-gesture }
"Sometimes a gesture needs to be presented to the user:"
{ $subsection gesture>string }
"Keyboard input:"

View File

@ -8,16 +8,12 @@ IN: ui.gestures
: set-gestures ( class hash -- ) "gestures" set-word-prop ;
GENERIC: handle-gesture* ( gadget gesture delegate -- ? )
GENERIC: handle-gesture ( gesture gadget -- ? )
: default-gesture-handler ( gadget gesture delegate -- ? )
class superclasses [ "gestures" word-prop ] map assoc-stack dup
[ call f ] [ 2drop t ] if ;
M: object handle-gesture* default-gesture-handler ;
: handle-gesture ( gesture gadget -- ? )
tuck >r 2dup r> handle-gesture* 2nip ;
M: object handle-gesture
tuck class superclasses
[ "gestures" word-prop ] map
assoc-stack dup [ call f ] [ 2drop t ] if ;
: send-gesture ( gesture gadget -- ? )
[ dupd handle-gesture ] each-parent nip ;

View File

@ -188,9 +188,9 @@ listener-gadget "toolbar" f {
{ T{ key-down f f "F1" } listener-help }
} define-command-map
M: listener-gadget handle-gesture* ( gadget gesture delegate -- ? )
3dup drop swap find-workspace workspace-page handle-gesture
[ default-gesture-handler ] [ 3drop f ] if ;
M: listener-gadget handle-gesture ( gesture gadget -- ? )
2dup find-workspace workspace-page handle-gesture
[ call-next-method ] [ 2drop f ] if ;
M: listener-gadget graft*
[ call-next-method ] [ restart-listener ] bi ;

View File

@ -20,8 +20,8 @@ TUPLE: live-search < track field list ;
search-value object-operations
[ operation-gesture = ] with find nip ;
M: live-search handle-gesture* ( gadget gesture delegate -- ? )
drop over search-gesture dup [
M: live-search handle-gesture ( gesture live-search -- ? )
tuck search-gesture dup [
over find-workspace hide-popup
>r search-value r> invoke-command f
] [

View File

@ -1,8 +1,8 @@
! Copyright (C) 2007 Slava Pestov.
! Copyright (C) 2007, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: io kernel prettyprint ui ui.gadgets ui.gadgets.panes
ui.gadgets.scrollers ui.gadgets.theme ui.gestures colors
accessors ;
USING: accessors io kernel prettyprint ui ui.gadgets
ui.gadgets.panes ui.gadgets.scrollers ui.gadgets.theme
ui.gestures colors ;
IN: gesture-logger
TUPLE: gesture-logger < gadget stream ;
@ -14,9 +14,8 @@ TUPLE: gesture-logger < gadget stream ;
black solid-interior ;
M: gesture-logger handle-gesture*
drop
dup T{ button-down } = [ over request-focus ] when
swap gesture-logger-stream [ . ] with-output-stream*
over T{ button-down } = [ dup request-focus ] when
stream>> [ . ] with-output-stream*
t ;
M: gesture-logger user-input*

View File

@ -169,7 +169,7 @@ M: key-caps-gadget ungraft*
alarm>> [ cancel-alarm ] when* ;
M: key-caps-gadget handle-gesture*
drop nip [ key-down? ] [ key-up? ] bi or not ;
drop [ key-down? ] [ key-up? ] bi or not ;
: key-caps ( -- )
[