Helios-Inspector.st 7.3 KB

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