PageRenderTime 58ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/basis/ui/tools/error-list/error-list.factor

https://github.com/Keyholder/factor
Unknown | 205 lines | 159 code | 46 blank | 0 comment | 0 complexity | 48f8c4a6782aa62d599723ca565c99d5 MD5 | raw file
  1. ! Copyright (C) 2009 Slava Pestov.
  2. ! See http://factorcode.org/license.txt for BSD license.
  3. USING: accessors arrays sequences sorting assocs colors.constants fry
  4. combinators combinators.smart combinators.short-circuit editors make
  5. memoize compiler.units fonts kernel io.pathnames prettyprint
  6. source-files.errors math.parser init math.order models models.arrow
  7. models.arrow.smart models.search models.mapping models.delay debugger
  8. namespaces summary locals ui ui.commands ui.gadgets ui.gadgets.panes
  9. ui.gadgets.tables ui.gadgets.labeled ui.gadgets.tracks ui.gestures
  10. ui.operations ui.tools.browser ui.tools.common ui.gadgets.scrollers
  11. ui.tools.inspector ui.gadgets.status-bar ui.operations
  12. ui.gadgets.buttons ui.gadgets.borders ui.gadgets.packs
  13. ui.gadgets.labels ui.baseline-alignment ui.images ui.tools.listener
  14. compiler.errors calendar tools.errors ;
  15. IN: ui.tools.error-list
  16. CONSTANT: source-file-icon
  17. T{ image-name f "vocab:ui/tools/error-list/icons/source-file.tiff" }
  18. MEMO: error-icon ( type -- image-name )
  19. error-icon-path <image-name> ;
  20. : <checkboxes> ( alist -- gadget )
  21. [ <shelf> { 15 0 } >>gap ] dip
  22. [ swap <checkbox> add-gadget ] assoc-each ;
  23. : <error-toggle> ( -- model gadget )
  24. #! Linkage errors are not shown by default.
  25. error-types get [ fatal?>> <model> ] assoc-map
  26. [ [ [ error-icon ] dip ] assoc-map <checkboxes> ]
  27. [ <mapping> ] bi ;
  28. TUPLE: error-list-gadget < tool
  29. visible-errors source-file error
  30. error-toggle source-file-table error-table error-display ;
  31. SINGLETON: source-file-renderer
  32. M: source-file-renderer row-columns
  33. drop first2 [
  34. [ source-file-icon ]
  35. [ +listener-input+ or ]
  36. [ length number>string ] tri*
  37. ] output>array ;
  38. M: source-file-renderer prototype-row
  39. drop source-file-icon "" "" 3array ;
  40. M: source-file-renderer row-value
  41. drop dup [ first [ <pathname> ] [ f ] if* ] when ;
  42. M: source-file-renderer column-titles
  43. drop { "" "File" "Errors" } ;
  44. M: source-file-renderer column-alignment drop { 0 0 1 } ;
  45. M: source-file-renderer filled-column drop 1 ;
  46. : <source-file-model> ( model -- model' )
  47. [ group-by-source-file >alist sort-keys ] <arrow> ;
  48. :: <source-file-table> ( error-list -- table )
  49. error-list model>> <source-file-model>
  50. source-file-renderer
  51. <table>
  52. [ invoke-primary-operation ] >>action
  53. COLOR: dark-gray >>column-line-color
  54. 6 >>gap
  55. 5 >>min-rows
  56. 5 >>max-rows
  57. 60 >>min-cols
  58. 60 >>max-cols
  59. t >>selection-required?
  60. error-list source-file>> >>selected-value ;
  61. SINGLETON: error-renderer
  62. M: error-renderer row-columns
  63. drop [
  64. {
  65. [ error-type error-icon ]
  66. [ line#>> [ number>string ] [ "" ] if* ]
  67. [ asset>> [ unparse-short ] [ "" ] if* ]
  68. [ error>> summary ]
  69. } cleave
  70. ] output>array ;
  71. M: error-renderer prototype-row
  72. drop [ +compiler-error+ error-icon "" "" "" ] output>array ;
  73. M: error-renderer row-value
  74. drop ;
  75. M: error-renderer column-titles
  76. drop { "" "Line" "Asset" "Error" } ;
  77. M: error-renderer column-alignment drop { 0 1 0 0 } ;
  78. : sort-errors ( seq -- seq' )
  79. [ [ [ line#>> ] [ asset>> unparse-short ] bi 2array ] keep ] { } map>assoc
  80. sort-keys values ;
  81. : file-matches? ( error pathname/f -- ? )
  82. [ file>> ] [ dup [ string>> ] when ] bi* = ;
  83. : <error-table-model> ( error-list -- model )
  84. [ model>> ] [ source-file>> ] bi
  85. [ file-matches? ] <search>
  86. [ sort-errors ] <arrow> ;
  87. :: <error-table> ( error-list -- table )
  88. error-list <error-table-model>
  89. error-renderer
  90. <table>
  91. [ invoke-primary-operation ] >>action
  92. COLOR: dark-gray >>column-line-color
  93. 6 >>gap
  94. 5 >>min-rows
  95. 5 >>max-rows
  96. 60 >>min-cols
  97. 60 >>max-cols
  98. t >>selection-required?
  99. error-list error>> >>selected-value ;
  100. TUPLE: error-display < track ;
  101. : <error-display> ( error-list -- gadget )
  102. vertical error-display new-track
  103. add-toolbar
  104. swap error>> >>model
  105. dup model>> [ [ print-error ] when* ] <pane-control> <scroller> 1 track-add ;
  106. : com-inspect ( error-display -- )
  107. model>> value>> [ inspector ] when* ;
  108. : com-help ( error-display -- )
  109. model>> value>> [ error>> error-help-window ] when* ;
  110. : com-edit ( error-display -- )
  111. model>> value>> [ edit-error ] when* ;
  112. error-display "toolbar" f {
  113. { f com-inspect }
  114. { f com-help }
  115. { f com-edit }
  116. } define-command-map
  117. : <error-list-toolbar> ( error-list -- toolbar )
  118. [ <toolbar> ] [ error-toggle>> "Show errors:" label-on-left add-gadget ] bi ;
  119. : <error-model> ( visible-errors model -- model' )
  120. [ swap '[ error-type _ at ] filter ] <smart-arrow> ;
  121. :: <error-list-gadget> ( model -- gadget )
  122. vertical error-list-gadget new-track
  123. <error-toggle> [ >>error-toggle ] [ >>visible-errors ] bi*
  124. dup visible-errors>> model <error-model> >>model
  125. f <model> >>source-file
  126. f <model> >>error
  127. dup <source-file-table> >>source-file-table
  128. dup <error-table> >>error-table
  129. dup <error-display> >>error-display
  130. :> error-list
  131. error-list vertical <track>
  132. { 5 5 } >>gap
  133. error-list <error-list-toolbar> f track-add
  134. error-list source-file-table>> <scroller> "Source files" <labeled-gadget> 1/4 track-add
  135. error-list error-table>> <scroller> "Errors" <labeled-gadget> 1/2 track-add
  136. error-list error-display>> "Details" <labeled-gadget> 1/4 track-add
  137. { 5 5 } <filled-border> 1 track-add ;
  138. M: error-list-gadget focusable-child*
  139. source-file-table>> ;
  140. : error-list-help ( -- ) "ui.tools.error-list" com-browse ;
  141. \ error-list-help H{ { +nullary+ t } } define-command
  142. error-list-gadget "toolbar" f {
  143. { T{ key-down f f "F1" } error-list-help }
  144. } define-command-map
  145. SYMBOL: error-list-model
  146. error-list-model [ f <model> ] initialize
  147. SINGLETON: updater
  148. M: updater errors-changed
  149. drop f error-list-model get-global set-model ;
  150. [ updater add-error-observer ] "ui.tools.error-list" add-init-hook
  151. : <error-list-model> ( -- model )
  152. error-list-model get-global
  153. 1/2 seconds <delay> [ drop all-errors ] <arrow> ;
  154. : error-list-window ( -- )
  155. <error-list-model> <error-list-gadget> "Errors" open-status-window ;
  156. : show-error-list ( -- )
  157. [ error-list-gadget? ] find-window
  158. [ raise-window ] [ error-list-window ] if* ;
  159. \ show-error-list H{ { +nullary+ t } } define-command