Helios-Inspector.st 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. Smalltalk createPackage: 'Helios-Inspector'!
  2. HLNavigationListWidget subclass: #HLInspectorDisplayWidget
  3. instanceVariableNames: 'model'
  4. package: 'Helios-Inspector'!
  5. !HLInspectorDisplayWidget methodsFor: 'accessing'!
  6. model
  7. ^ model
  8. !
  9. model: aModel
  10. model := aModel
  11. ! !
  12. !HLInspectorDisplayWidget methodsFor: 'rendering'!
  13. renderContentOn: html
  14. html div with: self selectionDisplayString
  15. !
  16. selectionDisplayString
  17. |selection|
  18. selection := model selection.
  19. ^ (model variables includesKey: selection)
  20. ifTrue:[ (model instVarObjectAt: selection) printString ]
  21. ifFalse:[ '' ]
  22. ! !
  23. HLModel subclass: #HLInspectorModel
  24. instanceVariableNames: 'inspectee code variables label selection'
  25. package: 'Helios-Inspector'!
  26. !HLInspectorModel commentStamp!
  27. I am the model of the Helios inspector `HLInspectorWidget`.
  28. ## API
  29. Use the method `inspect:on:` to inspect an object on an inspector.!
  30. !HLInspectorModel methodsFor: 'accessing'!
  31. code
  32. "Answers the code model working for this workspace model"
  33. ^ code ifNil:[ code := HLCodeModel on: self environment ]
  34. !
  35. inspectee
  36. ^ inspectee
  37. !
  38. inspectee: anObject
  39. inspectee := anObject
  40. !
  41. label
  42. ^ label ifNil: [ self inspectee printString ]
  43. !
  44. label: aString
  45. label := aString
  46. !
  47. selectedInstVarObject
  48. ^ self instVarObjectAt: self selection
  49. !
  50. selection
  51. ^ selection ifNil:[ '' ]
  52. !
  53. selection: anObject
  54. selection := anObject.
  55. self announcer announce: (HLInstanceVariableSelected on: selection)
  56. !
  57. variables
  58. ^ variables ifNil: [ Dictionary new ]
  59. !
  60. variables: aCollection
  61. variables := aCollection
  62. ! !
  63. !HLInspectorModel methodsFor: 'actions'!
  64. inspect: anObject on: anInspector
  65. inspectee := anObject.
  66. variables := #().
  67. inspectee inspectOn: anInspector
  68. !
  69. instVarObjectAt: anInstVarName
  70. ^ self variables at: anInstVarName
  71. !
  72. selectedInstVar: anInstVarName
  73. self selection: anInstVarName
  74. !
  75. subscribe: aWidget
  76. aWidget subscribeTo: self announcer
  77. ! !
  78. !HLInspectorModel class methodsFor: 'actions'!
  79. on: anEnvironment
  80. ^ self new
  81. environment: anEnvironment;
  82. yourself
  83. ! !
  84. HLNavigationListWidget subclass: #HLInspectorVariablesWidget
  85. instanceVariableNames: 'announcer model list diveButton'
  86. package: 'Helios-Inspector'!
  87. !HLInspectorVariablesWidget methodsFor: 'accessing'!
  88. announcer
  89. ^ announcer ifNil:[ announcer := Announcer new ]
  90. !
  91. label
  92. ^ self model label
  93. !
  94. model
  95. ^ model
  96. !
  97. model: aModel
  98. model := aModel
  99. !
  100. selection
  101. ^ model selection
  102. !
  103. variables
  104. ^ self model variables keys
  105. ! !
  106. !HLInspectorVariablesWidget methodsFor: 'actions'!
  107. refresh
  108. self variables = self items ifFalse: [
  109. self resetItems.
  110. super refresh ]
  111. !
  112. resetItems
  113. items := nil
  114. ! !
  115. !HLInspectorVariablesWidget methodsFor: 'defaults'!
  116. defaultItems
  117. ^ self variables
  118. ! !
  119. !HLInspectorVariablesWidget methodsFor: 'reactions'!
  120. selectItem: anObject
  121. super selectItem: anObject.
  122. self model selectedInstVar: anObject
  123. ! !
  124. !HLInspectorVariablesWidget methodsFor: 'rendering'!
  125. renderButtonsOn: html
  126. diveButton := html button
  127. class: 'btn';
  128. with: 'Dive';
  129. onClick: [ self announcer announce: HLDiveRequested new ]
  130. !
  131. renderContentOn: html
  132. self renderHeadOn: html.
  133. super renderContentOn: html
  134. !
  135. renderHeadOn: html
  136. html div
  137. class: 'list-label';
  138. with: self label
  139. ! !
  140. HLWidget subclass: #HLInspectorWidget
  141. instanceVariableNames: 'model variablesWidget displayWidget codeWidget'
  142. package: 'Helios-Inspector'!
  143. !HLInspectorWidget methodsFor: 'accessing'!
  144. codeWidget
  145. ^ codeWidget ifNil: [
  146. codeWidget := HLCodeWidget new
  147. model: model code;
  148. receiver: model inspectee;
  149. yourself ]
  150. !
  151. displayWidget
  152. ^ displayWidget ifNil: [
  153. displayWidget := HLInspectorDisplayWidget new
  154. model: self model;
  155. yourself ]
  156. !
  157. initialize
  158. super initialize.
  159. self register
  160. !
  161. inspectee
  162. ^ self model inspectee
  163. !
  164. inspectee: anObject
  165. self model inspectee: anObject
  166. !
  167. label
  168. ^ self model label
  169. !
  170. model
  171. ^ model ifNil: [
  172. self model: HLInspectorModel new.
  173. model ]
  174. !
  175. model: aModel
  176. model := aModel.
  177. self codeWidget model: aModel code.
  178. self
  179. observeCodeWidget;
  180. observeVariablesWidget;
  181. observeModel
  182. !
  183. tabLabel
  184. ^ 'Inspector'
  185. !
  186. variablesWidget
  187. ^ variablesWidget ifNil: [
  188. variablesWidget := HLInspectorVariablesWidget new
  189. model: self model;
  190. yourself ]
  191. ! !
  192. !HLInspectorWidget methodsFor: 'actions'!
  193. inspect: anObject
  194. self model inspect: anObject on: self.
  195. self codeWidget receiver: anObject.
  196. self
  197. refreshVariablesWidget;
  198. refreshDisplayWidget
  199. !
  200. observeCodeWidget
  201. self codeWidget announcer
  202. on: HLDoItExecuted
  203. do: [ self onDoneIt ]
  204. !
  205. observeModel
  206. self model announcer
  207. on: HLInstanceVariableSelected
  208. send: #onInstanceVariableSelected
  209. to: self
  210. !
  211. observeVariablesWidget
  212. self variablesWidget announcer
  213. on: HLDiveRequested do:[ self onDive ]
  214. !
  215. refresh
  216. self inspect: self inspectee
  217. !
  218. refreshDisplayWidget
  219. self displayWidget refresh
  220. !
  221. refreshVariablesWidget
  222. self variablesWidget refresh
  223. !
  224. setLabel: aString
  225. self model label: aString
  226. !
  227. setVariables: aDictionary
  228. self model variables: aDictionary
  229. ! !
  230. !HLInspectorWidget methodsFor: 'reactions'!
  231. onDive
  232. HLInspector new
  233. inspect: self model selectedInstVarObject;
  234. openAsTab
  235. !
  236. onDoneIt
  237. self refresh
  238. !
  239. onInspectIt
  240. !
  241. onInstanceVariableSelected
  242. self refreshDisplayWidget
  243. !
  244. onPrintIt
  245. ! !
  246. !HLInspectorWidget methodsFor: 'registration'!
  247. register
  248. HLInspector register: self
  249. !
  250. unregister
  251. super unregister.
  252. HLInspector unregister: self
  253. ! !
  254. !HLInspectorWidget methodsFor: 'rendering'!
  255. renderContentOn: html
  256. html with: (HLHorizontalSplitter
  257. with: (HLVerticalSplitter
  258. with: self variablesWidget
  259. with: self displayWidget)
  260. with: self codeWidget)
  261. ! !
  262. HLInspectorWidget subclass: #HLInspector
  263. instanceVariableNames: ''
  264. package: 'Helios-Inspector'!
  265. !HLInspector methodsFor: 'rendering'!
  266. renderContentOn: html
  267. html with: (HLContainer with: (HLHorizontalSplitter
  268. with: (HLVerticalSplitter
  269. with: self variablesWidget
  270. with: self displayWidget)
  271. with: self codeWidget)).
  272. self variablesWidget focus
  273. ! !
  274. HLInspector class instanceVariableNames: 'inspectors'!
  275. !HLInspector class methodsFor: 'accessing'!
  276. inspectors
  277. ^ inspectors ifNil: [ inspectors := OrderedCollection new ]
  278. !
  279. tabClass
  280. ^ 'inspector'
  281. !
  282. tabLabel
  283. ^ 'Inspector'
  284. !
  285. tabPriority
  286. ^ 10
  287. ! !
  288. !HLInspector class methodsFor: 'actions'!
  289. inspect: anObject
  290. self new
  291. openAsTab;
  292. inspect: anObject
  293. ! !
  294. !HLInspector class methodsFor: 'initialization'!
  295. initialize
  296. super initialize.
  297. self watchChanges
  298. !
  299. watchChanges
  300. [ self inspectors do: [ :each | each refresh ] ]
  301. valueWithInterval: 500
  302. ! !
  303. !HLInspector class methodsFor: 'registration'!
  304. register: anInspector
  305. self inspectors add: anInspector
  306. !
  307. unregister: anInspector
  308. self inspectors remove: anInspector
  309. ! !
  310. !HLInspector class methodsFor: 'testing'!
  311. canBeOpenAsTab
  312. ^ false
  313. ! !