Helios-Inspector.st 6.2 KB

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