]> gitweb.factorcode.org Git - factor.git/blob - basis/ui/tools/error-list/error-list.factor
core/basis/extra: using STARTUP-HOOK: and SHUTDOWN-HOOK:
[factor.git] / basis / ui / tools / error-list / error-list.factor
1 ! Copyright (C) 2009, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3
4 USING: accessors arrays assocs calendar colors combinators
5 combinators.smart compiler.errors debugger editors init
6 io.pathnames kernel math.parser models models.arrow
7 models.arrow.smart models.delay models.mapping models.search
8 namespaces prettyprint sequences sorting source-files.errors
9 source-files.errors.debugger summary ui ui.commands ui.gadgets
10 ui.gadgets.buttons ui.gadgets.labeled ui.gadgets.labels
11 ui.gadgets.packs ui.gadgets.panes ui.gadgets.scrollers
12 ui.gadgets.status-bar ui.gadgets.tables ui.gadgets.toolbar
13 ui.gadgets.tracks ui.gestures ui.images ui.operations ui.theme
14 ui.tools.browser ui.tools.common ui.tools.inspector ;
15
16 IN: ui.tools.error-list
17
18 CONSTANT: source-file-icon
19     T{ image-name f "vocab:ui/tools/error-list/icons/source-file.png" }
20
21 MEMO: error-icon ( type -- image-name )
22     error-icon-path <image-name> ;
23
24 : <checkboxes> ( alist -- gadget )
25     [ <shelf> { 15 0 } >>gap ] dip
26     [ swap <checkbox> add-gadget ] assoc-each ;
27
28 : <error-toggle> ( -- model gadget )
29     ! Linkage errors are not shown by default.
30     error-types get [ fatal?>> <model> ] assoc-map
31     [ [ [ error-icon ] dip ] assoc-map <checkboxes> ]
32     [ <mapping> ] bi ;
33
34 TUPLE: error-list-gadget < tool
35 visible-errors source-file error
36 error-toggle source-file-table error-table error-display ;
37
38 SINGLETON: source-file-renderer
39
40 M: source-file-renderer row-columns
41     drop first2 [
42         [ source-file-icon ]
43         [ +listener-input+ or ]
44         [ length number>string ] tri*
45     ] output>array ;
46
47 M: source-file-renderer prototype-row
48     drop source-file-icon "" "" 3array ;
49
50 M: source-file-renderer row-value
51     drop dup [ first [ <pathname> ] [ f ] if* ] when ;
52
53 M: source-file-renderer row-value? row-value = ;
54
55 M: source-file-renderer column-titles
56     drop { "" "File" "Errors" } ;
57
58 M: source-file-renderer column-alignment drop { 0 0 1 } ;
59
60 M: source-file-renderer filled-column drop 1 ;
61
62 : <source-file-model> ( model -- model' )
63     [ group-by-source-file sort-keys ] <arrow> ;
64
65 :: <source-file-table> ( error-list -- table )
66     error-list model>> <source-file-model>
67     source-file-renderer
68     <table>
69         [ invoke-primary-operation ] >>action
70         COLOR: dark-gray >>column-line-color
71         6 >>gap
72         4 >>min-rows
73         4 >>max-rows
74         60 >>min-cols
75         60 >>max-cols
76         t >>selection-required?
77         error-list source-file>> >>selection ;
78
79 SINGLETON: error-renderer
80
81 M: error-renderer row-columns
82     drop [
83         {
84             [ error-type error-icon ]
85             [ line#>> [ number>string ] [ "" ] if* ]
86             [ asset>> [ unparse-short ] [ "" ] if* ]
87             [ error>> safe-summary ]
88         } cleave
89     ] output>array ;
90
91 M: error-renderer prototype-row
92     drop [ +compiler-error+ error-icon "" "" "" ] output>array ;
93
94 M: error-renderer row-value
95     drop ;
96
97 M: error-renderer column-titles
98     drop { "" "Line" "Asset" "Error" } ;
99
100 M: error-renderer column-alignment drop { 0 1 0 0 } ;
101
102 : sort-errors ( seq -- seq' )
103     [ [ [ line#>> 0 or ] [ asset>> unparse-short ] bi 2array ] keep ] { } map>assoc
104     sort-keys values ;
105
106 : file-matches? ( error pathname/f -- ? )
107     [ path>> ] [ dup [ string>> ] when ] bi* = ;
108
109 : <error-table-model> ( error-list -- model )
110     [ model>> ] [ source-file>> ] bi
111     [ file-matches? ] <search>
112     [ sort-errors ] <arrow> ;
113
114 :: <error-table> ( error-list -- table )
115     error-list <error-table-model>
116     error-renderer
117     <table>
118         [ invoke-primary-operation ] >>action
119         COLOR: dark-gray >>column-line-color
120         6 >>gap
121         4 >>min-rows
122         4 >>max-rows
123         60 >>min-cols
124         60 >>max-cols
125         t >>selection-required?
126         error-list error>> >>selection ;
127
128 TUPLE: error-display < track ;
129
130 : <error-display> ( error-list -- gadget )
131     vertical error-display new-track with-lines
132         swap error>> >>model
133         dup model>> [ [ print-error ] when* ] <pane-control>
134         margins <scroller> white-interior 1 track-add 
135         add-toolbar ;
136
137 : com-inspect ( error-display -- )
138     control-value [ inspector ] when* ;
139
140 : com-help ( error-display -- )
141     control-value [ error>> error-help-window ] when* ;
142
143 : com-edit ( error-display -- )
144     control-value [ edit-error ] when* ;
145
146 error-display "toolbar" f {
147     { f com-inspect }
148     { f com-help }
149     { f com-edit }
150 } define-command-map
151
152 : <error-list-toolbar> ( error-list -- toolbar )
153     [ <toolbar> ] [ error-toggle>> "Show errors:" label-on-left f track-add ] bi
154     format-toolbar ;
155
156 : <error-model> ( visible-errors model -- model' )
157     [ swap '[ error-type _ at ] filter ] <smart-arrow> ;
158
159 :: <error-list-gadget> ( model -- gadget )
160     vertical error-list-gadget new-track
161         <error-toggle> [ >>error-toggle ] [ >>visible-errors ] bi*
162         dup visible-errors>> model <error-model> >>model
163         f <model> >>source-file
164         f <model> >>error
165         dup <source-file-table> >>source-file-table
166         dup <error-table> >>error-table
167         dup <error-display> >>error-display
168     :> error-list
169     error-list vertical <track> with-lines
170         error-list <error-list-toolbar> f track-add
171         error-list source-file-table>> margins <scroller> white-interior
172         "Source files" source-files-color <colored-labeled-gadget> 1/4 track-add
173         error-list error-table>> margins <scroller> white-interior
174         "Errors" errors-color <colored-labeled-gadget> 1/4 track-add
175         error-list error-display>>
176         "Details" details-color <colored-labeled-gadget> 1/2 track-add
177     1 track-add ;
178
179 M: error-list-gadget focusable-child*
180     source-file-table>> ;
181
182 SYMBOLS: error-list-model ;
183
184 SINGLETON: error-list-updater
185
186 M: error-list-updater errors-changed
187     drop f error-list-model get-global model>> set-model ;
188
189 : error-list-help ( -- ) "ui.tools.error-list" com-browse ;
190
191 \ error-list-help H{ { +nullary+ t } } define-command
192
193 \ error-list-gadget "toolbar" f {
194     { T{ key-down f f "F1" } error-list-help }
195 } define-command-map
196
197 : error-list-window ( -- )
198     error-list-model get-global [ drop all-errors ] <arrow>
199     <error-list-gadget> "Errors" open-status-window ;
200
201 : show-error-list ( -- )
202     [ error-list-gadget? ] find-window
203     [ raise-window ] [ error-list-window ] if* ;
204
205 \ show-error-list H{ { +nullary+ t } } define-command
206
207 STARTUP-HOOK: [
208     f <model> 100 milliseconds <delay> error-list-model set-global
209     error-list-updater add-error-observer
210 ]