Helios-Inspector.st 6.9 KB

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