Helios-Inspector.st 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. ^ 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. self variablesWidget focus
  115. ! !
  116. !HLInspector class methodsFor: 'accessing'!
  117. tabLabel
  118. ^ 'Inspector'
  119. !
  120. tabPriority
  121. ^ 10
  122. ! !
  123. !HLInspector class methodsFor: 'testing'!
  124. canBeOpenAsTab
  125. ^ false
  126. ! !
  127. HLNavigationListWidget subclass: #HLInspectorDisplayWidget
  128. instanceVariableNames: 'model'
  129. package: 'Helios-Inspector'!
  130. !HLInspectorDisplayWidget methodsFor: 'accessing'!
  131. model
  132. ^ model
  133. !
  134. model: aModel
  135. model := aModel
  136. ! !
  137. !HLInspectorDisplayWidget methodsFor: 'rendering'!
  138. renderContentOn: html
  139. html div with: self selectionDisplayString
  140. !
  141. selectionDisplayString
  142. |selection|
  143. selection := model selection.
  144. ^ (model variables keys includes: selection)
  145. ifTrue:[(model instVarObjectAt: selection) printString]
  146. ifFalse:['']
  147. ! !
  148. Object subclass: #HLInspectorModel
  149. instanceVariableNames: 'announcer environment inspectee code variables selection'
  150. package: 'Helios-Inspector'!
  151. !HLInspectorModel methodsFor: 'accessing'!
  152. announcer
  153. ^ announcer ifNil: [announcer := Announcer new ]
  154. !
  155. code
  156. "Answers the code model working for this workspace model"
  157. ^ code ifNil:[ code := HLCodeModel on: self environment ]
  158. !
  159. environment
  160. ^ environment ifNil: [ HLManager current environment ]
  161. !
  162. environment: anEnvironment
  163. environment := anEnvironment
  164. !
  165. inspectee
  166. ^ inspectee
  167. !
  168. inspectee: anObject
  169. inspectee := anObject
  170. !
  171. selectedInstVarObject
  172. ^ self instVarObjectAt: self selection
  173. !
  174. selection
  175. ^ selection ifNil:[ '' ]
  176. !
  177. selection: anObject
  178. selection := anObject.
  179. self announcer announce: (HLInstanceVariableSelected on: selection)
  180. !
  181. variables
  182. ^ variables
  183. !
  184. variables: aCollection
  185. variables := aCollection
  186. ! !
  187. !HLInspectorModel methodsFor: 'actions'!
  188. inspect: anObject on: anInspector
  189. inspectee := anObject.
  190. variables := #().
  191. inspectee inspectOn: anInspector
  192. !
  193. instVarObjectAt: anInstVarName
  194. ^ self variables at: anInstVarName
  195. !
  196. selectedInstVar: anInstVarName
  197. self selection: anInstVarName
  198. !
  199. subscribe: aWidget
  200. aWidget subscribeTo: self announcer
  201. ! !
  202. !HLInspectorModel methodsFor: 'reactions'!
  203. onKeyDown: anEvent
  204. <if(anEvent.ctrlKey) {
  205. if(anEvent.keyCode === 80) { //ctrl+p
  206. self._printIt();
  207. anEvent.preventDefault();
  208. return false;
  209. }
  210. if(anEvent.keyCode === 68) { //ctrl+d
  211. self._doIt();
  212. anEvent.preventDefault();
  213. return false;
  214. }
  215. if(anEvent.keyCode === 73) { //ctrl+i
  216. self._inspectIt();
  217. anEvent.preventDefault();
  218. return false;
  219. }
  220. }>
  221. ! !
  222. !HLInspectorModel class methodsFor: 'actions'!
  223. on: anEnvironment
  224. ^ self new
  225. environment: anEnvironment;
  226. yourself
  227. ! !
  228. HLNavigationListWidget subclass: #HLInspectorVariablesWidget
  229. instanceVariableNames: 'announcer model list diveButton'
  230. package: 'Helios-Inspector'!
  231. !HLInspectorVariablesWidget methodsFor: 'accessing'!
  232. announcer
  233. ^ announcer ifNil:[ announcer := Announcer new ]
  234. !
  235. model
  236. ^ model
  237. !
  238. model: aModel
  239. model := aModel
  240. !
  241. selection
  242. ^ model selection
  243. !
  244. variables
  245. ^ model variables
  246. ! !
  247. !HLInspectorVariablesWidget methodsFor: 'actions'!
  248. refresh
  249. self resetItems.
  250. super refresh
  251. !
  252. resetItems
  253. items := nil
  254. ! !
  255. !HLInspectorVariablesWidget methodsFor: 'defaults'!
  256. defaultItems
  257. ^ self model variables keys
  258. ! !
  259. !HLInspectorVariablesWidget methodsFor: 'reactions'!
  260. selectItem: anObject
  261. super selectItem: anObject.
  262. self model selectedInstVar: anObject
  263. ! !
  264. !HLInspectorVariablesWidget methodsFor: 'rendering'!
  265. renderButtonsOn: html
  266. html button
  267. class: 'btn';
  268. with: 'Refresh';
  269. onClick: [self announcer announce: HLRefreshRequested new].
  270. diveButton := html button
  271. class: 'btn';
  272. with: 'Dive';
  273. onClick: [self announcer announce: HLDiveRequested new]
  274. ! !