1
0

Helios-Inspector.st 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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. bindKeys
  114. self wrapper asJQuery
  115. keydown: [ :e | self handleKeyDown: e ]
  116. !
  117. dive
  118. self announcer announce: HLDiveRequested new
  119. !
  120. refresh
  121. self variables = self items ifFalse: [
  122. self resetItems.
  123. super refresh ]
  124. !
  125. resetItems
  126. items := nil
  127. ! !
  128. !HLInspectorVariablesWidget methodsFor: 'defaults'!
  129. defaultItems
  130. ^ self variables
  131. ! !
  132. !HLInspectorVariablesWidget methodsFor: 'reactions'!
  133. handleKeyDown: anEvent
  134. (anEvent keyCode = 66 and: [
  135. anEvent ctrlKey or: [
  136. anEvent metaKey ] ]) ifTrue: [
  137. (inspector model instVarObjectAt: selectedItem) browse ].
  138. (anEvent keyCode = 73 and: [
  139. anEvent ctrlKey or: [
  140. anEvent metaKey ] ]) ifTrue: [
  141. self dive ].
  142. !
  143. selectItem: anObject
  144. super selectItem: anObject.
  145. self model selectedInstVar: anObject
  146. ! !
  147. !HLInspectorVariablesWidget methodsFor: 'rendering'!
  148. renderButtonsOn: html
  149. diveButton := html button
  150. class: 'btn';
  151. with: 'Dive';
  152. onClick: [ self dive ]
  153. !
  154. renderContentOn: html
  155. self renderHeadOn: html.
  156. super renderContentOn: html.
  157. self wrapper onDblClick: [ self dive ].
  158. self bindKeys
  159. !
  160. renderHeadOn: html
  161. html div
  162. class: 'list-label';
  163. with: self label
  164. ! !
  165. HLWidget subclass: #HLInspectorWidget
  166. instanceVariableNames: 'model variablesWidget displayWidget codeWidget'
  167. package: 'Helios-Inspector'!
  168. !HLInspectorWidget methodsFor: 'accessing'!
  169. codeWidget
  170. ^ codeWidget ifNil: [
  171. codeWidget := self defaultCodeWidget ]
  172. !
  173. codeWidget: aWidget
  174. codeWidget := aWidget
  175. !
  176. displayWidget
  177. ^ displayWidget ifNil: [
  178. displayWidget := HLInspectorDisplayWidget new
  179. inspector: self;
  180. yourself ]
  181. !
  182. initialize
  183. super initialize.
  184. self register
  185. !
  186. inspectee
  187. ^ self model inspectee
  188. !
  189. inspectee: anObject
  190. self model inspectee: anObject
  191. !
  192. label
  193. ^ self model label
  194. !
  195. model
  196. ^ model ifNil: [
  197. self model: HLInspectorModel new.
  198. model ]
  199. !
  200. model: aModel
  201. model := aModel.
  202. self codeWidget model: aModel code.
  203. self
  204. observeCodeWidget;
  205. observeVariablesWidget;
  206. observeModel
  207. !
  208. tabLabel
  209. ^ 'Inspector'
  210. !
  211. variablesWidget
  212. ^ variablesWidget ifNil: [
  213. variablesWidget := HLInspectorVariablesWidget new
  214. inspector: self;
  215. yourself ]
  216. ! !
  217. !HLInspectorWidget methodsFor: 'actions'!
  218. inspect: anObject
  219. self model inspect: anObject on: self.
  220. self codeWidget receiver: anObject.
  221. self
  222. refreshVariablesWidget;
  223. refreshDisplayWidget
  224. !
  225. observeCodeWidget
  226. self codeWidget announcer
  227. on: HLDoItExecuted
  228. do: [ self onDoneIt ]
  229. !
  230. observeModel
  231. self model announcer
  232. on: HLInstanceVariableSelected
  233. send: #onInstanceVariableSelected
  234. to: self
  235. !
  236. observeVariablesWidget
  237. self variablesWidget announcer
  238. on: HLDiveRequested
  239. send: #onDive
  240. to: self
  241. !
  242. refresh
  243. self inspect: self inspectee
  244. !
  245. refreshDisplayWidget
  246. self displayWidget refresh
  247. !
  248. refreshVariablesWidget
  249. self variablesWidget refresh
  250. !
  251. setLabel: aString
  252. self model label: aString
  253. !
  254. setVariables: aDictionary
  255. self model variables: aDictionary
  256. ! !
  257. !HLInspectorWidget methodsFor: 'defaults'!
  258. defaultCodeWidget
  259. ^ HLCodeWidget new
  260. model: self model code;
  261. receiver: self model inspectee;
  262. yourself
  263. ! !
  264. !HLInspectorWidget methodsFor: 'reactions'!
  265. onDive
  266. HLInspector new
  267. inspect: self model selectedInstVarObject;
  268. openAsTab
  269. !
  270. onDoneIt
  271. self refresh
  272. !
  273. onInspectIt
  274. !
  275. onInstanceVariableSelected
  276. self refreshDisplayWidget
  277. !
  278. onPrintIt
  279. ! !
  280. !HLInspectorWidget methodsFor: 'registration'!
  281. register
  282. HLInspector register: self
  283. !
  284. unregister
  285. super unregister.
  286. HLInspector unregister: self
  287. ! !
  288. !HLInspectorWidget methodsFor: 'rendering'!
  289. renderContentOn: html
  290. html with: (HLHorizontalSplitter
  291. with: (HLVerticalSplitter
  292. with: self variablesWidget
  293. with: self displayWidget)
  294. with: self codeWidget)
  295. ! !
  296. HLInspectorWidget subclass: #HLInspector
  297. instanceVariableNames: ''
  298. package: 'Helios-Inspector'!
  299. !HLInspector methodsFor: 'actions'!
  300. inspect: anObject
  301. self setTabLabel: anObject printString.
  302. super inspect: anObject
  303. ! !
  304. !HLInspector methodsFor: 'rendering'!
  305. renderContentOn: html
  306. html with: (HLContainer with: (HLHorizontalSplitter
  307. with: (HLVerticalSplitter
  308. with: self variablesWidget
  309. with: self displayWidget)
  310. with: self codeWidget)).
  311. self variablesWidget focus
  312. ! !
  313. HLInspector class instanceVariableNames: 'inspectors'!
  314. !HLInspector class methodsFor: 'accessing'!
  315. inspectors
  316. ^ inspectors ifNil: [ inspectors := OrderedCollection new ]
  317. !
  318. tabClass
  319. ^ 'inspector'
  320. !
  321. tabLabel
  322. ^ 'Inspector'
  323. !
  324. tabPriority
  325. ^ 10
  326. ! !
  327. !HLInspector class methodsFor: 'actions'!
  328. inspect: anObject
  329. self new
  330. openAsTab;
  331. inspect: anObject
  332. ! !
  333. !HLInspector class methodsFor: 'initialization'!
  334. initialize
  335. super initialize.
  336. self watchChanges
  337. !
  338. watchChanges
  339. [ self inspectors do: [ :each | each refresh ] ]
  340. valueWithInterval: 500
  341. ! !
  342. !HLInspector class methodsFor: 'registration'!
  343. register: anInspector
  344. self inspectors add: anInspector
  345. !
  346. unregister: anInspector
  347. self inspectors remove: anInspector
  348. ! !
  349. !HLInspector class methodsFor: 'testing'!
  350. canBeOpenAsTab
  351. ^ false
  352. ! !