Helios-Inspector.st 7.7 KB

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