1
0

Helios-Inspector.st 6.0 KB

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