]> gitweb.factorcode.org Git - factor.git/blob - basis/ui/tools/inspector/inspector.factor
ui.theme: updates to color scheme.
[factor.git] / basis / ui / tools / inspector / inspector.factor
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
5 assocs classes io io.styles arrays hashtables math.order sorting
6 refs fonts ui.tools.browser ui.commands ui.operations ui.gadgets
7 ui.gadgets.panes ui.gadgets.scrollers ui.gadgets.slots
8 ui.gadgets.theme ui.gadgets.tracks ui.gestures
9 ui.gadgets.buttons ui.gadgets.tables ui.theme ui.gadgets.toolbar
10 ui.gadgets.status-bar ui.gadgets.labeled ui.tools.common ui
11 combinators ui.gadgets.worlds ;
12 IN: ui.tools.inspector
13
14 TUPLE: inspector-gadget < tool table ;
15
16 TUPLE: slot-description key key-string value value-string ;
17
18 : <slot-description> ( key value -- slot-description )
19     [ dup unparse-short ] bi@ slot-description boa ;
20
21 SINGLETON: inspector-renderer
22
23 M: inspector-renderer row-columns
24     drop [ key-string>> ] [ value-string>> ] bi 2array ;
25
26 M: inspector-renderer row-value
27     drop value>> ;
28
29 M: inspector-renderer column-titles
30     drop { "Key" "Value" } ;
31
32 : <summary-gadget> ( model -- gadget )
33     [
34         standard-table-style [
35             {
36                 [
37                     [
38                         [ "Class:" write ] with-cell
39                         [ class-of pprint ] with-cell
40                     ] with-row
41                 ]
42                 [
43                     [
44                         [ "Object:" write ] with-cell
45                         [ pprint-short ] with-cell
46                     ] with-row
47                 ]
48                 [
49                     [
50                         [ "Summary:" write ] with-cell
51                         [ print-summary ] with-cell
52                     ] with-row
53                 ]
54                 [
55                     content-gadget [
56                         [
57                             [ "Content:" write ] with-cell
58                             [ output-stream get write-gadget ] with-cell
59                         ] with-row
60                     ] when*
61                 ]
62             } cleave
63         ] tabular-output
64     ] <pane-control> ;
65
66 GENERIC: make-slot-descriptions ( obj -- seq )
67
68 M: object make-slot-descriptions
69     make-mirror [ <slot-description> ] { } assoc>map ;
70
71 M: hashtable make-slot-descriptions
72     call-next-method [ key-string>> ] sort-with ;
73
74 : <inspector-table> ( model -- table )
75     [ make-slot-descriptions ] <arrow> inspector-renderer <table>
76         [ invoke-primary-operation ] >>action
77         monospace-font >>font theme-font-colors
78         line-color >>column-line-color
79         6 >>gap
80         15 >>min-rows
81         15 >>max-rows
82         40 >>min-cols
83         40 >>max-cols ;
84
85 : <inspector-gadget> ( model -- gadget )
86     vertical inspector-gadget new-track with-lines
87         add-toolbar
88         swap >>model
89         dup model>> <inspector-table> >>table
90         dup model>> <summary-gadget> margins white-interior "Object" object-color <labeled> f track-add
91         dup table>> <scroller> margins white-interior "Contents" contents-color <labeled> 1 track-add ;
92
93 M: inspector-gadget focusable-child*
94     table>> ;
95
96 : com-refresh ( inspector -- )
97     model>> notify-connections ;
98
99 : com-push ( inspector -- obj )
100     control-value ;
101
102 \ com-push H{ { +listener+ t } } define-command
103
104 : slot-editor-window ( close-hook update-hook assoc key key-string -- )
105     [ <value-ref> <slot-editor> ]
106     [
107         <world-attributes>
108             swap "Slot editor: " prepend >>title
109             [ { dialog-window } append ] change-window-controls
110     ] bi*
111     open-status-window ;
112
113 : com-edit-slot ( inspector -- )
114     [ close-window ] swap
115     [ '[ _ com-refresh ] ]
116     [ control-value make-mirror ]
117     [ table>> (selected-row) ] tri [
118         [ key>> ] [ key-string>> ] bi
119         slot-editor-window
120     ] [ 4drop ] if ;
121
122 : inspector-help ( -- ) "ui-inspector" com-browse ;
123
124 \ inspector-help H{ { +nullary+ t } } define-command
125
126 inspector-gadget "toolbar" f {
127     { T{ update-object } com-refresh }
128     { T{ key-down f f "p" } com-push }
129     { T{ key-down f f "e" } com-edit-slot }
130     { T{ key-down f f "F1" } inspector-help }
131 } define-command-map
132
133 inspector-gadget "multi-touch" f {
134     { up-action com-refresh }
135 } define-command-map
136
137 : inspect-model ( model -- )
138     <inspector-gadget> "Inspector" open-status-window ;
139
140 : inspector ( obj -- )
141     <model> inspect-model ;
142
143 { 550 400 } inspector-gadget set-tool-dim