Helios-Inspector.st 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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. ^ self 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 btn-default';
  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 := self defaultCodeWidget ]
  157. !
  158. codeWidget: aWidget
  159. codeWidget := aWidget
  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: 'defaults'!
  243. defaultCodeWidget
  244. ^ HLCodeWidget new
  245. model: self model code;
  246. receiver: self model inspectee;
  247. yourself
  248. ! !
  249. !HLInspectorWidget methodsFor: 'reactions'!
  250. onDive
  251. HLInspector new
  252. inspect: self model selectedInstVarObject;
  253. openAsTab
  254. !
  255. onDoneIt
  256. self refresh
  257. !
  258. onInspectIt
  259. !
  260. onInstanceVariableSelected
  261. self refreshDisplayWidget
  262. !
  263. onPrintIt
  264. ! !
  265. !HLInspectorWidget methodsFor: 'registration'!
  266. register
  267. HLInspector register: self
  268. !
  269. unregister
  270. super unregister.
  271. HLInspector unregister: self
  272. ! !
  273. !HLInspectorWidget methodsFor: 'rendering'!
  274. renderContentOn: html
  275. html with: (HLHorizontalSplitter
  276. with: (HLVerticalSplitter
  277. with: self variablesWidget
  278. with: self displayWidget)
  279. with: self codeWidget)
  280. ! !
  281. HLInspectorWidget subclass: #HLInspector
  282. instanceVariableNames: ''
  283. package: 'Helios-Inspector'!
  284. !HLInspector methodsFor: 'actions'!
  285. inspect: anObject
  286. self setTabLabel: anObject printString.
  287. super inspect: anObject
  288. ! !
  289. !HLInspector methodsFor: 'rendering'!
  290. renderContentOn: html
  291. html with: (HLContainer with: (HLHorizontalSplitter
  292. with: (HLVerticalSplitter
  293. with: self variablesWidget
  294. with: self displayWidget)
  295. with: self codeWidget)).
  296. self variablesWidget focus
  297. ! !
  298. HLInspector class instanceVariableNames: 'inspectors'!
  299. !HLInspector class methodsFor: 'accessing'!
  300. inspectors
  301. ^ inspectors ifNil: [ inspectors := OrderedCollection new ]
  302. !
  303. tabClass
  304. ^ 'inspector'
  305. !
  306. tabLabel
  307. ^ 'Inspector'
  308. !
  309. tabPriority
  310. ^ 10
  311. ! !
  312. !HLInspector class methodsFor: 'actions'!
  313. inspect: anObject
  314. self new
  315. openAsTab;
  316. inspect: anObject
  317. ! !
  318. !HLInspector class methodsFor: 'initialization'!
  319. initialize
  320. super initialize.
  321. self watchChanges
  322. !
  323. watchChanges
  324. [ self inspectors do: [ :each | each refresh ] ]
  325. valueWithInterval: 500
  326. ! !
  327. !HLInspector class methodsFor: 'registration'!
  328. register: anInspector
  329. self inspectors add: anInspector
  330. !
  331. unregister: anInspector
  332. self inspectors remove: anInspector
  333. ! !
  334. !HLInspector class methodsFor: 'testing'!
  335. canBeOpenAsTab
  336. ^ false
  337. ! !