1 ! Copyright (C) 2006, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors inspector namespaces kernel models fry
4 colors.constants models.arrow prettyprint sequences mirrors assocs
5 classes io io.styles arrays hashtables math.order sorting refs fonts
6 ui.tools.browser ui.commands ui.operations ui.gadgets ui.gadgets.panes
7 ui.gadgets.scrollers ui.gadgets.slots ui.gadgets.tracks ui.gestures
8 ui.gadgets.buttons ui.gadgets.tables ui.gadgets.status-bar
9 ui.gadgets.labeled ui.tools.common ui combinators ui.gadgets.worlds ;
10 IN: ui.tools.inspector
12 TUPLE: inspector-gadget < tool table ;
14 TUPLE: slot-description key key-string value value-string ;
16 : <slot-description> ( key value -- slot-description )
17 [ dup unparse-short ] bi@ slot-description boa ;
19 SINGLETON: inspector-renderer
21 M: inspector-renderer row-columns
22 drop [ key-string>> ] [ value-string>> ] bi 2array ;
24 M: inspector-renderer row-value
27 M: inspector-renderer column-titles
28 drop { "Key" "Value" } ;
30 : <summary-gadget> ( model -- gadget )
32 standard-table-style [
36 [ "Class:" write ] with-cell
37 [ class-of pprint ] with-cell
42 [ "Object:" write ] with-cell
43 [ pprint-short ] with-cell
48 [ "Summary:" write ] with-cell
49 [ print-summary ] with-cell
55 [ "Content:" write ] with-cell
56 [ output-stream get write-gadget ] with-cell
64 GENERIC: make-slot-descriptions ( obj -- seq )
66 M: object make-slot-descriptions
67 make-mirror [ <slot-description> ] { } assoc>map ;
69 M: hashtable make-slot-descriptions
70 call-next-method [ key-string>> ] sort-with ;
72 : <inspector-table> ( model -- table )
73 [ make-slot-descriptions ] <arrow> inspector-renderer <table>
74 [ invoke-primary-operation ] >>action
76 COLOR: dark-gray >>column-line-color
83 : <inspector-gadget> ( model -- gadget )
84 vertical inspector-gadget new-track
88 dup model>> <inspector-table> >>table
89 dup model>> <summary-gadget> "Object" <labeled-gadget> f track-add
90 dup table>> <scroller> "Contents" <labeled-gadget> 1 track-add ;
92 M: inspector-gadget focusable-child*
95 : com-refresh ( inspector -- )
96 model>> notify-connections ;
98 : com-push ( inspector -- obj )
101 \ com-push H{ { +listener+ t } } define-command
103 : slot-editor-window ( close-hook update-hook assoc key key-string -- )
104 [ <value-ref> <slot-editor> ]
107 swap "Slot editor: " prepend >>title
108 [ { dialog-window } append ] change-window-controls
112 : com-edit-slot ( inspector -- )
113 [ close-window ] swap
114 [ '[ _ com-refresh ] ]
115 [ control-value make-mirror ]
116 [ table>> (selected-row) ] tri [
117 [ key>> ] [ key-string>> ] bi
121 : inspector-help ( -- ) "ui-inspector" com-browse ;
123 \ inspector-help H{ { +nullary+ t } } define-command
125 inspector-gadget "toolbar" f {
126 { T{ update-object } com-refresh }
127 { T{ key-down f f "p" } com-push }
128 { T{ key-down f f "e" } com-edit-slot }
129 { T{ key-down f f "F1" } inspector-help }
132 inspector-gadget "multi-touch" f {
133 { up-action com-refresh }
136 : inspect-model ( model -- )
137 <inspector-gadget> "Inspector" open-status-window ;
139 : inspector ( obj -- )
140 <model> inspect-model ;
142 { 550 400 } inspector-gadget set-tool-dim