Helios-Inspector.st 7.0 KB

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