1 ! Copyright (C) 2006, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors colors 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.theme
9 ui.gadgets.toolbar ui.gadgets.status-bar
10 ui.gadgets.labeled ui.tools.common ui combinators ui.gadgets.worlds ;
11 IN: ui.tools.inspector
13 TUPLE: inspector-gadget < tool table ;
15 TUPLE: slot-description key key-string value value-string ;
17 : <slot-description> ( key value -- slot-description )
18 [ dup unparse-short ] bi@ slot-description boa ;
20 SINGLETON: inspector-renderer
22 M: inspector-renderer row-columns
23 drop [ key-string>> ] [ value-string>> ] bi 2array ;
25 M: inspector-renderer row-value
28 M: inspector-renderer column-titles
29 drop { "Key" "Value" } ;
31 : <summary-gadget> ( model -- gadget )
33 standard-table-style [
37 [ "Class:" write ] with-cell
38 [ class-of pprint ] with-cell
43 [ "Object:" write ] with-cell
44 [ pprint-short ] with-cell
49 [ "Summary:" write ] with-cell
50 [ print-summary ] with-cell
56 [ "Content:" write ] with-cell
57 [ output-stream get write-gadget ] with-cell
65 GENERIC: make-slot-descriptions ( obj -- seq )
67 M: object make-slot-descriptions
68 make-mirror [ <slot-description> ] { } assoc>map ;
70 M: hashtable make-slot-descriptions
71 call-next-method [ key-string>> ] sort-with ;
73 : <inspector-table> ( model -- table )
74 [ make-slot-descriptions ] <arrow> inspector-renderer <table>
75 [ invoke-primary-operation ] >>action
76 monospace-font >>font theme-font-colors
77 line-color >>column-line-color
84 : <inspector-gadget> ( model -- gadget )
85 vertical inspector-gadget new-track with-lines
88 dup model>> <inspector-table> >>table
89 dup model>> <summary-gadget> margins white-interior "Object" object-color <labeled> f track-add
90 dup table>> <scroller> margins white-interior "Contents" contents-color <labeled> 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