factor/basis/ui/tools/debugger/debugger.factor

83 lines
2.4 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.
2008-11-24 13:29:24 -05:00
USING: accessors arrays hashtables io kernel math models
namespaces sequences sequences words continuations debugger
prettyprint help editors ui ui.commands ui.gestures ui.gadgets
ui.gadgets.worlds ui.gadgets.packs ui.gadgets.buttons
ui.gadgets.labels ui.gadgets.panes ui.gadgets.presentations
ui.gadgets.viewports ui.gadgets.lists ui.gadgets.tracks
ui.gadgets.scrollers ui.gadgets.panes ui.tools.traceback ;
2007-09-20 18:09:08 -04:00
IN: ui.tools.debugger
2008-11-24 13:29:24 -05:00
TUPLE: debugger < track error restarts restart-hook restart-list continuation ;
<PRIVATE
: <restart-list> ( debugger -- gadget )
[ restart-hook>> ] [ restarts>> ] bi
[ name>> ] swap <model> <list> ; inline
2007-09-20 18:09:08 -04:00
2008-11-24 13:29:24 -05:00
: <error-pane> ( error -- pane )
<pane> [ [ print-error ] with-pane ] keep ; inline
2007-09-20 18:09:08 -04:00
2008-11-24 13:29:24 -05:00
: <debugger-display> ( debugger -- gadget )
<filled-pile>
2008-11-24 13:29:24 -05:00
over error>> <error-pane> add-gadget
swap restart-list>> add-gadget ; inline
2008-11-24 13:29:24 -05:00
PRIVATE>
2007-09-20 18:09:08 -04:00
: <debugger> ( error restarts restart-hook -- gadget )
{ 0 1 } debugger new-track
2008-11-20 22:58:30 -05:00
add-toolbar
2008-11-24 13:29:24 -05:00
swap >>restart-hook
swap >>restarts
swap >>error
error-continuation get >>continuation
dup <restart-list> >>restart-list
dup <debugger-display> <scroller> 1 track-add ;
2007-09-20 18:09:08 -04:00
2008-11-24 13:29:24 -05:00
M: debugger focusable-child* restart-list>> ;
2007-09-20 18:09:08 -04:00
: debugger-window ( error -- )
#! No restarts for the debugger window
f [ drop ] <debugger> "Error" open-window ;
GENERIC: error-in-debugger? ( error -- ? )
M: world-error error-in-debugger? world>> gadget-child debugger? ;
M: object error-in-debugger? drop f ;
[
dup error-in-debugger? [ rethrow ] [ debugger-window ] if
] ui-error-hook set-global
2007-09-20 18:09:08 -04:00
M: world-error error.
"An error occurred while drawing the world " write
dup world>> pprint-short "." print
2007-09-20 18:09:08 -04:00
"This world has been deactivated to prevent cascading errors." print
error>> error. ;
2007-09-20 18:09:08 -04:00
debugger "gestures" f {
{ T{ button-down } request-focus }
} define-command-map
2008-11-24 13:29:24 -05:00
: com-traceback ( debugger -- ) continuation>> traceback-window ;
\ com-traceback H{ } define-command
: com-help ( debugger -- ) error>> (:help) ;
2007-09-20 18:09:08 -04:00
2008-11-24 13:29:24 -05:00
\ com-help H{ { +listener+ t } } define-command
2007-09-20 18:09:08 -04:00
2008-11-24 13:29:24 -05:00
: com-edit ( debugger -- ) error>> (:edit) ;
2007-09-20 18:09:08 -04:00
2008-11-24 13:29:24 -05:00
\ com-edit H{ { +listener+ t } } define-command
2007-09-20 18:09:08 -04:00
debugger "toolbar" f {
{ T{ key-down f f "s" } com-traceback }
2008-11-24 13:29:24 -05:00
{ T{ key-down f f "h" } com-help }
{ T{ key-down f f "e" } com-edit }
2007-09-20 18:09:08 -04:00
} define-command-map