Helios-Inspector.st 6.9 KB

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