1 ! Copyright (C) 2009, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs calendar colors.constants
4 combinators combinators.smart compiler.errors debugger editors
5 init io.pathnames kernel math.parser models models.arrow
6 models.arrow.smart models.delay models.mapping models.search
7 namespaces prettyprint sequences sorting source-files.errors
8 source-files.errors.debugger summary ui ui.commands ui.gadgets
9 ui.gadgets.buttons ui.gadgets.labeled ui.gadgets.labels
10 ui.gadgets.packs ui.gadgets.panes ui.gadgets.scrollers
11 ui.gadgets.status-bar ui.gadgets.tables ui.gadgets.toolbar
12 ui.gadgets.tracks ui.gestures ui.images ui.operations ui.theme
13 ui.tools.browser ui.tools.common ui.tools.inspector ;
14 IN: ui.tools.error-list
16 CONSTANT: source-file-icon
17 T{ image-name f "vocab:ui/tools/error-list/icons/source-file.png" }
19 MEMO: error-icon ( type -- image-name )
20 error-icon-path <image-name> ;
22 : <checkboxes> ( alist -- gadget )
23 [ <shelf> { 15 0 } >>gap ] dip
24 [ swap <checkbox> add-gadget ] assoc-each ;
26 : <error-toggle> ( -- model gadget )
27 ! Linkage errors are not shown by default.
28 error-types get [ fatal?>> <model> ] assoc-map
29 [ [ [ error-icon ] dip ] assoc-map <checkboxes> ]
32 TUPLE: error-list-gadget < tool
33 visible-errors source-file error
34 error-toggle source-file-table error-table error-display ;
36 SINGLETON: source-file-renderer
38 M: source-file-renderer row-columns
41 [ +listener-input+ or ]
42 [ length number>string ] tri*
45 M: source-file-renderer prototype-row
46 drop source-file-icon "" "" 3array ;
48 M: source-file-renderer row-value
49 drop dup [ first [ <pathname> ] [ f ] if* ] when ;
51 M: source-file-renderer row-value? row-value = ;
53 M: source-file-renderer column-titles
54 drop { "" "File" "Errors" } ;
56 M: source-file-renderer column-alignment drop { 0 0 1 } ;
58 M: source-file-renderer filled-column drop 1 ;
60 : <source-file-model> ( model -- model' )
61 [ group-by-source-file sort-keys ] <arrow> ;
63 :: <source-file-table> ( error-list -- table )
64 error-list model>> <source-file-model>
67 [ invoke-primary-operation ] >>action
68 COLOR: dark-gray >>column-line-color
74 t >>selection-required?
75 error-list source-file>> >>selection ;
77 SINGLETON: error-renderer
79 M: error-renderer row-columns
82 [ error-type error-icon ]
83 [ line#>> [ number>string ] [ "" ] if* ]
84 [ asset>> [ unparse-short ] [ "" ] if* ]
85 [ error>> safe-summary ]
89 M: error-renderer prototype-row
90 drop [ +compiler-error+ error-icon "" "" "" ] output>array ;
92 M: error-renderer row-value
95 M: error-renderer column-titles
96 drop { "" "Line" "Asset" "Error" } ;
98 M: error-renderer column-alignment drop { 0 1 0 0 } ;
100 : sort-errors ( seq -- seq' )
101 [ [ [ line#>> 0 or ] [ asset>> unparse-short ] bi 2array ] keep ] { } map>assoc
104 : file-matches? ( error pathname/f -- ? )
105 [ path>> ] [ dup [ string>> ] when ] bi* = ;
107 : <error-table-model> ( error-list -- model )
108 [ model>> ] [ source-file>> ] bi
109 [ file-matches? ] <search>
110 [ sort-errors ] <arrow> ;
112 :: <error-table> ( error-list -- table )
113 error-list <error-table-model>
116 [ invoke-primary-operation ] >>action
117 COLOR: dark-gray >>column-line-color
123 t >>selection-required?
124 error-list error>> >>selection ;
126 TUPLE: error-display < track ;
128 : <error-display> ( error-list -- gadget )
129 vertical error-display new-track with-lines
131 dup model>> [ [ print-error ] when* ] <pane-control>
132 margins <scroller> white-interior 1 track-add
135 : com-inspect ( error-display -- )
136 control-value [ inspector ] when* ;
138 : com-help ( error-display -- )
139 control-value [ error>> error-help-window ] when* ;
141 : com-edit ( error-display -- )
142 control-value [ edit-error ] when* ;
144 error-display "toolbar" f {
150 : <error-list-toolbar> ( error-list -- toolbar )
151 [ <toolbar> ] [ error-toggle>> "Show errors:" label-on-left f track-add ] bi
154 : <error-model> ( visible-errors model -- model' )
155 [ swap '[ error-type _ at ] filter ] <smart-arrow> ;
157 :: <error-list-gadget> ( model -- gadget )
158 vertical error-list-gadget new-track
159 <error-toggle> [ >>error-toggle ] [ >>visible-errors ] bi*
160 dup visible-errors>> model <error-model> >>model
161 f <model> >>source-file
163 dup <source-file-table> >>source-file-table
164 dup <error-table> >>error-table
165 dup <error-display> >>error-display
167 error-list vertical <track> with-lines
168 error-list <error-list-toolbar> f track-add
169 error-list source-file-table>> margins <scroller> white-interior
170 "Source files" source-files-color <colored-labeled-gadget> 1/4 track-add
171 error-list error-table>> margins <scroller> white-interior
172 "Errors" errors-color <colored-labeled-gadget> 1/4 track-add
173 error-list error-display>>
174 "Details" details-color <colored-labeled-gadget> 1/2 track-add
177 M: error-list-gadget focusable-child*
178 source-file-table>> ;
180 SYMBOLS: error-list-model ;
182 SINGLETON: error-list-updater
184 M: error-list-updater errors-changed
185 drop f error-list-model get-global model>> set-model ;
187 : error-list-help ( -- ) "ui.tools.error-list" com-browse ;
189 \ error-list-help H{ { +nullary+ t } } define-command
191 \ error-list-gadget "toolbar" f {
192 { T{ key-down f f "F1" } error-list-help }
195 : error-list-window ( -- )
196 error-list-model get-global [ drop all-errors ] <arrow>
197 <error-list-gadget> "Errors" open-status-window ;
199 : show-error-list ( -- )
200 [ error-list-gadget? ] find-window
201 [ raise-window ] [ error-list-window ] if* ;
203 \ show-error-list H{ { +nullary+ t } } define-command
206 f <model> 100 milliseconds <delay> error-list-model set-global
207 error-list-updater add-error-observer
208 ] "ui.tools.error-list" add-startup-hook