Helios-Inspector.st 6.6 KB

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